cleanup and better versioning of settings

This commit is contained in:
Patrick von Reth 2015-03-01 17:22:05 +01:00
parent 50ed661214
commit 70dfad1234
4 changed files with 13 additions and 28 deletions

View File

@ -85,7 +85,7 @@ Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
QString SnorePlugin::normaliseKey(const QString &key) const QString SnorePlugin::normaliseKey(const QString &key) const
{ {
return QString("%1/%2/%3").arg(m_name, settingsVersion(), key); return QString("%1/%2.%3").arg(m_name, key, settingsVersion());
} }
const QString &SnorePlugin::name() const const QString &SnorePlugin::name() const
@ -105,7 +105,7 @@ const QString SnorePlugin::typeName() const
QString SnorePlugin::settingsVersion() const QString SnorePlugin::settingsVersion() const
{ {
return "1"; return "v1";
} }
bool SnorePlugin::deinitialize() bool SnorePlugin::deinitialize()

View File

@ -197,35 +197,20 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
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);
QString nk = d->versionizeKey(key); return d->m_settings->value(d->normalizeKey(key,type));
if(type == LOCAL_SETTING)
{
nk = d->normalizeKey(key);
}
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)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
QString nk = d->versionizeKey(key); d->m_settings->setValue(d->normalizeKey(key,type),value);
if(type == LOCAL_SETTING)
{
nk = d->normalizeKey(key);
}
d->m_settings->setValue(nk,value);
} }
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, SettingsType type) void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, SettingsType type)
{ {
Q_D(SnoreCore); Q_D(SnoreCore);
QString nk = d->versionizeKey(key); QString nk = d->normalizeKey(key,type);
if(type == LOCAL_SETTING)
{
nk = d->normalizeKey(key);
}
if (!d->m_settings->contains(nk)) { if (!d->m_settings->contains(nk)) {
d->m_settings->setValue(nk, value); d->m_settings->setValue(nk, value);
} }

View File

@ -41,6 +41,7 @@ SnoreCorePrivate::SnoreCorePrivate():
snoreDebug(SNORE_DEBUG) << "Temp dir is" << tempPath(); snoreDebug(SNORE_DEBUG) << "Temp dir is" << tempPath();
snoreDebug(SNORE_DEBUG) << "Snore settings are located in" << m_settings->fileName(); snoreDebug(SNORE_DEBUG) << "Snore settings are located in" << m_settings->fileName();
snoreDebug(SNORE_DEBUG) << "Snore local settings are located in" << normalizeKey("Test", LOCAL_SETTING);
m_defaultApp.addAlert(Alert("Default", Icon(":/root/snore.png"))); m_defaultApp.addAlert(Alert("Default", Icon(":/root/snore.png")));
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit())); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit()));

View File

@ -67,18 +67,17 @@ public:
bool initPrimaryNotificationBackend(); bool initPrimaryNotificationBackend();
inline QString versionSchema() const { inline QString versionSchema() const {
return "1"; return "v1";
} }
void syncSettings(); void syncSettings();
QString normalizeKey(const QString &key, SettingsType type) const{
QString versionizeKey(const QString &key) const{ if(type == LOCAL_SETTING) {
return QString("%1/%2").arg(key, versionSchema()); return QString("%1/LocalSettings/%2.%3/%4").arg(versionSchema(), qApp->organizationName(), qApp->applicationName(), key);
} else {
return QString("%1/%2").arg(versionSchema(), key);
} }
QString normalizeKey(const QString &key) const{
return versionizeKey(QString("LocalSettings/%1.%2/%3").arg(qApp->organizationName(), qApp->applicationName(), key));
} }