diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 14:45:15 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 14:45:15 +0100 |
commit | d8e13159711576394099f8954368aeb9da7fa87a (patch) | |
tree | a498a2a390348abe0522b0203022e48518d32359 /framework/settings | |
parent | 91eca666b5491041c2d095d599b75830c56530dc (diff) | |
download | kube-d8e13159711576394099f8954368aeb9da7fa87a.tar.gz kube-d8e13159711576394099f8954368aeb9da7fa87a.zip |
AccountsController
Diffstat (limited to 'framework/settings')
-rw-r--r-- | framework/settings/settings.cpp | 30 | ||||
-rw-r--r-- | framework/settings/settings.h | 2 |
2 files changed, 28 insertions, 4 deletions
diff --git a/framework/settings/settings.cpp b/framework/settings/settings.cpp index a4e28190..246c4a99 100644 --- a/framework/settings/settings.cpp +++ b/framework/settings/settings.cpp | |||
@@ -26,21 +26,24 @@ | |||
26 | using namespace Kube; | 26 | using namespace Kube; |
27 | 27 | ||
28 | Settings::Settings(QObject *parent) | 28 | Settings::Settings(QObject *parent) |
29 | : QObject(parent) | 29 | : QObject(parent), |
30 | mLoaded(false) | ||
30 | { | 31 | { |
31 | 32 | ||
32 | } | 33 | } |
33 | 34 | ||
34 | Settings::Settings(const QByteArray &id, QObject *parent) | 35 | Settings::Settings(const QByteArray &id, QObject *parent) |
35 | : QObject(parent), | 36 | : QObject(parent), |
36 | mIdentifier(id) | 37 | mIdentifier(id), |
38 | mLoaded(false) | ||
37 | { | 39 | { |
38 | load(); | 40 | load(); |
39 | } | 41 | } |
40 | 42 | ||
41 | Settings::Settings(const Settings &other) | 43 | Settings::Settings(const Settings &other) |
42 | : QObject(other.parent()), | 44 | : QObject(other.parent()), |
43 | mIdentifier(other.mIdentifier) | 45 | mIdentifier(other.mIdentifier), |
46 | mLoaded(false) | ||
44 | { | 47 | { |
45 | load(); | 48 | load(); |
46 | } | 49 | } |
@@ -59,8 +62,19 @@ void Settings::save() | |||
59 | { | 62 | { |
60 | qWarning() << "Saving" << mIdentifier; | 63 | qWarning() << "Saving" << mIdentifier; |
61 | auto settings = getSettings(); | 64 | auto settings = getSettings(); |
65 | |||
66 | for (const auto &p : dynamicPropertyNames()) { | ||
67 | qWarning() << "setting " << p << property(p); | ||
68 | if (p == "identifier") { | ||
69 | continue; | ||
70 | } | ||
71 | settings->setValue(p, property(p)); | ||
72 | } | ||
62 | for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { | 73 | for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { |
63 | const auto p = metaObject()->property(i).name(); | 74 | const auto p = metaObject()->property(i).name(); |
75 | if (p == QByteArray("identifier")) { | ||
76 | continue; | ||
77 | } | ||
64 | qWarning() << "setting " << p << property(p); | 78 | qWarning() << "setting " << p << property(p); |
65 | settings->setValue(p, property(p)); | 79 | settings->setValue(p, property(p)); |
66 | } | 80 | } |
@@ -69,7 +83,10 @@ void Settings::save() | |||
69 | 83 | ||
70 | void Settings::load() | 84 | void Settings::load() |
71 | { | 85 | { |
72 | qWarning() << "loading" << mIdentifier; | 86 | if (mLoaded) { |
87 | return; | ||
88 | } | ||
89 | mLoaded = true; | ||
73 | for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { | 90 | for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); i++) { |
74 | auto p = metaObject()->property(i).name(); | 91 | auto p = metaObject()->property(i).name(); |
75 | setProperty(p, QVariant()); | 92 | setProperty(p, QVariant()); |
@@ -114,6 +131,11 @@ Identity Account::primaryIdentity() const | |||
114 | return Identity(property("primaryIdentityId").toByteArray()); | 131 | return Identity(property("primaryIdentityId").toByteArray()); |
115 | } | 132 | } |
116 | 133 | ||
134 | QByteArray Account::type() const | ||
135 | { | ||
136 | return property("type").toByteArray(); | ||
137 | } | ||
138 | |||
117 | Identity::Identity(const QByteArray &identifier) | 139 | Identity::Identity(const QByteArray &identifier) |
118 | : Settings("identity." + identifier) | 140 | : Settings("identity." + identifier) |
119 | { | 141 | { |
diff --git a/framework/settings/settings.h b/framework/settings/settings.h index bfee55cb..685d67aa 100644 --- a/framework/settings/settings.h +++ b/framework/settings/settings.h | |||
@@ -42,6 +42,7 @@ private: | |||
42 | void load(); | 42 | void load(); |
43 | QSharedPointer<QSettings> getSettings(); | 43 | QSharedPointer<QSettings> getSettings(); |
44 | QByteArray mIdentifier; | 44 | QByteArray mIdentifier; |
45 | bool mLoaded; | ||
45 | }; | 46 | }; |
46 | 47 | ||
47 | class Account; | 48 | class Account; |
@@ -63,6 +64,7 @@ class Account : public Settings | |||
63 | public: | 64 | public: |
64 | Account(const QByteArray &identifier); | 65 | Account(const QByteArray &identifier); |
65 | Identity primaryIdentity() const; | 66 | Identity primaryIdentity() const; |
67 | QByteArray type() const; | ||
66 | }; | 68 | }; |
67 | 69 | ||
68 | class Identity : public Settings | 70 | class Identity : public Settings |