summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/mailcontroller.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 21:51:24 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-24 21:51:24 +0200
commitb3223155b178427354b44f05167d0afba0926cbd (patch)
tree25021116a0f465a6973e36b668945080f3b9fc4b /framework/src/domain/mailcontroller.cpp
parent4ba8c5b72fd7a3db6e593853c4669750dc6dd2a2 (diff)
downloadkube-b3223155b178427354b44f05167d0afba0926cbd.tar.gz
kube-b3223155b178427354b44f05167d0afba0926cbd.zip
Another bunch of controllers gone
Diffstat (limited to 'framework/src/domain/mailcontroller.cpp')
-rw-r--r--framework/src/domain/mailcontroller.cpp142
1 files changed, 0 insertions, 142 deletions
diff --git a/framework/src/domain/mailcontroller.cpp b/framework/src/domain/mailcontroller.cpp
deleted file mode 100644
index ea0fe690..00000000
--- a/framework/src/domain/mailcontroller.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#include "mailcontroller.h"
20
21#include <sink/store.h>
22#include <sink/log.h>
23#include <sink/standardqueries.h>
24
25SINK_DEBUG_AREA("mailcontroller");
26
27using namespace Sink;
28using namespace Sink::ApplicationDomain;
29
30MailController::MailController()
31 : Kube::Controller(),
32 action_markAsRead{new Kube::ControllerAction{this, &MailController::markAsRead}},
33 action_markAsUnread{new Kube::ControllerAction{this, &MailController::markAsUnread}},
34 action_markAsImportant{new Kube::ControllerAction{this, &MailController::markAsImportant}},
35 action_toggleImportant{new Kube::ControllerAction{this, &MailController::toggleImportant}},
36 action_moveToTrash{new Kube::ControllerAction{this, &MailController::moveToTrash}},
37 action_restoreFromTrash{new Kube::ControllerAction{this, &MailController::restoreFromTrash}},
38 action_remove{new Kube::ControllerAction{this, &MailController::remove}},
39 action_moveToFolder{new Kube::ControllerAction{this, &MailController::moveToFolder}}
40{
41 QObject::connect(this, &MailController::mailChanged, &MailController::updateActions);
42 QObject::connect(this, &MailController::importantChanged, &MailController::updateActions);
43 QObject::connect(this, &MailController::draftChanged, &MailController::updateActions);
44 QObject::connect(this, &MailController::trashChanged, &MailController::updateActions);
45 QObject::connect(this, &MailController::unreadChanged, &MailController::updateActions);
46 updateActions();
47}
48
49void MailController::runModification(const std::function<void(ApplicationDomain::Mail &)> &f)
50{
51 if (auto mail = getMail()) {
52 f(*mail);
53 if (getOperateOnThreads()) {
54 run(Store::modify(Sink::StandardQueries::completeThread(*mail), *mail));
55 } else {
56 run(Store::modify(*mail));
57 }
58 }
59}
60
61void MailController::updateActions()
62{
63 if (auto mail = getMail()) {
64 action_moveToTrash->setEnabled(!getTrash());
65 action_restoreFromTrash->setEnabled(getTrash());
66 action_markAsRead->setEnabled(getUnread());
67 action_markAsUnread->setEnabled(!getUnread());
68 action_markAsImportant->setEnabled(!getImportant());
69 } else {
70 action_moveToTrash->setEnabled(false);
71 action_restoreFromTrash->setEnabled(false);
72 action_markAsRead->setEnabled(false);
73 action_markAsUnread->setEnabled(false);
74 action_markAsImportant->setEnabled(false);
75 }
76}
77
78void MailController::markAsRead()
79{
80 runModification([] (ApplicationDomain::Mail &mail) {
81 mail.setUnread(false);
82 SinkLog() << "Mark as read " << mail.identifier();
83 });
84}
85
86void MailController::markAsUnread()
87{
88 runModification([] (ApplicationDomain::Mail &mail) {
89 mail.setUnread(true);
90 SinkLog() << "Mark as unread " << mail.identifier();
91 });
92}
93
94void MailController::markAsImportant()
95{
96 runModification([] (ApplicationDomain::Mail &mail) {
97 mail.setImportant(true);
98 SinkLog() << "Mark as important " << mail.identifier();
99 });
100}
101
102void MailController::toggleImportant()
103{
104 runModification([this] (ApplicationDomain::Mail &mail) {
105 mail.setImportant(!getImportant());
106 SinkLog() << "Toggle important " << mail.identifier() << mail.getImportant();
107 });
108}
109
110void MailController::moveToTrash()
111{
112 runModification([] (ApplicationDomain::Mail &mail) {
113 mail.setTrash(true);
114 SinkLog() << "Move to trash " << mail.identifier();
115 });
116}
117
118void MailController::restoreFromTrash()
119{
120 runModification([] (ApplicationDomain::Mail &mail) {
121 mail.setTrash(false);
122 SinkLog() << "Restore from trash " << mail.identifier();
123 });
124}
125
126void MailController::remove()
127{
128 runModification([] (ApplicationDomain::Mail &mail) {
129 mail.setTrash(true);
130 SinkLog() << "Remove " << mail.identifier();
131 });
132}
133
134void MailController::moveToFolder()
135{
136 runModification([&] (ApplicationDomain::Mail &mail) {
137 auto targetFolder = getTargetFolder();
138 mail.setFolder(*targetFolder);
139 SinkLog() << "Moving to folder " << mail.identifier() << targetFolder->identifier();
140 });
141}
142