From 8cf790d6bc91e5e9c06651ffe4a193b625207f0d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 1 Jan 2017 23:18:24 +0100 Subject: Outboxcontroller and Mailcontroller --- components/mail/contents/ui/main.qml | 37 ++++++----------- components/package/contents/ui/Outbox.qml | 9 ++--- framework/domain/CMakeLists.txt | 2 + framework/domain/actions/sinkactions.cpp | 62 ----------------------------- framework/domain/composercontroller.cpp | 1 + framework/domain/composercontroller.h | 1 + framework/domain/mailcontroller.cpp | 66 +++++++++++++++++++++++++++++++ framework/domain/mailcontroller.h | 42 ++++++++++++++++++++ framework/domain/mailplugin.cpp | 4 ++ framework/domain/outboxcontroller.cpp | 50 +++++++++++++++++++++++ framework/domain/outboxcontroller.h | 39 ++++++++++++++++++ 11 files changed, 221 insertions(+), 92 deletions(-) create mode 100644 framework/domain/mailcontroller.cpp create mode 100644 framework/domain/mailcontroller.h create mode 100644 framework/domain/outboxcontroller.cpp create mode 100644 framework/domain/outboxcontroller.h diff --git a/components/mail/contents/ui/main.qml b/components/mail/contents/ui/main.qml index cf5cfd6a..423d8f34 100644 --- a/components/mail/contents/ui/main.qml +++ b/components/mail/contents/ui/main.qml @@ -61,24 +61,6 @@ Controls2.ApplicationWindow { context: maillistcontext } - KubeAction.Action { - id: editAction - actionId: "org.kde.kube.actions.edit" - context: maillistcontext - } - - KubeAction.Action { - id: markAsReadAction - actionId: "org.kde.kube.actions.mark-as-read" - context: maillistcontext - } - - KubeAction.Action { - id: deleteAction - actionId: "org.kde.kube.actions.move-to-trash" - context: maillistcontext - } - KubeAction.Action { id: syncAction actionId: "org.kde.kube.actions.synchronize" @@ -115,6 +97,13 @@ Controls2.ApplicationWindow { */ //END ActionHandler + //Controller + KubeFramework.MailController { + id: mailController + mail: mailListView.currentMail + } + + //BEGIN Shortcuts Shortcut { sequence: StandardKey.Refresh @@ -123,8 +112,8 @@ Controls2.ApplicationWindow { } Shortcut { sequence: StandardKey.Delete - onActivated: deleteAction.execute() - enabled: deleteAction.ready + onActivated: mailController.moveToTrashAction.execute() + enabled: mailController.moveToTrashAction.enabled } Shortcut { sequence: StandardKey.MoveToNextLine @@ -221,10 +210,10 @@ Controls2.ApplicationWindow { ToolButton { iconName: "mail-mark-unread" text: "Mark As Read" - enabled: markAsReadAction.ready + enabled: mailController.markAsRead.enabled tooltip: "mark mail as read" onClicked: { - markAsReadAction.execute() + mailController.markAsRead.execute() } } @@ -240,10 +229,10 @@ Controls2.ApplicationWindow { ToolButton { iconName: "edit-delete" text: "Delete Mail" - enabled: deleteAction.ready + enabled: mailController.moveToTrashAction.enabled tooltip: "delete email" onClicked: { - deleteAction.execute() + mailController.moveToTrashAction.execute() } } } diff --git a/components/package/contents/ui/Outbox.qml b/components/package/contents/ui/Outbox.qml index 5330cd4e..3a51e51a 100644 --- a/components/package/contents/ui/Outbox.qml +++ b/components/package/contents/ui/Outbox.qml @@ -37,11 +37,8 @@ ToolButton { dialog.visible = dialog.visible ? false : true } - KubeAction.Action { - id: sendNowAction - actionId: "org.kde.kube.actions.sendOutbox" - context: KubeAction.Context { - } + KubeFramework.OutboxController { + id: outboxController } //BEGIN Dialog @@ -88,7 +85,7 @@ ToolButton { height: Kirigami.Units.gridUnit * 2 text: qsTr("Send now.") onClicked: { - sendNowAction.execute() + outboxController.sendOutboxAction.execute() } } diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index bb522416..8f343928 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt @@ -23,6 +23,8 @@ set(mailplugin_SRCS selector.cpp completer.cpp controller.cpp + outboxcontroller.cpp + mailcontroller.cpp ) find_package(KF5 REQUIRED COMPONENTS Package) diff --git a/framework/domain/actions/sinkactions.cpp b/framework/domain/actions/sinkactions.cpp index a2d4c02c..460cb6a1 100644 --- a/framework/domain/actions/sinkactions.cpp +++ b/framework/domain/actions/sinkactions.cpp @@ -31,53 +31,6 @@ using namespace Kube; using namespace Sink; using namespace Sink::ApplicationDomain; -static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", - [](Context *context) -> bool { - return context->property("mail").isValid(); - }, - [](Context *context) { - auto mail = context->property("mail").value(); - if (!mail) { - SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); - return; - } - mail->setProperty("unread", false); - SinkLog() << "Mark as read " << mail->identifier(); - Store::modify(*mail).exec(); - } -); - -static ActionHandlerHelper moveToTrashHandler("org.kde.kube.actions.move-to-trash", - [](Context *context) -> bool { - return context->property("mail").isValid(); - }, - [](Context *context) { - auto mail = context->property("mail").value(); - if (!mail) { - SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); - return; - } - mail->setTrash(true); - SinkLog() << "Move to trash " << mail->identifier(); - Store::modify(*mail).exec(); - } -); - -static ActionHandlerHelper deleteHandler("org.kde.kube.actions.delete", - [](Context *context) -> bool { - return context->property("mail").isValid(); - }, - [](Context *context) { - auto mail = context->property("mail").value(); - if (!mail) { - SinkWarning() << "Failed to get the mail mail: " << context->property("mail"); - return; - } - SinkLog() << "Remove " << mail->identifier(); - Store::remove(*mail).exec(); - } -); - class FolderContext : public Kube::ContextWrapper { using Kube::ContextWrapper::ContextWrapper; KUBE_CONTEXTWRAPPER_PROPERTY(Sink::ApplicationDomain::Folder::Ptr, Folder, folder) @@ -101,18 +54,3 @@ static ActionHandlerHelper synchronizeHandler("org.kde.kube.actions.synchronize" } ); -static ActionHandlerHelper sendOutboxHandler("org.kde.kube.actions.sendOutbox", - [](Context *context) -> bool { - return true; - }, - ActionHandlerHelper::JobHandler{[](Context *context) -> KAsync::Job { - using namespace Sink::ApplicationDomain; - Query query; - query.containsFilter(ResourceCapabilities::Mail::transport); - return Store::fetchAll(query) - .each([=](const SinkResource::Ptr &resource) -> KAsync::Job { - return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier())); - }); - }} -); - diff --git a/framework/domain/composercontroller.cpp b/framework/domain/composercontroller.cpp index 4ce356a9..75396735 100644 --- a/framework/domain/composercontroller.cpp +++ b/framework/domain/composercontroller.cpp @@ -1,5 +1,6 @@ /* Copyright (c) 2016 Michael Bohlender + 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 diff --git a/framework/domain/composercontroller.h b/framework/domain/composercontroller.h index c5046306..2e74954e 100644 --- a/framework/domain/composercontroller.h +++ b/framework/domain/composercontroller.h @@ -1,5 +1,6 @@ /* Copyright (c) 2016 Michael Bohlender + 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 diff --git a/framework/domain/mailcontroller.cpp b/framework/domain/mailcontroller.cpp new file mode 100644 index 00000000..4c5ae5c6 --- /dev/null +++ b/framework/domain/mailcontroller.cpp @@ -0,0 +1,66 @@ +/* + 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 "mailcontroller.h" + +#include +#include + +SINK_DEBUG_AREA("mailcontroller"); + +MailController::MailController() + : Kube::Controller(), + action_markAsRead{new Kube::ControllerAction}, + action_moveToTrash{new Kube::ControllerAction}, + action_remove{new Kube::ControllerAction} +{ + QObject::connect(markAsReadAction(), &Kube::ControllerAction::triggered, this, &MailController::markAsRead); + QObject::connect(moveToTrashAction(), &Kube::ControllerAction::triggered, this, &MailController::moveToTrash); + QObject::connect(removeAction(), &Kube::ControllerAction::triggered, this, &MailController::remove); +} + +void MailController::markAsRead() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + auto mail = getMail(); + mail->setUnread(false); + SinkLog() << "Mark as read " << mail->identifier(); + run(Store::modify(*mail)); +} + +void MailController::moveToTrash() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + auto mail = getMail(); + mail->setTrash(true); + SinkLog() << "Move to trash " << mail->identifier(); + run(Store::modify(*mail)); +} + +void MailController::remove() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + auto mail = getMail(); + mail->setTrash(true); + SinkLog() << "Remove " << mail->identifier(); + run(Store::remove(*mail)); +} + diff --git a/framework/domain/mailcontroller.h b/framework/domain/mailcontroller.h new file mode 100644 index 00000000..66cb7b4b --- /dev/null +++ b/framework/domain/mailcontroller.h @@ -0,0 +1,42 @@ +/* + 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. +*/ +#pragma once + +#include +#include "controller.h" +#include "sink/applicationdomaintype.h" + +#define KUBE_CONTROLLER_ACTION(NAME) \ + Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \ + private: QScopedPointer action_##NAME; \ + public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \ + private slots: void NAME(); \ + + +class MailController : public Kube::Controller +{ + Q_OBJECT + KUBE_CONTROLLER_PROPERTY(Sink::ApplicationDomain::Mail::Ptr, Mail, mail) + KUBE_CONTROLLER_ACTION(markAsRead) + KUBE_CONTROLLER_ACTION(moveToTrash) + KUBE_CONTROLLER_ACTION(remove) + +public: + explicit MailController(); +}; diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index c7023bde..eeb1aeb1 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp @@ -29,6 +29,8 @@ #include "accountscontroller.h" #include "accountsmodel.h" #include "outboxmodel.h" +#include "outboxcontroller.h" +#include "mailcontroller.h" #include @@ -44,5 +46,7 @@ void MailPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "AccountFactory"); qmlRegisterType(uri, 1, 0, "AccountsController"); qmlRegisterType(uri, 1, 0, "AccountsModel"); + qmlRegisterType(uri, 1, 0, "OutboxController"); qmlRegisterType(uri, 1, 0, "OutboxModel"); + qmlRegisterType(uri, 1, 0, "MailController"); } diff --git a/framework/domain/outboxcontroller.cpp b/framework/domain/outboxcontroller.cpp new file mode 100644 index 00000000..3b4f0e62 --- /dev/null +++ b/framework/domain/outboxcontroller.cpp @@ -0,0 +1,50 @@ +/* + 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 "outboxcontroller.h" + +#include +#include + +SINK_DEBUG_AREA("outboxcontroller"); + +OutboxController::OutboxController() + : Kube::Controller(), + mSynchronizeOutboxAction{new Kube::ControllerAction} +{ + QObject::connect(mSynchronizeOutboxAction.data(), &Kube::ControllerAction::triggered, this, &OutboxController::sendOutbox); +} + +Kube::ControllerAction* OutboxController::sendOutboxAction() const +{ + return mSynchronizeOutboxAction.data(); +} + +void OutboxController::sendOutbox() +{ + using namespace Sink; + using namespace Sink::ApplicationDomain; + Query query; + query.containsFilter(ResourceCapabilities::Mail::transport); + auto job = Store::fetchAll(query) + .each([=](const SinkResource::Ptr &resource) -> KAsync::Job { + return Store::synchronize(SyncScope{}.resourceFilter(resource->identifier())); + }); + run(job); +} + diff --git a/framework/domain/outboxcontroller.h b/framework/domain/outboxcontroller.h new file mode 100644 index 00000000..4c24ad59 --- /dev/null +++ b/framework/domain/outboxcontroller.h @@ -0,0 +1,39 @@ +/* + 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. +*/ +#pragma once + +#include +#include "controller.h" + +class OutboxController : public Kube::Controller +{ + Q_OBJECT + Q_PROPERTY (Kube::ControllerAction* sendOutboxAction READ sendOutboxAction CONSTANT) + +public: + explicit OutboxController(); + + Kube::ControllerAction* sendOutboxAction() const; + +private slots: + void sendOutbox(); + +private: + QScopedPointer mSynchronizeOutboxAction; +}; -- cgit v1.2.3