diff options
author | KitsuneRal <Kitsune-Ral@users.sf.net> | 2016-09-07 08:34:03 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-07 08:34:03 +0900 |
commit | 34e7ba238f46734893111110235e032d44fd3690 (patch) | |
tree | 6fc1008c9d2dc50a7acd21c601ac06aff1365f2e /settings.cpp | |
parent | c02174bc8f09761c2e4ee3ca4a250ce49025343e (diff) | |
parent | 573e0e478c4a904ba69e6b523dead41eb28121c1 (diff) | |
download | libquotient-34e7ba238f46734893111110235e032d44fd3690.tar.gz libquotient-34e7ba238f46734893111110235e032d44fd3690.zip |
Merge pull request #24 from Fxrh/kitsune-settings
Settings classes
Diffstat (limited to 'settings.cpp')
-rw-r--r-- | settings.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/settings.cpp b/settings.cpp new file mode 100644 index 00000000..45af33e3 --- /dev/null +++ b/settings.cpp @@ -0,0 +1,102 @@ +#include "settings.h"
+
+#include <QtCore/QUrl>
+#include <QtCore/QDebug>
+
+using namespace QMatrixClient;
+
+Settings::~Settings()
+{ }
+
+void Settings::setValue(const QString& key, const QVariant& value)
+{
+// qDebug() << "Setting" << key << "to" << value;
+ QSettings::setValue(key, value);
+}
+
+QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
+{
+ return QSettings::value(key, defaultValue);
+}
+
+SettingsGroup::~SettingsGroup()
+{ }
+
+void SettingsGroup::setValue(const QString& key, const QVariant& value)
+{
+ Settings::setValue(groupPath + "/" + key, value);
+}
+
+bool SettingsGroup::contains(const QString& key) const
+{
+ return Settings::contains(groupPath + "/" + key);
+}
+
+QVariant SettingsGroup::value(const QString& key, const QVariant& defaultValue) const
+{
+ return Settings::value(groupPath + "/" + key, defaultValue);
+}
+
+QString SettingsGroup::group() const
+{
+ return groupPath;
+}
+
+QStringList SettingsGroup::childGroups() const
+{
+ const_cast<SettingsGroup*>(this)->beginGroup(groupPath);
+ QStringList l { Settings::childGroups() };
+ const_cast<SettingsGroup*>(this)->endGroup();
+ return l;
+}
+
+void SettingsGroup::remove(const QString& key)
+{
+ QString fullKey { groupPath };
+ if (!key.isEmpty())
+ fullKey += "/" + key;
+ Settings::remove(fullKey);
+}
+
+AccountSettings::~AccountSettings()
+{ }
+
+bool AccountSettings::keepLoggedIn() const
+{
+ return value("keep_logged_in", false).toBool();
+}
+
+void AccountSettings::setKeepLoggedIn(bool newSetting)
+{
+ setValue("keep_logged_in", newSetting);
+}
+
+QUrl AccountSettings::homeserver() const
+{
+ return QUrl::fromUserInput(value("homeserver").toString());
+}
+
+void AccountSettings::setHomeserver(const QUrl& url)
+{
+ setValue("homeserver", url.toString());
+}
+
+QString AccountSettings::userId() const
+{
+ return group().section('/', -1);
+}
+
+QString AccountSettings::accessToken() const
+{
+ return value("access_token").toString();
+}
+
+void AccountSettings::setAccessToken(const QString& accessToken)
+{
+ setValue("access_token", accessToken);
+}
+
+void AccountSettings::clearAccessToken()
+{
+ remove("access_token");
+}
|