Make it possible to override default value with app specific default values

This commit is contained in:
Patrick von Reth 2015-06-24 12:35:58 +02:00
parent 051e2d1818
commit f00b7dd6e9
3 changed files with 21 additions and 3 deletions

View File

@ -210,7 +210,11 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets(SnorePlugin::PluginTypes
QVariant SnoreCore::value(const QString &key, SettingsType type) const QVariant SnoreCore::value(const QString &key, SettingsType type) const
{ {
Q_D(const SnoreCore); 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) void SnoreCore::setValue(const QString &key, const QVariant &value, SettingsType type)

View File

@ -139,11 +139,20 @@ bool SnoreCorePrivate::initPrimaryNotificationBackend()
void SnoreCorePrivate::init() void SnoreCorePrivate::init()
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);
q->setDefaultValue("Timeout", 10, LOCAL_SETTING); setDefaultValueIntern("Timeout", 10);
q->setDefaultValue("Silent", false, LOCAL_SETTING); setDefaultValueIntern("Silent", false);
q->setDefaultApplication(Application("SnoreNotify", Icon(":/root/snore.png"))); 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() void SnoreCorePrivate::syncSettings()
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);

View File

@ -71,6 +71,11 @@ public:
void init(); 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: private slots:
//TODO: find a better solutinon for the slots in this section //TODO: find a better solutinon for the slots in this section
friend class Snore::SnoreBackend; friend class Snore::SnoreBackend;