aboutsummaryrefslogtreecommitdiff
path: root/lib/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/settings.cpp')
-rw-r--r--lib/settings.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/settings.cpp b/lib/settings.cpp
index e0a1783f..f8f1eae5 100644
--- a/lib/settings.cpp
+++ b/lib/settings.cpp
@@ -32,8 +32,7 @@ QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
// (QVariant("false") == true in JavaScript). Since we have a mixed
// environment where both QSettings and Qt.labs.Settings may potentially
// work with same settings, better ensure compatibility.
- return value.toString() == QStringLiteral("false") ? QVariant(false)
- : value;
+ return value.toString() == QStringLiteral("false") ? QVariant(false) : value;
}
bool Settings::contains(const QString& key) const
@@ -83,40 +82,44 @@ void SettingsGroup::remove(const QString& key)
Settings::remove(fullKey);
}
-QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", "",
+QMC_DEFINE_SETTING(AccountSettings, QString, deviceId, "device_id", {},
setDeviceId)
-QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", "",
+QMC_DEFINE_SETTING(AccountSettings, QString, deviceName, "device_name", {},
setDeviceName)
QMC_DEFINE_SETTING(AccountSettings, bool, keepLoggedIn, "keep_logged_in", false,
setKeepLoggedIn)
+static const auto HomeserverKey = QStringLiteral("homeserver");
+static const auto AccessTokenKey = QStringLiteral("access_token");
+
QUrl AccountSettings::homeserver() const
{
- return QUrl::fromUserInput(value("homeserver").toString());
+ return QUrl::fromUserInput(value(HomeserverKey).toString());
}
void AccountSettings::setHomeserver(const QUrl& url)
{
- setValue("homeserver", url.toString());
+ setValue(HomeserverKey, url.toString());
}
QString AccountSettings::userId() const { return group().section('/', -1); }
QString AccountSettings::accessToken() const
{
- return value("access_token").toString();
+ return value(AccessTokenKey).toString();
}
void AccountSettings::setAccessToken(const QString& accessToken)
{
qCWarning(MAIN) << "Saving access_token to QSettings is insecure."
" Developers, please save access_token separately.";
- setValue("access_token", accessToken);
+ setValue(AccessTokenKey, accessToken);
}
void AccountSettings::clearAccessToken()
{
- legacySettings.remove("access_token");
- legacySettings.remove("device_id"); // Force the server to re-issue it
- remove("access_token");
+ legacySettings.remove(AccessTokenKey);
+ legacySettings.remove(QStringLiteral("device_id")); // Force the server to
+ // re-issue it
+ remove(AccessTokenKey);
}