From 4b094beb151373abb4a24d473c6d69a11674c5ba Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 Feb 2016 12:37:51 +0100 Subject: Moved the ActionHandlerHelper --- framework/actions/actionhandler.cpp | 20 +++++++++++++++++ framework/actions/actionhandler.h | 17 +++++++++++++++ framework/mail/actions/sinkactions.cpp | 21 +----------------- framework/mail/actions/sinkactions.h | 40 ---------------------------------- 4 files changed, 38 insertions(+), 60 deletions(-) delete mode 100644 framework/mail/actions/sinkactions.h (limited to 'framework') diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp index 748c2303..d4b01734 100644 --- a/framework/actions/actionhandler.cpp +++ b/framework/actions/actionhandler.cpp @@ -68,3 +68,23 @@ QByteArray ActionHandler::actionId() const { return mActionId; } + + + +ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler) + : ActionHandler(nullptr), + isReadyFunction(isReady), + handlerFunction(handler) +{ + setActionId(actionId); +} + +bool ActionHandlerHelper::isActionReady(Context *context) +{ + return isReadyFunction(context); +} + +void ActionHandlerHelper::execute(Context *context) +{ + handlerFunction(context); +} diff --git a/framework/actions/actionhandler.h b/framework/actions/actionhandler.h index cfcfddd7..1820bfd4 100644 --- a/framework/actions/actionhandler.h +++ b/framework/actions/actionhandler.h @@ -20,6 +20,7 @@ #include #include +#include namespace Kube { class Context; @@ -45,4 +46,20 @@ private: QByteArray mActionId; }; +class ActionHandlerHelper : public ActionHandler +{ + Q_OBJECT +public: + typedef std::function IsReadyFunction; + typedef std::function Handler; + + ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &); + + bool isActionReady(Context *context) Q_DECL_OVERRIDE; + void execute(Context *context) Q_DECL_OVERRIDE; +private: + const std::function isReadyFunction; + const std::function handlerFunction; +}; + } diff --git a/framework/mail/actions/sinkactions.cpp b/framework/mail/actions/sinkactions.cpp index 978a045b..e00d3947 100644 --- a/framework/mail/actions/sinkactions.cpp +++ b/framework/mail/actions/sinkactions.cpp @@ -16,32 +16,13 @@ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "sinkactions.h" - #include +#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(); diff --git a/framework/mail/actions/sinkactions.h b/framework/mail/actions/sinkactions.h deleted file mode 100644 index a583ebf8..00000000 --- a/framework/mail/actions/sinkactions.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - 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