summaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-24 12:37:51 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-02-24 12:37:51 +0100
commit4b094beb151373abb4a24d473c6d69a11674c5ba (patch)
tree815b83ac455d5c62948f4ab02b33ea622567127f /framework
parent37d1ff146cda492b02c6b199e1b33f671c1fa9f9 (diff)
downloadkube-4b094beb151373abb4a24d473c6d69a11674c5ba.tar.gz
kube-4b094beb151373abb4a24d473c6d69a11674c5ba.zip
Moved the ActionHandlerHelper
Diffstat (limited to 'framework')
-rw-r--r--framework/actions/actionhandler.cpp20
-rw-r--r--framework/actions/actionhandler.h17
-rw-r--r--framework/mail/actions/sinkactions.cpp21
-rw-r--r--framework/mail/actions/sinkactions.h40
4 files changed, 38 insertions, 60 deletions
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
68{ 68{
69 return mActionId; 69 return mActionId;
70} 70}
71
72
73
74ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &isReady, const Handler &handler)
75 : ActionHandler(nullptr),
76 isReadyFunction(isReady),
77 handlerFunction(handler)
78{
79 setActionId(actionId);
80}
81
82bool ActionHandlerHelper::isActionReady(Context *context)
83{
84 return isReadyFunction(context);
85}
86
87void ActionHandlerHelper::execute(Context *context)
88{
89 handlerFunction(context);
90}
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 @@
20 20
21#include <QObject> 21#include <QObject>
22#include <QMultiMap> 22#include <QMultiMap>
23#include <functional>
23 24
24namespace Kube { 25namespace Kube {
25class Context; 26class Context;
@@ -45,4 +46,20 @@ private:
45 QByteArray mActionId; 46 QByteArray mActionId;
46}; 47};
47 48
49class ActionHandlerHelper : public ActionHandler
50{
51 Q_OBJECT
52public:
53 typedef std::function<bool(Context*)> IsReadyFunction;
54 typedef std::function<void(Context*)> Handler;
55
56 ActionHandlerHelper(const QByteArray &actionId, const IsReadyFunction &, const Handler &);
57
58 bool isActionReady(Context *context) Q_DECL_OVERRIDE;
59 void execute(Context *context) Q_DECL_OVERRIDE;
60private:
61 const std::function<bool(Context*)> isReadyFunction;
62 const std::function<void(Context*)> handlerFunction;
63};
64
48} 65}
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 @@
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA. 17 02110-1301, USA.
18*/ 18*/
19#include "sinkactions.h"
20
21#include <actions/context.h> 19#include <actions/context.h>
20#include <actions/actionhandler.h>
22 21
23#include <sink/store.h> 22#include <sink/store.h>
24 23
25using namespace Kube; 24using namespace Kube;
26 25
27ActionHandlerHelper::ActionHandlerHelper(const QByteArray &actionId, const std::function<bool(Context*)> &isReady, const std::function<void(Context*)> &handler)
28 : ActionHandler(nullptr),
29 isReadyFunction(isReady),
30 handlerFunction(handler)
31{
32 setActionId(actionId);
33}
34
35bool ActionHandlerHelper::isActionReady(Context *context)
36{
37 return isReadyFunction(context);
38}
39
40void ActionHandlerHelper::execute(Context *context)
41{
42 handlerFunction(context);
43}
44
45static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read", 26static ActionHandlerHelper markAsReadHandler("org.kde.kube.actions.mark-as-read",
46 [](Context *context) -> bool { 27 [](Context *context) -> bool {
47 return context->property("mail").isValid(); 28 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 @@
1/*
2 Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#pragma once
20
21#include <actions/actionhandler.h>
22#include <functional>
23
24namespace Kube {
25class Context;
26
27class ActionHandlerHelper : public ActionHandler
28{
29 Q_OBJECT
30public:
31 ActionHandlerHelper(const QByteArray &actionId, const std::function<bool(Context*)> &, const std::function<void(Context*)> &);
32
33 bool isActionReady(Context *context) Q_DECL_OVERRIDE;
34 void execute(Context *context) Q_DECL_OVERRIDE;
35private:
36 const std::function<bool(Context*)> isReadyFunction;
37 const std::function<void(Context*)> handlerFunction;
38};
39
40}