summaryrefslogtreecommitdiffstats
path: root/framework/src
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src')
-rw-r--r--framework/src/CMakeLists.txt5
-rw-r--r--framework/src/domain/foldercontroller.cpp62
-rw-r--r--framework/src/domain/foldercontroller.h36
-rw-r--r--framework/src/domain/mailcontroller.cpp142
-rw-r--r--framework/src/domain/mailcontroller.h51
-rw-r--r--framework/src/domain/outboxcontroller.cpp60
-rw-r--r--framework/src/domain/outboxcontroller.h37
-rw-r--r--framework/src/frameworkplugin.cpp6
-rw-r--r--framework/src/sinkfabric.cpp15
9 files changed, 16 insertions, 398 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index 73e489b1..8dc844cc 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -39,12 +39,9 @@ set(SRCS
39 domain/settings/accountsettings.cpp 39 domain/settings/accountsettings.cpp
40 domain/selector.cpp 40 domain/selector.cpp
41 domain/completer.cpp 41 domain/completer.cpp
42 domain/controller.cpp
43 domain/outboxcontroller.cpp
44 domain/mailcontroller.cpp
45 domain/foldercontroller.cpp
46 domain/mouseproxy.cpp 42 domain/mouseproxy.cpp
47 domain/contactcontroller.cpp 43 domain/contactcontroller.cpp
44 domain/controller.cpp
48 domain/peoplemodel.cpp 45 domain/peoplemodel.cpp
49 accounts/accountfactory.cpp 46 accounts/accountfactory.cpp
50 accounts/accountsmodel.cpp 47 accounts/accountsmodel.cpp
diff --git a/framework/src/domain/foldercontroller.cpp b/framework/src/domain/foldercontroller.cpp
deleted file mode 100644
index 3c10f773..00000000
--- a/framework/src/domain/foldercontroller.cpp
+++ /dev/null
@@ -1,62 +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 "foldercontroller.h"
20
21#include <sink/store.h>
22#include <sink/log.h>
23
24SINK_DEBUG_AREA("foldercontroller");
25
26using namespace Sink;
27using namespace Sink::ApplicationDomain;
28
29FolderController::FolderController()
30 : Kube::Controller(),
31 action_synchronize{new Kube::ControllerAction{this, &FolderController::synchronize}},
32 action_moveToFolder{new Kube::ControllerAction{this, &FolderController::moveToFolder}}
33{
34}
35
36void FolderController::synchronize()
37{
38 auto job = [&] {
39 auto accountId = getAccountId();
40 if (auto folder = getFolder()) {
41 SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier();
42 auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<ApplicationDomain::Mail::Folder>(QVariant::fromValue(folder->identifier()));
43 scope.setType<ApplicationDomain::Mail>();
44 return Store::synchronize(scope);
45 } else if (!accountId.isEmpty()) {
46 return Store::synchronize(SyncScope{}.resourceFilter<ApplicationDomain::SinkResource::Account>(accountId));
47 } else {
48 SinkLog() << "Synchronizing all";
49 return Store::synchronize(SyncScope());
50 }
51 }();
52 run(job);
53}
54
55void FolderController::moveToFolder()
56{
57 auto mail = getMail();
58 auto targetFolder = getFolder();
59 mail->setFolder(*targetFolder);
60 SinkLog() << "Moving to folder " << mail->identifier() << targetFolder->identifier();
61 run(Store::modify(*mail));
62}
diff --git a/framework/src/domain/foldercontroller.h b/framework/src/domain/foldercontroller.h
deleted file mode 100644
index c0815546..00000000
--- a/framework/src/domain/foldercontroller.h
+++ /dev/null
@@ -1,36 +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#pragma once
20
21#include <QObject>
22#include "controller.h"
23#include "sink/applicationdomaintype.h"
24
25class FolderController : public Kube::Controller
26{
27 Q_OBJECT
28 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder)
29 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail)
30 KUBE_CONTROLLER_PROPERTY(QByteArray, AccountId, accountId)
31 KUBE_CONTROLLER_ACTION(synchronize)
32 KUBE_CONTROLLER_ACTION(moveToFolder)
33
34public:
35 explicit FolderController();
36};
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
diff --git a/framework/src/domain/mailcontroller.h b/framework/src/domain/mailcontroller.h
deleted file mode 100644
index 0bc000f1..00000000
--- a/framework/src/domain/mailcontroller.h
+++ /dev/null
@@ -1,51 +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#pragma once
20
21#include <QObject>
22#include "controller.h"
23#include "sink/applicationdomaintype.h"
24
25class MailController : public Kube::Controller
26{
27 Q_OBJECT
28 //Use this instead of mail property to get overall status of thread.
29 KUBE_CONTROLLER_PROPERTY(bool, Unread, unread)
30 KUBE_CONTROLLER_PROPERTY(bool, Important, important)
31 KUBE_CONTROLLER_PROPERTY(bool, Trash, trash)
32 KUBE_CONTROLLER_PROPERTY(bool, Draft, draft)
33
34 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail)
35 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, TargetFolder, targetFolder)
36 KUBE_CONTROLLER_PROPERTY(bool, OperateOnThreads, operateOnThreads)
37 KUBE_CONTROLLER_ACTION(markAsRead)
38 KUBE_CONTROLLER_ACTION(markAsUnread)
39 KUBE_CONTROLLER_ACTION(markAsImportant)
40 KUBE_CONTROLLER_ACTION(toggleImportant)
41 KUBE_CONTROLLER_ACTION(moveToTrash)
42 KUBE_CONTROLLER_ACTION(restoreFromTrash)
43 KUBE_CONTROLLER_ACTION(remove)
44 KUBE_CONTROLLER_ACTION(moveToFolder)
45
46public:
47 explicit MailController();
48private slots:
49 void updateActions();
50 void runModification(const std::function<void(Sink::ApplicationDomain::Mail &)> &f);
51};
diff --git a/framework/src/domain/outboxcontroller.cpp b/framework/src/domain/outboxcontroller.cpp
deleted file mode 100644
index 51b481fe..00000000
--- a/framework/src/domain/outboxcontroller.cpp
+++ /dev/null
@@ -1,60 +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 "outboxcontroller.h"
20
21#include <sink/store.h>
22#include <sink/log.h>
23
24using namespace Sink;
25using namespace Sink::ApplicationDomain;
26
27OutboxController::OutboxController()
28 : Kube::Controller(),
29 action_sendOutbox{new Kube::ControllerAction{this, &OutboxController::sendOutbox}},
30 action_edit{new Kube::ControllerAction{this, &OutboxController::edit}},
31 action_moveToTrash{new Kube::ControllerAction{this, &OutboxController::moveToTrash}}
32{
33}
34
35void OutboxController::sendOutbox()
36{
37 Query query;
38 query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport);
39 auto job = Store::fetchAll<SinkResource>(query)
40 .each([=](const SinkResource::Ptr &resource) -> KAsync::Job<void> {
41 return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier()));
42 });
43 run(job);
44}
45
46void OutboxController::moveToTrash()
47{
48 auto mail = getMail();
49 mail->setTrash(true);
50 run(Store::modify(*mail));
51}
52
53void OutboxController::edit()
54{
55 auto mail = getMail();
56 mail->setDraft(true);
57 run(Store::modify(*mail));
58 //TODO trigger edit when item has been moved
59}
60
diff --git a/framework/src/domain/outboxcontroller.h b/framework/src/domain/outboxcontroller.h
deleted file mode 100644
index 24fe9584..00000000
--- a/framework/src/domain/outboxcontroller.h
+++ /dev/null
@@ -1,37 +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#pragma once
20
21#include <QObject>
22#include "controller.h"
23#include "sink/applicationdomaintype.h"
24
25class OutboxController : public Kube::Controller
26{
27 Q_OBJECT
28
29 KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail)
30 KUBE_CONTROLLER_ACTION(sendOutbox)
31 //Trigger a move to drafts and then trigger an edit
32 KUBE_CONTROLLER_ACTION(edit)
33 KUBE_CONTROLLER_ACTION(moveToTrash)
34
35public:
36 explicit OutboxController();
37};
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index 2f77bef4..294fbbc7 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -26,9 +26,6 @@
26#include "domain/messageparser.h" 26#include "domain/messageparser.h"
27#include "domain/retriever.h" 27#include "domain/retriever.h"
28#include "domain/outboxmodel.h" 28#include "domain/outboxmodel.h"
29#include "domain/outboxcontroller.h"
30#include "domain/mailcontroller.h"
31#include "domain/foldercontroller.h"
32#include "domain/mouseproxy.h" 29#include "domain/mouseproxy.h"
33#include "domain/contactcontroller.h" 30#include "domain/contactcontroller.h"
34#include "domain/peoplemodel.h" 31#include "domain/peoplemodel.h"
@@ -57,10 +54,7 @@ void FrameworkPlugin::registerTypes (const char *uri)
57 qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController"); 54 qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController");
58 qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); 55 qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser");
59 qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); 56 qmlRegisterType<Retriever>(uri, 1, 0, "Retriever");
60 qmlRegisterType<OutboxController>(uri, 1, 0, "OutboxController");
61 qmlRegisterType<OutboxModel>(uri, 1, 0, "OutboxModel"); 57 qmlRegisterType<OutboxModel>(uri, 1, 0, "OutboxModel");
62 qmlRegisterType<MailController>(uri, 1, 0, "MailController");
63 qmlRegisterType<FolderController>(uri, 1, 0, "FolderController");
64 qmlRegisterType<MouseProxy>(uri, 1, 0, "MouseProxy"); 58 qmlRegisterType<MouseProxy>(uri, 1, 0, "MouseProxy");
65 qmlRegisterType<ContactController>(uri, 1, 0,"ContactController"); 59 qmlRegisterType<ContactController>(uri, 1, 0,"ContactController");
66 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel"); 60 qmlRegisterType<PeopleModel>(uri, 1, 0,"PeopleModel");
diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp
index 68a75a86..5e209526 100644
--- a/framework/src/sinkfabric.cpp
+++ b/framework/src/sinkfabric.cpp
@@ -53,6 +53,15 @@ public:
53 Store::synchronize(SyncScope()).exec(); 53 Store::synchronize(SyncScope()).exec();
54 } 54 }
55 } 55 }
56 if (id == "sendOutbox"/*Kube::Messages::synchronize*/) {
57 Query query;
58 query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport);
59 auto job = Store::fetchAll<SinkResource>(query)
60 .each([=](const SinkResource::Ptr &resource) -> KAsync::Job<void> {
61 return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier()));
62 });
63 job.exec();
64 }
56 if (id == "markAsRead"/*Kube::Messages::synchronize*/) { 65 if (id == "markAsRead"/*Kube::Messages::synchronize*/) {
57 if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { 66 if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) {
58 mail->setUnread(false); 67 mail->setUnread(false);
@@ -77,6 +86,12 @@ public:
77 Store::modify(*mail).exec(); 86 Store::modify(*mail).exec();
78 } 87 }
79 } 88 }
89 if (id == "moveToDrafts"/*Kube::Messages::synchronize*/) {
90 if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) {
91 mail->setDraft(true);
92 Store::modify(*mail).exec();
93 }
94 }
80 if (id == "moveToFolder"/*Kube::Messages::synchronize*/) { 95 if (id == "moveToFolder"/*Kube::Messages::synchronize*/) {
81 if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { 96 if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) {
82 auto folder = message["folder"].value<ApplicationDomain::Folder::Ptr>(); 97 auto folder = message["folder"].value<ApplicationDomain::Folder::Ptr>();