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/qml/Messages.qml | 1 + framework/src/fabric.cpp | 12 +++++++++ framework/src/sinkfabric.cpp | 63 +++++++++++++++++++++++++++++++++++--------- framework/src/sinkfabric.h | 33 +++++++++++++++++++++++ 4 files changed, 97 insertions(+), 12 deletions(-) (limited to 'framework') 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 { property string moveToDrafts: "moveToDrafts" property string notification: "notification" + property string progressNotification: "progressNotification" property string search: "search" property string synchronize: "synchronize" 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 @@ */ #include "fabric.h" +#include "sinkfabric.h" #include @@ -35,9 +36,18 @@ public: return bus; } + void bringUpDeps() + { + if (!mDepsUp) { + mDepsUp = true; + SinkFabric::instance(); + } + } + void registerListener(Listener *listener) { mListener << listener; + bringUpDeps(); } void unregisterListener(Listener *listener) @@ -47,6 +57,7 @@ public: void postMessage(const QString &id, const QVariantMap &message) { + bringUpDeps(); for (const auto &l : mListener) { l->notify(id, message); } @@ -54,6 +65,7 @@ public: private: QVector mListener; + bool mDepsUp = false; }; 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 @@ 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; +} 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 @@ +/* + Copyright (c) 2017 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#pragma once + +#include + +class SinkFabric : public QObject { + Q_OBJECT +public: + SinkFabric(); + ~SinkFabric(); + + static SinkFabric &instance(); +private: + class Private; + Private *d; +}; -- cgit v1.2.3