From b352f61f136f21854b3da5b76d49fe45cbb2d3fd Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Thu, 24 Dec 2015 10:36:56 +0100 Subject: 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). --- akonadish/main.cpp | 1 + akonadish/state.cpp | 31 +++++++++++++++++++++++++++---- akonadish/state.h | 2 ++ 3 files changed, 30 insertions(+), 4 deletions(-) (limited to 'akonadish') 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[]) // JsonListener listener(syntax); } + State::setHasEventLoop(true); return app.exec(); } else if (!interactive) { 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 @@ #include "state.h" +#include #include #include #include +static bool s_hasEventLoop = false; + class State::Private { public: @@ -31,8 +34,17 @@ public: { } + QEventLoop *eventLoop() + { + if (!event) { + event = new QEventLoop; + } + + return event; + } + int debugLevel = 0; - QEventLoop eventLoop; + QEventLoop *event = 0; QTextStream outStream; }; @@ -76,8 +88,10 @@ unsigned int State::debugLevel() const int State::commandStarted() const { - if (!d->eventLoop.isRunning()) { - return d->eventLoop.exec(); + if (!s_hasEventLoop) { + return QCoreApplication::exec(); + } else if (!d->eventLoop()->isRunning()) { + return d->eventLoop()->exec(); } return 0; @@ -85,6 +99,15 @@ int State::commandStarted() const void State::commandFinished(int returnCode) const { - d->eventLoop.exit(returnCode); + if (!s_hasEventLoop) { + QCoreApplication::exit(returnCode); + } else { + d->eventLoop()->exit(returnCode); + } +} + +void State::setHasEventLoop(bool evented) +{ + s_hasEventLoop = evented; } 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: int commandStarted() const; void commandFinished(int returnCode = 0) const; + static void setHasEventLoop(bool evented); + private: class Private; Private * const d; -- cgit v1.2.3