1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-29 19:28:47 -05:00

Merge pull request #1555 from srcejon/device_enum

Add progress dialog for device enumeration, as some drivers are slow on Windows.
This commit is contained in:
Edouard Griffiths 2023-01-04 18:48:50 +01:00 committed by GitHub
commit 20bdbfa306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 72 additions and 13 deletions

View File

@ -253,6 +253,7 @@ void DeviceEnumerator::enumerateDevices(PluginAPI::SamplingDeviceRegistrations&
for (int i = 0; i < deviceRegistrations.count(); i++) for (int i = 0; i < deviceRegistrations.count(); i++)
{ {
qDebug("DeviceEnumerator::enumerateDevices: %s", qPrintable(deviceRegistrations[i].m_deviceId)); qDebug("DeviceEnumerator::enumerateDevices: %s", qPrintable(deviceRegistrations[i].m_deviceId));
emit enumeratingDevices(deviceRegistrations[i].m_deviceId);
deviceRegistrations[i].m_plugin->enumOriginDevices(originDevicesHwIds, originDevices); deviceRegistrations[i].m_plugin->enumOriginDevices(originDevicesHwIds, originDevices);
PluginInterface::SamplingDevices samplingDevices; PluginInterface::SamplingDevices samplingDevices;
if (type == PluginInterface::SamplingDevice::StreamSingleRx) { if (type == PluginInterface::SamplingDevice::StreamSingleRx) {

View File

@ -27,8 +27,10 @@
class PluginManager; class PluginManager;
class SDRBASE_API DeviceEnumerator class SDRBASE_API DeviceEnumerator : public QObject
{ {
Q_OBJECT
public: public:
DeviceEnumerator(); DeviceEnumerator();
~DeviceEnumerator(); ~DeviceEnumerator();
@ -67,6 +69,9 @@ public:
int getBestTxSamplingDeviceIndex(const QString& deviceId, const QString& serial, int sequence, int deviceItemIndex); int getBestTxSamplingDeviceIndex(const QString& deviceId, const QString& serial, int sequence, int deviceItemIndex);
int getBestMIMOSamplingDeviceIndex(const QString& deviceId, const QString& serial, int sequence); int getBestMIMOSamplingDeviceIndex(const QString& deviceId, const QString& serial, int sequence);
signals:
void enumeratingDevices(const QString &deviceId);
private: private:
struct DeviceEnumeration struct DeviceEnumeration
{ {

View File

@ -19,6 +19,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include <QThread>
#include "samplingdevicedialog.h" #include "samplingdevicedialog.h"
#include "ui_samplingdevicedialog.h" #include "ui_samplingdevicedialog.h"
#include "device/deviceenumerator.h" #include "device/deviceenumerator.h"
@ -32,7 +34,8 @@ SamplingDeviceDialog::SamplingDeviceDialog(int deviceType, QWidget* parent) :
m_hasChanged(false) m_hasChanged(false)
{ {
ui->setupUi(this); ui->setupUi(this);
on_refreshDevices_clicked(); // Don't automatically call on_refreshDevices_clicked(), some drivers can be slow to enumerate
displayDevices();
} }
SamplingDeviceDialog::~SamplingDeviceDialog() SamplingDeviceDialog::~SamplingDeviceDialog()
@ -84,17 +87,22 @@ void SamplingDeviceDialog::on_deviceSelect_currentIndexChanged(int index)
void SamplingDeviceDialog::on_refreshDevices_clicked() void SamplingDeviceDialog::on_refreshDevices_clicked()
{ {
PluginManager *pluginManager = MainCore::instance()->getPluginManager(); QProgressDialog *progressDialog = new QProgressDialog("Enumerating devices", "", 0, 0, this);
progressDialog->setWindowModality(Qt::WindowModal);
if (m_deviceType == 0) { progressDialog->setCancelButton(nullptr);
DeviceEnumerator::instance()->enumerateRxDevices(pluginManager); progressDialog->setWindowFlag(Qt::WindowCloseButtonHint, false);
} else if (m_deviceType == 1) { progressDialog->show();
DeviceEnumerator::instance()->enumerateTxDevices(pluginManager); SamplingDeviceDialogWorker *worker = new SamplingDeviceDialogWorker(m_deviceType, progressDialog);
} else if (m_deviceType == 2) { QThread *thread = new QThread();
DeviceEnumerator::instance()->enumerateMIMODevices(pluginManager); worker->moveToThread(thread);
} connect(thread, &QThread::started, worker, &SamplingDeviceDialogWorker::enumerateDevices);
connect(worker, &SamplingDeviceDialogWorker::finishedWork, thread, &QThread::quit);
displayDevices(); connect(worker, &SamplingDeviceDialogWorker::finishedWork, progressDialog, &QProgressDialog::close);
connect(worker, &SamplingDeviceDialogWorker::finishedWork, progressDialog, &QProgressDialog::deleteLater);
connect(worker, &SamplingDeviceDialogWorker::finishedWork, this, &SamplingDeviceDialog::displayDevices);
connect(worker, &SamplingDeviceDialogWorker::finishedWork, worker, &SamplingDeviceDialog::deleteLater);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start();
} }
void SamplingDeviceDialog::accept() void SamplingDeviceDialog::accept()
@ -108,3 +116,23 @@ void SamplingDeviceDialog::reject()
m_hasChanged = false; m_hasChanged = false;
QDialog::reject(); QDialog::reject();
} }
void SamplingDeviceDialogWorker::enumerateDevices()
{
PluginManager *pluginManager = MainCore::instance()->getPluginManager();
connect(DeviceEnumerator::instance(), &DeviceEnumerator::enumeratingDevices, this, &SamplingDeviceDialogWorker::enumeratingDevices);
if (m_deviceType == 0) {
DeviceEnumerator::instance()->enumerateRxDevices(pluginManager);
} else if (m_deviceType == 1) {
DeviceEnumerator::instance()->enumerateTxDevices(pluginManager);
} else if (m_deviceType == 2) {
DeviceEnumerator::instance()->enumerateMIMODevices(pluginManager);
}
emit finishedWork();
}
void SamplingDeviceDialogWorker::enumeratingDevices(const QString &deviceId)
{
m_progressDialog->setLabelText("Enumerating " + deviceId);
}

View File

@ -23,6 +23,8 @@
#define SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ #define SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_
#include <QDialog> #include <QDialog>
#include <QProgressDialog>
#include <vector> #include <vector>
#include "export.h" #include "export.h"
@ -31,6 +33,28 @@ namespace Ui {
class SamplingDeviceDialog; class SamplingDeviceDialog;
} }
class SDRGUI_API SamplingDeviceDialogWorker : public QObject {
Q_OBJECT
public:
SamplingDeviceDialogWorker(int deviceType, QProgressDialog *progressDialog) :
m_deviceType(deviceType),
m_progressDialog(progressDialog)
{
}
void enumerateDevices();
signals:
void finishedWork();
private slots:
void enumeratingDevices(const QString &deviceId);
private:
int m_deviceType;
QProgressDialog *m_progressDialog;
};
class SDRGUI_API SamplingDeviceDialog : public QDialog { class SDRGUI_API SamplingDeviceDialog : public QDialog {
Q_OBJECT Q_OBJECT
@ -60,3 +84,4 @@ private slots:
}; };
#endif /* SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ */ #endif /* SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ */