summaryrefslogtreecommitdiffstats
path: root/framework/domain/controller.h
diff options
context:
space:
mode:
Diffstat (limited to 'framework/domain/controller.h')
-rw-r--r--framework/domain/controller.h90
1 files changed, 0 insertions, 90 deletions
diff --git a/framework/domain/controller.h b/framework/domain/controller.h
deleted file mode 100644
index bf2a7ace..00000000
--- a/framework/domain/controller.h
+++ /dev/null
@@ -1,90 +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 <QObject>
22#include <QVariant>
23#include <KAsync/Async>
24
25#define KUBE_CONTROLLER_PROPERTY(TYPE, NAME, LOWERCASENAME) \
26 public: Q_PROPERTY(TYPE LOWERCASENAME MEMBER m##NAME NOTIFY LOWERCASENAME##Changed) \
27 Q_SIGNALS: void LOWERCASENAME##Changed(); \
28 private: TYPE m##NAME; \
29 public: \
30 struct NAME { \
31 static constexpr const char *name = #LOWERCASENAME; \
32 typedef TYPE Type; \
33 }; \
34 void set##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \
35 void clear##NAME() { setProperty(NAME::name, QVariant{}); } \
36 TYPE get##NAME() const { return m##NAME; } \
37
38
39#define KUBE_CONTROLLER_ACTION(NAME) \
40 Q_PROPERTY (Kube::ControllerAction* NAME##Action READ NAME##Action CONSTANT) \
41 private: QScopedPointer<Kube::ControllerAction> action_##NAME; \
42 public: Kube::ControllerAction* NAME##Action() const { Q_ASSERT(action_##NAME); return action_##NAME.data(); } \
43 private slots: void NAME(); \
44
45
46namespace Kube {
47
48class ControllerAction : public QObject {
49 Q_OBJECT
50 Q_PROPERTY(bool enabled MEMBER mEnabled NOTIFY enabledChanged)
51public:
52 ControllerAction();
53 template <typename Func>
54 ControllerAction(const typename QtPrivate::FunctionPointer<Func>::Object *obj, Func slot)
55 : ControllerAction()
56 {
57 QObject::connect(this, &ControllerAction::triggered, obj, slot);
58 }
59
60 ~ControllerAction() = default;
61
62 Q_INVOKABLE void execute();
63 void setEnabled(bool enabled) { setProperty("enabled", enabled); }
64
65signals:
66 void enabledChanged();
67 void triggered();
68
69private:
70 bool mEnabled = true;
71};
72
73class Controller : public QObject {
74 Q_OBJECT
75public:
76 Controller() = default;
77 virtual ~Controller() = default;
78
79public slots:
80 virtual void clear();
81
82signals:
83 void done();
84 void error();
85
86protected:
87 void run(const KAsync::Job<void> &job);
88};
89
90}