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/qml/ConversationView.qml | 24 +------ framework/qml/FolderListView.qml | 17 +---- framework/qml/MailListView.qml | 66 +++++------------ framework/qml/Messages.qml | 10 +++ framework/src/CMakeLists.txt | 1 + framework/src/sinkfabric.cpp | 141 +++++++++++++++++++++++++++++++++++++ framework/src/sinkfabric.h | 0 7 files changed, 173 insertions(+), 86 deletions(-) create mode 100644 framework/src/sinkfabric.cpp create mode 100644 framework/src/sinkfabric.h (limited to 'framework') diff --git a/framework/qml/ConversationView.qml b/framework/qml/ConversationView.qml index 85712a5a..d7d33c78 100644 --- a/framework/qml/ConversationView.qml +++ b/framework/qml/ConversationView.qml @@ -548,32 +548,12 @@ Rectangle { rightMargin: Kube.Units.largeSpacing } - Kube.Context { - id: mailcontext - property variant mail - property bool isDraft - mail: model.mail - isDraft: model.draft - } - - Kube.Action { - id: replyAction - actionId: "org.kde.kube.actions.reply" - context: maillistcontext - } - - Kube.Action { - id: editAction - actionId: "org.kde.kube.actions.edit" - context: maillistcontext - } - iconName: model.draft ? Kube.Icons.edit : Kube.Icons.replyToSender onClicked: { if (model.draft) { - editAction.execute() + Kube.Fabric.postMessage(Kube.Messages.edit, {"mail": model.mail, "isDraft": model.draft}) } else { - replyAction.execute() + Kube.Fabric.postMessage(Kube.Messages.reply, {"mail": model.mail, "isDraft": model.draft}) } } } diff --git a/framework/qml/FolderListView.qml b/framework/qml/FolderListView.qml index 78d3c5d0..42841221 100644 --- a/framework/qml/FolderListView.qml +++ b/framework/qml/FolderListView.qml @@ -30,17 +30,6 @@ Rectangle { color: Kube.Colors.textColor - Kube.FolderController { - id: folderController - } - Kube.Listener { - id: controllerListener - filter: Kube.Messages.folderSelection - onMessageReceived: { - folderController.folder = message.folder - } - } - TreeView { id: treeView @@ -66,7 +55,7 @@ Rectangle { model.fetchMore(currentIndex) Kube.Fabric.postMessage(Kube.Messages.folderSelection, {"folder":model.data(currentIndex, Kube.FolderListModel.DomainObject), "trash":model.data(currentIndex, Kube.FolderListModel.Trash)}) - folderController.synchronizeAction.execute() + Kube.Fabric.postMessage(Kube.Messages.synchronize, {"folder":model.data(currentIndex, Kube.FolderListModel.DomainObject)}) console.error(model.data) } @@ -117,9 +106,7 @@ Rectangle { visible: parent.containsDrag } onDropped: { - folderController.folder = model.domainObject - folderController.mail = drop.source.mail - folderController.moveToFolderAction.execute() + Kube.Fabric.postMessage(Kube.Messages.moveToFolder, {"mail": drop.source.mail, "folder":model.domainObject}) drop.accept(Qt.MoveAction) drop.source.visible = false } diff --git a/framework/qml/MailListView.qml b/framework/qml/MailListView.qml index 570b92f8..97a222a7 100644 --- a/framework/qml/MailListView.qml +++ b/framework/qml/MailListView.qml @@ -31,12 +31,15 @@ Item { property bool isImportant : false property bool isTrash : false property bool isUnread : false + property variant currentMail: null + + onCurrentMailChanged: Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail":currentMail}) Kube.Listener { filter: Kube.Messages.folderSelection onMessageReceived: { parentFolder = message.folder - Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail":null}) + currentMail = null } } @@ -47,35 +50,10 @@ Item { } } - Kube.MailController { - id: mailController - unread: root.isUnread - trash: root.isTrash - important: root.isImportant - draft: root.isDraft - operateOnThreads: mailListModel.isThreaded - } - - Kube.Listener { - id: controllerListener - filter: Kube.Messages.mailSelection - onMessageReceived: { - mailController.mail = message.mail - } - } - Shortcut { sequence: StandardKey.Delete - onActivated: mailController.moveToTrashAction.execute() - enabled: mailController.moveToTrashAction.enabled - } - Shortcut { - sequence: StandardKey.MoveToNextLine - onActivated: root.currentIndex++ - } - Shortcut { - sequence: StandardKey.MoveToPreviousLine - onActivated: root.currentIndex-- + enabled: isTrash + onActivated: Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail":currentMail}) } Kube.Label { @@ -106,7 +84,7 @@ Item { //END keyboard nav onCurrentItemChanged: { - Kube.Fabric.postMessage(Kube.Messages.mailSelection, {"mail":currentItem.currentData.mail}) + root.currentMail = currentItem.currentData.mail; root.isDraft = currentItem.currentData.draft; root.isTrash = currentItem.currentData.trash; root.isImportant = currentItem.currentData.important; @@ -286,50 +264,40 @@ Item { Kube.Button { id: readButton text: "r" - enabled: mailController.markAsReadAction.enabled visible: enabled - onClicked: { - mailController.markAsReadAction.execute() - } + enabled: model.unread + onClicked: Kube.Fabric.postMessage(Kube.Messages.markAsRead, {"mail": model.mail}) } Kube.Button { id: unreadButton text: "u" - enabled: mailController.markAsUnreadAction.enabled visible: enabled - onClicked: { - mailController.markAsUnreadAction.execute() - } + enabled: !model.unread + onClicked: Kube.Fabric.postMessage(Kube.Messages.markAsUnread, {"mail": model.mail}) } Kube.Button { id: importantButton text: "i" - enabled: mailController.toggleImportantAction.enabled visible: enabled - onClicked: { - mailController.toggleImportantAction.execute() - } + enabled: !!model.mail + onClicked: Kube.Fabric.postMessage(Kube.Messages.toggleImportant, {"mail": model.mail, "important": model.important}) } Kube.Button { id: deleteButton text: "d" - enabled: mailController.moveToTrashAction.enabled visible: enabled - onClicked: { - mailController.moveToTrashAction.execute() - } + enabled: !!model.mail + onClicked: Kube.Fabric.postMessage(Kube.Messages.moveToTrash, {"mail": model.mail}) } Kube.Button { id: restoreButton text: "re" - enabled: mailController.restoreFromTrashAction.enabled visible: enabled - onClicked: { - mailController.restoreFromTrashAction.execute() - } + enabled: !!model.trash + onClicked: Kube.Fabric.postMessage(Kube.Messages.restoreFromTrash, {"mail": model.mail}) } } } diff --git a/framework/qml/Messages.qml b/framework/qml/Messages.qml index b4b170ec..1b384bfa 100644 --- a/framework/qml/Messages.qml +++ b/framework/qml/Messages.qml @@ -27,6 +27,16 @@ Item { //Actions property string moveToTrash: "moveToTrash" + property string restoreFromTrash: "restoreFromTrash" + property string markAsRead: "markAsRead" + property string markAsUnread: "markAsUnread" + property string toggleImportant: "toggleImportant" + property string moveToFolder: "moveToFolder" + + property string notification: "notification" property string search: "search" + property string synchronize: "synchronize" + property string reply: "reply" + property string edit: "edit" } diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index 39f17c32..cf971497 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -50,6 +50,7 @@ set(SRCS accounts/accountsmodel.cpp notifications/notificationhandler.cpp fabric.cpp + sinkfabric.cpp ) add_library(frameworkplugin SHARED ${SRCS}) 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; + +}; + diff --git a/framework/src/sinkfabric.h b/framework/src/sinkfabric.h new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3