diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-11-03 17:53:23 +0300 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-11-03 17:53:23 +0300 |
commit | 02fa295085ae2297062d10f476a0b40b7fcb2559 (patch) | |
tree | cfdeb3da9e25be1e0bd0da68ae71b9869573fcdd /settings.cpp | |
parent | 352810b5945d4994369379c568eb48dd41071776 (diff) | |
download | libquotient-02fa295085ae2297062d10f476a0b40b7fcb2559.tar.gz libquotient-02fa295085ae2297062d10f476a0b40b7fcb2559.zip |
Provide facilities to migrate from legacy settings location
This is for a case of renaming an organisation or an application
Diffstat (limited to 'settings.cpp')
-rw-r--r-- | settings.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/settings.cpp b/settings.cpp index 3a5f4d26..98921869 100644 --- a/settings.cpp +++ b/settings.cpp @@ -5,6 +5,16 @@ using namespace QMatrixClient;
+QString Settings::legacyOrganizationName {};
+QString Settings::legacyApplicationName {};
+
+void Settings::setLegacyNames(const QString& organizationName,
+ const QString& applicationName)
+{
+ legacyOrganizationName = organizationName;
+ legacyApplicationName = applicationName;
+}
+
void Settings::setValue(const QString& key, const QVariant& value)
{
// qCDebug() << "Setting" << key << "to" << value;
@@ -13,22 +23,33 @@ void Settings::setValue(const QString& key, const QVariant& value) QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
{
- return QSettings::value(key, defaultValue);
+ return QSettings::value(key, legacySettings.value(key, defaultValue));
+}
+
+bool Settings::contains(const QString& key) const
+{
+ return QSettings::contains(key) || legacySettings.contains(key);
+}
+
+QStringList Settings::childGroups() const
+{
+ auto l = QSettings::childGroups();
+ return !l.isEmpty() ? l : legacySettings.childGroups();
}
void SettingsGroup::setValue(const QString& key, const QVariant& value)
{
- Settings::setValue(groupPath + "/" + key, value);
+ Settings::setValue(groupPath + '/' + key, value);
}
bool SettingsGroup::contains(const QString& key) const
{
- return Settings::contains(groupPath + "/" + key);
+ return Settings::contains(groupPath + '/' + key);
}
QVariant SettingsGroup::value(const QString& key, const QVariant& defaultValue) const
{
- return Settings::value(groupPath + "/" + key, defaultValue);
+ return Settings::value(groupPath + '/' + key, defaultValue);
}
QString SettingsGroup::group() const
@@ -39,8 +60,10 @@ QString SettingsGroup::group() const QStringList SettingsGroup::childGroups() const
{
const_cast<SettingsGroup*>(this)->beginGroup(groupPath);
- QStringList l { Settings::childGroups() };
+ const_cast<QSettings&>(legacySettings).beginGroup(groupPath);
+ QStringList l = Settings::childGroups();
const_cast<SettingsGroup*>(this)->endGroup();
+ const_cast<QSettings&>(legacySettings).endGroup();
return l;
}
|