diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-24 17:51:18 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-24 17:51:18 +0200 |
commit | 47e0f0c14b4bbcc64cb8bf562c566d29313db7ad (patch) | |
tree | c50362e5c6f68a8994bcc7177c7d401b48179371 /framework/src | |
parent | b8962ee2d35772ab4f2bed1c415a386207067157 (diff) | |
download | kube-47e0f0c14b4bbcc64cb8bf562c566d29313db7ad.tar.gz kube-47e0f0c14b4bbcc64cb8bf562c566d29313db7ad.zip |
Ported more actions to the fabric
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/sinkfabric.cpp | 141 | ||||
-rw-r--r-- | framework/src/sinkfabric.h | 0 |
3 files changed, 142 insertions, 0 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 39f17c32..cf971497 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -50,6 +50,7 @@ set(SRCS | |||
50 | accounts/accountsmodel.cpp | 50 | accounts/accountsmodel.cpp |
51 | notifications/notificationhandler.cpp | 51 | notifications/notificationhandler.cpp |
52 | fabric.cpp | 52 | fabric.cpp |
53 | sinkfabric.cpp | ||
53 | ) | 54 | ) |
54 | 55 | ||
55 | add_library(frameworkplugin SHARED ${SRCS}) | 56 | add_library(frameworkplugin SHARED ${SRCS}) |
diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp new file mode 100644 index 00000000..68a75a86 --- /dev/null +++ b/framework/src/sinkfabric.cpp | |||
@@ -0,0 +1,141 @@ | |||
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 | |||
20 | #include <actions/actionhandler.h> | ||
21 | |||
22 | #include <QFile> | ||
23 | |||
24 | #include <sink/store.h> | ||
25 | #include <sink/log.h> | ||
26 | #include <sink/notification.h> | ||
27 | #include <sink/notifier.h> | ||
28 | |||
29 | #include "fabric.h" | ||
30 | |||
31 | SINK_DEBUG_AREA("sinkactions") | ||
32 | |||
33 | using namespace Kube; | ||
34 | using namespace Sink; | ||
35 | using namespace Sink::ApplicationDomain; | ||
36 | |||
37 | class SinkListener : public Kube::Fabric::Listener | ||
38 | { | ||
39 | public: | ||
40 | SinkListener() = default; | ||
41 | |||
42 | void notify(const QString &id, const QVariantMap &message) | ||
43 | { | ||
44 | SinkLog() << "Received message: " << id << message; | ||
45 | if (id == "synchronize"/*Kube::Messages::synchronize*/) { | ||
46 | if (auto folder = message["folder"].value<ApplicationDomain::Folder::Ptr>()) { | ||
47 | SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); | ||
48 | auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier())); | ||
49 | scope.setType<ApplicationDomain::Mail>(); | ||
50 | Store::synchronize(scope).exec(); | ||
51 | } else { | ||
52 | SinkLog() << "Synchronizing all"; | ||
53 | Store::synchronize(SyncScope()).exec(); | ||
54 | } | ||
55 | } | ||
56 | if (id == "markAsRead"/*Kube::Messages::synchronize*/) { | ||
57 | if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { | ||
58 | mail->setUnread(false); | ||
59 | Store::modify(*mail).exec(); | ||
60 | } | ||
61 | } | ||
62 | if (id == "markAsUnread"/*Kube::Messages::synchronize*/) { | ||
63 | if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { | ||
64 | mail->setUnread(true); | ||
65 | Store::modify(*mail).exec(); | ||
66 | } | ||
67 | } | ||
68 | if (id == "toggleImportant"/*Kube::Messages::synchronize*/) { | ||
69 | if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { | ||
70 | mail->setImportant(message["important"].toBool()); | ||
71 | Store::modify(*mail).exec(); | ||
72 | } | ||
73 | } | ||
74 | if (id == "moveToTrash"/*Kube::Messages::synchronize*/) { | ||
75 | if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { | ||
76 | mail->setTrash(true); | ||
77 | Store::modify(*mail).exec(); | ||
78 | } | ||
79 | } | ||
80 | if (id == "moveToFolder"/*Kube::Messages::synchronize*/) { | ||
81 | if (auto mail = message["mail"].value<ApplicationDomain::Mail::Ptr>()) { | ||
82 | auto folder = message["folder"].value<ApplicationDomain::Folder::Ptr>(); | ||
83 | mail->setFolder(*folder); | ||
84 | Store::modify(*mail).exec(); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | } | ||
89 | |||
90 | }; | ||
91 | |||
92 | static SinkListener sinkListener; | ||
93 | |||
94 | class NotificationListener { | ||
95 | NotificationListener() | ||
96 | : mNotifier{Sink::Query{Sink::Query::LiveQuery}} | ||
97 | { | ||
98 | mNotifier.registerHandler([this] (const Sink::Notification ¬ification) { | ||
99 | Notification n; | ||
100 | qWarning() << "Received notification: " << notification; | ||
101 | QVariantMap message; | ||
102 | if (notification.type == Sink::Notification::Warning) { | ||
103 | message["type"] = Notification::Warning; | ||
104 | if (notification.code == Sink::ApplicationDomain::TransmissionError) { | ||
105 | message["message"] = "Failed to send message."; | ||
106 | } else { | ||
107 | return; | ||
108 | } | ||
109 | } else if (notification.type == Sink::Notification::Status) { | ||
110 | if (notification.code == Sink::ApplicationDomain::ErrorStatus) { | ||
111 | //A resource entered error status | ||
112 | message["type"] = Notification::Warning; | ||
113 | message["message"] = "A resource experienced an error."; | ||
114 | } else { | ||
115 | return; | ||
116 | } | ||
117 | } else if (notification.type == Sink::Notification::Error) { | ||
118 | if (notification.code == Sink::ApplicationDomain::ConnectionError) { | ||
119 | message["type"] = Notification::Warning; | ||
120 | message["message"] = "Failed to connect to server."; | ||
121 | } else { | ||
122 | return; | ||
123 | } | ||
124 | } else if (notification.type == Sink::Notification::Info) { | ||
125 | if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { | ||
126 | message["type"] = Notification::Info; | ||
127 | message["message"] = "A message has been sent."; | ||
128 | } else { | ||
129 | return; | ||
130 | } | ||
131 | } else { | ||
132 | return; | ||
133 | } | ||
134 | }); | ||
135 | |||
136 | } | ||
137 | |||
138 | Sink::Notifier mNotifier; | ||
139 | |||
140 | }; | ||
141 | |||
diff --git a/framework/src/sinkfabric.h b/framework/src/sinkfabric.h new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/framework/src/sinkfabric.h | |||