From 42d3a9e04e72c77004abecc01a816ea1981e2fc5 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 6 Jan 2016 12:18:02 +0100 Subject: Implemented some akonadi actions --- .../kube-mail/package/contents/ui/main.qml | 50 ++++++--------- framework/CMakeLists.txt | 1 + framework/mail/CMakeLists.txt | 3 +- framework/mail/actions/akonadiactions.cpp | 75 ++++++++++++++++++++++ framework/mail/actions/akonadiactions.h | 40 ++++++++++++ 5 files changed, 139 insertions(+), 30 deletions(-) create mode 100644 framework/mail/actions/akonadiactions.cpp create mode 100644 framework/mail/actions/akonadiactions.h diff --git a/applications/kube-mail/package/contents/ui/main.qml b/applications/kube-mail/package/contents/ui/main.qml index 33744157..ef37ae19 100644 --- a/applications/kube-mail/package/contents/ui/main.qml +++ b/applications/kube-mail/package/contents/ui/main.qml @@ -32,16 +32,16 @@ ApplicationWindow { visible: true - Action.ActionHandler { - actionId: "org.kde.kube.actions.mark-as-read" - function isReady(context) { - return context.mail ? true : false; - } - - function handler(context) { - console.warn("Got message:", context.mail) - } - } + // Action.ActionHandler { + // actionId: "org.kde.kube.actions.mark-as-read" + // function isReady(context) { + // return context.mail ? true : false; + // } + // + // function handler(context) { + // console.warn("Got message:", context.mail) + // } + // } Action.Context { id: "maillistcontext" @@ -55,6 +55,12 @@ ApplicationWindow { context: maillistcontext } + Action.Action { + id: "deleteAction" + actionId: "org.kde.kube.actions.delete" + context: maillistcontext + } + //UI toolBar: ToolBar { @@ -62,48 +68,38 @@ ApplicationWindow { anchors.fill: parent PlasmaComponents.ToolButton { - height: parent.height - iconName: "mail-message-new" - text: "Compose" + enabled: false } PlasmaComponents.ToolButton { - height: parent.height - iconName: "mail-mark-unread" - text: "Mark Unread" + text: "Mark As Read" enabled: markAsReadAction.ready - onClicked: { markAsReadAction.execute() } } PlasmaComponents.ToolButton { - height: parent.height - iconName: "mail-mark-important" text: "Mark Important" - + enabled: false onClicked: { - mailList.markMailImportant(true) } } PlasmaComponents.ToolButton { - height: parent.height - iconName: "edit-delete" text: "Delete Mail" - + enabled: deleteAction.ready onClicked: { - mailList.deleteMail() + deleteAction.execute() } } } @@ -114,7 +110,6 @@ ApplicationWindow { FolderListView { id: folderListView - width: unit.size * 55 Layout.maximumWidth: unit.size * 150 Layout.minimumWidth: unit.size * 30 @@ -123,7 +118,6 @@ ApplicationWindow { MailListView { id: mailListView parentFolder: folderListView.currentFolder - width: unit.size * 80 Layout.maximumWidth: unit.size * 250 Layout.minimumWidth: unit.size * 50 @@ -132,7 +126,6 @@ ApplicationWindow { SingleMailView { id: mailView mail: mailListView.currentMail - Layout.fillWidth: true } @@ -141,7 +134,6 @@ ApplicationWindow { //TODO find a better way to scale UI Item { id: unit - property int size: 5 } diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 3a441f99..d59061d2 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -18,6 +18,7 @@ find_package(Qt5 COMPONENTS REQUIRED Core Qml) set(CMAKE_AUTOMOC ON) add_definitions("-Wall -std=c++0x -g") +include_directories(.) include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/common) include_directories(SYSTEM /work/install/include/) include_directories(SYSTEM /work/install/include/KF5/) diff --git a/framework/mail/CMakeLists.txt b/framework/mail/CMakeLists.txt index 38ba3935..6188c93c 100644 --- a/framework/mail/CMakeLists.txt +++ b/framework/mail/CMakeLists.txt @@ -5,13 +5,14 @@ set(mailplugin_SRCS singlemailcontroller.cpp folderlistmodel.cpp folderlistcontroller.cpp + actions/akonadiactions.cpp ) add_library(mailplugin SHARED ${mailplugin_SRCS}) qt5_use_modules(mailplugin Core Quick Qml) -target_link_libraries(mailplugin /work/install/lib64/libakonadi2common.so) +target_link_libraries(mailplugin /work/install/lib64/libakonadi2common.so actionplugin) #target_link_libraries(mailplugin /home/mike/projects/_install/lib/x86_64-linux-gnu/libakonadi2common.so) install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/mail) diff --git a/framework/mail/actions/akonadiactions.cpp b/framework/mail/actions/akonadiactions.cpp new file mode 100644 index 00000000..d0a51deb --- /dev/null +++ b/framework/mail/actions/akonadiactions.cpp @@ -0,0 +1,75 @@ +/* + 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 "akonadiactions.h" + +#include + +#include + +using namespace Kube; + +ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const std::function &isReady, const std::function &handler) + : ActionHandler(nullptr), + isReadyFunction(isReady), + handlerFunction(handler) +{ + setActionId(actionId); +} + +bool ActionHandlerHelper::isActionReady(Context *context) +{ + return isReadyFunction(context); +} + +void ActionHandlerHelper::execute(Context *context) +{ + handlerFunction(context); +} + +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) { + qWarning() << "Failed to get the mail mail: " << context->property("mail"); + return; + } + mail->setProperty("unread", false); + qDebug() << "Mark as read " << mail->identifier(); + Akonadi2::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) { + qWarning() << "Failed to get the mail mail: " << context->property("mail"); + return; + } + mail->setProperty("unread", false); + qDebug() << "Remove " << mail->identifier(); + Akonadi2::Store::remove(*mail).exec(); + } +); diff --git a/framework/mail/actions/akonadiactions.h b/framework/mail/actions/akonadiactions.h new file mode 100644 index 00000000..a583ebf8 --- /dev/null +++ b/framework/mail/actions/akonadiactions.h @@ -0,0 +1,40 @@ +/* + 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 + +namespace Kube { +class Context; + +class ActionHandlerHelper : public ActionHandler +{ + Q_OBJECT +public: + ActionHandlerHelper(const QByteArray &actionId, const std::function &, const std::function &); + + bool isActionReady(Context *context) Q_DECL_OVERRIDE; + void execute(Context *context) Q_DECL_OVERRIDE; +private: + const std::function isReadyFunction; + const std::function handlerFunction; +}; + +} -- cgit v1.2.3