aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--settings.cpp33
-rw-r--r--settings.h22
2 files changed, 49 insertions, 6 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;
}
diff --git a/settings.h b/settings.h
index a6c0420e..ab3aae8b 100644
--- a/settings.h
+++ b/settings.h
@@ -28,7 +28,17 @@ namespace QMatrixClient
{
class Settings: public QSettings
{
+ Q_OBJECT
public:
+ /**
+ * Use this function before creating any Settings objects in order
+ * to setup a read-only location where configuration has previously
+ * been stored. This will provide an additional fallback in case of
+ * renaming the organisation/application.
+ */
+ static void setLegacyNames(const QString& organizationName,
+ const QString& applicationName = {});
+
#if defined(_MSC_VER) && _MSC_VER < 1900
// VS 2013 (and probably older) aren't friends with 'using' statements
// that involve private constructors
@@ -41,6 +51,16 @@ namespace QMatrixClient
const QVariant &value);
Q_INVOKABLE QVariant value(const QString &key,
const QVariant &defaultValue = {}) const;
+ Q_INVOKABLE bool contains(const QString& key) const;
+ Q_INVOKABLE QStringList childGroups() const;
+
+ private:
+ static QString legacyOrganizationName;
+ static QString legacyApplicationName;
+
+ protected:
+ const QSettings legacySettings { legacyOrganizationName,
+ legacyApplicationName };
};
class SettingsGroup: public Settings
@@ -69,7 +89,7 @@ namespace QMatrixClient
class AccountSettings: public SettingsGroup
{
Q_OBJECT
- Q_PROPERTY(QString userId READ userId)
+ Q_PROPERTY(QString userId READ userId CONSTANT)
Q_PROPERTY(QString deviceId READ deviceId WRITE setDeviceId)
Q_PROPERTY(QString deviceName READ deviceName WRITE setDeviceName)
Q_PROPERTY(QUrl homeserver READ homeserver WRITE setHomeserver)