summaryrefslogtreecommitdiffstats
path: root/framework/src/domain/controller.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-05 15:04:00 +0200
commit4b1798f0cdf87361869e7cf2b341acacd056c410 (patch)
tree3ff780641acdcb20b81f9b41533afd50a2525d38 /framework/src/domain/controller.cpp
parent71721aa4f3e85bea1a2fe504e86d99f80a3106a9 (diff)
downloadkube-4b1798f0cdf87361869e7cf2b341acacd056c410.tar.gz
kube-4b1798f0cdf87361869e7cf2b341acacd056c410.zip
Moved cpp code into src directory
Diffstat (limited to 'framework/src/domain/controller.cpp')
-rw-r--r--framework/src/domain/controller.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/framework/src/domain/controller.cpp b/framework/src/domain/controller.cpp
new file mode 100644
index 00000000..52f4cd1f
--- /dev/null
+++ b/framework/src/domain/controller.cpp
@@ -0,0 +1,59 @@
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 "controller.h"
20
21#include <QQmlEngine>
22#include <QMetaProperty>
23#include <sink/log.h>
24
25using namespace Kube;
26
27ControllerAction::ControllerAction()
28 : QObject()
29{
30 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
31}
32
33void ControllerAction::execute()
34{
35 emit triggered();
36}
37
38void Controller::clear()
39{
40 auto meta = metaObject();
41 for (auto i = meta->propertyOffset(); i < meta->propertyCount(); i++) {
42 auto property = meta->property(i);
43 setProperty(property.name(), QVariant());
44 }
45 for (const auto &p : dynamicPropertyNames()) {
46 setProperty(p, QVariant());
47 }
48}
49
50void Controller::run(const KAsync::Job<void> &job)
51{
52 auto jobToExec = job;
53 jobToExec.onError([] (const KAsync::Error &error) {
54 SinkWarningCtx(Sink::Log::Context{"controller"}) << "Error while executing job: " << error.errorMessage;
55 });
56 //TODO handle error
57 //TODO attach a log context to the execution that we can gather from the job?
58 jobToExec.exec();
59}