From 322a616573dfe52ee412573bd93fbc646b4ca008 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 4 May 2017 16:03:26 +0200 Subject: Properly hook up the sink fabric --- framework/src/sinkfabric.cpp | 63 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 12 deletions(-) (limited to 'framework/src/sinkfabric.cpp') 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 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "sinkfabric.h" #include @@ -26,7 +27,7 @@ #include "fabric.h" -SINK_DEBUG_AREA("sinkactions") +SINK_DEBUG_AREA("sinkfabric") using namespace Kube; using namespace Sink; @@ -46,13 +47,25 @@ public: auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter(QVariant::fromValue(folder->identifier())); scope.setType(); Store::synchronize(scope).exec(); - } else if (message["type"].value() == "contacts") { - auto scope = SyncScope(); - scope.setType(); - Store::synchronize(scope).exec(); } else { - SinkLog() << "Synchronizing all"; - Store::synchronize(SyncScope()).exec(); + auto accountId = message["accountId"].value(); + auto type = message["type"].value(); + SyncScope scope; + if (!accountId.isEmpty()) { + //FIXME this should work with either string or bytearray, but is apparently very picky + scope.resourceFilter(accountId.toLatin1()); + } + if (type == "contacts") { + scope.setType(); + } + if (type == "mail") { + scope.setType(); + } + if (type == "folder") { + scope.setType(); + } + SinkLog() << "Synchronizing all. AccountId: " << accountId << " Type: " << type; + Store::synchronize(scope).exec(); } } if (id == "sendOutbox"/*Kube::Messages::synchronize*/) { @@ -106,15 +119,14 @@ public: }; -static SinkListener sinkListener; - -class NotificationListener { - NotificationListener() +class SinkNotifier { +public: + SinkNotifier() : mNotifier{Sink::Query{Sink::Query::LiveQuery}} { mNotifier.registerHandler([this] (const Sink::Notification ¬ification) { Notification n; - qWarning() << "Received notification: " << notification; + SinkLog() << "Received notification: " << notification; QVariantMap message; if (notification.type == Sink::Notification::Warning) { message["type"] = Notification::Warning; @@ -145,14 +157,41 @@ class NotificationListener { } else { return; } + } else if (notification.type == Sink::Notification::Progress) { + message["progress"] = notification.progress; + message["total"] = notification.total; + Fabric::Fabric{}.postMessage("progressNotification", message); + return; } else { return; } + Fabric::Fabric{}.postMessage("notification", message); + }); } Sink::Notifier mNotifier; +}; +class SinkFabric::Private +{ + SinkNotifier notifier; + SinkListener listener; }; +SinkFabric::SinkFabric() + : QObject(), + d(new SinkFabric::Private) +{ +} + +SinkFabric::~SinkFabric() +{ + delete d; +} +SinkFabric &SinkFabric::instance() +{ + static SinkFabric instance; + return instance; +} -- cgit v1.2.3