cleanup settings for backends

This commit is contained in:
Patrick von Reth 2015-02-04 09:57:50 +01:00
parent c07e04faeb
commit d9aac2372f
3 changed files with 21 additions and 6 deletions

View File

@ -90,7 +90,11 @@ void SnorePlugin::setDefaultValue(const QString &key, const QVariant &value, con
Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
{
return new PluginSettingsWidget(this);
if(type() != SnorePlugin::BACKEND) {
// don't display a useless default widget for backends
return new PluginSettingsWidget(this);
}
return nullptr;
}
QString SnorePlugin::normaliseKey(const QString &key) const

View File

@ -32,7 +32,10 @@ PluginSettingsWidget::PluginSettingsWidget(SnorePlugin *snorePlugin, QWidget *pa
{
setLayout(m_layout);
addRow("Type:", new QLabel(snorePlugin->typeName()));
addRow("Enabled:", m_enabled);
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
// backends are handled through a combo box.
addRow("Enabled:", m_enabled);
}
}
@ -53,14 +56,19 @@ void PluginSettingsWidget::addRow(const QString &label, QWidget *widget)
void PluginSettingsWidget::loadSettings()
{
m_enabled->setChecked(m_snorePlugin->value("Enabled").toBool());
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
m_enabled->setChecked(m_snorePlugin->value("Enabled").toBool());
}
load();
}
void PluginSettingsWidget::saveSettings()
{
m_snorePlugin->setValue("Enabled", m_enabled->isChecked());
m_snorePlugin->snore()->setPluginEnabled(m_snorePlugin->name(), m_enabled->isChecked());
if (m_snorePlugin->type() != SnorePlugin::BACKEND) {
m_snorePlugin->setValue("Enabled", m_enabled->isChecked());
// we only allow one active primary backend
m_snorePlugin->snore()->setPluginEnabled(m_snorePlugin->name(), m_enabled->isChecked());
}
save();
}

View File

@ -180,7 +180,10 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
QList<PluginSettingsWidget *> list;
for (auto p : d->m_plugins) {
//TODO: mem leak?
list.append(p->settingsWidget());
PluginSettingsWidget *widget = p->settingsWidget();
if (widget) {
list.append(p->settingsWidget());
}
}
return list;
}