refs #513 Make plugin selection persistent

* Saved listeners are started on application startup
* CVariant has support for QStringList
This commit is contained in:
Michał Garapich
2016-01-03 13:42:10 +01:00
parent f4eadddee7
commit 1a3e610cbf
9 changed files with 92 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
#include "settingssimulatorcomponent.h"
#include "ui_settingssimulatorcomponent.h"
#include "blackcore/contextapplication.h"
#include "blackgui/guiapplication.h"
#include "blackgui/pluginconfigwindow.h"
#include "blackgui/plugindetailswindow.h"
@@ -36,13 +36,6 @@ namespace BlackGui
this->ui->led_RestrictedRendering->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Limited", "Unlimited", 14);
this->ui->led_RenderingEnabled->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Rendering enabled", "No aircraft will be rendered", 14);
// set values
for (const auto &p : getAvailablePlugins())
{
QString config = m_plugins->getPluginConfigId(p.getIdentifier());
ui->ps_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), !config.isEmpty(), false);
}
// connects
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::ps_simulatorPluginChanged);
connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::ps_pluginStateChanged);
@@ -56,12 +49,21 @@ namespace BlackGui
connect(this->ui->sb_MaxAircraft, &QSpinBox::editingFinished, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft);
connect(this->ui->sb_MaxDistance, &QSpinBox::editingFinished, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance);
// values
this->ps_simulatorPluginChanged(sGui->getIContextSimulator()->getSimulatorPluginInfo());
// list all available simulators
for (const auto &p : getAvailablePlugins())
{
QString config = m_plugins->getPluginConfigId(p.getIdentifier());
ui->ps_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), !config.isEmpty(), false);
}
ps_reloadPluginConfig();
}
CSettingsSimulatorComponent::~CSettingsSimulatorComponent()
{ }
{
if (!m_enabledSimulators.isSaved())
sGui->getIContextApplication()->saveSettings(m_enabledSimulators.getKey());
}
void CSettingsSimulatorComponent::setGuiValues()
{
@@ -127,17 +129,18 @@ namespace BlackGui
return;
}
if (enabled)
auto e = m_enabledSimulators.get();
if (enabled && !e.contains(selected->getIdentifier()))
{
sGui->getIContextSimulator()->startSimulatorPlugin(*selected);
CLogMessage(this).info("Started listening for %1") << selected->getName();
e << selected->getIdentifier();
}
else
else if (!enabled)
{
sGui->getIContextSimulator()->stopSimulatorPlugin(*selected);
CLogMessage(this).info("Stopped listening for %1") << selected->getName();
e.removeAll(selected->getIdentifier());
}
m_enabledSimulators.set(e);
// changing of GUI state will be done via received signal
}
@@ -273,6 +276,16 @@ namespace BlackGui
window->setAttribute(Qt::WA_DeleteOnClose);
window->show();
}
void CSettingsSimulatorComponent::ps_reloadPluginConfig()
{
// list all available simulators
auto enabledSimulators = m_enabledSimulators.get();
for (const auto &p : getAvailablePlugins())
{
ui->ps_EnabledSimulators->setEnabled(p.getIdentifier(), enabledSimulators.contains(p.getIdentifier()));
}
}
}
} // namespace

View File

@@ -11,6 +11,7 @@
#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#include "blackcore/pluginmanagersimulator.h"
#include "blackcore/settings/application.h"
#include "blackgui/blackguiexport.h"
#include "blackmisc/simulation/simulatorplugininfolist.h"
#include <QFrame>
@@ -62,6 +63,9 @@ namespace BlackGui
//! Show plugin config
void ps_showPluginConfig(const QString &identifier);
//! Select/deselect enabled/disabled plugins
void ps_reloadPluginConfig();
private:
//! Set the GUI values
void setGuiValues();
@@ -72,6 +76,7 @@ namespace BlackGui
QScopedPointer<Ui::CSettingsSimulatorComponent> ui; //!< UI
bool m_pluginLoaded = false; //!< plugin loaded
BlackCore::CPluginManagerSimulator* m_plugins = nullptr;
BlackMisc::CSetting<BlackCore::Settings::Application::EnabledSimulators> m_enabledSimulators { this, &CSettingsSimulatorComponent::ps_reloadPluginConfig };
};
}