summaryrefslogtreecommitdiffstats
path: root/framework/src/actions/action.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/actions/action.cpp')
-rw-r--r--framework/src/actions/action.cpp127
1 files changed, 0 insertions, 127 deletions
diff --git a/framework/src/actions/action.cpp b/framework/src/actions/action.cpp
deleted file mode 100644
index 1344d112..00000000
--- a/framework/src/actions/action.cpp
+++ /dev/null
@@ -1,127 +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#include "action.h"
20
21#include <QDebug>
22#include <QEvent>
23#include <QPointer>
24#include <QDynamicPropertyChangeEvent>
25#include <QMetaObject>
26#include <QMetaProperty>
27
28#include "actionbroker.h"
29#include "actionhandler.h"
30#include "context.h"
31
32using namespace Kube;
33
34Action::Action(QObject *parent)
35 : QObject(parent),
36 mContext(nullptr)
37{
38}
39
40Action::Action(const QByteArray &actionId, Context &context, QObject *parent)
41 : QObject(parent),
42 mContext(&context),
43 mActionId(actionId)
44{
45 setContext(&context);
46}
47
48Action::~Action()
49{
50}
51
52void Action::setContext(Context *context)
53{
54 //Get notified when any property changes
55 for (int i = context->metaObject()->propertyOffset(); i < context->metaObject()->propertyCount(); i++) {
56 auto property = context->metaObject()->property(i) ;
57 // qWarning() << "Property " << property.name() << property.hasNotifySignal() << property.notifySignal().name();
58 if (QString(property.name()) != "objectName") {
59 //We do what SIGNAL does to connect to the changed signal automatically
60 QObject::connect(context, "2"+property.notifySignal().name()+"()", this, SLOT(contextChanged()));
61 }
62 }
63 mContext = context;
64 mContext->installEventFilter(this);
65 emit readyChanged();
66}
67
68bool Action::eventFilter(QObject *obj, QEvent *e)
69{
70 if (obj == mContext) {
71 if (e->type() == QEvent::DynamicPropertyChange) {
72 contextChanged();
73 }
74 }
75 return QObject::eventFilter(obj, e);
76}
77
78void Action::contextChanged()
79{
80 emit readyChanged();
81}
82
83Context *Action::context() const
84{
85 return mContext;
86}
87
88void Action::setActionId(const QByteArray &actionId)
89{
90 mActionId = actionId;
91 emit readyChanged();
92}
93
94QByteArray Action::actionId() const
95{
96 return mActionId;
97}
98
99bool Action::ready() const
100{
101 return ActionBroker::instance().isActionReady(mActionId, mContext, mPreHandler);
102}
103
104void Action::execute()
105{
106 ActionBroker::instance().executeAction(mActionId, mContext, mPreHandler, mPostHandler);
107}
108
109ActionResult Action::executeWithResult()
110{
111 return ActionBroker::instance().executeAction(mActionId, mContext, mPreHandler, mPostHandler);
112}
113
114void Action::addPreHandler(ActionHandler *handler)
115{
116 //For cleanup
117 handler->setParent(this);
118 mPreHandler << handler;
119}
120
121void Action::addPostHandler(ActionHandler *handler)
122{
123 //For cleanup
124 handler->setParent(this);
125 mPostHandler << handler;
126}
127