diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-24 10:50:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-24 10:50:28 +0100 |
commit | c607a01b6931604baffef846dccad38f7a71a192 (patch) | |
tree | 3d29fc49740068c5c66f5da95aea11d884e5a30e /framework/domain/composercontroller.cpp | |
parent | 1bafda42888c37b47bdd5d18118bf3e6912f0f82 (diff) | |
parent | 07b55e8e8b21873eeb5b39f1306f6665b1630c46 (diff) | |
download | kube-c607a01b6931604baffef846dccad38f7a71a192.tar.gz kube-c607a01b6931604baffef846dccad38f7a71a192.zip |
Merge branch 'dev/imapsync' into develop
Diffstat (limited to 'framework/domain/composercontroller.cpp')
-rw-r--r-- | framework/domain/composercontroller.cpp | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index a4a8857f..207c5047 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -97,9 +97,20 @@ ComposerController::ComposerController() | |||
97 | 97 | ||
98 | QObject::connect(this, &ComposerController::toChanged, &ComposerController::updateSendAction); | 98 | QObject::connect(this, &ComposerController::toChanged, &ComposerController::updateSendAction); |
99 | QObject::connect(this, &ComposerController::subjectChanged, &ComposerController::updateSendAction); | 99 | QObject::connect(this, &ComposerController::subjectChanged, &ComposerController::updateSendAction); |
100 | QObject::connect(this, &ComposerController::accountIdChanged, &ComposerController::updateSendAction); | ||
101 | QObject::connect(this, &ComposerController::toChanged, &ComposerController::updateSaveAsDraftAction); | ||
102 | QObject::connect(this, &ComposerController::subjectChanged, &ComposerController::updateSaveAsDraftAction); | ||
103 | QObject::connect(this, &ComposerController::accountIdChanged, &ComposerController::updateSaveAsDraftAction); | ||
100 | updateSendAction(); | 104 | updateSendAction(); |
101 | } | 105 | } |
102 | 106 | ||
107 | void ComposerController::clear() | ||
108 | { | ||
109 | Controller::clear(); | ||
110 | //Reapply account and identity from selection | ||
111 | mIdentitySelector->reapplyCurrentIndex(); | ||
112 | } | ||
113 | |||
103 | Completer *ComposerController::recipientCompleter() const | 114 | Completer *ComposerController::recipientCompleter() const |
104 | { | 115 | { |
105 | return mRecipientCompleter.data(); | 116 | return mRecipientCompleter.data(); |
@@ -123,7 +134,7 @@ void ComposerController::loadMessage(const QVariant &message, bool loadAsDraft) | |||
123 | { | 134 | { |
124 | Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); | 135 | Sink::Query query(*message.value<Sink::ApplicationDomain::Mail::Ptr>()); |
125 | query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); | 136 | query.request<Sink::ApplicationDomain::Mail::MimeMessage>(); |
126 | Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).syncThen<void, Sink::ApplicationDomain::Mail>([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { | 137 | Sink::Store::fetchOne<Sink::ApplicationDomain::Mail>(query).then([this, loadAsDraft](const Sink::ApplicationDomain::Mail &mail) { |
127 | setExistingMail(mail); | 138 | setExistingMail(mail); |
128 | 139 | ||
129 | //TODO this should probably happen as reaction to the property being set. | 140 | //TODO this should probably happen as reaction to the property being set. |
@@ -199,7 +210,7 @@ KMime::Message::Ptr ComposerController::assembleMessage() | |||
199 | 210 | ||
200 | void ComposerController::updateSendAction() | 211 | void ComposerController::updateSendAction() |
201 | { | 212 | { |
202 | auto enabled = !getTo().isEmpty() && !getSubject().isEmpty(); | 213 | auto enabled = !getTo().isEmpty() && !getSubject().isEmpty() && !getAccountId().isEmpty(); |
203 | sendAction()->setEnabled(enabled); | 214 | sendAction()->setEnabled(enabled); |
204 | } | 215 | } |
205 | 216 | ||
@@ -214,33 +225,42 @@ void ComposerController::send() | |||
214 | using namespace Sink; | 225 | using namespace Sink; |
215 | using namespace Sink::ApplicationDomain; | 226 | using namespace Sink::ApplicationDomain; |
216 | 227 | ||
228 | Q_ASSERT(!accountId.isEmpty()); | ||
217 | Query query; | 229 | Query query; |
218 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); | 230 | query.containsFilter<ApplicationDomain::SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::transport); |
219 | query.filter<SinkResource::Account>(accountId); | 231 | query.filter<SinkResource::Account>(accountId); |
220 | auto job = Store::fetchAll<ApplicationDomain::SinkResource>(query) | 232 | auto job = Store::fetchAll<ApplicationDomain::SinkResource>(query) |
221 | .then<void, QList<ApplicationDomain::SinkResource::Ptr>>([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) -> KAsync::Job<void> { | 233 | .then([=](const QList<ApplicationDomain::SinkResource::Ptr> &resources) { |
222 | if (!resources.isEmpty()) { | 234 | if (!resources.isEmpty()) { |
223 | auto resourceId = resources[0]->identifier(); | 235 | auto resourceId = resources[0]->identifier(); |
224 | SinkTrace() << "Sending message via resource: " << resourceId; | 236 | SinkLog() << "Sending message via resource: " << resourceId; |
225 | Mail mail(resourceId); | 237 | Mail mail(resourceId); |
226 | mail.setBlobProperty("mimeMessage", message->encodedContent()); | 238 | mail.setMimeMessage(message->encodedContent()); |
227 | return Store::create(mail); | 239 | return Store::create(mail) |
240 | .then<void>([=] { | ||
241 | //Trigger a sync, but don't wait for it. | ||
242 | Store::synchronize(Sink::SyncScope{}.resourceFilter(resourceId)).exec(); | ||
243 | }); | ||
228 | } | 244 | } |
245 | SinkWarning() << "Failed to find a mailtransport resource"; | ||
229 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); | 246 | return KAsync::error<void>(0, "Failed to find a MailTransport resource."); |
247 | }) | ||
248 | .then([&] (const KAsync::Error &error) { | ||
249 | SinkLog() << "Message was sent: "; | ||
250 | emit done(); | ||
230 | }); | 251 | }); |
231 | run(job); | 252 | run(job); |
232 | job = job.syncThen<void>([&] { | ||
233 | emit done(); | ||
234 | }); | ||
235 | } | 253 | } |
236 | 254 | ||
237 | void ComposerController::updateSaveAsDraftAction() | 255 | void ComposerController::updateSaveAsDraftAction() |
238 | { | 256 | { |
239 | sendAction()->setEnabled(true); | 257 | bool enabled = !getAccountId().isEmpty(); |
258 | sendAction()->setEnabled(enabled); | ||
240 | } | 259 | } |
241 | 260 | ||
242 | void ComposerController::saveAsDraft() | 261 | void ComposerController::saveAsDraft() |
243 | { | 262 | { |
263 | SinkLog() << "Save as draft"; | ||
244 | const auto accountId = getAccountId(); | 264 | const auto accountId = getAccountId(); |
245 | auto existingMail = getExistingMail(); | 265 | auto existingMail = getExistingMail(); |
246 | 266 | ||
@@ -249,7 +269,6 @@ void ComposerController::saveAsDraft() | |||
249 | if (!message) { | 269 | if (!message) { |
250 | SinkWarning() << "Failed to get the mail: "; | 270 | SinkWarning() << "Failed to get the mail: "; |
251 | return; | 271 | return; |
252 | // return KAsync::error<void>(1, "Failed to get the mail."); | ||
253 | } | 272 | } |
254 | 273 | ||
255 | using namespace Sink; | 274 | using namespace Sink; |
@@ -257,24 +276,28 @@ void ComposerController::saveAsDraft() | |||
257 | 276 | ||
258 | auto job = [&] { | 277 | auto job = [&] { |
259 | if (existingMail.identifier().isEmpty()) { | 278 | if (existingMail.identifier().isEmpty()) { |
279 | SinkLog() << "Creating a new draft" << existingMail.identifier(); | ||
260 | Query query; | 280 | Query query; |
261 | query.containsFilter<SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::drafts); | 281 | query.containsFilter<SinkResource::Capabilities>(ApplicationDomain::ResourceCapabilities::Mail::drafts); |
262 | query.filter<SinkResource::Account>(accountId); | 282 | query.filter<SinkResource::Account>(accountId); |
263 | return Store::fetchOne<SinkResource>(query) | 283 | return Store::fetchOne<SinkResource>(query) |
264 | .then<void, SinkResource>([=](const SinkResource &resource) -> KAsync::Job<void> { | 284 | .then([=](const SinkResource &resource) { |
265 | Mail mail(resource.identifier()); | 285 | Mail mail(resource.identifier()); |
266 | mail.setDraft(true); | 286 | mail.setDraft(true); |
267 | mail.setMimeMessage(message->encodedContent()); | 287 | mail.setMimeMessage(message->encodedContent()); |
268 | return Store::create(mail); | 288 | return Store::create(mail); |
289 | }) | ||
290 | .onError([] (const KAsync::Error &error) { | ||
291 | SinkWarning() << "Error while creating draft: " << error.errorMessage; | ||
269 | }); | 292 | }); |
270 | } else { | 293 | } else { |
271 | SinkWarning() << "Modifying an existing mail" << existingMail.identifier(); | 294 | SinkLog() << "Modifying an existing mail" << existingMail.identifier(); |
272 | existingMail.setDraft(true); | 295 | existingMail.setDraft(true); |
273 | existingMail.setMimeMessage(message->encodedContent()); | 296 | existingMail.setMimeMessage(message->encodedContent()); |
274 | return Store::modify(existingMail); | 297 | return Store::modify(existingMail); |
275 | } | 298 | } |
276 | }(); | 299 | }(); |
277 | job = job.syncThen<void>([&] { | 300 | job = job.then([&] (const KAsync::Error &) { |
278 | emit done(); | 301 | emit done(); |
279 | }); | 302 | }); |
280 | run(job); | 303 | run(job); |