diff options
author | Aaron Seigo <aseigo@kde.org> | 2015-12-24 10:36:56 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2015-12-24 10:36:56 +0100 |
commit | b352f61f136f21854b3da5b76d49fe45cbb2d3fd (patch) | |
tree | 53accb06f16a6cf1c381176d59e3d2449212a4e8 | |
parent | f5d4b7dc12dbb3b38b70bcbe94298972208d64f5 (diff) | |
download | sink-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.cpp | 1 | ||||
-rw-r--r-- | akonadish/state.cpp | 31 | ||||
-rw-r--r-- | akonadish/state.h | 2 |
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 | ||
27 | static bool s_hasEventLoop = false; | ||
28 | |||
26 | class State::Private | 29 | class State::Private |
27 | { | 30 | { |
28 | public: | 31 | public: |
@@ -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 | ||
77 | int State::commandStarted() const | 89 | int 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 | ||
86 | void State::commandFinished(int returnCode) const | 100 | void 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 | |||
109 | void 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 | |||
39 | private: | 41 | private: |
40 | class Private; | 42 | class Private; |
41 | Private * const d; | 43 | Private * const d; |