diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index 9e52498f1..3123b6afc 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -171,6 +171,9 @@ namespace BlackCore //! Listen for the specific simulator to start, load plugin automatically virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) = 0; + //! Listen for all available simulators + virtual void listenForAllSimulators() = 0; + //! Listen for simulator as set in settings virtual void listenForSimulatorFromSettings() = 0; diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index ca7ecb192..54e0a145b 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -413,10 +413,22 @@ namespace BlackCore } + void CContextSimulator::listenForAllSimulators() + { + auto plugins = getAvailableSimulatorPlugins(); + for (const auto &p: plugins) + listenForSimulator(p); + } + void CContextSimulator::listenForSimulatorFromSettings() { Q_ASSERT(this->getIContextSettings()); - listenForSimulator(getIContextSettings()->getSimulatorSettings().getSelectedPlugin()); + + auto plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin(); + if (plugin.isUnspecified()) + listenForAllSimulators(); + else + listenForSimulator(plugin); } void CContextSimulator::unloadSimulatorPlugin() @@ -512,30 +524,31 @@ namespace BlackCore void CContextSimulator::settingsChanged(uint type) { Q_ASSERT(this->getIContextSettings()); - Q_ASSERT(this->m_simulator); - if (!this->getIContextSettings()) return; + auto settingsType = static_cast(type); - if (settingsType != IContextSettings::SettingsSimulator) return; + if (settingsType != IContextSettings::SettingsSimulator) + return; // plugin CSettingsSimulator settingsSim = this->getIContextSettings()->getSimulatorSettings(); - CSimulatorInfo plugin = settingsSim.getSelectedPlugin(); - if (!this->getSimulatorInfo().isSameSimulator(plugin)) - { - if (this->loadSimulatorPlugin(plugin)) - { - CLogMessage(this).info("Plugin loaded: '%1'") << plugin.toQString(true); - } - else - { - CLogMessage(this).error("Cannot load driver: '%1'") << plugin.toQString(true); + CSimulatorInfo plugin = getIContextSettings()->getSimulatorSettings().getSelectedPlugin(); + + // no simulator loaded yet, listen + if (!m_simulator) { + stopSimulatorListeners(); + if (plugin.isSameSimulator(CSimulatorInfo::UnspecifiedSim())) { + listenForAllSimulators(); + } else { + listenForSimulator(plugin); } } - - // time sync - bool timeSync = settingsSim.isTimeSyncEnabled(); - CTime syncOffset = settingsSim.getSyncTimeOffset(); - this->m_simulator->setTimeSynchronization(timeSync, syncOffset); + else + { + // time sync + bool timeSync = settingsSim.isTimeSyncEnabled(); + CTime syncOffset = settingsSim.getSyncTimeOffset(); + m_simulator->setTimeSynchronization(timeSync, syncOffset); + } } CPixmap CContextSimulator::iconForModel(const QString &modelString) const diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index 78b337d10..0f58c8ad5 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -41,6 +41,7 @@ namespace BlackCore //! Lazy-loads the driver, instantiates the factory and returns it. //! \return nullptr if no corresponding driver was found or an error occured during loading it. + //! \todo Consider moving to private scope. ISimulatorFactory* getSimulatorFactory(const BlackSim::CSimulatorInfo& simulator); public slots: @@ -132,6 +133,9 @@ namespace BlackCore //! \copydoc IContextSimulator::listenForSimulator() virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override; + //! \copydoc IContextSimulator::listenForAllSimulators() + virtual void listenForAllSimulators() override; + //! \copydoc IContextSimulator::listenForSimulatorFromSettings() virtual void listenForSimulatorFromSettings() override; diff --git a/src/blackcore/context_simulator_proxy.cpp b/src/blackcore/context_simulator_proxy.cpp index 2e4a9ec22..dec44e9a2 100644 --- a/src/blackcore/context_simulator_proxy.cpp +++ b/src/blackcore/context_simulator_proxy.cpp @@ -189,6 +189,11 @@ namespace BlackCore m_dBusInterface->callDBus(QLatin1Literal("listenForSimulator"), simulatorInfo); } + void CContextSimulatorProxy::listenForAllSimulators() + { + m_dBusInterface->callDBus(QLatin1Literal("listenForAllSimulators")); + } + void CContextSimulatorProxy::listenForSimulatorFromSettings() { m_dBusInterface->callDBus(QLatin1Literal("listenForSimulatorFromSettings")); diff --git a/src/blackcore/context_simulator_proxy.h b/src/blackcore/context_simulator_proxy.h index 3bb8df22f..030778353 100644 --- a/src/blackcore/context_simulator_proxy.h +++ b/src/blackcore/context_simulator_proxy.h @@ -131,6 +131,9 @@ namespace BlackCore //! \copydoc IContextSimulator::listenForSimulator() virtual void listenForSimulator(const BlackSim::CSimulatorInfo &simulatorInfo) override; + //! \copydoc IContextSimulator::listenForAllSimulators() + virtual void listenForAllSimulators() override; + //! \copydoc IContextSimulator::listenForSimulatorFromSettings() virtual void listenForSimulatorFromSettings() override; diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index ffe1f84e0..921c9e085 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -43,39 +43,35 @@ namespace BlackGui { Q_ASSERT(this->getIContextSimulator()); Q_ASSERT(this->getIContextSettings()); - if (this->getIContextSimulator()) + + // set values + this->setRestrictedValues(); + + ui->cb_Plugins->addItem(tr("Auto"), CSimulatorPluginInfo().toQVariant()); + + for (const auto &p: getIContextSimulator()->getAvailableSimulatorPlugins()) { - QStringList plugins = this->getIContextSimulator()->getAvailableSimulatorPlugins().toStringList(true); - CSimulatorInfo currentPlugin = this->getIContextSimulator()->getSimulatorInfo(); - this->ui->cb_Plugins->addItems(plugins); - this->setCurrentPlugin(currentPlugin); - - // disable / enable driver specific GUI parts - bool fsxDriver = this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(CSimulatorInfo::FSX()); - this->ui->comp_SettingsSimulatorFsx->setVisible(fsxDriver); - - // time sync - bool timeSynced = this->getIContextSimulator()->isTimeSynchronized(); - this->ui->cb_TimeSync->setChecked(timeSynced); - CTime timeOffset = this->getIContextSimulator()->getTimeSynchronizationOffset(); - this->ui->le_TimeSyncOffset->setText(timeOffset.formattedHrsMin()); - - // only with simulator context set GUI values - bool connected = this->connect(this->ui->cb_Plugins, static_cast (&QComboBox::currentIndexChanged), this, &CSettingsSimulatorComponent::ps_pluginHasChanged); - Q_ASSERT(connected); - connected = this->connect(getIContextSimulator(), &IContextSimulator::restrictedRenderingChanged, this, &CSettingsSimulatorComponent::ps_onRenderingRestricted); - Q_ASSERT(connected); - Q_UNUSED(connected); - - // set values - this->setRestrictedValues(); + ui->cb_Plugins->addItem(p.toQString(), p.toQVariant()); } - if (this->getIContextSettings()) - { - connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsSimulatorComponent::ps_settingsHaveChanged); - } + this->setCurrentPlugin(getIContextSettings()->getSimulatorSettings().getSelectedPlugin()); + // disable / enable driver specific GUI parts + bool hasFsxDriver = + this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(QStringLiteral("fsx")); + this->ui->comp_SettingsSimulatorFsx->setVisible(hasFsxDriver); + + // time sync + bool timeSynced = this->getIContextSimulator()->isTimeSynchronized(); + this->ui->cb_TimeSync->setChecked(timeSynced); + CTime timeOffset = this->getIContextSimulator()->getTimeSynchronizationOffset(); + this->ui->le_TimeSyncOffset->setText(timeOffset.formattedHrsMin()); + + // max.aircraft + this->ui->sb_MaxAircraft->setValue(getIContextSimulator()->getMaxRenderedAircraft()); + + connect(this->ui->cb_Plugins, static_cast (&QComboBox::currentIndexChanged), this, &CSettingsSimulatorComponent::ps_pluginHasChanged); + connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsSimulatorComponent::ps_settingsHaveChanged); connect(this->ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft); connect(this->ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyTimeSync); connect(this->ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance); @@ -84,7 +80,11 @@ namespace BlackGui void CSettingsSimulatorComponent::setCurrentPlugin(const CSimulatorInfo &plugin) { - if (plugin.isUnspecified()) return; + if (plugin.isUnspecified()) { + ui->cb_Plugins->setCurrentIndex(0); + return; + } + const QString searchFor = plugin.getShortName(); for (int i = 0; i < this->ui->cb_Plugins->count(); ++i) { @@ -119,6 +119,7 @@ namespace BlackGui if (!this->getIContextSimulator() || !this->getIContextSettings()) return; CSimulatorInfoList simDrivers = this->getIContextSimulator()->getAvailableSimulatorPlugins(); + simDrivers.insert(simDrivers.begin(), CSimulatorInfo::UnspecifiedSim()); if (simDrivers.isEmpty()) { CLogMessage(this).error("No drivers available"); diff --git a/src/blacksim/setsimulator.cpp b/src/blacksim/setsimulator.cpp index ba2449d61..e4207ca70 100644 --- a/src/blacksim/setsimulator.cpp +++ b/src/blacksim/setsimulator.cpp @@ -42,7 +42,7 @@ namespace BlackSim */ void CSettingsSimulator::initDefaultValues() { - this->m_selectedPlugin = CSimulatorInfo::FSX(); + this->m_selectedPlugin = CSimulatorInfo::UnspecifiedSim(); this->m_timeSyncOffset = CTime(0, CTimeUnit::hrmin()); this->m_timeSync = false; }