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/mailcontroller.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/mailcontroller.cpp')
-rw-r--r-- | framework/domain/mailcontroller.cpp | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/framework/domain/mailcontroller.cpp b/framework/domain/mailcontroller.cpp index 3e5e6ed4..962b785f 100644 --- a/framework/domain/mailcontroller.cpp +++ b/framework/domain/mailcontroller.cpp | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <sink/store.h> | 21 | #include <sink/store.h> |
22 | #include <sink/log.h> | 22 | #include <sink/log.h> |
23 | #include <sink/standardqueries.h> | ||
23 | 24 | ||
24 | SINK_DEBUG_AREA("mailcontroller"); | 25 | SINK_DEBUG_AREA("mailcontroller"); |
25 | 26 | ||
@@ -33,15 +34,31 @@ MailController::MailController() | |||
33 | action_markAsImportant{new Kube::ControllerAction{this, &MailController::markAsImportant}}, | 34 | action_markAsImportant{new Kube::ControllerAction{this, &MailController::markAsImportant}}, |
34 | action_moveToTrash{new Kube::ControllerAction{this, &MailController::moveToTrash}}, | 35 | action_moveToTrash{new Kube::ControllerAction{this, &MailController::moveToTrash}}, |
35 | action_restoreFromTrash{new Kube::ControllerAction{this, &MailController::restoreFromTrash}}, | 36 | action_restoreFromTrash{new Kube::ControllerAction{this, &MailController::restoreFromTrash}}, |
36 | action_remove{new Kube::ControllerAction{this, &MailController::remove}} | 37 | action_remove{new Kube::ControllerAction{this, &MailController::remove}}, |
38 | action_moveToFolder{new Kube::ControllerAction{this, &MailController::moveToFolder}} | ||
37 | { | 39 | { |
38 | QObject::connect(this, &MailController::mailChanged, &MailController::updateActions); | 40 | QObject::connect(this, &MailController::mailChanged, &MailController::updateActions); |
39 | updateActions(); | 41 | updateActions(); |
40 | } | 42 | } |
41 | 43 | ||
42 | void MailController::updateActions() | 44 | void MailController::runModification(const std::function<void(ApplicationDomain::Mail &)> &f) |
43 | { | 45 | { |
44 | if (auto mail = getMail()) { | 46 | if (auto mail = getMail()) { |
47 | f(*mail); | ||
48 | run(Store::modify(*mail)); | ||
49 | } else if (auto mail = getThreadLeader()) { | ||
50 | f(*mail); | ||
51 | run(Store::modify(Sink::StandardQueries::completeThread(*mail), *mail)); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | void MailController::updateActions() | ||
56 | { | ||
57 | auto mail = getMail(); | ||
58 | if (!mail) { | ||
59 | mail= getThreadLeader(); | ||
60 | } | ||
61 | if (mail) { | ||
45 | action_moveToTrash->setEnabled(!mail->getTrash()); | 62 | action_moveToTrash->setEnabled(!mail->getTrash()); |
46 | action_restoreFromTrash->setEnabled(mail->getTrash()); | 63 | action_restoreFromTrash->setEnabled(mail->getTrash()); |
47 | } | 64 | } |
@@ -49,49 +66,58 @@ void MailController::updateActions() | |||
49 | 66 | ||
50 | void MailController::markAsRead() | 67 | void MailController::markAsRead() |
51 | { | 68 | { |
52 | auto mail = getMail(); | 69 | runModification([] (ApplicationDomain::Mail &mail) { |
53 | mail->setUnread(false); | 70 | mail.setUnread(false); |
54 | SinkLog() << "Mark as read " << mail->identifier(); | 71 | SinkLog() << "Mark as read " << mail.identifier(); |
55 | run(Store::modify(*mail)); | 72 | }); |
56 | } | 73 | } |
57 | 74 | ||
58 | void MailController::markAsUnread() | 75 | void MailController::markAsUnread() |
59 | { | 76 | { |
60 | auto mail = getMail(); | 77 | runModification([] (ApplicationDomain::Mail &mail) { |
61 | mail->setUnread(true); | 78 | mail.setUnread(true); |
62 | SinkLog() << "Mark as unread " << mail->identifier(); | 79 | SinkLog() << "Mark as unread " << mail.identifier(); |
63 | run(Store::modify(*mail)); | 80 | }); |
64 | } | 81 | } |
65 | 82 | ||
66 | void MailController::markAsImportant() | 83 | void MailController::markAsImportant() |
67 | { | 84 | { |
68 | auto mail = getMail(); | 85 | runModification([] (ApplicationDomain::Mail &mail) { |
69 | mail->setImportant(true); | 86 | mail.setImportant(true); |
70 | SinkLog() << "Mark as important " << mail->identifier(); | 87 | SinkLog() << "Mark as important " << mail.identifier(); |
71 | run(Store::modify(*mail)); | 88 | }); |
72 | } | 89 | } |
73 | 90 | ||
74 | void MailController::moveToTrash() | 91 | void MailController::moveToTrash() |
75 | { | 92 | { |
76 | auto mail = getMail(); | 93 | runModification([] (ApplicationDomain::Mail &mail) { |
77 | mail->setTrash(true); | 94 | mail.setTrash(true); |
78 | SinkLog() << "Move to trash " << mail->identifier(); | 95 | SinkLog() << "Move to trash " << mail.identifier(); |
79 | run(Store::modify(*mail)); | 96 | }); |
80 | } | 97 | } |
81 | 98 | ||
82 | void MailController::restoreFromTrash() | 99 | void MailController::restoreFromTrash() |
83 | { | 100 | { |
84 | auto mail = getMail(); | 101 | runModification([] (ApplicationDomain::Mail &mail) { |
85 | mail->setTrash(false); | 102 | mail.setTrash(false); |
86 | SinkLog() << "Restore from trash " << mail->identifier(); | 103 | SinkLog() << "Restore from trash " << mail.identifier(); |
87 | run(Store::modify(*mail)); | 104 | }); |
88 | } | 105 | } |
89 | 106 | ||
90 | void MailController::remove() | 107 | void MailController::remove() |
91 | { | 108 | { |
92 | auto mail = getMail(); | 109 | runModification([] (ApplicationDomain::Mail &mail) { |
93 | mail->setTrash(true); | 110 | mail.setTrash(true); |
94 | SinkLog() << "Remove " << mail->identifier(); | 111 | SinkLog() << "Remove " << mail.identifier(); |
95 | run(Store::remove(*mail)); | 112 | }); |
113 | } | ||
114 | |||
115 | void MailController::moveToFolder() | ||
116 | { | ||
117 | runModification([&] (ApplicationDomain::Mail &mail) { | ||
118 | auto targetFolder = getTargetFolder(); | ||
119 | mail.setFolder(*targetFolder); | ||
120 | SinkLog() << "Moving to folder " << mail.identifier() << targetFolder->identifier(); | ||
121 | }); | ||
96 | } | 122 | } |
97 | 123 | ||