cleanup and better versioning of settings
This commit is contained in:
parent
50ed661214
commit
70dfad1234
|
@ -85,7 +85,7 @@ Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
|
|||
|
||||
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
|
||||
|
@ -105,7 +105,7 @@ const QString SnorePlugin::typeName() const
|
|||
|
||||
QString SnorePlugin::settingsVersion() const
|
||||
{
|
||||
return "1";
|
||||
return "v1";
|
||||
}
|
||||
|
||||
bool SnorePlugin::deinitialize()
|
||||
|
|
|
@ -197,35 +197,20 @@ QList<PluginSettingsWidget *> SnoreCore::settingWidgets()
|
|||
QVariant SnoreCore::value(const QString &key, SettingsType type) const
|
||||
{
|
||||
Q_D(const SnoreCore);
|
||||
QString nk = d->versionizeKey(key);
|
||||
if(type == LOCAL_SETTING)
|
||||
{
|
||||
nk = d->normalizeKey(key);
|
||||
}
|
||||
return d->m_settings->value(nk);
|
||||
|
||||
return d->m_settings->value(d->normalizeKey(key,type));
|
||||
}
|
||||
|
||||
void SnoreCore::setValue(const QString &key, const QVariant &value, SettingsType type)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = d->versionizeKey(key);
|
||||
if(type == LOCAL_SETTING)
|
||||
{
|
||||
nk = d->normalizeKey(key);
|
||||
}
|
||||
d->m_settings->setValue(nk,value);
|
||||
d->m_settings->setValue(d->normalizeKey(key,type),value);
|
||||
}
|
||||
|
||||
|
||||
void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, SettingsType type)
|
||||
{
|
||||
Q_D(SnoreCore);
|
||||
QString nk = d->versionizeKey(key);
|
||||
if(type == LOCAL_SETTING)
|
||||
{
|
||||
nk = d->normalizeKey(key);
|
||||
}
|
||||
QString nk = d->normalizeKey(key,type);
|
||||
if (!d->m_settings->contains(nk)) {
|
||||
d->m_settings->setValue(nk, value);
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ SnoreCorePrivate::SnoreCorePrivate():
|
|||
|
||||
snoreDebug(SNORE_DEBUG) << "Temp dir is" << tempPath();
|
||||
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")));
|
||||
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(slotAboutToQuit()));
|
||||
|
|
|
@ -67,18 +67,17 @@ public:
|
|||
bool initPrimaryNotificationBackend();
|
||||
|
||||
inline QString versionSchema() const {
|
||||
return "1";
|
||||
return "v1";
|
||||
}
|
||||
|
||||
void syncSettings();
|
||||
|
||||
|
||||
QString versionizeKey(const QString &key) const{
|
||||
return QString("%1/%2").arg(key, versionSchema());
|
||||
QString normalizeKey(const QString &key, SettingsType type) const{
|
||||
if(type == LOCAL_SETTING) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue