diff options
Diffstat (limited to 'accounts')
-rw-r--r-- | accounts/maildir/maildirsettings.cpp | 75 | ||||
-rw-r--r-- | accounts/maildir/maildirsettings.h | 9 | ||||
-rw-r--r-- | accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | 12 |
3 files changed, 46 insertions, 50 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp index 1d48fc24..847ce92e 100644 --- a/accounts/maildir/maildirsettings.cpp +++ b/accounts/maildir/maildirsettings.cpp | |||
@@ -31,23 +31,6 @@ MaildirSettings::MaildirSettings(QObject *parent) | |||
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | void MaildirSettings::setIdentifier(const QByteArray &id) | ||
35 | { | ||
36 | mIdentifier = id; | ||
37 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::IdentityFilter(mIdentifier) + Sink::Query::RequestedProperties(QList<QByteArray>() << "path")) | ||
38 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | ||
39 | auto path = resource.getProperty("path").toString(); | ||
40 | if (mPath != path) { | ||
41 | mPath = path; | ||
42 | emit pathChanged(); | ||
43 | } | ||
44 | }).exec(); | ||
45 | } | ||
46 | |||
47 | QByteArray MaildirSettings::identifier() const | ||
48 | { | ||
49 | return mIdentifier; | ||
50 | } | ||
51 | 34 | ||
52 | void MaildirSettings::setAccountIdentifier(const QByteArray &id) | 35 | void MaildirSettings::setAccountIdentifier(const QByteArray &id) |
53 | { | 36 | { |
@@ -56,9 +39,22 @@ void MaildirSettings::setAccountIdentifier(const QByteArray &id) | |||
56 | } | 39 | } |
57 | mAccountIdentifier = id; | 40 | mAccountIdentifier = id; |
58 | Q_ASSERT(!id.isEmpty()); | 41 | Q_ASSERT(!id.isEmpty()); |
59 | Kube::Account account(id); | 42 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(id)) |
60 | auto maildirResource = account.property("maildirResource").toByteArray(); | 43 | .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { |
61 | setIdentifier(maildirResource); | 44 | mIcon = account.getProperty("icon").toString(); |
45 | mName = account.getProperty("name").toString(); | ||
46 | emit changed(); | ||
47 | }).exec(); | ||
48 | |||
49 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::PropertyFilter("account", QVariant::fromValue(id))) | ||
50 | .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | ||
51 | mIdentifier = resource.identifier(); | ||
52 | auto path = resource.getProperty("path").toString(); | ||
53 | if (mPath != path) { | ||
54 | mPath = path; | ||
55 | emit pathChanged(); | ||
56 | } | ||
57 | }).exec(); | ||
62 | } | 58 | } |
63 | 59 | ||
64 | QByteArray MaildirSettings::accountIdentifier() const | 60 | QByteArray MaildirSettings::accountIdentifier() const |
@@ -102,6 +98,19 @@ void MaildirSettings::save() | |||
102 | qWarning() << "The path doesn't exist: " << mPath; | 98 | qWarning() << "The path doesn't exist: " << mPath; |
103 | return; | 99 | return; |
104 | } | 100 | } |
101 | qDebug() << "Saving account " << mAccountIdentifier << mIdentifier; | ||
102 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | ||
103 | Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); | ||
104 | account.setProperty("type", "maildir"); | ||
105 | account.setProperty("name", mName); | ||
106 | account.setProperty("icon", mIcon); | ||
107 | Q_ASSERT(!account.identifier().isEmpty()); | ||
108 | Sink::Store::modify(account).then<void>([]() {}, | ||
109 | [](int errorCode, const QString &errorMessage) { | ||
110 | qWarning() << "Error while creating account: " << errorMessage; | ||
111 | }) | ||
112 | .exec(); | ||
113 | |||
105 | if (!mIdentifier.isEmpty()) { | 114 | if (!mIdentifier.isEmpty()) { |
106 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); | 115 | Sink::ApplicationDomain::SinkResource resource(mIdentifier); |
107 | resource.setProperty("path", mPath); | 116 | resource.setProperty("path", mPath); |
@@ -117,12 +126,8 @@ void MaildirSettings::save() | |||
117 | resource.setProperty("path", property("path")); | 126 | resource.setProperty("path", property("path")); |
118 | resource.setProperty("identifier", resourceIdentifier); | 127 | resource.setProperty("identifier", resourceIdentifier); |
119 | resource.setProperty("type", "org.kde.maildir"); | 128 | resource.setProperty("type", "org.kde.maildir"); |
120 | Sink::Store::create(resource).then<void>([this, resourceIdentifier]() { | 129 | resource.setProperty("account", mAccountIdentifier); |
121 | Q_ASSERT(!mAccountIdentifier.isEmpty()); | 130 | Sink::Store::create(resource).then<void>([]() {}, |
122 | Kube::Account account(mAccountIdentifier); | ||
123 | account.setProperty("maildirResource", resourceIdentifier); | ||
124 | account.save(); | ||
125 | }, | ||
126 | [](int errorCode, const QString &errorMessage) { | 131 | [](int errorCode, const QString &errorMessage) { |
127 | qWarning() << "Error while creating resource: " << errorMessage; | 132 | qWarning() << "Error while creating resource: " << errorMessage; |
128 | }) | 133 | }) |
@@ -136,20 +141,18 @@ void MaildirSettings::remove() | |||
136 | qWarning() << "We're missing an identifier"; | 141 | qWarning() << "We're missing an identifier"; |
137 | } else { | 142 | } else { |
138 | Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 143 | Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); |
139 | Sink::Store::remove(resource).then<void>([this]() { | 144 | Sink::Store::remove(resource).then<void>([]() {}, |
140 | Kube::Account account(mAccountIdentifier); | ||
141 | account.remove(); | ||
142 | |||
143 | Kube::Settings settings("accounts"); | ||
144 | auto accounts = settings.property("accounts").toStringList(); | ||
145 | accounts.removeAll(mAccountIdentifier); | ||
146 | settings.setProperty("accounts", accounts); | ||
147 | settings.save(); | ||
148 | }, | ||
149 | [](int errorCode, const QString &errorMessage) { | 145 | [](int errorCode, const QString &errorMessage) { |
150 | qWarning() << "Error while removing resource: " << errorMessage; | 146 | qWarning() << "Error while removing resource: " << errorMessage; |
151 | }) | 147 | }) |
152 | .exec(); | 148 | .exec(); |
149 | |||
150 | Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | ||
151 | Sink::Store::remove(account).then<void>([]() {}, | ||
152 | [](int errorCode, const QString &errorMessage) { | ||
153 | qWarning() << "Error while removing account: " << errorMessage; | ||
154 | }) | ||
155 | .exec(); | ||
153 | } | 156 | } |
154 | } | 157 | } |
155 | 158 | ||
diff --git a/accounts/maildir/maildirsettings.h b/accounts/maildir/maildirsettings.h index 9e5b6a4c..f79208db 100644 --- a/accounts/maildir/maildirsettings.h +++ b/accounts/maildir/maildirsettings.h | |||
@@ -24,17 +24,15 @@ | |||
24 | class MaildirSettings : public QObject | 24 | class MaildirSettings : public QObject |
25 | { | 25 | { |
26 | Q_OBJECT | 26 | Q_OBJECT |
27 | Q_PROPERTY(QByteArray identifier READ identifier WRITE setIdentifier) | ||
28 | Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) | 27 | Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) |
29 | Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) | 28 | Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) |
30 | Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) | 29 | Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) |
30 | Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) | ||
31 | Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) | ||
31 | 32 | ||
32 | public: | 33 | public: |
33 | MaildirSettings(QObject *parent = 0); | 34 | MaildirSettings(QObject *parent = 0); |
34 | 35 | ||
35 | void setIdentifier(const QByteArray &); | ||
36 | QByteArray identifier() const; | ||
37 | |||
38 | void setAccountIdentifier(const QByteArray &); | 36 | void setAccountIdentifier(const QByteArray &); |
39 | QByteArray accountIdentifier() const; | 37 | QByteArray accountIdentifier() const; |
40 | 38 | ||
@@ -47,9 +45,12 @@ public: | |||
47 | 45 | ||
48 | signals: | 46 | signals: |
49 | void pathChanged(); | 47 | void pathChanged(); |
48 | void changed(); | ||
50 | 49 | ||
51 | private: | 50 | private: |
52 | QByteArray mIdentifier; | 51 | QByteArray mIdentifier; |
53 | QByteArray mAccountIdentifier; | 52 | QByteArray mAccountIdentifier; |
54 | QString mPath; | 53 | QString mPath; |
54 | QString mIcon; | ||
55 | QString mName; | ||
55 | }; | 56 | }; |
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index 174683c4..0175fc46 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | |||
@@ -49,8 +49,8 @@ Rectangle { | |||
49 | id: name | 49 | id: name |
50 | placeholderText: accountName | 50 | placeholderText: accountName |
51 | Layout.fillWidth: true | 51 | Layout.fillWidth: true |
52 | text: accountSettings.accountName | 52 | text: maildirSettings.accountName |
53 | onTextChanged: { accountSettings.accountName = text; } | 53 | onTextChanged: { maildirSettings.accountName = text; } |
54 | } | 54 | } |
55 | 55 | ||
56 | Text { | 56 | Text { |
@@ -149,19 +149,11 @@ Rectangle { | |||
149 | property string password; | 149 | property string password; |
150 | } | 150 | } |
151 | 151 | ||
152 | KubeSettings.Settings { | ||
153 | id: accountSettings | ||
154 | identifier: "account." + accountId | ||
155 | property string accountName; | ||
156 | property string icon: root.icon; | ||
157 | } | ||
158 | |||
159 | Button { | 152 | Button { |
160 | text: "Save" | 153 | text: "Save" |
161 | onClicked: { | 154 | onClicked: { |
162 | transportSettings.save(); | 155 | transportSettings.save(); |
163 | maildirSettings.save(); | 156 | maildirSettings.save(); |
164 | accountSettings.save(); | ||
165 | } | 157 | } |
166 | } | 158 | } |
167 | Button { | 159 | Button { |