summaryrefslogtreecommitdiffstats
path: root/framework/src/sinkfabric.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/sinkfabric.cpp')
-rw-r--r--framework/src/sinkfabric.cpp63
1 files changed, 51 insertions, 12 deletions
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
29SINK_DEBUG_AREA("sinkactions") 30SINK_DEBUG_AREA("sinkfabric")
30 31
31using namespace Kube; 32using namespace Kube;
32using namespace Sink; 33using 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
109static SinkListener sinkListener; 122class SinkNotifier {
110 123public:
111class 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 &notification) { 127 mNotifier.registerHandler([this] (const Sink::Notification &notification) {
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
177class SinkFabric::Private
178{
179 SinkNotifier notifier;
180 SinkListener listener;
157}; 181};
158 182
183SinkFabric::SinkFabric()
184 : QObject(),
185 d(new SinkFabric::Private)
186{
187}
188
189SinkFabric::~SinkFabric()
190{
191 delete d;
192}
193SinkFabric &SinkFabric::instance()
194{
195 static SinkFabric instance;
196 return instance;
197}