summaryrefslogtreecommitdiffstats
path: root/framework/domain/mailcontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/mailcontroller.cpp')
-rw-r--r--framework/domain/mailcontroller.cpp78
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
24SINK_DEBUG_AREA("mailcontroller"); 25SINK_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
42void MailController::updateActions() 44void 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
55void 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
50void MailController::markAsRead() 67void 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
58void MailController::markAsUnread() 75void 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
66void MailController::markAsImportant() 83void 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
74void MailController::moveToTrash() 91void 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
82void MailController::restoreFromTrash() 99void 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
90void MailController::remove() 107void 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
115void 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