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 --- framework/CMakeLists.txt | 1 + framework/mail/CMakeLists.txt | 3 +- framework/mail/actions/akonadiactions.cpp | 75 +++++++++++++++++++++++++++++++ framework/mail/actions/akonadiactions.h | 40 +++++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 framework/mail/actions/akonadiactions.cpp create mode 100644 framework/mail/actions/akonadiactions.h (limited to 'framework') 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