From f00b7dd6e9853bdb7258d7849ec0b88ca01ef93a Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 24 Jun 2015 12:35:58 +0200 Subject: [PATCH] Make it possible to override default value with app specific default values --- src/libsnore/snore.cpp | 6 +++++- src/libsnore/snore_p.cpp | 13 +++++++++++-- src/libsnore/snore_p.h | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index b18cd70..5fe4d60 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -210,7 +210,11 @@ QList SnoreCore::settingWidgets(SnorePlugin::PluginTypes QVariant SnoreCore::value(const QString &key, SettingsType type) const { Q_D(const SnoreCore); - return d->m_settings->value(d->normalizeKey(key, type)); + QString nk = d->normalizeKey(key, type); + if(key == LOCAL_SETTING && !d->m_settings->contains(nk)){ + nk = d->normalizeKey(QString("%1-SnoreDefault").arg(key),type); + } + return d->m_settings->value(nk); } void SnoreCore::setValue(const QString &key, const QVariant &value, SettingsType type) diff --git a/src/libsnore/snore_p.cpp b/src/libsnore/snore_p.cpp index b292873..004759e 100644 --- a/src/libsnore/snore_p.cpp +++ b/src/libsnore/snore_p.cpp @@ -139,11 +139,20 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend() void SnoreCorePrivate::init() { Q_Q(SnoreCore); - q->setDefaultValue("Timeout", 10, LOCAL_SETTING); - q->setDefaultValue("Silent", false, LOCAL_SETTING); + setDefaultValueIntern("Timeout", 10); + setDefaultValueIntern("Silent", false); q->setDefaultApplication(Application("SnoreNotify", Icon(":/root/snore.png"))); } +void SnoreCorePrivate::setDefaultValueIntern(const QString &key, const QVariant &value) +{ + Q_Q(SnoreCore); + QString nk = normalizeKey(QString("%1-SnoreDefault").arg(key), LOCAL_SETTING); + if (!m_settings->contains(nk)) { + m_settings->setValue(nk, value); + } +} + void SnoreCorePrivate::syncSettings() { Q_Q(SnoreCore); diff --git a/src/libsnore/snore_p.h b/src/libsnore/snore_p.h index 59c5e4f..d63fdb5 100644 --- a/src/libsnore/snore_p.h +++ b/src/libsnore/snore_p.h @@ -71,6 +71,11 @@ public: void init(); + /** + * Set a default value wich can be overritten by a client application call to SnoreCore::setDefaultValue() + */ + void setDefaultValueIntern(const QString &key, const QVariant &value); + private slots: //TODO: find a better solutinon for the slots in this section friend class Snore::SnoreBackend;