summaryrefslogtreecommitdiffstats
path: root/framework/actions/action.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'framework/actions/action.cpp')
-rw-r--r--framework/actions/action.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/framework/actions/action.cpp b/framework/actions/action.cpp
new file mode 100644
index 00000000..1f94ae81
--- /dev/null
+++ b/framework/actions/action.cpp
@@ -0,0 +1,84 @@
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 <QDynamicPropertyChangeEvent>
24#include <QMetaObject>
25#include <QMetaProperty>
26
27#include "actionbroker.h"
28#include "context.h"
29
30using namespace Kube;
31
32Action::Action(QObject *parent)
33 : QObject(parent),
34 mContext(nullptr)
35{
36}
37
38void Action::setContext(Context *context)
39{
40 //Get notified when any property changes
41 for (int i = 0; i < context->metaObject()->propertyCount(); i++) {
42 auto property = context->metaObject()->property(i) ;
43 qWarning() << "Property " << property.name() << property.hasNotifySignal() << property.notifySignal().name();
44 if (QString(property.name()) != "objectName") {
45 //We do what SIGNAL does to connect to the changed signal automatically
46 QObject::connect(context, "2"+property.notifySignal().name()+"()", this, SLOT(contextChanged()));
47 }
48 }
49 mContext = context;
50 mContext->installEventFilter(this);
51 emit readyChanged();
52}
53
54void Action::contextChanged()
55{
56 emit readyChanged();
57}
58
59Context *Action::context() const
60{
61 return mContext;
62}
63
64void Action::setActionId(const QByteArray &actionId)
65{
66 mActionId = actionId;
67 emit readyChanged();
68}
69
70QByteArray Action::actionId() const
71{
72 return mActionId;
73}
74
75bool Action::ready() const
76{
77 return ActionBroker::instance().isActionReady(mActionId, mContext);
78}
79
80void Action::execute()
81{
82 ActionBroker::instance().executeAction(mActionId, mContext);
83}
84