summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-24 10:36:56 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-24 10:36:56 +0100
commitb352f61f136f21854b3da5b76d49fe45cbb2d3fd (patch)
tree53accb06f16a6cf1c381176d59e3d2449212a4e8
parentf5d4b7dc12dbb3b38b70bcbe94298972208d64f5 (diff)
downloadsink-b352f61f136f21854b3da5b76d49fe45cbb2d3fd.tar.gz
sink-b352f61f136f21854b3da5b76d49fe45cbb2d3fd.zip
if not being run interactively, then use the main app loop
QEventLoop requires QCoreApplication is running; so when we don't have one running the whole app, just start/stop the core app on demand (from/for commands).
-rw-r--r--akonadish/main.cpp1
-rw-r--r--akonadish/state.cpp31
-rw-r--r--akonadish/state.h2
3 files changed, 30 insertions, 4 deletions
diff --git a/akonadish/main.cpp b/akonadish/main.cpp
index 695fb82..bd85fb4 100644
--- a/akonadish/main.cpp
+++ b/akonadish/main.cpp
@@ -60,6 +60,7 @@ int main(int argc, char *argv[])
60// JsonListener listener(syntax); 60// JsonListener listener(syntax);
61 } 61 }
62 62
63 State::setHasEventLoop(true);
63 return app.exec(); 64 return app.exec();
64 } else if (!interactive) { 65 } else if (!interactive) {
65 QTextStream inputStream(stdin); 66 QTextStream inputStream(stdin);
diff --git a/akonadish/state.cpp b/akonadish/state.cpp
index 968c0ac..c9f9ee3 100644
--- a/akonadish/state.cpp
+++ b/akonadish/state.cpp
@@ -19,10 +19,13 @@
19 19
20#include "state.h" 20#include "state.h"
21 21
22#include <QCoreApplication>
22#include <QDebug> 23#include <QDebug>
23#include <QEventLoop> 24#include <QEventLoop>
24#include <QTextStream> 25#include <QTextStream>
25 26
27static bool s_hasEventLoop = false;
28
26class State::Private 29class State::Private
27{ 30{
28public: 31public:
@@ -31,8 +34,17 @@ public:
31 { 34 {
32 } 35 }
33 36
37 QEventLoop *eventLoop()
38 {
39 if (!event) {
40 event = new QEventLoop;
41 }
42
43 return event;
44 }
45
34 int debugLevel = 0; 46 int debugLevel = 0;
35 QEventLoop eventLoop; 47 QEventLoop *event = 0;
36 QTextStream outStream; 48 QTextStream outStream;
37}; 49};
38 50
@@ -76,8 +88,10 @@ unsigned int State::debugLevel() const
76 88
77int State::commandStarted() const 89int State::commandStarted() const
78{ 90{
79 if (!d->eventLoop.isRunning()) { 91 if (!s_hasEventLoop) {
80 return d->eventLoop.exec(); 92 return QCoreApplication::exec();
93 } else if (!d->eventLoop()->isRunning()) {
94 return d->eventLoop()->exec();
81 } 95 }
82 96
83 return 0; 97 return 0;
@@ -85,6 +99,15 @@ int State::commandStarted() const
85 99
86void State::commandFinished(int returnCode) const 100void State::commandFinished(int returnCode) const
87{ 101{
88 d->eventLoop.exit(returnCode); 102 if (!s_hasEventLoop) {
103 QCoreApplication::exit(returnCode);
104 } else {
105 d->eventLoop()->exit(returnCode);
106 }
107}
108
109void State::setHasEventLoop(bool evented)
110{
111 s_hasEventLoop = evented;
89} 112}
90 113
diff --git a/akonadish/state.h b/akonadish/state.h
index eb07f56..1ba86dd 100644
--- a/akonadish/state.h
+++ b/akonadish/state.h
@@ -36,6 +36,8 @@ public:
36 int commandStarted() const; 36 int commandStarted() const;
37 void commandFinished(int returnCode = 0) const; 37 void commandFinished(int returnCode = 0) const;
38 38
39 static void setHasEventLoop(bool evented);
40
39private: 41private:
40 class Private; 42 class Private;
41 Private * const d; 43 Private * const d;