diff options
Diffstat (limited to 'akonadish/state.cpp')
-rw-r--r-- | akonadish/state.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
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 | ||