diff --git a/src/core/plugins/plugins.cpp b/src/core/plugins/plugins.cpp index 054b612..b32a77a 100644 --- a/src/core/plugins/plugins.cpp +++ b/src/core/plugins/plugins.cpp @@ -85,7 +85,7 @@ Snore::PluginSettingsWidget *SnorePlugin::settingsWidget() QString SnorePlugin::normaliseKey(const QString &key) const { - return QString("%1/%2").arg(m_name, key); + return QString("%1/%2/%3").arg(m_name, settingsVersion(), key); } const QString &SnorePlugin::name() const @@ -103,6 +103,11 @@ const QString SnorePlugin::typeName() const return PluginContainer::typeToString(m_type); } +QString SnorePlugin::settingsVersion() const +{ + return "1"; +} + bool SnorePlugin::deinitialize() { if (m_initialized) { diff --git a/src/core/plugins/plugins.h b/src/core/plugins/plugins.h index c9ce72b..e216019 100644 --- a/src/core/plugins/plugins.h +++ b/src/core/plugins/plugins.h @@ -59,8 +59,11 @@ public: virtual PluginSettingsWidget *settingsWidget(); +protected: + virtual QString settingsVersion() const; + private: - SnorePlugin() {} + SnorePlugin() = delete; QString normaliseKey(const QString &key) const; QString m_name; diff --git a/src/core/settingsdialog.cpp b/src/core/settingsdialog.cpp index d4fc436..24db5b7 100644 --- a/src/core/settingsdialog.cpp +++ b/src/core/settingsdialog.cpp @@ -41,7 +41,6 @@ SettingsDialog::SettingsDialog(QWidget *parent) : ui->tabWidget->addTab(widget, widget->name()); m_tabs.append(widget); } - load(); } SettingsDialog::~SettingsDialog() @@ -77,10 +76,10 @@ void SettingsDialog::load() void SettingsDialog::save() { snoreDebug(SNORE_DEBUG) << "saving"; - SnoreCorePrivate::instance()->setBackendIfAvailible(ui->primaryBackendComboBox->currentText()); for (auto w : m_tabs) { w->saveSettings(); } + SnoreCorePrivate::instance()->syncSettings(); } void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button) @@ -99,3 +98,9 @@ void Snore::SettingsDialog::on_buttonBox_clicked(QAbstractButton *button) snoreDebug(SNORE_WARNING) << "unhandled role" << button->text(); } } + +void SettingsDialog::show() +{ + load(); + QDialog::show(); +} diff --git a/src/core/settingsdialog.h b/src/core/settingsdialog.h index 774dffe..f366620 100644 --- a/src/core/settingsdialog.h +++ b/src/core/settingsdialog.h @@ -48,6 +48,8 @@ public: explicit SettingsDialog(QWidget *parent = 0); ~SettingsDialog(); + void show(); + private slots: void on_pushButton_clicked(); void load(); diff --git a/src/core/snore.cpp b/src/core/snore.cpp index ec1c75f..5250a78 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -100,9 +100,6 @@ void SnoreCore::broadcastNotification(Notification notification) { Q_D(SnoreCore); snoreDebug(SNORE_DEBUG) << "Broadcasting" << notification << "timeout:" << notification.timeout(); - if (!notification.isUpdate()) { - d->syncSettings(); - } if (d->m_notificationBackend != nullptr) { if (notification.isUpdate() && !d->m_notificationBackend->canUpdateNotification()) { requestCloseNotification(notification.old(), Notification::REPLACED); @@ -200,22 +197,22 @@ QList SnoreCore::settingWidgets() QVariant SnoreCore::value(const QString &key) const { Q_D(const SnoreCore); - QString nk = d->normalizeKey(key); + QString nk = d->specificKey(key); if(d->m_settings->contains(nk)) { return d->m_settings->value(nk); } - return d->m_settings->value(key); + return d->m_settings->value(d->versionizeKey(key)); } void SnoreCore::setValue(const QString &key, const QVariant &value) { Q_D(SnoreCore); - QString nk = key; + QString nk = d->versionizeKey(key); if(value.canConvert() && value.value().isSpecific()) { - nk = d->normalizeKey(nk); + nk = d->specificKey(key); } d->m_settings->setValue(nk,value); } @@ -224,10 +221,10 @@ void SnoreCore::setValue(const QString &key, const QVariant &value) void SnoreCore::setDefaultValue(const QString &key, const QVariant &value) { Q_D(SnoreCore); - QString nk = key; + QString nk = d->versionizeKey(key); if(value.canConvert() && value.value().isSpecific()) { - nk = d->normalizeKey(nk); + nk = d->specificKey(key); } if (!d->m_settings->contains(nk)) { d->m_settings->setValue(nk, value); diff --git a/src/core/snore_p.cpp b/src/core/snore_p.cpp index 3cec763..b0fe376 100644 --- a/src/core/snore_p.cpp +++ b/src/core/snore_p.cpp @@ -133,8 +133,16 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend() void SnoreCorePrivate::syncSettings() { - setBackendIfAvailible(m_settings->value("PrimaryBackend").value().value().toString()); - for (auto pluginName : m_pluginNames[SnorePlugin::SECONDARY_BACKEND]) { + Q_Q(SnoreCore); + QString oldBackend = q->primaryNotificationBackend(); + m_notificationBackend->deinitialize(); + m_notificationBackend = nullptr; + if(!setBackendIfAvailible(q->value("PrimaryBackend").value().value().toString())) + { + setBackendIfAvailible(oldBackend); + } +//TODO: cleanup + auto syncPluginStatus = [&](const QString &pluginName){ SnorePlugin *plugin = m_plugins.value(pluginName); bool enable = m_plugins[pluginName]->value("Enabled").toBool(); if (!plugin->isInitialized() && enable) { @@ -142,6 +150,16 @@ void SnoreCorePrivate::syncSettings() } 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); } } diff --git a/src/core/snore_p.h b/src/core/snore_p.h index 3fc0644..de27138 100644 --- a/src/core/snore_p.h +++ b/src/core/snore_p.h @@ -20,6 +20,7 @@ #define SNORECOREPRIVATE_H #include "snore.h" +#include "version.h" #include "plugins/snorebackend.h" #include @@ -46,6 +47,7 @@ public: */ static QString tempPath(); + public: static SnoreCorePrivate *instance(); ~SnoreCorePrivate(); @@ -63,10 +65,19 @@ public: bool initPrimaryNotificationBackend(); + inline QString versionSchema() const { + return "1"; + } + void syncSettings(); - QString normalizeKey(const QString &key) const{ - return QString("AppSpecificSettings/%1/%2").arg(m_hints.value("app_specific_settings","SnoreNotify").toString(),key); + + QString versionizeKey(const QString &key) const{ + return QString("%1/%2").arg(key, versionSchema()); + } + + QString specificKey(const QString &key) const{ + return versionizeKey(QString("AppSpecificSettings/%1/%2").arg(m_hints.value("app_specific_settings","SnoreNotify").toString(),key)); } @@ -80,7 +91,6 @@ private slots: void slotAboutToQuit(); private: - SnoreCorePrivate(); SnoreCore *q_ptr; diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index cea5905..ce1ee2a 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -125,6 +125,7 @@ bool SnarlBackend::initialize() { SnarlInterface *snarlInterface = new SnarlInterface(); if (!snarlInterface->IsSnarlRunning()) { + snoreDebug(SNORE_WARNING) << "Snarl is not running"; delete snarlInterface; return false; }