1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-26 09:48:45 -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++)
{
qDebug("DeviceEnumerator::enumerateDevices: %s", qPrintable(deviceRegistrations[i].m_deviceId));
emit enumeratingDevices(deviceRegistrations[i].m_deviceId);
deviceRegistrations[i].m_plugin->enumOriginDevices(originDevicesHwIds, originDevices);
PluginInterface::SamplingDevices samplingDevices;
if (type == PluginInterface::SamplingDevice::StreamSingleRx) {

View File

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

View File

@ -19,6 +19,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QThread>
#include "samplingdevicedialog.h"
#include "ui_samplingdevicedialog.h"
#include "device/deviceenumerator.h"
@ -32,7 +34,8 @@ SamplingDeviceDialog::SamplingDeviceDialog(int deviceType, QWidget* parent) :
m_hasChanged(false)
{
ui->setupUi(this);
on_refreshDevices_clicked();
// Don't automatically call on_refreshDevices_clicked(), some drivers can be slow to enumerate
displayDevices();
}
SamplingDeviceDialog::~SamplingDeviceDialog()
@ -84,17 +87,22 @@ void SamplingDeviceDialog::on_deviceSelect_currentIndexChanged(int index)
void SamplingDeviceDialog::on_refreshDevices_clicked()
{
PluginManager *pluginManager = MainCore::instance()->getPluginManager();
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);
}
displayDevices();
QProgressDialog *progressDialog = new QProgressDialog("Enumerating devices", "", 0, 0, this);
progressDialog->setWindowModality(Qt::WindowModal);
progressDialog->setCancelButton(nullptr);
progressDialog->setWindowFlag(Qt::WindowCloseButtonHint, false);
progressDialog->show();
SamplingDeviceDialogWorker *worker = new SamplingDeviceDialogWorker(m_deviceType, progressDialog);
QThread *thread = new QThread();
worker->moveToThread(thread);
connect(thread, &QThread::started, worker, &SamplingDeviceDialogWorker::enumerateDevices);
connect(worker, &SamplingDeviceDialogWorker::finishedWork, thread, &QThread::quit);
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()
@ -108,3 +116,23 @@ void SamplingDeviceDialog::reject()
m_hasChanged = false;
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_
#include <QDialog>
#include <QProgressDialog>
#include <vector>
#include "export.h"
@ -31,6 +33,28 @@ namespace Ui {
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 {
Q_OBJECT
@ -60,3 +84,4 @@ private slots:
};
#endif /* SDRGUI_GUI_SAMPLINGDEVICEDIALOG_H_ */