diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/qml/Messages.qml | 1 | ||||
-rw-r--r-- | framework/src/fabric.cpp | 12 | ||||
-rw-r--r-- | framework/src/sinkfabric.cpp | 63 | ||||
-rw-r--r-- | framework/src/sinkfabric.h | 33 |
4 files changed, 97 insertions, 12 deletions
diff --git a/framework/qml/Messages.qml b/framework/qml/Messages.qml index a6ca6fe0..19d0c402 100644 --- a/framework/qml/Messages.qml +++ b/framework/qml/Messages.qml | |||
@@ -35,6 +35,7 @@ Item { | |||
35 | property string moveToDrafts: "moveToDrafts" | 35 | property string moveToDrafts: "moveToDrafts" |
36 | 36 | ||
37 | property string notification: "notification" | 37 | property string notification: "notification" |
38 | property string progressNotification: "progressNotification" | ||
38 | property string search: "search" | 39 | property string search: "search" |
39 | property string synchronize: "synchronize" | 40 | property string synchronize: "synchronize" |
40 | property string reply: "reply" | 41 | property string reply: "reply" |
diff --git a/framework/src/fabric.cpp b/framework/src/fabric.cpp index b14ed55d..30d1ac51 100644 --- a/framework/src/fabric.cpp +++ b/framework/src/fabric.cpp | |||
@@ -18,6 +18,7 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | #include "fabric.h" | 20 | #include "fabric.h" |
21 | #include "sinkfabric.h" | ||
21 | 22 | ||
22 | #include <QDebug> | 23 | #include <QDebug> |
23 | 24 | ||
@@ -35,9 +36,18 @@ public: | |||
35 | return bus; | 36 | return bus; |
36 | } | 37 | } |
37 | 38 | ||
39 | void bringUpDeps() | ||
40 | { | ||
41 | if (!mDepsUp) { | ||
42 | mDepsUp = true; | ||
43 | SinkFabric::instance(); | ||
44 | } | ||
45 | } | ||
46 | |||
38 | void registerListener(Listener *listener) | 47 | void registerListener(Listener *listener) |
39 | { | 48 | { |
40 | mListener << listener; | 49 | mListener << listener; |
50 | bringUpDeps(); | ||
41 | } | 51 | } |
42 | 52 | ||
43 | void unregisterListener(Listener *listener) | 53 | void unregisterListener(Listener *listener) |
@@ -47,6 +57,7 @@ public: | |||
47 | 57 | ||
48 | void postMessage(const QString &id, const QVariantMap &message) | 58 | void postMessage(const QString &id, const QVariantMap &message) |
49 | { | 59 | { |
60 | bringUpDeps(); | ||
50 | for (const auto &l : mListener) { | 61 | for (const auto &l : mListener) { |
51 | l->notify(id, message); | 62 | l->notify(id, message); |
52 | } | 63 | } |
@@ -54,6 +65,7 @@ public: | |||
54 | 65 | ||
55 | private: | 66 | private: |
56 | QVector<Listener*> mListener; | 67 | QVector<Listener*> mListener; |
68 | bool mDepsUp = false; | ||
57 | }; | 69 | }; |
58 | 70 | ||
59 | void Fabric::postMessage(const QString &id, const QVariantMap &msg) | 71 | void Fabric::postMessage(const QString &id, const QVariantMap &msg) |
diff --git a/framework/src/sinkfabric.cpp b/framework/src/sinkfabric.cpp index 09075174..67d37292 100644 --- a/framework/src/sinkfabric.cpp +++ b/framework/src/sinkfabric.cpp | |||
@@ -16,6 +16,7 @@ | |||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. | 17 | 02110-1301, USA. |
18 | */ | 18 | */ |
19 | #include "sinkfabric.h" | ||
19 | 20 | ||
20 | #include <QFile> | 21 | #include <QFile> |
21 | 22 | ||
@@ -26,7 +27,7 @@ | |||
26 | 27 | ||
27 | #include "fabric.h" | 28 | #include "fabric.h" |
28 | 29 | ||
29 | SINK_DEBUG_AREA("sinkactions") | 30 | SINK_DEBUG_AREA("sinkfabric") |
30 | 31 | ||
31 | using namespace Kube; | 32 | using namespace Kube; |
32 | using namespace Sink; | 33 | using namespace Sink; |
@@ -46,13 +47,25 @@ public: | |||
46 | auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier())); | 47 | auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter<Mail::Folder>(QVariant::fromValue(folder->identifier())); |
47 | scope.setType<ApplicationDomain::Mail>(); | 48 | scope.setType<ApplicationDomain::Mail>(); |
48 | Store::synchronize(scope).exec(); | 49 | Store::synchronize(scope).exec(); |
49 | } else if (message["type"].value<QString>() == "contacts") { | ||
50 | auto scope = SyncScope(); | ||
51 | scope.setType<ApplicationDomain::Contact>(); | ||
52 | Store::synchronize(scope).exec(); | ||
53 | } else { | 50 | } else { |
54 | SinkLog() << "Synchronizing all"; | 51 | auto accountId = message["accountId"].value<QString>(); |
55 | Store::synchronize(SyncScope()).exec(); | 52 | auto type = message["type"].value<QString>(); |
53 | SyncScope scope; | ||
54 | if (!accountId.isEmpty()) { | ||
55 | //FIXME this should work with either string or bytearray, but is apparently very picky | ||
56 | scope.resourceFilter<SinkResource::Account>(accountId.toLatin1()); | ||
57 | } | ||
58 | if (type == "contacts") { | ||
59 | scope.setType<ApplicationDomain::Contact>(); | ||
60 | } | ||
61 | if (type == "mail") { | ||
62 | scope.setType<ApplicationDomain::Mail>(); | ||
63 | } | ||
64 | if (type == "folder") { | ||
65 | scope.setType<ApplicationDomain::Folder>(); | ||
66 | } | ||
67 | SinkLog() << "Synchronizing all. AccountId: " << accountId << " Type: " << type; | ||
68 | Store::synchronize(scope).exec(); | ||
56 | } | 69 | } |
57 | } | 70 | } |
58 | if (id == "sendOutbox"/*Kube::Messages::synchronize*/) { | 71 | if (id == "sendOutbox"/*Kube::Messages::synchronize*/) { |
@@ -106,15 +119,14 @@ public: | |||
106 | 119 | ||
107 | }; | 120 | }; |
108 | 121 | ||
109 | static SinkListener sinkListener; | 122 | class SinkNotifier { |
110 | 123 | public: | |
111 | class NotificationListener { | 124 | SinkNotifier() |
112 | NotificationListener() | ||
113 | : mNotifier{Sink::Query{Sink::Query::LiveQuery}} | 125 | : mNotifier{Sink::Query{Sink::Query::LiveQuery}} |
114 | { | 126 | { |
115 | mNotifier.registerHandler([this] (const Sink::Notification ¬ification) { | 127 | mNotifier.registerHandler([this] (const Sink::Notification ¬ification) { |
116 | Notification n; | 128 | Notification n; |
117 | qWarning() << "Received notification: " << notification; | 129 | SinkLog() << "Received notification: " << notification; |
118 | QVariantMap message; | 130 | QVariantMap message; |
119 | if (notification.type == Sink::Notification::Warning) { | 131 | if (notification.type == Sink::Notification::Warning) { |
120 | message["type"] = Notification::Warning; | 132 | message["type"] = Notification::Warning; |
@@ -145,14 +157,41 @@ class NotificationListener { | |||
145 | } else { | 157 | } else { |
146 | return; | 158 | return; |
147 | } | 159 | } |
160 | } else if (notification.type == Sink::Notification::Progress) { | ||
161 | message["progress"] = notification.progress; | ||
162 | message["total"] = notification.total; | ||
163 | Fabric::Fabric{}.postMessage("progressNotification", message); | ||
164 | return; | ||
148 | } else { | 165 | } else { |
149 | return; | 166 | return; |
150 | } | 167 | } |
168 | Fabric::Fabric{}.postMessage("notification", message); | ||
169 | |||
151 | }); | 170 | }); |
152 | 171 | ||
153 | } | 172 | } |
154 | 173 | ||
155 | Sink::Notifier mNotifier; | 174 | Sink::Notifier mNotifier; |
175 | }; | ||
156 | 176 | ||
177 | class SinkFabric::Private | ||
178 | { | ||
179 | SinkNotifier notifier; | ||
180 | SinkListener listener; | ||
157 | }; | 181 | }; |
158 | 182 | ||
183 | SinkFabric::SinkFabric() | ||
184 | : QObject(), | ||
185 | d(new SinkFabric::Private) | ||
186 | { | ||
187 | } | ||
188 | |||
189 | SinkFabric::~SinkFabric() | ||
190 | { | ||
191 | delete d; | ||
192 | } | ||
193 | SinkFabric &SinkFabric::instance() | ||
194 | { | ||
195 | static SinkFabric instance; | ||
196 | return instance; | ||
197 | } | ||
diff --git a/framework/src/sinkfabric.h b/framework/src/sinkfabric.h index e69de29b..1c835791 100644 --- a/framework/src/sinkfabric.h +++ b/framework/src/sinkfabric.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | Copyright (c) 2017 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 | |||
23 | class SinkFabric : public QObject { | ||
24 | Q_OBJECT | ||
25 | public: | ||
26 | SinkFabric(); | ||
27 | ~SinkFabric(); | ||
28 | |||
29 | static SinkFabric &instance(); | ||
30 | private: | ||
31 | class Private; | ||
32 | Private *d; | ||
33 | }; | ||