summaryrefslogtreecommitdiffstats
path: root/framework/domain/settings/accountsettings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/settings/accountsettings.cpp')
-rw-r--r--framework/domain/settings/accountsettings.cpp133
1 files changed, 67 insertions, 66 deletions
diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp
index cf348f39..ea798a73 100644
--- a/framework/domain/settings/accountsettings.cpp
+++ b/framework/domain/settings/accountsettings.cpp
@@ -23,6 +23,9 @@
23#include <QDir> 23#include <QDir>
24#include <QUrl> 24#include <QUrl>
25 25
26using namespace Sink;
27using namespace Sink::ApplicationDomain;
28
26AccountSettings::AccountSettings(QObject *parent) 29AccountSettings::AccountSettings(QObject *parent)
27 : QObject(parent) 30 : QObject(parent)
28{ 31{
@@ -130,87 +133,83 @@ void AccountSettings::saveAccount()
130{ 133{
131 qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; 134 qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier;
132 Q_ASSERT(!mAccountIdentifier.isEmpty()); 135 Q_ASSERT(!mAccountIdentifier.isEmpty());
133 Sink::ApplicationDomain::SinkAccount account(mAccountIdentifier); 136 SinkAccount account(mAccountIdentifier);
134 account.setProperty("type", "imap"); 137 account.setAccountType("imap");
135 account.setProperty("name", mName); 138 account.setName(mName);
136 account.setProperty("icon", mIcon); 139 account.setIcon(mIcon);
137 Q_ASSERT(!account.identifier().isEmpty()); 140 Q_ASSERT(!account.identifier().isEmpty());
138 Sink::Store::modify(account).then<void>([]() {}, 141 Store::modify(account)
139 [](int errorCode, const QString &errorMessage) { 142 .onError([](const KAsync::Error &error) {
140 qWarning() << "Error while creating account: " << errorMessage; 143 qWarning() << "Error while creating account: " << error.errorMessage;;
141 }) 144 })
142 .exec(); 145 .exec();
143} 146}
144 147
145void AccountSettings::loadAccount() 148void AccountSettings::loadAccount()
146{ 149{
147 Q_ASSERT(!mAccountIdentifier.isEmpty()); 150 Q_ASSERT(!mAccountIdentifier.isEmpty());
148 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkAccount>(Sink::Query::IdentityFilter(mAccountIdentifier)) 151 Store::fetchOne<SinkAccount>(Query().filter(mAccountIdentifier))
149 .then<void, Sink::ApplicationDomain::SinkAccount>([this](const Sink::ApplicationDomain::SinkAccount &account) { 152 .syncThen<void, SinkAccount>([this](const SinkAccount &account) {
150 mIcon = account.getProperty("icon").toString(); 153 mIcon = account.getIcon();
151 mName = account.getProperty("name").toString(); 154 mName = account.getName();
152 emit changed(); 155 emit changed();
153 }).exec(); 156 }).exec();
154} 157}
155 158
156void AccountSettings::loadImapResource() 159void AccountSettings::loadImapResource()
157{ 160{
158 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) 161 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage))
159 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 162 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
160 mImapIdentifier = resource.identifier(); 163 mImapIdentifier = resource.identifier();
161 mImapServer = resource.getProperty("server").toString(); 164 mImapServer = resource.getProperty("server").toString();
162 mImapUsername = resource.getProperty("username").toString(); 165 mImapUsername = resource.getProperty("username").toString();
163 mImapPassword = resource.getProperty("password").toString(); 166 mImapPassword = resource.getProperty("password").toString();
164 emit imapResourceChanged(); 167 emit imapResourceChanged();
165 }, 168 }).onError([](const KAsync::Error &error) {
166 [](int errorCode, const QString &errorMessage) { 169 qWarning() << "Failed to find the imap resource: " << error.errorMessage;
167 qWarning() << "Failed to find the imap resource: " << errorMessage;
168 }).exec(); 170 }).exec();
169} 171}
170 172
171void AccountSettings::loadMaildirResource() 173void AccountSettings::loadMaildirResource()
172{ 174{
173 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) 175 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage))
174 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 176 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
175 mMaildirIdentifier = resource.identifier(); 177 mMaildirIdentifier = resource.identifier();
176 auto path = resource.getProperty("path").toString(); 178 auto path = resource.getProperty("path").toString();
177 if (mPath != path) { 179 if (mPath != path) {
178 mPath = path; 180 mPath = path;
179 emit pathChanged(); 181 emit pathChanged();
180 } 182 }
181 }, 183 }).onError([](const KAsync::Error &error) {
182 [](int errorCode, const QString &errorMessage) { 184 qWarning() << "Failed to find the maildir resource: " << error.errorMessage;
183 qWarning() << "Failed to find the maildir resource: " << errorMessage;
184 }).exec(); 185 }).exec();
185} 186}
186 187
187void AccountSettings::loadMailtransportResource() 188void AccountSettings::loadMailtransportResource()
188{ 189{
189 Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query::AccountFilter(mAccountIdentifier) + Sink::Query::CapabilityFilter(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) 190 Store::fetchOne<SinkResource>(Query().filter<SinkResource::Account>(mAccountIdentifier).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport))
190 .then<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { 191 .syncThen<void, SinkResource>([this](const SinkResource &resource) {
191 mMailtransportIdentifier = resource.identifier(); 192 mMailtransportIdentifier = resource.identifier();
192 mSmtpServer = resource.getProperty("server").toString(); 193 mSmtpServer = resource.getProperty("server").toString();
193 mSmtpUsername = resource.getProperty("username").toString(); 194 mSmtpUsername = resource.getProperty("username").toString();
194 mSmtpPassword = resource.getProperty("password").toString(); 195 mSmtpPassword = resource.getProperty("password").toString();
195 emit smtpResourceChanged(); 196 emit smtpResourceChanged();
196 }, 197 }).onError([](const KAsync::Error &error) {
197 [](int errorCode, const QString &errorMessage) { 198 qWarning() << "Failed to find the smtp resource: " << error.errorMessage;
198 qWarning() << "Failed to find the smtp resource: " << errorMessage;
199 }).exec(); 199 }).exec();
200} 200}
201 201
202void AccountSettings::loadIdentity() 202void AccountSettings::loadIdentity()
203{ 203{
204 //FIXME this assumes that we only ever have one identity per account 204 //FIXME this assumes that we only ever have one identity per account
205 Sink::Store::fetchOne<Sink::ApplicationDomain::Identity>(Sink::Query::AccountFilter(mAccountIdentifier)) 205 Store::fetchOne<Identity>(Query().filter<Identity::Account>(mAccountIdentifier))
206 .then<void, Sink::ApplicationDomain::Identity>([this](const Sink::ApplicationDomain::Identity &identity) { 206 .syncThen<void, Identity>([this](const Identity &identity) {
207 mIdentityIdentifier = identity.identifier(); 207 mIdentityIdentifier = identity.identifier();
208 mUsername = identity.getProperty("username").toString(); 208 mUsername = identity.getProperty("username").toString();
209 mEmailAddress = identity.getProperty("address").toString(); 209 mEmailAddress = identity.getProperty("address").toString();
210 emit identityChanged(); 210 emit identityChanged();
211 }, 211 }).onError([](const KAsync::Error &error) {
212 [](int errorCode, const QString &errorMessage) { 212 qWarning() << "Failed to find the identity resource: " << error.errorMessage;
213 qWarning() << "Failed to find the identity resource: " << errorMessage;
214 }).exec(); 213 }).exec();
215} 214}
216 215
@@ -220,25 +219,26 @@ template<typename ResourceType>
220static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties) 219static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties)
221{ 220{
222 if (!identifier.isEmpty()) { 221 if (!identifier.isEmpty()) {
223 Sink::ApplicationDomain::SinkResource resource(identifier); 222 SinkResource resource(identifier);
224 for (const auto &pair : properties) { 223 for (const auto &pair : properties) {
225 resource.setProperty(pair.first, pair.second); 224 resource.setProperty(pair.first, pair.second);
226 } 225 }
227 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) { 226 Store::modify(resource)
228 qWarning() << "Error while modifying resource: " << errorMessage; 227 .onError([](const KAsync::Error &error) {
229 }) 228 qWarning() << "Error while modifying resource: " << error.errorMessage;
230 .exec(); 229 })
230 .exec();
231 } else { 231 } else {
232 auto resource = ResourceType::create(accountIdentifier); 232 auto resource = ResourceType::create(accountIdentifier);
233 auto newIdentifier = resource.identifier(); 233 auto newIdentifier = resource.identifier();
234 for (const auto &pair : properties) { 234 for (const auto &pair : properties) {
235 resource.setProperty(pair.first, pair.second); 235 resource.setProperty(pair.first, pair.second);
236 } 236 }
237 Sink::Store::create(resource).template then<void>([]() {}, 237 Store::create(resource)
238 [](int errorCode, const QString &errorMessage) { 238 .onError([](const KAsync::Error &error) {
239 qWarning() << "Error while creating resource: " << errorMessage; 239 qWarning() << "Error while creating resource: " << error.errorMessage;
240 }) 240 })
241 .exec(); 241 .exec();
242 return newIdentifier; 242 return newIdentifier;
243 } 243 }
244 return identifier; 244 return identifier;
@@ -246,7 +246,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA
246 246
247void AccountSettings::saveImapResource() 247void AccountSettings::saveImapResource()
248{ 248{
249 mImapIdentifier = saveResource<Sink::ApplicationDomain::ImapResource>(mAccountIdentifier, mImapIdentifier, { 249 mImapIdentifier = saveResource<ImapResource>(mAccountIdentifier, mImapIdentifier, {
250 {"server", mImapServer}, 250 {"server", mImapServer},
251 {"username", mImapUsername}, 251 {"username", mImapUsername},
252 {"password", mImapPassword}, 252 {"password", mImapPassword},
@@ -255,14 +255,14 @@ void AccountSettings::saveImapResource()
255 255
256void AccountSettings::saveMaildirResource() 256void AccountSettings::saveMaildirResource()
257{ 257{
258 mMaildirIdentifier = saveResource<Sink::ApplicationDomain::MaildirResource>(mAccountIdentifier, mMaildirIdentifier, { 258 mMaildirIdentifier = saveResource<MaildirResource>(mAccountIdentifier, mMaildirIdentifier, {
259 {"path", mPath}, 259 {"path", mPath},
260 }); 260 });
261} 261}
262 262
263void AccountSettings::saveMailtransportResource() 263void AccountSettings::saveMailtransportResource()
264{ 264{
265 mMailtransportIdentifier = saveResource<Sink::ApplicationDomain::MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, { 265 mMailtransportIdentifier = saveResource<MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, {
266 {"server", mSmtpServer}, 266 {"server", mSmtpServer},
267 {"username", mSmtpUsername}, 267 {"username", mSmtpUsername},
268 {"password", mSmtpPassword}, 268 {"password", mSmtpPassword},
@@ -272,22 +272,23 @@ void AccountSettings::saveMailtransportResource()
272void AccountSettings::saveIdentity() 272void AccountSettings::saveIdentity()
273{ 273{
274 if (!mIdentityIdentifier.isEmpty()) { 274 if (!mIdentityIdentifier.isEmpty()) {
275 Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); 275 Identity identity(mMailtransportIdentifier);
276 identity.setProperty("username", mUsername); 276 identity.setProperty("username", mUsername);
277 identity.setProperty("address", mEmailAddress); 277 identity.setProperty("address", mEmailAddress);
278 Sink::Store::modify(identity).then<void>([](){}, [](int errorCode, const QString &errorMessage) { 278 Store::modify(identity)
279 qWarning() << "Error while modifying identity: " << errorMessage; 279 .onError([](const KAsync::Error &error) {
280 qWarning() << "Error while modifying identity: " << error.errorMessage;
280 }) 281 })
281 .exec(); 282 .exec();
282 } else { 283 } else {
283 auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>(); 284 auto identity = ApplicationDomainType::createEntity<Identity>();
284 mIdentityIdentifier = identity.identifier(); 285 mIdentityIdentifier = identity.identifier();
285 identity.setProperty("account", mAccountIdentifier); 286 identity.setAccount(mAccountIdentifier);
286 identity.setProperty("username", mUsername); 287 identity.setProperty("username", mUsername);
287 identity.setProperty("address", mEmailAddress); 288 identity.setProperty("address", mEmailAddress);
288 Sink::Store::create(identity).then<void>([]() {}, 289 Store::create(identity)
289 [](int errorCode, const QString &errorMessage) { 290 .onError([](const KAsync::Error &error) {
290 qWarning() << "Error while creating identity: " << errorMessage; 291 qWarning() << "Error while creating identity: " << error.errorMessage;
291 }) 292 })
292 .exec(); 293 .exec();
293 } 294 }
@@ -298,10 +299,10 @@ void AccountSettings::removeResource(const QByteArray &identifier)
298 if (identifier.isEmpty()) { 299 if (identifier.isEmpty()) {
299 qWarning() << "We're missing an identifier"; 300 qWarning() << "We're missing an identifier";
300 } else { 301 } else {
301 Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 302 SinkResource resource(identifier);
302 Sink::Store::remove(resource).template then<void>([]() {}, 303 Store::remove(resource)
303 [](int errorCode, const QString &errorMessage) { 304 .onError([](const KAsync::Error &error) {
304 qWarning() << "Error while removing resource: " << errorMessage; 305 qWarning() << "Error while removing resource: " << error.errorMessage;
305 }) 306 })
306 .exec(); 307 .exec();
307 } 308 }
@@ -312,10 +313,10 @@ void AccountSettings::removeAccount()
312 if (mAccountIdentifier.isEmpty()) { 313 if (mAccountIdentifier.isEmpty()) {
313 qWarning() << "We're missing an identifier"; 314 qWarning() << "We're missing an identifier";
314 } else { 315 } else {
315 Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 316 SinkAccount account(mAccountIdentifier);
316 Sink::Store::remove(account).then<void>([]() {}, 317 Store::remove(account)
317 [](int errorCode, const QString &errorMessage) { 318 .onError([](const KAsync::Error &error) {
318 qWarning() << "Error while removing account: " << errorMessage; 319 qWarning() << "Error while removing account: " << error.errorMessage;
319 }) 320 })
320 .exec(); 321 .exec();
321 } 322 }
@@ -326,10 +327,10 @@ void AccountSettings::removeIdentity()
326 if (mIdentityIdentifier.isEmpty()) { 327 if (mIdentityIdentifier.isEmpty()) {
327 qWarning() << "We're missing an identifier"; 328 qWarning() << "We're missing an identifier";
328 } else { 329 } else {
329 Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); 330 Identity identity(mIdentityIdentifier);
330 Sink::Store::remove(identity).then<void>([]() {}, 331 Store::remove(identity)
331 [](int errorCode, const QString &errorMessage) { 332 .onError([](const KAsync::Error &error) {
332 qWarning() << "Error while removing identity: " << errorMessage; 333 qWarning() << "Error while removing identity: " << error.errorMessage;
333 }) 334 })
334 .exec(); 335 .exec();
335 } 336 }