From 47e0f0c14b4bbcc64cb8bf562c566d29313db7ad Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 24 Apr 2017 17:51:18 +0200 Subject: Ported more actions to the fabric --- framework/src/sinkfabric.cpp | 141 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 framework/src/sinkfabric.cpp (limited to 'framework/src/sinkfabric.cpp') 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 @@ +/* + Copyright (c) 2016 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. +*/ + +#include + +#include + +#include +#include +#include +#include + +#include "fabric.h" + +SINK_DEBUG_AREA("sinkactions") + +using namespace Kube; +using namespace Sink; +using namespace Sink::ApplicationDomain; + +class SinkListener : public Kube::Fabric::Listener +{ +public: + SinkListener() = default; + + void notify(const QString &id, const QVariantMap &message) + { + SinkLog() << "Received message: " << id << message; + if (id == "synchronize"/*Kube::Messages::synchronize*/) { + if (auto folder = message["folder"].value()) { + SinkLog() << "Synchronizing folder " << folder->resourceInstanceIdentifier() << folder->identifier(); + auto scope = SyncScope().resourceFilter(folder->resourceInstanceIdentifier()).filter(QVariant::fromValue(folder->identifier())); + scope.setType(); + Store::synchronize(scope).exec(); + } else { + SinkLog() << "Synchronizing all"; + Store::synchronize(SyncScope()).exec(); + } + } + if (id == "markAsRead"/*Kube::Messages::synchronize*/) { + if (auto mail = message["mail"].value()) { + mail->setUnread(false); + Store::modify(*mail).exec(); + } + } + if (id == "markAsUnread"/*Kube::Messages::synchronize*/) { + if (auto mail = message["mail"].value()) { + mail->setUnread(true); + Store::modify(*mail).exec(); + } + } + if (id == "toggleImportant"/*Kube::Messages::synchronize*/) { + if (auto mail = message["mail"].value()) { + mail->setImportant(message["important"].toBool()); + Store::modify(*mail).exec(); + } + } + if (id == "moveToTrash"/*Kube::Messages::synchronize*/) { + if (auto mail = message["mail"].value()) { + mail->setTrash(true); + Store::modify(*mail).exec(); + } + } + if (id == "moveToFolder"/*Kube::Messages::synchronize*/) { + if (auto mail = message["mail"].value()) { + auto folder = message["folder"].value(); + mail->setFolder(*folder); + Store::modify(*mail).exec(); + } + } + + } + +}; + +static SinkListener sinkListener; + +class NotificationListener { + NotificationListener() + : mNotifier{Sink::Query{Sink::Query::LiveQuery}} + { + mNotifier.registerHandler([this] (const Sink::Notification ¬ification) { + Notification n; + qWarning() << "Received notification: " << notification; + QVariantMap message; + if (notification.type == Sink::Notification::Warning) { + message["type"] = Notification::Warning; + if (notification.code == Sink::ApplicationDomain::TransmissionError) { + message["message"] = "Failed to send message."; + } else { + return; + } + } else if (notification.type == Sink::Notification::Status) { + if (notification.code == Sink::ApplicationDomain::ErrorStatus) { + //A resource entered error status + message["type"] = Notification::Warning; + message["message"] = "A resource experienced an error."; + } else { + return; + } + } else if (notification.type == Sink::Notification::Error) { + if (notification.code == Sink::ApplicationDomain::ConnectionError) { + message["type"] = Notification::Warning; + message["message"] = "Failed to connect to server."; + } else { + return; + } + } else if (notification.type == Sink::Notification::Info) { + if (notification.code == Sink::ApplicationDomain::TransmissionSuccess) { + message["type"] = Notification::Info; + message["message"] = "A message has been sent."; + } else { + return; + } + } else { + return; + } + }); + + } + + Sink::Notifier mNotifier; + +}; + -- cgit v1.2.3