diff --git a/src/libsnore/plugins/plugins.cpp b/src/libsnore/plugins/plugins.cpp index 139fd59..4aed845 100644 --- a/src/libsnore/plugins/plugins.cpp +++ b/src/libsnore/plugins/plugins.cpp @@ -129,7 +129,7 @@ QString SnorePlugin::typeToString(const SnorePlugin::PluginTypes t) return SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).valueToKey(t); } -const QList &SnorePlugin::types() +QList SnorePlugin::types() { static QList t; if (t.isEmpty()) { diff --git a/src/libsnore/plugins/plugins.h b/src/libsnore/plugins/plugins.h index d863c4f..4eb7d89 100644 --- a/src/libsnore/plugins/plugins.h +++ b/src/libsnore/plugins/plugins.h @@ -45,7 +45,7 @@ public: static PluginTypes typeFromString(const QString &t); static QString typeToString(const PluginTypes t); - static const QList &types(); + static QList types(); SnorePlugin(const QString &name); virtual ~SnorePlugin(); diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index 3ea1562..78928fc 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -146,8 +146,8 @@ void SnoreCorePrivate::init() void SnoreCorePrivate::syncSettings() { Q_Q(SnoreCore); - QString newBackend = q->value("PrimaryBackend", LOCAL_SETTING); - if (newBackend) { + QString newBackend = q->value("PrimaryBackend", LOCAL_SETTING).toString(); + if (!newBackend.isEmpty()) { QString oldBackend; if (m_notificationBackend) { oldBackend = m_notificationBackend->name(); @@ -159,25 +159,19 @@ void SnoreCorePrivate::syncSettings() setBackendIfAvailible(oldBackend); } } -//TODO: cleanup - auto syncPluginStatus = [&](const QString & pluginName) { - SnorePlugin *plugin = m_plugins.value(pluginName); - bool enable = m_plugins[pluginName]->value("Enabled", LOCAL_SETTING).toBool(); - if (!plugin->isInitialized() && enable) { - plugin->initialize(); - } else if (plugin->isInitialized() && !enable) { - plugin->deinitialize(); - } - }; - for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) { - syncPluginStatus(pluginName); - } - for (auto pluginName : m_pluginNames[SnorePlugin::FRONTEND]) { - syncPluginStatus(pluginName); - } - for (auto pluginName : m_pluginNames[SnorePlugin::PLUGIN]) { - syncPluginStatus(pluginName); + auto types = SnorePlugin::types(); + types.removeOne(SnorePlugin::BACKEND); + for(auto type : types) { + for (auto &pluginName : m_pluginNames[type]) { + SnorePlugin *plugin = m_plugins.value(pluginName); + bool enable = m_plugins[pluginName]->value("Enabled", LOCAL_SETTING).toBool(); + if (!plugin->isInitialized() && enable) { + plugin->initialize(); + } else if (plugin->isInitialized() && !enable) { + plugin->deinitialize(); + } + } } }