diff options
Diffstat (limited to 'framework/domain/mailcontroller.cpp')
-rw-r--r-- | framework/domain/mailcontroller.cpp | 76 |
1 files changed, 46 insertions, 30 deletions
diff --git a/framework/domain/mailcontroller.cpp b/framework/domain/mailcontroller.cpp index a5d7efb7..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 | ||
@@ -40,9 +41,24 @@ MailController::MailController() | |||
40 | updateActions(); | 41 | updateActions(); |
41 | } | 42 | } |
42 | 43 | ||
43 | void MailController::updateActions() | 44 | void MailController::runModification(const std::function<void(ApplicationDomain::Mail &)> &f) |
44 | { | 45 | { |
45 | 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) { | ||
46 | action_moveToTrash->setEnabled(!mail->getTrash()); | 62 | action_moveToTrash->setEnabled(!mail->getTrash()); |
47 | action_restoreFromTrash->setEnabled(mail->getTrash()); | 63 | action_restoreFromTrash->setEnabled(mail->getTrash()); |
48 | } | 64 | } |
@@ -50,58 +66,58 @@ void MailController::updateActions() | |||
50 | 66 | ||
51 | void MailController::markAsRead() | 67 | void MailController::markAsRead() |
52 | { | 68 | { |
53 | auto mail = getMail(); | 69 | runModification([] (ApplicationDomain::Mail &mail) { |
54 | mail->setUnread(false); | 70 | mail.setUnread(false); |
55 | SinkLog() << "Mark as read " << mail->identifier(); | 71 | SinkLog() << "Mark as read " << mail.identifier(); |
56 | run(Store::modify(*mail)); | 72 | }); |
57 | } | 73 | } |
58 | 74 | ||
59 | void MailController::markAsUnread() | 75 | void MailController::markAsUnread() |
60 | { | 76 | { |
61 | auto mail = getMail(); | 77 | runModification([] (ApplicationDomain::Mail &mail) { |
62 | mail->setUnread(true); | 78 | mail.setUnread(true); |
63 | SinkLog() << "Mark as unread " << mail->identifier(); | 79 | SinkLog() << "Mark as unread " << mail.identifier(); |
64 | run(Store::modify(*mail)); | 80 | }); |
65 | } | 81 | } |
66 | 82 | ||
67 | void MailController::markAsImportant() | 83 | void MailController::markAsImportant() |
68 | { | 84 | { |
69 | auto mail = getMail(); | 85 | runModification([] (ApplicationDomain::Mail &mail) { |
70 | mail->setImportant(true); | 86 | mail.setImportant(true); |
71 | SinkLog() << "Mark as important " << mail->identifier(); | 87 | SinkLog() << "Mark as important " << mail.identifier(); |
72 | run(Store::modify(*mail)); | 88 | }); |
73 | } | 89 | } |
74 | 90 | ||
75 | void MailController::moveToTrash() | 91 | void MailController::moveToTrash() |
76 | { | 92 | { |
77 | auto mail = getMail(); | 93 | runModification([] (ApplicationDomain::Mail &mail) { |
78 | mail->setTrash(true); | 94 | mail.setTrash(true); |
79 | SinkLog() << "Move to trash " << mail->identifier(); | 95 | SinkLog() << "Move to trash " << mail.identifier(); |
80 | run(Store::modify(*mail)); | 96 | }); |
81 | } | 97 | } |
82 | 98 | ||
83 | void MailController::restoreFromTrash() | 99 | void MailController::restoreFromTrash() |
84 | { | 100 | { |
85 | auto mail = getMail(); | 101 | runModification([] (ApplicationDomain::Mail &mail) { |
86 | mail->setTrash(false); | 102 | mail.setTrash(false); |
87 | SinkLog() << "Restore from trash " << mail->identifier(); | 103 | SinkLog() << "Restore from trash " << mail.identifier(); |
88 | run(Store::modify(*mail)); | 104 | }); |
89 | } | 105 | } |
90 | 106 | ||
91 | void MailController::remove() | 107 | void MailController::remove() |
92 | { | 108 | { |
93 | auto mail = getMail(); | 109 | runModification([] (ApplicationDomain::Mail &mail) { |
94 | mail->setTrash(true); | 110 | mail.setTrash(true); |
95 | SinkLog() << "Remove " << mail->identifier(); | 111 | SinkLog() << "Remove " << mail.identifier(); |
96 | run(Store::remove(*mail)); | 112 | }); |
97 | } | 113 | } |
98 | 114 | ||
99 | void MailController::moveToFolder() | 115 | void MailController::moveToFolder() |
100 | { | 116 | { |
101 | auto mail = getMail(); | 117 | runModification([&] (ApplicationDomain::Mail &mail) { |
102 | auto targetFolder = getTargetFolder(); | 118 | auto targetFolder = getTargetFolder(); |
103 | mail->setFolder(*targetFolder); | 119 | mail.setFolder(*targetFolder); |
104 | SinkLog() << "Moving to folder " << mail->identifier() << targetFolder->identifier(); | 120 | SinkLog() << "Moving to folder " << mail.identifier() << targetFolder->identifier(); |
105 | run(Store::modify(*mail)); | 121 | }); |
106 | } | 122 | } |
107 | 123 | ||