summaryrefslogtreecommitdiffstats
path: root/framework/actions/actionhandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/actions/actionhandler.cpp')
-rw-r--r--framework/actions/actionhandler.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/framework/actions/actionhandler.cpp b/framework/actions/actionhandler.cpp
new file mode 100644
index 00000000..748c2303
--- /dev/null
+++ b/framework/actions/actionhandler.cpp
@@ -0,0 +1,70 @@
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
20#include "actionhandler.h"
21
22#include "context.h"
23#include "actionbroker.h"
24#include <QDebug>
25
26using namespace Kube;
27
28ActionHandler::ActionHandler(QObject *parent)
29 : QObject(parent)
30{
31
32}
33
34bool ActionHandler::isActionReady(Context *context)
35{
36 if (context) {
37 QVariant returnedValue;
38 QMetaObject::invokeMethod(this, "isReady",
39 Q_RETURN_ARG(QVariant, returnedValue),
40 Q_ARG(QVariant, QVariant::fromValue(context)));
41 return returnedValue.toBool();
42 } else {
43 qWarning() << "The handler didn't get a context";
44 }
45 return false;
46}
47
48void ActionHandler::execute(Context *context)
49{
50 QVariant returnedValue;
51 qWarning() << "Executing the handler";
52 if (context) {
53 QMetaObject::invokeMethod(this, "handler",
54 Q_RETURN_ARG(QVariant, returnedValue),
55 Q_ARG(QVariant, QVariant::fromValue(context)));
56 } else {
57 qWarning() << "The handler didn't get a context";
58 }
59}
60
61void ActionHandler::setActionId(const QByteArray &actionId)
62{
63 mActionId = actionId;
64 ActionBroker::instance().registerHandler(actionId, this);
65}
66
67QByteArray ActionHandler::actionId() const
68{
69 return mActionId;
70}