diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-01 23:18:24 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-02 00:31:49 +0100 |
commit | 8cf790d6bc91e5e9c06651ffe4a193b625207f0d (patch) | |
tree | 41cd4e957a62b2c2c35579a19a252b5484374364 /framework/domain | |
parent | ba7128b30850594c7efb258d1794e377eede364a (diff) | |
download | kube-8cf790d6bc91e5e9c06651ffe4a193b625207f0d.tar.gz kube-8cf790d6bc91e5e9c06651ffe4a193b625207f0d.zip |
Outboxcontroller and Mailcontroller
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/CMakeLists.txt | 2 | ||||
-rw-r--r-- | framework/domain/actions/sinkactions.cpp | 62 | ||||
-rw-r--r-- | framework/domain/composercontroller.cpp | 1 | ||||
-rw-r--r-- | framework/domain/composercontroller.h | 1 | ||||
-rw-r--r-- | framework/domain/mailcontroller.cpp | 66 | ||||
-rw-r--r-- | framework/domain/mailcontroller.h | 42 | ||||
-rw-r--r-- | framework/domain/mailplugin.cpp | 4 | ||||
-rw-r--r-- | framework/domain/outboxcontroller.cpp | 50 | ||||
-rw-r--r-- | framework/domain/outboxcontroller.h | 39 |
9 files changed, 205 insertions, 62 deletions
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index bb522416..8f343928 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -23,6 +23,8 @@ set(mailplugin_SRCS | |||
23 | selector.cpp | 23 | selector.cpp |
24 | completer.cpp | 24 | completer.cpp |
25 | controller.cpp | 25 | controller.cpp |
26 | outboxcontroller.cpp | ||
27 | mailcontroller.cpp | ||
26 | ) | 28 | ) |
27 | find_package(KF5 REQUIRED COMPONENTS Package) | 29 | find_package(KF5 REQUIRED COMPONENTS Package) |
28 | 30 | ||
diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index a2d4c02c..460cb6a1 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp | |||
@@ -31,53 +31,6 @@ using namespace Kube; | |||
31 | using namespace Sink; | 31 | using namespace Sink; |
32 | using namespace Sink::ApplicationDomain; | 32 | using namespace Sink::ApplicationDomain; |
33 | 33 | ||
34 | static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", | ||
35 | [](Context *context) -> bool { | ||
36 | return context->property("mail").isValid(); | ||
37 | }, | ||
38 | [](Context *context) { | ||
39 | auto mail = context->property("mail").value<Mail::Ptr>(); | ||
40 | if (!mail) { | ||
41 | SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); | ||
42 | return; | ||
43 | } | ||
44 | mail->setProperty("unread", false); | ||
45 | SinkLog() << "Mark as read " << mail->identifier(); | ||
46 | Store::modify(*mail).exec(); | ||
47 | } | ||
48 | ); | ||
49 | |||
50 | static ActionHandlerHelper moveToTrashHandler("org.kde.kube.actions.move-to-trash", | ||
51 | [](Context *context) -> bool { | ||
52 | return context->property("mail").isValid(); | ||
53 | }, | ||
54 | [](Context *context) { | ||
55 | auto mail = context->property("mail").value<Mail::Ptr>(); | ||
56 | if (!mail) { | ||
57 | SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); | ||
58 | return; | ||
59 | } | ||
60 | mail->setTrash(true); | ||
61 | SinkLog() << "Move to trash " << mail->identifier(); | ||
62 | Store::modify(*mail).exec(); | ||
63 | } | ||
64 | ); | ||
65 | |||
66 | static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete", | ||
67 | [](Context *context) -> bool { | ||
68 | return context->property("mail").isValid(); | ||
69 | }, | ||
70 | [](Context *context) { | ||
71 | auto mail = context->property("mail").value<Mail::Ptr>(); | ||
72 | if (!mail) { | ||
73 | SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); | ||
74 | return; | ||
75 | } | ||
76 | SinkLog() << "Remove " << mail->identifier(); | ||
77 | Store::remove(*mail).exec(); | ||
78 | } | ||
79 | ); | ||
80 | |||
81 | class FolderContext : public Kube::ContextWrapper { | 34 | class FolderContext : public Kube::ContextWrapper { |
82 | using Kube::ContextWrapper::ContextWrapper; | 35 | using Kube::ContextWrapper::ContextWrapper; |
83 | KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) | 36 | KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) |
@@ -101,18 +54,3 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" | |||
101 | } | 54 | } |
102 | ); | 55 | ); |
103 | 56 | ||
104 | static ActionHandlerHelper sendOutboxHandler("org.kde.kube.actions.sendOutbox", | ||
105 | [](Context *context) -> bool { | ||
106 | return true; | ||
107 | }, | ||
108 | ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job<void> { | ||
109 | using namespace Sink::ApplicationDomain; | ||
110 | Query query; | ||
111 | query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport); | ||
112 | return Store::fetchAll<SinkResource>(query) | ||
113 | .each([=](const SinkResource::Ptr &resource) -> KAsync::Job<void> { | ||
114 | return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier())); | ||
115 | }); | ||
116 | }} | ||
117 | ); | ||
118 | |||
diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 4ce356a9..75396735 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> | 2 | Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> |
3 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | 4 | ||
4 | This library is free software; you can redistribute it and/or modify it | 5 | 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 | under the terms of the GNU Library General Public License as published by |
diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index c5046306..2e74954e 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> | 2 | Copyright (c) 2016 Michael Bohlender <michael.bohlender@kdemail.net> |
3 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | 4 | ||
4 | This library is free software; you can redistribute it and/or modify it | 5 | 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 | under the terms of the GNU Library General Public License as published by |
diff --git a/framework/domain/mailcontroller.cpp b/framework/domain/mailcontroller.cpp new file mode 100644 index 00000000..4c5ae5c6 --- /dev/null +++ b/framework/domain/mailcontroller.cpp | |||
@@ -0,0 +1,66 @@ | |||
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 | |||
24 | SINK_DEBUG_AREA("mailcontroller"); | ||
25 | |||
26 | MailController::MailController() | ||
27 | : Kube::Controller(), | ||
28 | action_markAsRead{new Kube::ControllerAction}, | ||
29 | action_moveToTrash{new Kube::ControllerAction}, | ||
30 | action_remove{new Kube::ControllerAction} | ||
31 | { | ||
32 | QObject::connect(markAsReadAction(), &Kube::ControllerAction::triggered, this, &MailController::markAsRead); | ||
33 | QObject::connect(moveToTrashAction(), &Kube::ControllerAction::triggered, this, &MailController::moveToTrash); | ||
34 | QObject::connect(removeAction(), &Kube::ControllerAction::triggered, this, &MailController::remove); | ||
35 | } | ||
36 | |||
37 | void MailController::markAsRead() | ||
38 | { | ||
39 | using namespace Sink; | ||
40 | using namespace Sink::ApplicationDomain; | ||
41 | auto mail = getMail(); | ||
42 | mail->setUnread(false); | ||
43 | SinkLog() << "Mark as read " << mail->identifier(); | ||
44 | run(Store::modify(*mail)); | ||
45 | } | ||
46 | |||
47 | void MailController::moveToTrash() | ||
48 | { | ||
49 | using namespace Sink; | ||
50 | using namespace Sink::ApplicationDomain; | ||
51 | auto mail = getMail(); | ||
52 | mail->setTrash(true); | ||
53 | SinkLog() << "Move to trash " << mail->identifier(); | ||
54 | run(Store::modify(*mail)); | ||
55 | } | ||
56 | |||
57 | void MailController::remove() | ||
58 | { | ||
59 | using namespace Sink; | ||
60 | using namespace Sink::ApplicationDomain; | ||
61 | auto mail = getMail(); | ||
62 | mail->setTrash(true); | ||
63 | SinkLog() << "Remove " << mail->identifier(); | ||
64 | run(Store::remove(*mail)); | ||
65 | } | ||
66 | |||
diff --git a/framework/domain/mailcontroller.h b/framework/domain/mailcontroller.h new file mode 100644 index 00000000..66cb7b4b --- /dev/null +++ b/framework/domain/mailcontroller.h | |||
@@ -0,0 +1,42 @@ | |||
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 | |||
25 | #define KUBE_CONTROLLER_ACTION(NAME) \ | ||
26 | Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \ | ||
27 | private: QScopedPointer<Kube::ControllerAction> action_##NAME; \ | ||
28 | public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \ | ||
29 | private slots: void NAME(); \ | ||
30 | |||
31 | |||
32 | class MailController : public Kube::Controller | ||
33 | { | ||
34 | Q_OBJECT | ||
35 | KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail) | ||
36 | KUBE_CONTROLLER_ACTION(markAsRead) | ||
37 | KUBE_CONTROLLER_ACTION(moveToTrash) | ||
38 | KUBE_CONTROLLER_ACTION(remove) | ||
39 | |||
40 | public: | ||
41 | explicit MailController(); | ||
42 | }; | ||
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index c7023bde..eeb1aeb1 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp | |||
@@ -29,6 +29,8 @@ | |||
29 | #include "accountscontroller.h" | 29 | #include "accountscontroller.h" |
30 | #include "accountsmodel.h" | 30 | #include "accountsmodel.h" |
31 | #include "outboxmodel.h" | 31 | #include "outboxmodel.h" |
32 | #include "outboxcontroller.h" | ||
33 | #include "mailcontroller.h" | ||
32 | 34 | ||
33 | #include <QtQml> | 35 | #include <QtQml> |
34 | 36 | ||
@@ -44,5 +46,7 @@ void MailPlugin::registerTypes (const char *uri) | |||
44 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); | 46 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); |
45 | qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController"); | 47 | qmlRegisterType<AccountsController>(uri, 1, 0, "AccountsController"); |
46 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); | 48 | qmlRegisterType<AccountsModel>(uri, 1, 0, "AccountsModel"); |
49 | qmlRegisterType<OutboxController>(uri, 1, 0, "OutboxController"); | ||
47 | qmlRegisterType<OutboxModel>(uri, 1, 0, "OutboxModel"); | 50 | qmlRegisterType<OutboxModel>(uri, 1, 0, "OutboxModel"); |
51 | qmlRegisterType<MailController>(uri, 1, 0, "MailController"); | ||
48 | } | 52 | } |
diff --git a/framework/domain/outboxcontroller.cpp b/framework/domain/outboxcontroller.cpp new file mode 100644 index 00000000..3b4f0e62 --- /dev/null +++ b/framework/domain/outboxcontroller.cpp | |||
@@ -0,0 +1,50 @@ | |||
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 | |||
24 | SINK_DEBUG_AREA("outboxcontroller"); | ||
25 | |||
26 | OutboxController::OutboxController() | ||
27 | : Kube::Controller(), | ||
28 | mSynchronizeOutboxAction{new Kube::ControllerAction} | ||
29 | { | ||
30 | QObject::connect(mSynchronizeOutboxAction.data(), &Kube::ControllerAction::triggered, this, &OutboxController::sendOutbox); | ||
31 | } | ||
32 | |||
33 | Kube::ControllerAction* OutboxController::sendOutboxAction() const | ||
34 | { | ||
35 | return mSynchronizeOutboxAction.data(); | ||
36 | } | ||
37 | |||
38 | void OutboxController::sendOutbox() | ||
39 | { | ||
40 | using namespace Sink; | ||
41 | using namespace Sink::ApplicationDomain; | ||
42 | Query query; | ||
43 | query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport); | ||
44 | auto job = Store::fetchAll<SinkResource>(query) | ||
45 | .each([=](const SinkResource::Ptr &resource) -> KAsync::Job<void> { | ||
46 | return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier())); | ||
47 | }); | ||
48 | run(job); | ||
49 | } | ||
50 | |||
diff --git a/framework/domain/outboxcontroller.h b/framework/domain/outboxcontroller.h new file mode 100644 index 00000000..4c24ad59 --- /dev/null +++ b/framework/domain/outboxcontroller.h | |||
@@ -0,0 +1,39 @@ | |||
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 | |||
24 | class OutboxController : public Kube::Controller | ||
25 | { | ||
26 | Q_OBJECT | ||
27 | Q_PROPERTY (Kube::ControllerAction* sendOutboxAction READ sendOutboxAction CONSTANT) | ||
28 | |||
29 | public: | ||
30 | explicit OutboxController(); | ||
31 | |||
32 | Kube::ControllerAction* sendOutboxAction() const; | ||
33 | |||
34 | private slots: | ||
35 | void sendOutbox(); | ||
36 | |||
37 | private: | ||
38 | QScopedPointer<Kube::ControllerAction> mSynchronizeOutboxAction; | ||
39 | }; | ||