diff options
Diffstat (limited to 'framework/domain/settings/accountsettings.cpp')
-rw-r--r-- | framework/domain/settings/accountsettings.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index 020fd503..635aef6e 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 | ||
26 | using namespace Sink; | ||
27 | using namespace Sink::ApplicationDomain; | ||
28 | |||
26 | AccountSettings::AccountSettings(QObject *parent) | 29 | AccountSettings::AccountSettings(QObject *parent) |
27 | : QObject(parent) | 30 | : QObject(parent) |
28 | { | 31 | { |
@@ -130,12 +133,12 @@ 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.setProperty("type", "imap"); |
135 | account.setProperty("name", mName); | 138 | account.setProperty("name", mName); |
136 | account.setProperty("icon", mIcon); | 139 | account.setProperty("icon", mIcon); |
137 | Q_ASSERT(!account.identifier().isEmpty()); | 140 | Q_ASSERT(!account.identifier().isEmpty()); |
138 | Sink::Store::modify(account) | 141 | Store::modify(account) |
139 | .onError([](const KAsync::Error &error) { | 142 | .onError([](const KAsync::Error &error) { |
140 | qWarning() << "Error while creating account: " << error.errorMessage;; | 143 | qWarning() << "Error while creating account: " << error.errorMessage;; |
141 | }) | 144 | }) |
@@ -145,8 +148,8 @@ void AccountSettings::saveAccount() | |||
145 | void AccountSettings::loadAccount() | 148 | void 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::IdentityFilter(mAccountIdentifier)) |
149 | .syncThen<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.getProperty("icon").toString(); |
151 | mName = account.getProperty("name").toString(); | 154 | mName = account.getProperty("name").toString(); |
152 | emit changed(); | 155 | emit changed(); |
@@ -155,8 +158,8 @@ void AccountSettings::loadAccount() | |||
155 | 158 | ||
156 | void AccountSettings::loadImapResource() | 159 | void AccountSettings::loadImapResource() |
157 | { | 160 | { |
158 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter<Sink::ApplicationDomain::SinkResource::Capabilities>(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) | 161 | Store::fetchOne<SinkResource>(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage)) |
159 | .syncThen<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(); |
@@ -169,8 +172,8 @@ void AccountSettings::loadImapResource() | |||
169 | 172 | ||
170 | void AccountSettings::loadMaildirResource() | 173 | void AccountSettings::loadMaildirResource() |
171 | { | 174 | { |
172 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter<Sink::ApplicationDomain::SinkResource::Capabilities>(Sink::ApplicationDomain::ResourceCapabilities::Mail::storage)) | 175 | Store::fetchOne<SinkResource>(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage)) |
173 | .syncThen<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | 176 | .syncThen<void, SinkResource>([this](const SinkResource &resource) { |
174 | mMaildirIdentifier = resource.identifier(); | 177 | mMaildirIdentifier = resource.identifier(); |
175 | auto path = resource.getProperty("path").toString(); | 178 | auto path = resource.getProperty("path").toString(); |
176 | if (mPath != path) { | 179 | if (mPath != path) { |
@@ -184,8 +187,8 @@ void AccountSettings::loadMaildirResource() | |||
184 | 187 | ||
185 | void AccountSettings::loadMailtransportResource() | 188 | void AccountSettings::loadMailtransportResource() |
186 | { | 189 | { |
187 | Sink::Store::fetchOne<Sink::ApplicationDomain::SinkResource>(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier)).containsFilter<Sink::ApplicationDomain::SinkResource::Capabilities>(Sink::ApplicationDomain::ResourceCapabilities::Mail::transport)) | 190 | Store::fetchOne<SinkResource>(Query().filter(SinkAccount(mAccountIdentifier)).containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport)) |
188 | .syncThen<void, Sink::ApplicationDomain::SinkResource>([this](const Sink::ApplicationDomain::SinkResource &resource) { | 191 | .syncThen<void, SinkResource>([this](const SinkResource &resource) { |
189 | mMailtransportIdentifier = resource.identifier(); | 192 | mMailtransportIdentifier = resource.identifier(); |
190 | mSmtpServer = resource.getProperty("server").toString(); | 193 | mSmtpServer = resource.getProperty("server").toString(); |
191 | mSmtpUsername = resource.getProperty("username").toString(); | 194 | mSmtpUsername = resource.getProperty("username").toString(); |
@@ -199,8 +202,8 @@ void AccountSettings::loadMailtransportResource() | |||
199 | void AccountSettings::loadIdentity() | 202 | void AccountSettings::loadIdentity() |
200 | { | 203 | { |
201 | //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 |
202 | Sink::Store::fetchOne<Sink::ApplicationDomain::Identity>(Sink::Query().filter(Sink::ApplicationDomain::SinkAccount(mAccountIdentifier))) | 205 | Store::fetchOne<Identity>(Query().filter(SinkAccount(mAccountIdentifier))) |
203 | .syncThen<void, Sink::ApplicationDomain::Identity>([this](const Sink::ApplicationDomain::Identity &identity) { | 206 | .syncThen<void, Identity>([this](const Identity &identity) { |
204 | mIdentityIdentifier = identity.identifier(); | 207 | mIdentityIdentifier = identity.identifier(); |
205 | mUsername = identity.getProperty("username").toString(); | 208 | mUsername = identity.getProperty("username").toString(); |
206 | mEmailAddress = identity.getProperty("address").toString(); | 209 | mEmailAddress = identity.getProperty("address").toString(); |
@@ -216,11 +219,11 @@ template<typename ResourceType> | |||
216 | static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties) | 219 | static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteArray &identifier, const std::map<QByteArray, QVariant> &properties) |
217 | { | 220 | { |
218 | if (!identifier.isEmpty()) { | 221 | if (!identifier.isEmpty()) { |
219 | Sink::ApplicationDomain::SinkResource resource(identifier); | 222 | SinkResource resource(identifier); |
220 | for (const auto &pair : properties) { | 223 | for (const auto &pair : properties) { |
221 | resource.setProperty(pair.first, pair.second); | 224 | resource.setProperty(pair.first, pair.second); |
222 | } | 225 | } |
223 | Sink::Store::modify(resource) | 226 | Store::modify(resource) |
224 | .onError([](const KAsync::Error &error) { | 227 | .onError([](const KAsync::Error &error) { |
225 | qWarning() << "Error while modifying resource: " << error.errorMessage; | 228 | qWarning() << "Error while modifying resource: " << error.errorMessage; |
226 | }) | 229 | }) |
@@ -231,7 +234,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA | |||
231 | for (const auto &pair : properties) { | 234 | for (const auto &pair : properties) { |
232 | resource.setProperty(pair.first, pair.second); | 235 | resource.setProperty(pair.first, pair.second); |
233 | } | 236 | } |
234 | Sink::Store::create(resource) | 237 | Store::create(resource) |
235 | .onError([](const KAsync::Error &error) { | 238 | .onError([](const KAsync::Error &error) { |
236 | qWarning() << "Error while creating resource: " << error.errorMessage; | 239 | qWarning() << "Error while creating resource: " << error.errorMessage; |
237 | }) | 240 | }) |
@@ -243,7 +246,7 @@ static QByteArray saveResource(const QByteArray &accountIdentifier, const QByteA | |||
243 | 246 | ||
244 | void AccountSettings::saveImapResource() | 247 | void AccountSettings::saveImapResource() |
245 | { | 248 | { |
246 | mImapIdentifier = saveResource<Sink::ApplicationDomain::ImapResource>(mAccountIdentifier, mImapIdentifier, { | 249 | mImapIdentifier = saveResource<ImapResource>(mAccountIdentifier, mImapIdentifier, { |
247 | {"server", mImapServer}, | 250 | {"server", mImapServer}, |
248 | {"username", mImapUsername}, | 251 | {"username", mImapUsername}, |
249 | {"password", mImapPassword}, | 252 | {"password", mImapPassword}, |
@@ -252,14 +255,14 @@ void AccountSettings::saveImapResource() | |||
252 | 255 | ||
253 | void AccountSettings::saveMaildirResource() | 256 | void AccountSettings::saveMaildirResource() |
254 | { | 257 | { |
255 | mMaildirIdentifier = saveResource<Sink::ApplicationDomain::MaildirResource>(mAccountIdentifier, mMaildirIdentifier, { | 258 | mMaildirIdentifier = saveResource<MaildirResource>(mAccountIdentifier, mMaildirIdentifier, { |
256 | {"path", mPath}, | 259 | {"path", mPath}, |
257 | }); | 260 | }); |
258 | } | 261 | } |
259 | 262 | ||
260 | void AccountSettings::saveMailtransportResource() | 263 | void AccountSettings::saveMailtransportResource() |
261 | { | 264 | { |
262 | mMailtransportIdentifier = saveResource<Sink::ApplicationDomain::MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, { | 265 | mMailtransportIdentifier = saveResource<MailtransportResource>(mAccountIdentifier, mMailtransportIdentifier, { |
263 | {"server", mSmtpServer}, | 266 | {"server", mSmtpServer}, |
264 | {"username", mSmtpUsername}, | 267 | {"username", mSmtpUsername}, |
265 | {"password", mSmtpPassword}, | 268 | {"password", mSmtpPassword}, |
@@ -269,21 +272,21 @@ void AccountSettings::saveMailtransportResource() | |||
269 | void AccountSettings::saveIdentity() | 272 | void AccountSettings::saveIdentity() |
270 | { | 273 | { |
271 | if (!mIdentityIdentifier.isEmpty()) { | 274 | if (!mIdentityIdentifier.isEmpty()) { |
272 | Sink::ApplicationDomain::Identity identity(mMailtransportIdentifier); | 275 | Identity identity(mMailtransportIdentifier); |
273 | identity.setProperty("username", mUsername); | 276 | identity.setProperty("username", mUsername); |
274 | identity.setProperty("address", mEmailAddress); | 277 | identity.setProperty("address", mEmailAddress); |
275 | Sink::Store::modify(identity) | 278 | Store::modify(identity) |
276 | .onError([](const KAsync::Error &error) { | 279 | .onError([](const KAsync::Error &error) { |
277 | qWarning() << "Error while modifying identity: " << error.errorMessage; | 280 | qWarning() << "Error while modifying identity: " << error.errorMessage; |
278 | }) | 281 | }) |
279 | .exec(); | 282 | .exec(); |
280 | } else { | 283 | } else { |
281 | auto identity = Sink::ApplicationDomain::ApplicationDomainType::createEntity<Sink::ApplicationDomain::Identity>(); | 284 | auto identity = ApplicationDomainType::createEntity<Identity>(); |
282 | mIdentityIdentifier = identity.identifier(); | 285 | mIdentityIdentifier = identity.identifier(); |
283 | identity.setProperty("account", mAccountIdentifier); | 286 | identity.setProperty("account", mAccountIdentifier); |
284 | identity.setProperty("username", mUsername); | 287 | identity.setProperty("username", mUsername); |
285 | identity.setProperty("address", mEmailAddress); | 288 | identity.setProperty("address", mEmailAddress); |
286 | Sink::Store::create(identity) | 289 | Store::create(identity) |
287 | .onError([](const KAsync::Error &error) { | 290 | .onError([](const KAsync::Error &error) { |
288 | qWarning() << "Error while creating identity: " << error.errorMessage; | 291 | qWarning() << "Error while creating identity: " << error.errorMessage; |
289 | }) | 292 | }) |
@@ -296,8 +299,8 @@ void AccountSettings::removeResource(const QByteArray &identifier) | |||
296 | if (identifier.isEmpty()) { | 299 | if (identifier.isEmpty()) { |
297 | qWarning() << "We're missing an identifier"; | 300 | qWarning() << "We're missing an identifier"; |
298 | } else { | 301 | } else { |
299 | Sink::ApplicationDomain::SinkResource resource("", identifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 302 | SinkResource resource("", identifier, 0, QSharedPointer<MemoryBufferAdaptor>::create()); |
300 | Sink::Store::remove(resource) | 303 | Store::remove(resource) |
301 | .onError([](const KAsync::Error &error) { | 304 | .onError([](const KAsync::Error &error) { |
302 | qWarning() << "Error while removing resource: " << error.errorMessage; | 305 | qWarning() << "Error while removing resource: " << error.errorMessage; |
303 | }) | 306 | }) |
@@ -310,8 +313,8 @@ void AccountSettings::removeAccount() | |||
310 | if (mAccountIdentifier.isEmpty()) { | 313 | if (mAccountIdentifier.isEmpty()) { |
311 | qWarning() << "We're missing an identifier"; | 314 | qWarning() << "We're missing an identifier"; |
312 | } else { | 315 | } else { |
313 | Sink::ApplicationDomain::SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 316 | SinkAccount account("", mAccountIdentifier, 0, QSharedPointer<MemoryBufferAdaptor>::create()); |
314 | Sink::Store::remove(account) | 317 | Store::remove(account) |
315 | .onError([](const KAsync::Error &error) { | 318 | .onError([](const KAsync::Error &error) { |
316 | qWarning() << "Error while removing account: " << error.errorMessage; | 319 | qWarning() << "Error while removing account: " << error.errorMessage; |
317 | }) | 320 | }) |
@@ -324,8 +327,8 @@ void AccountSettings::removeIdentity() | |||
324 | if (mIdentityIdentifier.isEmpty()) { | 327 | if (mIdentityIdentifier.isEmpty()) { |
325 | qWarning() << "We're missing an identifier"; | 328 | qWarning() << "We're missing an identifier"; |
326 | } else { | 329 | } else { |
327 | Sink::ApplicationDomain::Identity identity("", mIdentityIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create()); | 330 | Identity identity("", mIdentityIdentifier, 0, QSharedPointer<MemoryBufferAdaptor>::create()); |
328 | Sink::Store::remove(identity) | 331 | Store::remove(identity) |
329 | .onError([](const KAsync::Error &error) { | 332 | .onError([](const KAsync::Error &error) { |
330 | qWarning() << "Error while removing identity: " << error.errorMessage; | 333 | qWarning() << "Error while removing identity: " << error.errorMessage; |
331 | }) | 334 | }) |