mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #513 Make plugin selection persistent
* Saved listeners are started on application startup * CVariant has support for QStringList
This commit is contained in:
@@ -425,6 +425,8 @@ namespace BlackCore
|
||||
bool s = QMetaObject::invokeMethod(listener, "start", Qt::QueuedConnection);
|
||||
Q_ASSERT_X(s, Q_FUNC_INFO, "cannot invoke method");
|
||||
Q_UNUSED(s);
|
||||
|
||||
CLogMessage(this).info("Listening for simulator %1") << simulatorInfo.getIdentifier();
|
||||
}
|
||||
|
||||
void CContextSimulator::listenForAllSimulators()
|
||||
@@ -560,6 +562,21 @@ namespace BlackCore
|
||||
m_simulatorPlugin.second->updateOwnSimulatorCockpit(ownAircraft, originator);
|
||||
}
|
||||
|
||||
void CContextSimulator::restoreSimulatorPlugins()
|
||||
{
|
||||
stopSimulatorListeners();
|
||||
|
||||
auto enabledSimulators = m_enabledSimulators.get();
|
||||
auto allSimulators = m_plugins->getAvailableSimulatorPlugins();
|
||||
for (const CSimulatorPluginInfo& s: allSimulators)
|
||||
{
|
||||
if (enabledSimulators.contains(s.getIdentifier()))
|
||||
{
|
||||
startSimulatorPlugin(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CPixmap CContextSimulator::iconForModel(const QString &modelString) const
|
||||
{
|
||||
if (m_simulatorPlugin.first.isUnspecified()) { return CPixmap(); }
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "blackcore/contextsimulator.h"
|
||||
#include "blackcore/simulator.h"
|
||||
#include "blackcore/weathermanager.h"
|
||||
#include "blackcore/settings/application.h"
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/simulation/simulatedaircraftlist.h"
|
||||
#include "blackmisc/network/textmessagelist.h"
|
||||
@@ -161,6 +162,9 @@ namespace BlackCore
|
||||
//! \remarks set by runtime, only to be used locally (not via DBus)
|
||||
void ps_updateSimulatorCockpitFromContext(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
//! Reads list of enabled simulators, starts listeners
|
||||
void restoreSimulatorPlugins();
|
||||
|
||||
private:
|
||||
//! Load plugin, if required start listeners before
|
||||
bool loadSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo, bool withListeners);
|
||||
@@ -181,6 +185,7 @@ namespace BlackCore
|
||||
CPluginManagerSimulator *m_plugins = nullptr;
|
||||
BlackMisc::CRegularThread m_listenersThread;
|
||||
BlackCore::CWeatherManager m_weatherManager { this };
|
||||
BlackMisc::CSetting<BlackCore::Settings::Application::EnabledSimulators> m_enabledSimulators { this, &CContextSimulator::restoreSimulatorPlugins };
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/input/actionhotkeylist.h"
|
||||
#include <QStringList>
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -39,6 +40,27 @@ namespace BlackCore
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//! Selected simulator plugins
|
||||
struct EnabledSimulators : public BlackMisc::CSettingTrait<QStringList>
|
||||
{
|
||||
//! \copydoc BlackCore::CSettingTrait::key
|
||||
static const char *key() { return "application/enabledsimulators"; }
|
||||
|
||||
//! \copydoc BlackCore::CSettingTrait::defaultValue
|
||||
static const QStringList &defaultValue()
|
||||
{
|
||||
// All default simulators
|
||||
static const QStringList enabledSimulators
|
||||
{
|
||||
QStringLiteral("org.swift-project.plugins.simulator.fs9"),
|
||||
QStringLiteral("org.swift-project.plugins.simulator.fsx"),
|
||||
QStringLiteral("org.swift-project.plugins.simulator.xplane")
|
||||
};
|
||||
|
||||
return enabledSimulators;
|
||||
}
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user