From ad4eb3d502c6a0ef6a00c2342182e872e8a9af01 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Tue, 1 Aug 2017 08:50:40 +0200 Subject: [PATCH] Move settings keys to constants --- autotest/display_test.cpp | 5 ++-- autotest/snorebenchmark.cpp | 3 ++- src/libsnore/application_p.cpp | 3 ++- src/libsnore/notification/notification.cpp | 3 ++- src/libsnore/plugins/plugins.cpp | 19 +++++++-------- src/libsnore/plugins/plugins.h | 8 +++---- .../settings/pluginsettingswidget.cpp | 13 ++++++----- src/libsnore/settings/pluginsettingswidget.h | 4 ++-- src/libsnore/settings/settingsdialog.cpp | 23 ++++++++++--------- src/libsnore/snore.cpp | 21 +++++++++-------- src/libsnore/snore.h | 6 ++--- src/libsnore/snore_p.cpp | 13 ++++++----- src/libsnore/snoreconstants.h | 22 ++++++++++++++++++ src/libsnore/snoreglobals.h | 5 ++++ src/plugins/backends/growl/growlbackend.cpp | 11 +++++---- src/plugins/backends/growl/growlconstants.h | 12 ++++++++++ src/plugins/backends/growl/growlsettings.cpp | 9 ++++---- src/plugins/backends/snarl/snarl.cpp | 5 ++-- src/plugins/backends/snarl/snarlconstants.h | 9 ++++++++ src/plugins/backends/snarl/snarlsettings.cpp | 5 ++-- src/plugins/backends/snore/notifywidget.cpp | 3 ++- .../backends/snore/snorebackendconstants.h | 11 +++++++++ src/plugins/backends/snore/snorenotifier.cpp | 3 ++- .../backends/snore/snorenotifiersettings.cpp | 5 ++-- .../pushover_frontend/pushover_frontend.cpp | 9 ++++++-- .../pushover_frontend/pushoverclient.cpp | 16 +++++++------ .../pushover_frontend/pushoversettings.cpp | 3 ++- src/plugins/secondary_backends/nma/nma.cpp | 5 ++-- .../secondary_backends/nma/nmaconstants.h | 9 ++++++++ .../secondary_backends/nma/nmasettings.cpp | 5 ++-- .../pushover_backend/pushover.cpp | 15 ++++++------ .../pushover_backend/pushoverconstants.h | 17 ++++++++++++++ .../pushover_backend/pushoversettings.cpp | 13 ++++++----- .../secondary_backends/sound/sound.cpp | 7 +++--- .../secondary_backends/sound/soundconstants.h | 11 +++++++++ .../sound/soundsettings.cpp | 9 ++++---- .../secondary_backends/toasty/toasty.cpp | 5 ++-- .../toasty/toastyconstants.h | 11 +++++++++ .../toasty/toastysettings.cpp | 5 ++-- 39 files changed, 250 insertions(+), 111 deletions(-) create mode 100644 src/libsnore/snoreconstants.h create mode 100644 src/plugins/backends/growl/growlconstants.h create mode 100644 src/plugins/backends/snarl/snarlconstants.h create mode 100644 src/plugins/backends/snore/snorebackendconstants.h create mode 100644 src/plugins/secondary_backends/nma/nmaconstants.h create mode 100644 src/plugins/secondary_backends/pushover_backend/pushoverconstants.h create mode 100644 src/plugins/secondary_backends/sound/soundconstants.h create mode 100644 src/plugins/secondary_backends/toasty/toastyconstants.h diff --git a/autotest/display_test.cpp b/autotest/display_test.cpp index b46a79f..3ed4e75 100644 --- a/autotest/display_test.cpp +++ b/autotest/display_test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -17,7 +18,7 @@ public: { SnoreCore &instance = SnoreCore::instance(); instance.loadPlugins(SnorePlugin::Backend); - instance.setSettingsValue(QStringLiteral("Timeout"), 10, LocalSetting); + instance.setSettingsValue(Snore::Constants::SettingsKeys::Timeout, 10); SnoreCore::instance().registerApplication(app); } @@ -46,7 +47,7 @@ private: QString old = snore.primaryNotificationBackend(); while (!backends.empty() && snore.primaryNotificationBackend() == old) { QString p = backends.takeLast(); - snore.setSettingsValue(QStringLiteral("PrimaryBackend"), p, LocalSetting); + snore.setSettingsValue(Snore::Constants::SettingsKeys::PrimaryBackend, p); SnoreCorePrivate::instance()->syncSettings(); if (snore.primaryNotificationBackend() == p) { for (const auto &message : messages) { diff --git a/autotest/snorebenchmark.cpp b/autotest/snorebenchmark.cpp index 0ec4fb5..ee6bfc7 100644 --- a/autotest/snorebenchmark.cpp +++ b/autotest/snorebenchmark.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -16,7 +17,7 @@ public: { SnoreCore &instance = SnoreCore::instance(); instance.loadPlugins(SnorePlugin::Backend); - instance.setSettingsValue(QStringLiteral("Timeout"), 1, LocalSetting); + instance.setSettingsValue(Snore::Constants::SettingsKeys::Timeout, 1); } // clazy is complaining about this string but QStringLiteral won't work for the multiline string, so use QStringBuilder to silence it. diff --git a/src/libsnore/application_p.cpp b/src/libsnore/application_p.cpp index 726ff9e..1602a9b 100644 --- a/src/libsnore/application_p.cpp +++ b/src/libsnore/application_p.cpp @@ -19,6 +19,7 @@ #include "application_p.h" #include "lambdahint.h" #include "snore_p.h" +#include "snoreconstants.h" #include @@ -36,7 +37,7 @@ ApplicationData::ApplicationData(const QString &key, const QString &name, const m_hint.setValue("pushover-token", QLatin1String("aFB1TPCyZkkr7mubCGEKy5vJEWak9t")); m_hint.setValue("use-markup", false); m_hint.setValue("silent", QVariant::fromValue(LambdaHint([]() { - return SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting); + return SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent); }))); } diff --git a/src/libsnore/notification/notification.cpp b/src/libsnore/notification/notification.cpp index a00f67a..5849b11 100644 --- a/src/libsnore/notification/notification.cpp +++ b/src/libsnore/notification/notification.cpp @@ -18,6 +18,7 @@ #include "notification.h" #include "snore.h" +#include "snoreconstants.h" #include "notification/icon.h" #include "notification/notification_p.h" #include "plugins/plugincontainer.h" @@ -181,7 +182,7 @@ NotificationData *Notification::data() int Notification::defaultTimeout() { - return SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt(); + return SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt(); } QDataStream &operator<< (QDataStream &stream, const Notification ¬i) diff --git a/src/libsnore/plugins/plugins.cpp b/src/libsnore/plugins/plugins.cpp index 2abf1cb..0e59b93 100644 --- a/src/libsnore/plugins/plugins.cpp +++ b/src/libsnore/plugins/plugins.cpp @@ -18,6 +18,7 @@ #include "../snore.h" #include "../snore_p.h" +#include "../snoreconstants.h" #include "snorebackend.h" #include "snorefrontend.h" #include "../notification/notification_p.h" @@ -47,19 +48,19 @@ bool SnorePlugin::isEnabled() const return m_enabled; } -QVariant SnorePlugin::settingsValue(const QString &key, SettingsType type) const +QVariant SnorePlugin::settingsValue(const SettingsKey &key) const { - return SnoreCore::instance().settingsValue(normaliseKey(key), type); + return SnoreCore::instance().settingsValue(normaliseKey(key)); } -void SnorePlugin::setSettingsValue(const QString &key, const QVariant &value, SettingsType type) +void SnorePlugin::setSettingsValue(const SettingsKey &key, const QVariant &value) { - SnoreCore::instance().setSettingsValue(normaliseKey(key), value, type); + SnoreCore::instance().setSettingsValue(normaliseKey(key), value); } -void SnorePlugin::setDefaultSettingsValue(const QString &key, const QVariant &value, SettingsType type) +void SnorePlugin::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value) { - SnoreCore::instance().setDefaultSettingsValue(normaliseKey(key), value, type); + SnoreCore::instance().setDefaultSettingsValue(normaliseKey(key), value); } const Hint &SnorePlugin::constHints() const @@ -72,9 +73,9 @@ Hint &SnorePlugin::hints() return m_hints; } -QString SnorePlugin::normaliseKey(const QString &key) const +SettingsKey SnorePlugin::normaliseKey(const SettingsKey &key) const { - return name() + QLatin1Char('-') + typeName() + QLatin1Char('/') + key + QLatin1Char('.') + settingsVersion(); + return SettingsKey{name() + QLatin1Char('-') + typeName() + QLatin1Char('/') + key.key + QLatin1Char('.') + settingsVersion(), key.type}; } const QString &SnorePlugin::name() const @@ -104,7 +105,7 @@ QString SnorePlugin::settingsVersion() const void SnorePlugin::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("Enabled"), false, LocalSetting); + setDefaultSettingsValue(Constants::SettingsKeys::Enabled, false); } void SnorePlugin::setErrorString(const QString &_error) diff --git a/src/libsnore/plugins/plugins.h b/src/libsnore/plugins/plugins.h index 1ac9311..d279a55 100644 --- a/src/libsnore/plugins/plugins.h +++ b/src/libsnore/plugins/plugins.h @@ -133,9 +133,9 @@ public: */ QString errorString() const; - QVariant settingsValue(const QString &key, SettingsType type = GlobalSetting) const; - void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting); - void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting); + QVariant settingsValue(const SettingsKey &key) const; + void setSettingsValue(const SettingsKey &key, const QVariant &settingsValue); + void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue); const Hint &constHints() const; @@ -158,7 +158,7 @@ protected: Hint &hints(); private: - QString normaliseKey(const QString &key) const; + SettingsKey normaliseKey(const SettingsKey &key) const; void setDefaultSettingsPlugin(); bool m_enabled = false; diff --git a/src/libsnore/settings/pluginsettingswidget.cpp b/src/libsnore/settings/pluginsettingswidget.cpp index d746c37..081c71a 100644 --- a/src/libsnore/settings/pluginsettingswidget.cpp +++ b/src/libsnore/settings/pluginsettingswidget.cpp @@ -17,6 +17,7 @@ */ #include "pluginsettingswidget.h" #include "libsnore/plugins/plugins.h" +#include "libsnore/snoreconstants.h" #include "snore.h" #include @@ -61,7 +62,7 @@ void PluginSettingsWidget::addRow(const QString &label, QWidget *widget, const Q void PluginSettingsWidget::loadSettings() { if (m_snorePlugin->type() != SnorePlugin::Backend) { - m_enabled->setChecked(m_snorePlugin->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool()); + m_enabled->setChecked(m_snorePlugin->settingsValue(Constants::SettingsKeys::Enabled).toBool()); } load(); } @@ -69,7 +70,7 @@ void PluginSettingsWidget::loadSettings() void PluginSettingsWidget::saveSettings() { if (m_snorePlugin->type() != SnorePlugin::Backend) { - m_snorePlugin->setSettingsValue(QStringLiteral("Enabled"), m_enabled->isChecked(), LocalSetting); + m_snorePlugin->setSettingsValue(Constants::SettingsKeys::Enabled, m_enabled->isChecked()); } save(); } @@ -79,15 +80,15 @@ bool PluginSettingsWidget::isDirty() return m_dirty; } -QVariant PluginSettingsWidget::settingsValue(const QString &key, SettingsType type) const +QVariant PluginSettingsWidget::settingsValue(const SettingsKey &key) const { - return m_snorePlugin->settingsValue(key, type); + return m_snorePlugin->settingsValue(key); } -void PluginSettingsWidget::setSettingsValue(const QString &key, const QVariant &value, SettingsType type) +void PluginSettingsWidget::setSettingsValue(const SettingsKey &key, const QVariant &value) { if (this->settingsValue(key) != value) { - m_snorePlugin->setSettingsValue(key, value, type); + m_snorePlugin->setSettingsValue(key, value); m_dirty = true; } } diff --git a/src/libsnore/settings/pluginsettingswidget.h b/src/libsnore/settings/pluginsettingswidget.h index ddeb04c..dc881a2 100644 --- a/src/libsnore/settings/pluginsettingswidget.h +++ b/src/libsnore/settings/pluginsettingswidget.h @@ -46,8 +46,8 @@ public: bool isDirty(); protected: - QVariant settingsValue(const QString &key, Snore::SettingsType type = Snore::GlobalSetting) const; - void setSettingsValue(const QString &key, const QVariant &settingsValue, Snore::SettingsType type = Snore::GlobalSetting); + QVariant settingsValue(const SettingsKey &key) const; + void setSettingsValue(const SettingsKey &key, const QVariant &settingsValue); virtual void load(); virtual void save(); diff --git a/src/libsnore/settings/settingsdialog.cpp b/src/libsnore/settings/settingsdialog.cpp index 7add146..0df3b72 100644 --- a/src/libsnore/settings/settingsdialog.cpp +++ b/src/libsnore/settings/settingsdialog.cpp @@ -20,6 +20,7 @@ #include "ui_settingsdialog.h" #include "snore.h" #include "snore_p.h" +#include "snoreconstants.h" #include "settings.h" #include @@ -42,7 +43,7 @@ SettingsDialog::~SettingsDialog() void SettingsDialog::initTabs() { - SnorePlugin::PluginTypes types = SnoreCore::instance().settingsValue(QStringLiteral("PluginTypes"), LocalSetting).value(); + SnorePlugin::PluginTypes types = SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PluginTypes).value(); if (types == SnorePlugin::None) { types = SnorePlugin::All; } @@ -90,9 +91,9 @@ void SettingsDialog::on_pushButton_clicked() void SettingsDialog::load() { qCDebug(SNORE) << "loading"; - loadPrimaryBackendBox(SnoreCore::instance().settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString()); - ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt()); - ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting).toBool()); + loadPrimaryBackendBox(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PrimaryBackend).toString()); + ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt()); + ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent).toBool()); foreach(auto widget, m_tabs) { widget->loadSettings(); } @@ -100,7 +101,7 @@ void SettingsDialog::load() void SettingsDialog::loadPrimaryBackendBox(const QString &backend) { - if (SnoreCore::instance().settingsValue(QStringLiteral("PluginTypes"), LocalSetting).value() & SnorePlugin::Backend) { + if (SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PluginTypes).value() & SnorePlugin::Backend) { ui->primaryBackendComboBox->clear(); QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::Backend); ui->primaryBackendComboBox->addItems(list); @@ -121,13 +122,13 @@ void SettingsDialog::save() w->saveSettings(); dirty |= w->isDirty(); } - dirty |= SnoreCore::instance().settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString() != ui->primaryBackendComboBox->currentText(); - dirty |= SnoreCore::instance().settingsValue(QStringLiteral("Timeout"), LocalSetting).toInt() != ui->timeoutSpinBox->value(); - dirty |= SnoreCore::instance().settingsValue(QStringLiteral("Silent"), LocalSetting).toBool() != ui->disableNotificationSoundCheckBox->isChecked(); + dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::PrimaryBackend).toString() != ui->primaryBackendComboBox->currentText(); + dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Timeout).toInt() != ui->timeoutSpinBox->value(); + dirty |= SnoreCore::instance().settingsValue(Snore::Constants::SettingsKeys::Silent).toBool() != ui->disableNotificationSoundCheckBox->isChecked(); - SnoreCore::instance().setSettingsValue(QStringLiteral("PrimaryBackend"), ui->primaryBackendComboBox->currentText(), LocalSetting); - SnoreCore::instance().setSettingsValue(QStringLiteral("Timeout"), ui->timeoutSpinBox->value(), LocalSetting); - SnoreCore::instance().setSettingsValue(QStringLiteral("Silent"), ui->disableNotificationSoundCheckBox->isChecked(), LocalSetting); + SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::PrimaryBackend, ui->primaryBackendComboBox->currentText()); + SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::Timeout, ui->timeoutSpinBox->value()); + SnoreCore::instance().setSettingsValue(Snore::Constants::SettingsKeys::Silent, ui->disableNotificationSoundCheckBox->isChecked()); if (dirty) { SnoreCorePrivate::instance()->syncSettings(); diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index 63e50da..36cfd3a 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -18,6 +18,7 @@ #include "snore.h" #include "snore_p.h" +#include "snoreconstants.h" #include "lambdahint.h" #include "notification/notification.h" #include "notification/notification_p.h" @@ -74,7 +75,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) return; } Q_D(SnoreCore); - setSettingsValue(QStringLiteral("PluginTypes"), QVariant::fromValue(types), LocalSetting); + setSettingsValue(Constants::SettingsKeys::PluginTypes, QVariant::fromValue(types)); qCDebug(SNORE) << "Loading plugin types:" << types; foreach(const SnorePlugin::PluginTypes type, SnorePlugin::types()) { if (type != SnorePlugin::All && types & type) { @@ -91,7 +92,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types) case SnorePlugin::Frontend: case SnorePlugin::Plugin: case SnorePlugin::Settings: - plugin->setEnabled(plugin->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool()); + plugin->setEnabled(plugin->settingsValue(Constants::SettingsKeys::Enabled).toBool()); break; default: qCWarning(SNORE) << "Plugin Cache corrupted\n" << info->file() << info->type(); @@ -209,26 +210,26 @@ void SnoreCore::setDefaultApplication(const Application app) d->m_defaultApp = app; } -QVariant SnoreCore::settingsValue(const QString &key, SettingsType type) const +QVariant SnoreCore::settingsValue(const SettingsKey &key) const { Q_D(const SnoreCore); - QString nk = d->normalizeSettingsKey(key, type); - if (type == LocalSetting && !d->m_settings->contains(nk)) { - nk = d->normalizeSettingsKey(key + QStringLiteral("-SnoreDefault"), type); + QString nk = d->normalizeSettingsKey(key.key, key.type); + if (key.type == LocalSetting && !d->m_settings->contains(nk)) { + nk = d->normalizeSettingsKey(key.key + QStringLiteral("-SnoreDefault"), key.type); } return d->m_settings->value(nk); } -void SnoreCore::setSettingsValue(const QString &key, const QVariant &value, SettingsType type) +void SnoreCore::setSettingsValue(const SettingsKey &key, const QVariant &value) { Q_D(SnoreCore); - d->m_settings->setValue(d->normalizeSettingsKey(key, type), value); + d->m_settings->setValue(d->normalizeSettingsKey(key.key, key.type), value); } -void SnoreCore::setDefaultSettingsValue(const QString &key, const QVariant &value, SettingsType type) +void SnoreCore::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value) { Q_D(SnoreCore); - QString nk = d->normalizeSettingsKey(key, type); + QString nk = d->normalizeSettingsKey(key.key, key.type); if (!d->m_settings->contains(nk)) { qCDebug(SNORE) << "Set default value" << nk << value; d->m_settings->setValue(nk, value); diff --git a/src/libsnore/snore.h b/src/libsnore/snore.h index a5fad19..7a91100 100644 --- a/src/libsnore/snore.h +++ b/src/libsnore/snore.h @@ -138,9 +138,9 @@ public: */ void setDefaultApplication(Application app); - QVariant settingsValue(const QString &key, SettingsType type = GlobalSetting) const; - void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting); - void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GlobalSetting); + QVariant settingsValue(const SettingsKey &key) const; + void setSettingsValue(const SettingsKey &key, const QVariant &value); + void setDefaultSettingsValue(const SettingsKey &key, const QVariant &settingsValue); Notification getActiveNotificationByID(uint id) const; diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index c68129f..583204c 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -18,6 +18,7 @@ #include "snore_p.h" #include "snore.h" +#include "snoreconstants.h" #include "plugins/plugins.h" #include "plugins/snorebackend.h" #include "plugins/snorefrontend.h" @@ -107,7 +108,7 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend) } m_notificationBackend = b; m_notificationBackend->enable(); - q->setSettingsValue(QStringLiteral("PrimaryBackend"), backend, LocalSetting); + q->setSettingsValue(Constants::SettingsKeys::PrimaryBackend, backend); connect(b, &SnoreBackend::error, [this, b](const QString &) { slotInitPrimaryNotificationBackend(); @@ -121,8 +122,8 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend) bool SnoreCorePrivate::slotInitPrimaryNotificationBackend() { Q_Q(SnoreCore); - qCDebug(SNORE) << q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString(); - if (setBackendIfAvailible(q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString())) { + qCDebug(SNORE) << q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString(); + if (setBackendIfAvailible(q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString())) { return true; } #ifdef Q_OS_WIN @@ -171,7 +172,7 @@ void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const Q void SnoreCorePrivate::syncSettings() { Q_Q(SnoreCore); - QString newBackend = q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString(); + QString newBackend = q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString(); if (!newBackend.isEmpty()) { QString oldBackend; if (m_notificationBackend) { @@ -180,7 +181,7 @@ void SnoreCorePrivate::syncSettings() m_notificationBackend = nullptr; } if (!setBackendIfAvailible(newBackend)) { - qCWarning(SNORE) << "Failed to set new backend" << q->settingsValue(QStringLiteral("PrimaryBackend"), LocalSetting).toString() << "restoring" << oldBackend; + qCWarning(SNORE) << "Failed to set new backend" << q->settingsValue(Constants::SettingsKeys::PrimaryBackend).toString() << "restoring" << oldBackend; setBackendIfAvailible(oldBackend); } } @@ -191,7 +192,7 @@ void SnoreCorePrivate::syncSettings() foreach(auto & pluginName, m_pluginNames[type]) { auto key = qMakePair(type, pluginName); SnorePlugin *plugin = m_plugins.value(key); - bool enable = m_plugins[key]->settingsValue(QStringLiteral("Enabled"), LocalSetting).toBool(); + bool enable = m_plugins[key]->settingsValue(Constants::SettingsKeys::Enabled).toBool(); plugin->setEnabled(enable); } } diff --git a/src/libsnore/snoreconstants.h b/src/libsnore/snoreconstants.h new file mode 100644 index 0000000..19dfb2f --- /dev/null +++ b/src/libsnore/snoreconstants.h @@ -0,0 +1,22 @@ +#ifndef SNORECONSTANTS_H +#define SNORECONSTANTS_H + +#include "snoreglobals.h" + +#include + +namespace Snore { +namespace Constants { +namespace SettingsKeys { +static const SettingsKey PrimaryBackend = {QStringLiteral("PrimaryBackend"), GlobalSetting}; +static const SettingsKey Timeout = {QStringLiteral("Timeout"), GlobalSetting}; +static const SettingsKey Silent = {QStringLiteral("Silent"), LocalSetting}; +static const SettingsKey Enabled = {QStringLiteral("Enabled"), LocalSetting}; +static const SettingsKey PluginTypes = {QStringLiteral("PluginTypes"), LocalSetting}; + +} + +} +} + +#endif // SNORECONSTANTS_H diff --git a/src/libsnore/snoreglobals.h b/src/libsnore/snoreglobals.h index d1f5f1e..3aaff50 100644 --- a/src/libsnore/snoreglobals.h +++ b/src/libsnore/snoreglobals.h @@ -31,6 +31,11 @@ enum SettingsType { LocalSetting }; +struct SettingsKey { + QString key; + SettingsType type; +}; + } SNORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(SNORE) diff --git a/src/plugins/backends/growl/growlbackend.cpp b/src/plugins/backends/growl/growlbackend.cpp index fda2c0c..e99d3e7 100644 --- a/src/plugins/backends/growl/growlbackend.cpp +++ b/src/plugins/backends/growl/growlbackend.cpp @@ -17,6 +17,7 @@ */ #include "growlbackend.h" +#include "growlconstants.h" #include "libsnore/snore.h" #include "libsnore/snore_p.h" @@ -63,7 +64,7 @@ SnorePlugin::Growl::~Growl() bool SnorePlugin::Growl::isReady() { - bool running = ::Growl::isRunning(GROWL_TCP, settingsValue(QStringLiteral("Host")).toString().toUtf8().constData()); + bool running = ::Growl::isRunning(GROWL_TCP, settingsValue(GrowlConstants::Host).toString().toUtf8().constData()); if (!running) { setErrorString(tr("%1 is not running.").arg(name())); } @@ -80,8 +81,8 @@ void SnorePlugin::Growl::slotRegisterApplication(const Snore::Application &appli alerts.push_back(a.name().toUtf8().constData()); } - ::Growl *growl = new ::Growl(GROWL_TCP, settingsValue(QStringLiteral("Host")).toString().toUtf8().constData(), - settingsValue(QStringLiteral("Password")).toString().toUtf8().constData(), + ::Growl *growl = new ::Growl(GROWL_TCP, settingsValue(GrowlConstants::Host).toString().toUtf8().constData(), + settingsValue(GrowlConstants::Password).toString().toUtf8().constData(), application.name().toUtf8().constData()); m_applications.insert(application.name(), growl); growl->Register(alerts, application.icon().localUrl(QSize(128, 128)).toUtf8().constData()); @@ -117,7 +118,7 @@ void SnorePlugin::Growl::slotNotify(Snore::Notification notification) void SnorePlugin::Growl::setDefaultSettings() { SnoreBackend::setDefaultSettings(); - setDefaultSettingsValue(QStringLiteral("Host"), QLatin1String("localhost")); - setDefaultSettingsValue(QStringLiteral("Password"), QString()); + setDefaultSettingsValue(GrowlConstants::Host, QLatin1String("localhost")); + setDefaultSettingsValue(GrowlConstants::Password, QString()); } diff --git a/src/plugins/backends/growl/growlconstants.h b/src/plugins/backends/growl/growlconstants.h new file mode 100644 index 0000000..2295d1d --- /dev/null +++ b/src/plugins/backends/growl/growlconstants.h @@ -0,0 +1,12 @@ +#ifndef GROWLCONSTANTS_H +#define GROWLCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace GrowlConstants { +static const Snore::SettingsKey Host = {QStringLiteral("Host"), Snore::GlobalSetting}; +static const Snore::SettingsKey Password = {QStringLiteral("Password"), Snore::GlobalSetting}; + +} + +#endif // GROWLCONSTANTS_H diff --git a/src/plugins/backends/growl/growlsettings.cpp b/src/plugins/backends/growl/growlsettings.cpp index 0d995ed..486cb32 100644 --- a/src/plugins/backends/growl/growlsettings.cpp +++ b/src/plugins/backends/growl/growlsettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "growlsettings.h" +#include "growlconstants.h" #include @@ -36,13 +37,13 @@ GrowlSettings::~GrowlSettings() void GrowlSettings::load() { - m_host->setText(settingsValue(QStringLiteral("Host")).toString()); - m_password->setText(settingsValue(QStringLiteral("Password")).toString()); + m_host->setText(settingsValue(GrowlConstants::Host).toString()); + m_password->setText(settingsValue(GrowlConstants::Password).toString()); } void GrowlSettings::save() { - setSettingsValue(QStringLiteral("Host"), m_host->text()); - setSettingsValue(QStringLiteral("Password"), m_password->text()); + setSettingsValue(GrowlConstants::Host, m_host->text()); + setSettingsValue(GrowlConstants::Password, m_password->text()); } diff --git a/src/plugins/backends/snarl/snarl.cpp b/src/plugins/backends/snarl/snarl.cpp index e767b16..b2ca9d9 100644 --- a/src/plugins/backends/snarl/snarl.cpp +++ b/src/plugins/backends/snarl/snarl.cpp @@ -17,6 +17,7 @@ */ #include "snarl.h" +#include "snarlconstants.h" #include "libsnore/snore.h" #include "libsnore/snore_p.h" @@ -157,7 +158,7 @@ bool SnorePlugin::Snarl::isReady() void SnorePlugin::Snarl::setDefaultSettings() { - setDefaultSettingsValue(QLatin1String("Password"), QString()); + setDefaultSettingsValue(SnarlConstants::Password, QString()); SnoreBackend::setDefaultSettings(); } @@ -171,7 +172,7 @@ void SnorePlugin::Snarl::slotRegisterApplication(const Snore::Application &appli m_applications.insert(application.name(), snarlInterface); QString appName = application.name().replace(QLatin1Char(' '), QLatin1Char('_')); //app sig must not contain spaces - QString password = settingsValue(QLatin1String("Password")).toString(); + QString password = settingsValue(SnarlConstants::Password).toString(); LONG32 result = snarlInterface->Register(appName.toUtf8().constData(), application.name().toUtf8().constData(), application.icon().localUrl(QSize(128, 128)).toUtf8().constData(), diff --git a/src/plugins/backends/snarl/snarlconstants.h b/src/plugins/backends/snarl/snarlconstants.h new file mode 100644 index 0000000..05fa45a --- /dev/null +++ b/src/plugins/backends/snarl/snarlconstants.h @@ -0,0 +1,9 @@ +#ifndef SNARLCONSTANTS_H +#define SNARLCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace SnarlConstants { +static const Snore::SettingsKey Password = {QStringLiteral("Password"), Snore::LocalSetting}; +} +#endif // SNARLCONSTANTS_H diff --git a/src/plugins/backends/snarl/snarlsettings.cpp b/src/plugins/backends/snarl/snarlsettings.cpp index a63b83e..9c84447 100644 --- a/src/plugins/backends/snarl/snarlsettings.cpp +++ b/src/plugins/backends/snarl/snarlsettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "snarlsettings.h" +#include "snarlconstants.h" #include @@ -34,11 +35,11 @@ SnarlSettings::~SnarlSettings() void SnarlSettings::load() { - m_password->setText(settingsValue(QLatin1String("Password")).toString()); + m_password->setText(settingsValue(SnarlConstants::Password).toString()); } void SnarlSettings::save() { - setSettingsValue(QLatin1String("Password"), m_password->text()); + setSettingsValue(SnarlConstants::Password, m_password->text()); } diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp index e22366d..d77753d 100644 --- a/src/plugins/backends/snore/notifywidget.cpp +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -18,6 +18,7 @@ #include "notifywidget.h" #include "snorenotifier.h" +#include "snorebackendconstants.h" #include "libsnore/utils.h" #include @@ -179,7 +180,7 @@ int NotifyWidget::id() const void NotifyWidget::syncSettings() { - Qt::Corner c = static_cast(m_parent->settingsValue(QStringLiteral("Position")).toInt()); + Qt::Corner c = static_cast(m_parent->settingsValue(SnoreBackendConstants::Position).toInt()); if (c != m_corner || !m_initialized) { m_initialized = true; m_corner = c; diff --git a/src/plugins/backends/snore/snorebackendconstants.h b/src/plugins/backends/snore/snorebackendconstants.h new file mode 100644 index 0000000..7274f25 --- /dev/null +++ b/src/plugins/backends/snore/snorebackendconstants.h @@ -0,0 +1,11 @@ +#ifndef SNOREBACKENDCONSTANTS_H +#define SNOREBACKENDCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace SnoreBackendConstants +{ +static const Snore::SettingsKey Position = {QStringLiteral("Position"), Snore::GlobalSetting}; +} + +#endif // SNOREBACKENDCONSTANTS_H diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp index 58016a5..a0f696d 100644 --- a/src/plugins/backends/snore/snorenotifier.cpp +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -18,6 +18,7 @@ #include "snorenotifier.h" #include "notifywidget.h" +#include "snorebackendconstants.h" #include "libsnore/notification/notification_p.h" #include "libsnore/snore_p.h" @@ -107,6 +108,6 @@ int SnorePlugin::Snore::maxNumberOfActiveNotifications() const void SnorePlugin::Snore::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("Position"), Qt::TopRightCorner); + setDefaultSettingsValue(SnoreBackendConstants::Position, Qt::TopRightCorner); SnoreBackend::setDefaultSettings(); } diff --git a/src/plugins/backends/snore/snorenotifiersettings.cpp b/src/plugins/backends/snore/snorenotifiersettings.cpp index 6d46e42..be7dc48 100644 --- a/src/plugins/backends/snore/snorenotifiersettings.cpp +++ b/src/plugins/backends/snore/snorenotifiersettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "snorenotifiersettings.h" +#include "snorebackendconstants.h" #include "snore.h" #include @@ -37,10 +38,10 @@ SnoreSettings::~SnoreSettings() void SnoreSettings::load() { - m_comboBox->setCurrentIndex(settingsValue(QStringLiteral("Position")).toInt()); + m_comboBox->setCurrentIndex(settingsValue(SnoreBackendConstants::Position).toInt()); } void SnoreSettings::save() { - setSettingsValue(QStringLiteral("Position"), m_comboBox->currentIndex()); + setSettingsValue(SnoreBackendConstants::Position, m_comboBox->currentIndex()); } diff --git a/src/plugins/frontends/pushover_frontend/pushover_frontend.cpp b/src/plugins/frontends/pushover_frontend/pushover_frontend.cpp index c798758..9a6628e 100644 --- a/src/plugins/frontends/pushover_frontend/pushover_frontend.cpp +++ b/src/plugins/frontends/pushover_frontend/pushover_frontend.cpp @@ -23,6 +23,11 @@ #include "libsnore/notification/notification_p.h" #include "libsnore/hint.h" +namespace { +static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::GlobalSetting}; +static const Snore::SettingsKey Secret = {QStringLiteral("Secret"), Snore::GlobalSetting}; +} + using namespace Snore; PushoverFrontend::PushoverFrontend(): @@ -40,8 +45,8 @@ PushoverFrontend::PushoverFrontend(): void PushoverFrontend::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("Secret"), QString(), LocalSetting); - setDefaultSettingsValue(QStringLiteral("DeviceID"), QString(), LocalSetting); + setDefaultSettingsValue(Secret, QString()); + setDefaultSettingsValue(DeviceID, QString()); SnoreFrontend::setDefaultSettings(); } diff --git a/src/plugins/frontends/pushover_frontend/pushoverclient.cpp b/src/plugins/frontends/pushover_frontend/pushoverclient.cpp index 9560a77..b43cd2b 100644 --- a/src/plugins/frontends/pushover_frontend/pushoverclient.cpp +++ b/src/plugins/frontends/pushover_frontend/pushoverclient.cpp @@ -18,6 +18,8 @@ #include "pushoverclient.h" #include "pushover_frontend.h" +#include "../../secondary_backends/pushover_backend/pushoverconstants.h" + #include "libsnore/snore.h" #include "libsnore/notification/notification_p.h" @@ -47,7 +49,7 @@ PushoverClient::PushoverClient(PushoverFrontend *frontend): void PushoverClient::login(const QString &email, const QString &password, const QString &deviceName) { - m_frontend->setSettingsValue(QStringLiteral("DeviceName"), deviceName, Snore::LocalSetting); + m_frontend->setSettingsValue(PushoverConstants::DeviceName, deviceName); QNetworkRequest request(QUrl(QStringLiteral("https://api.pushover.net/1/users/login.json"))); @@ -73,8 +75,8 @@ void PushoverClient::login(const QString &email, const QString &password, const void PushoverClient::logOut() { - m_frontend->setSettingsValue(QStringLiteral("Secret"), QString(), LocalSetting); - m_frontend->setSettingsValue(QStringLiteral("DeviceID"), QString(), LocalSetting); + m_frontend->setSettingsValue(PushoverConstants::Secret, QString()); + m_frontend->setSettingsValue(PushoverConstants::DeviceID, QString()); m_socket->close(); m_socket->deleteLater(); emit loggedInChanged(LoggedOut); @@ -92,12 +94,12 @@ QString PushoverClient::errorMessage() QString PushoverClient::secret() { - return m_frontend->settingsValue(QStringLiteral("Secret"), LocalSetting).toString(); + return m_frontend->settingsValue(PushoverConstants::Secret).toString(); } QString PushoverClient::device() { - return m_frontend->settingsValue(QStringLiteral("DeviceID"), LocalSetting).toString(); + return m_frontend->settingsValue(PushoverConstants::DeviceID).toString(); } void PushoverClient::connectToService() @@ -175,8 +177,8 @@ void PushoverClient::registerDevice(const QString &secret, const QString &device reply->deleteLater(); QJsonObject message = QJsonDocument::fromJson(input).object(); if (message.value(QStringLiteral("status")).toInt() == 1) { - m_frontend->setSettingsValue(QStringLiteral("Secret"), secret, LocalSetting); - m_frontend->setSettingsValue(QStringLiteral("DeviceID"), message.value(QStringLiteral("id")).toString(), LocalSetting);; + m_frontend->setSettingsValue(PushoverConstants::Secret, secret); + m_frontend->setSettingsValue(PushoverConstants::DeviceID, message.value(QStringLiteral("id")).toString()); connectToService(); } else { qCWarning(SNORE) << "An error occured" << input; diff --git a/src/plugins/frontends/pushover_frontend/pushoversettings.cpp b/src/plugins/frontends/pushover_frontend/pushoversettings.cpp index c44b201..35f5212 100644 --- a/src/plugins/frontends/pushover_frontend/pushoversettings.cpp +++ b/src/plugins/frontends/pushover_frontend/pushoversettings.cpp @@ -17,6 +17,7 @@ */ #include "pushoversettings.h" #include "pushoverclient.h" +#include "../../secondary_backends/pushover_backend/pushoverconstants.h" #include "libsnore/plugins/plugins.h" #include "libsnore/hint.h" @@ -80,7 +81,7 @@ PushoverSettings::~PushoverSettings() void PushoverSettings::load() { - m_deviceLineEdit->setText(settingsValue(QStringLiteral("DeviceName"), Snore::LocalSetting).toString()); + m_deviceLineEdit->setText(settingsValue(PushoverConstants::Devices).toString()); } void PushoverSettings::save() diff --git a/src/plugins/secondary_backends/nma/nma.cpp b/src/plugins/secondary_backends/nma/nma.cpp index 4e4f482..bee3c5f 100644 --- a/src/plugins/secondary_backends/nma/nma.cpp +++ b/src/plugins/secondary_backends/nma/nma.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "nma.h" +#include "nmaconstants.h" #include "libsnore/utils.h" @@ -26,7 +27,7 @@ namespace SnorePlugin { void NMA::slotNotify(Snore::Notification notification) { - QString key = settingsValue(QStringLiteral("ApiKey")).toString(); + QString key = settingsValue(NMAConstants::ApiKey).toString(); if (key.isEmpty()) { return; } @@ -60,7 +61,7 @@ void NMA::slotNotify(Snore::Notification notification) void NMA::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("ApiKey"), QString()); + setDefaultSettingsValue(NMAConstants::ApiKey, QString()); SnoreSecondaryBackend::setDefaultSettings(); } diff --git a/src/plugins/secondary_backends/nma/nmaconstants.h b/src/plugins/secondary_backends/nma/nmaconstants.h new file mode 100644 index 0000000..6321039 --- /dev/null +++ b/src/plugins/secondary_backends/nma/nmaconstants.h @@ -0,0 +1,9 @@ +#ifndef NMACONSTANTS_H +#define NMACONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace NMAConstants { +static const Snore::SettingsKey ApiKey = {QStringLiteral("ApiKey"), Snore::GlobalSetting}; +} +#endif // NMACONSTANTS_H diff --git a/src/plugins/secondary_backends/nma/nmasettings.cpp b/src/plugins/secondary_backends/nma/nmasettings.cpp index e7a08e5..08230c7 100644 --- a/src/plugins/secondary_backends/nma/nmasettings.cpp +++ b/src/plugins/secondary_backends/nma/nmasettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "nmasettings.h" +#include "nmaconstants.h" #include "libsnore/plugins/plugins.h" @@ -36,10 +37,10 @@ NMASettings::~NMASettings() void NMASettings::load() { - m_lineEdit->setText(settingsValue(QStringLiteral("ApiKey")).toString()); + m_lineEdit->setText(settingsValue(NMAConstants::ApiKey).toString()); } void NMASettings::save() { - setSettingsValue(QStringLiteral("ApiKey"), m_lineEdit->text()); + setSettingsValue(NMAConstants::ApiKey, m_lineEdit->text()); } diff --git a/src/plugins/secondary_backends/pushover_backend/pushover.cpp b/src/plugins/secondary_backends/pushover_backend/pushover.cpp index b8bfb65..723825d 100644 --- a/src/plugins/secondary_backends/pushover_backend/pushover.cpp +++ b/src/plugins/secondary_backends/pushover_backend/pushover.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "pushover.h" +#include "pushoverconstants.h" #include "libsnore/utils.h" #include "libsnore/notification/notification_p.h" @@ -32,7 +33,7 @@ void Pushover::slotNotify(Snore::Notification notification) return; } - QString key = settingsValue(QStringLiteral("UserKey")).toString(); + QString key = settingsValue(PushoverConstants::UserKey).toString(); if (key.isEmpty()) { return; } @@ -86,14 +87,14 @@ void Pushover::slotNotify(Snore::Notification notification) if (notification.hints().value("silent").toBool()) { sound.setBody("none"); } else { - sound.setBody(settingsValue(QStringLiteral("Sound"), Snore::LocalSetting).toString().toUtf8().constData()); + sound.setBody((settingsValue(PushoverConstants::Sound)).toString().toUtf8().constData()); } mp->append(sound); - if (!settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString().isEmpty()) { + if (!settingsValue(PushoverConstants::Devices).toString().isEmpty()) { QHttpPart devices; devices.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant(QLatin1String("form-data; name=\"device\""))); - devices.setBody(settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString().toUtf8().constData()); + devices.setBody(settingsValue(PushoverConstants::Devices).toString().toUtf8().constData()); mp->append(devices); } @@ -121,9 +122,9 @@ void Pushover::slotNotify(Snore::Notification notification) void Pushover::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("UserKey"), QString()); - setDefaultSettingsValue(QStringLiteral("Sound"), QLatin1String("pushover"), Snore::LocalSetting); - setDefaultSettingsValue(QStringLiteral("Devices"), QString(), Snore::LocalSetting); + setDefaultSettingsValue(PushoverConstants::UserKey, QString()); + setDefaultSettingsValue(PushoverConstants::Sound, QLatin1String("pushover")); + setDefaultSettingsValue(PushoverConstants::Devices, QString()); SnoreSecondaryBackend::setDefaultSettings(); } diff --git a/src/plugins/secondary_backends/pushover_backend/pushoverconstants.h b/src/plugins/secondary_backends/pushover_backend/pushoverconstants.h new file mode 100644 index 0000000..23abd13 --- /dev/null +++ b/src/plugins/secondary_backends/pushover_backend/pushoverconstants.h @@ -0,0 +1,17 @@ +#ifndef PUSHOVERCONSTANTS_H +#define PUSHOVERCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace PushoverConstants { +static const Snore::SettingsKey UserKey = {QStringLiteral("UserKey"), Snore::GlobalSetting}; +static const Snore::SettingsKey Devices = {QStringLiteral("Devices"), Snore::LocalSetting}; +static const Snore::SettingsKey Sound = {QStringLiteral("Sound"), Snore::LocalSetting}; + +//frontend +static const Snore::SettingsKey Secret = {QStringLiteral("Secret"), Snore::LocalSetting}; +static const Snore::SettingsKey DeviceName = {QStringLiteral("DeviceName"), Snore::LocalSetting}; +static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::LocalSetting}; + +} +#endif // PUSHOVERCONSTANTS_H diff --git a/src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp b/src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp index 3ea0454..58de2ba 100644 --- a/src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp +++ b/src/plugins/secondary_backends/pushover_backend/pushoversettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "pushoversettings.h" +#include "pushoverconstants.h" #include "plugins/plugins.h" @@ -40,14 +41,14 @@ PushoverSettings::~PushoverSettings() void PushoverSettings::load() { - m_keyLineEdit->setText(settingsValue(QStringLiteral("UserKey")).toString()); - m_soundLineEdit->setText(settingsValue(QStringLiteral("Sound"), Snore::LocalSetting).toString()); - m_deviceLineEdit->setText(settingsValue(QStringLiteral("Devices"), Snore::LocalSetting).toString()); + m_keyLineEdit->setText(settingsValue(PushoverConstants::UserKey).toString()); + m_soundLineEdit->setText(settingsValue(PushoverConstants::Sound).toString()); + m_deviceLineEdit->setText(settingsValue(PushoverConstants::Devices).toString()); } void PushoverSettings::save() { - setSettingsValue(QStringLiteral("UserKey"), m_keyLineEdit->text()); - setSettingsValue(QStringLiteral("Sound"), m_soundLineEdit->text(), Snore::LocalSetting); - setSettingsValue(QStringLiteral("Devices"), m_deviceLineEdit->text(), Snore::LocalSetting); + setSettingsValue(PushoverConstants::UserKey, m_keyLineEdit->text()); + setSettingsValue(PushoverConstants::Sound, m_soundLineEdit->text()); + setSettingsValue(PushoverConstants::Devices, m_deviceLineEdit->text()); } diff --git a/src/plugins/secondary_backends/sound/sound.cpp b/src/plugins/secondary_backends/sound/sound.cpp index 96f6e0e..f0715f0 100644 --- a/src/plugins/secondary_backends/sound/sound.cpp +++ b/src/plugins/secondary_backends/sound/sound.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "sound.h" +#include "soundconstants.h" #include #include @@ -35,7 +36,7 @@ Sound::Sound(): void Sound::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("Volume"), 50); + setDefaultSettingsValue(SoundConstants::Volume, 50); SnoreSecondaryBackend::setDefaultSettings(); } @@ -44,11 +45,11 @@ void Sound::slotNotificationDisplayed(Snore::Notification notification) if (notification.hints().value("silent").toBool()) { return; } - m_player->setVolume(settingsValue(QStringLiteral("Volume")).toInt()); + m_player->setVolume(settingsValue(SoundConstants::Volume).toInt()); QString sound = notification.hints().value("sound").toString(); if (sound.isEmpty()) { - sound = settingsValue(QStringLiteral("Sound")).toString(); + sound = settingsValue(SoundConstants::SoundKey).toString(); } qCDebug(SNORE) << "SoundFile:" << sound; if (!sound.isEmpty()) { diff --git a/src/plugins/secondary_backends/sound/soundconstants.h b/src/plugins/secondary_backends/sound/soundconstants.h new file mode 100644 index 0000000..bc1c00c --- /dev/null +++ b/src/plugins/secondary_backends/sound/soundconstants.h @@ -0,0 +1,11 @@ +#ifndef SOUNDCONSTANTS_H +#define SOUNDCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace SoundConstants { +static const Snore::SettingsKey Volume = {QStringLiteral("Volume"), Snore::GlobalSetting}; +static const Snore::SettingsKey SoundKey = {QStringLiteral("Sound"), Snore::LocalSetting}; + +} +#endif // SOUNDCONSTANTS_H diff --git a/src/plugins/secondary_backends/sound/soundsettings.cpp b/src/plugins/secondary_backends/sound/soundsettings.cpp index b9836d2..44ba557 100644 --- a/src/plugins/secondary_backends/sound/soundsettings.cpp +++ b/src/plugins/secondary_backends/sound/soundsettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "soundsettings.h" +#include "soundconstants.h" #include "plugins/plugins.h" #include @@ -52,13 +53,13 @@ SoundSettings::~SoundSettings() void SoundSettings::load() { - m_lineEditFileName->setText(settingsValue(QStringLiteral("Sound")).toString()); - m_spinBoxVolume->setValue(settingsValue(QStringLiteral("Volume")).toInt()); + m_lineEditFileName->setText(settingsValue(SoundConstants::SoundKey).toString()); + m_spinBoxVolume->setValue(settingsValue(SoundConstants::Volume).toInt()); } void SoundSettings::save() { - setSettingsValue(QStringLiteral("Sound"), m_lineEditFileName->text()); - setSettingsValue(QStringLiteral("Volume"), m_spinBoxVolume->value()); + setSettingsValue(SoundConstants::SoundKey, m_lineEditFileName->text()); + setSettingsValue(SoundConstants::Volume, m_spinBoxVolume->value()); } diff --git a/src/plugins/secondary_backends/toasty/toasty.cpp b/src/plugins/secondary_backends/toasty/toasty.cpp index 662c419..bbd5417 100644 --- a/src/plugins/secondary_backends/toasty/toasty.cpp +++ b/src/plugins/secondary_backends/toasty/toasty.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "toasty.h" +#include "toastyconstants.h" #include "libsnore/utils.h" @@ -28,7 +29,7 @@ namespace SnorePlugin { void Toasty::slotNotify(Snore::Notification notification) { - QString key = settingsValue(QStringLiteral("DeviceID")).toString(); + QString key = settingsValue(ToastyConstants::DeviceID).toString(); if (key.isEmpty()) { return; } @@ -74,7 +75,7 @@ void Toasty::slotNotify(Snore::Notification notification) void Toasty::setDefaultSettings() { - setDefaultSettingsValue(QStringLiteral("DeviceID"), QString()); + setDefaultSettingsValue(ToastyConstants::DeviceID, QString()); SnoreSecondaryBackend::setDefaultSettings(); } diff --git a/src/plugins/secondary_backends/toasty/toastyconstants.h b/src/plugins/secondary_backends/toasty/toastyconstants.h new file mode 100644 index 0000000..d8cb987 --- /dev/null +++ b/src/plugins/secondary_backends/toasty/toastyconstants.h @@ -0,0 +1,11 @@ +#ifndef TOASTYCONSTANTS_H +#define TOASTYCONSTANTS_H + +#include "libsnore/snoreglobals.h" + +namespace ToastyConstants { +static const Snore::SettingsKey DeviceID = {QStringLiteral("DeviceID"), Snore::GlobalSetting}; +} + + +#endif // TOASTYCONSTANTS_H diff --git a/src/plugins/secondary_backends/toasty/toastysettings.cpp b/src/plugins/secondary_backends/toasty/toastysettings.cpp index d521334..4f62155 100644 --- a/src/plugins/secondary_backends/toasty/toastysettings.cpp +++ b/src/plugins/secondary_backends/toasty/toastysettings.cpp @@ -16,6 +16,7 @@ along with SnoreNotify. If not, see . */ #include "toastysettings.h" +#include "toastyconstants.h" #include "plugins/plugins.h" @@ -36,10 +37,10 @@ ToastySettings::~ToastySettings() void ToastySettings::load() { - m_lineEdit->setText(settingsValue(QStringLiteral("DeviceID")).toString()); + m_lineEdit->setText(settingsValue(ToastyConstants::DeviceID).toString()); } void ToastySettings::save() { - setSettingsValue(QStringLiteral("DeviceID"), m_lineEdit->text()); + setSettingsValue(ToastyConstants::DeviceID, m_lineEdit->text()); }