diff --git a/include-gpl/plugin/pluginmanager.h b/include-gpl/plugin/pluginmanager.h index 6bd324ddd..da713f35e 100644 --- a/include-gpl/plugin/pluginmanager.h +++ b/include-gpl/plugin/pluginmanager.h @@ -57,8 +57,8 @@ public: bool handleMessage(const Message& message); void updateSampleSourceDevices(); - int fillSampleSourceSelector(QComboBox* comboBox); - int selectSampleSource(int index); + void fillSampleSourceSelector(QComboBox* comboBox); + int selectSampleSourceByIndex(int index); int selectFirstSampleSource(const QString& sourceId); int selectSampleSourceBySerialOrSequence(const QString& sourceId, const QString& sourceSerial, int sourceSequence); diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index b8e95fe64..b915ed2e3 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -98,7 +98,7 @@ MainWindow::MainWindow(QWidget* parent) : m_pluginManager->loadPlugins(); bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true); - int nbSources = m_pluginManager->fillSampleSourceSelector(ui->sampleSource); + m_pluginManager->fillSampleSourceSelector(ui->sampleSource); ui->sampleSource->blockSignals(sampleSourceSignalsBlocked); m_spectrumVis = new SpectrumVis(ui->glSpectrum); @@ -116,15 +116,10 @@ MainWindow::MainWindow(QWidget* parent) : qDebug() << "MainWindow::MainWindow: select SampleSource from settings..."; int sampleSourceIndex = m_settings.getSourceIndex(); + sampleSourceIndex = m_pluginManager->selectSampleSourceByIndex(sampleSourceIndex); - if(sampleSourceIndex >= nbSources) + if (sampleSourceIndex >= 0) { - sampleSourceIndex = 0; - } - - if (nbSources > 0) - { - m_pluginManager->selectSampleSource(sampleSourceIndex); bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true); ui->sampleSource->setCurrentIndex(sampleSourceIndex); ui->sampleSource->blockSignals(sampleSourceSignalsBlocked); @@ -562,7 +557,7 @@ void MainWindow::on_action_Preferences_triggered() void MainWindow::on_sampleSource_currentIndexChanged(int index) { m_pluginManager->saveSourceSettings(m_settings.getWorkingPreset()); - m_pluginManager->selectSampleSource(ui->sampleSource->currentIndex()); + m_pluginManager->selectSampleSourceByIndex(ui->sampleSource->currentIndex()); m_settings.setSourceIndex(ui->sampleSource->currentIndex()); m_pluginManager->loadSourceSettings(m_settings.getWorkingPreset()); } diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index 21b406f81..3fd672098 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -274,9 +274,9 @@ int PluginManager::fillSampleSourceSelector(QComboBox* comboBox) return i; } -int PluginManager::selectSampleSource(int index) +int PluginManager::selectSampleSourceByIndex(int index) { - qDebug("PluginManager::selectSampleSource by index: index: %d", index); + qDebug("PluginManager::selectSampleSourceByIndex: index: %d", index); m_dspEngine->stopAcquistion(); @@ -288,31 +288,19 @@ int PluginManager::selectSampleSource(int index) m_sampleSourceId.clear(); } - if(index == -1) + if (m_sampleSourceDevices.count() == 0) { - if(!m_sampleSourceId.isEmpty()) - { - for(int i = 0; i < m_sampleSourceDevices.count(); i++) - { - if(m_sampleSourceDevices[i].m_sourceId == m_sampleSourceId) - { - index = i; - break; - } - } - } + return -1; + } - if(index == -1) - { - if(m_sampleSourceDevices.count() > 0) - { - index = 0; - } - else - { - return -1; - } - } + if (index < 0) + { + return -1; + } + + if (index >= m_sampleSourceDevices.count()) + { + index = 0; } m_sampleSourceId = m_sampleSourceDevices[index].m_sourceId;