From 109fa78cd929b134e8fa826ec5c64b09dc88c3b7 Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Wed, 23 Dec 2015 20:22:15 +0100 Subject: get around const'ness with a dptr and introduce an event loop --- akonadi2_cli/state.cpp | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'akonadi2_cli/state.cpp') diff --git a/akonadi2_cli/state.cpp b/akonadi2_cli/state.cpp index 08934a8..257da6b 100644 --- a/akonadi2_cli/state.cpp +++ b/akonadi2_cli/state.cpp @@ -20,30 +20,44 @@ #include "state.h" #include +#include #include +class State::Private +{ +public: + Private() + : outStream(stdout) + { + } + + int debugLevel = 0; + QEventLoop eventLoop; + QTextStream outStream; +}; + State::State() - : m_outStream(stdout) + : d(new Private) { } -void State::print(const QString &message, unsigned int indentationLevel) +void State::print(const QString &message, unsigned int indentationLevel) const { for (unsigned int i = 0; i < indentationLevel; ++i) { - m_outStream << "\t"; + d->outStream << "\t"; } - m_outStream << message; + d->outStream << message; } -void State::printLine(const QString &message, unsigned int indentationLevel) +void State::printLine(const QString &message, unsigned int indentationLevel) const { print(message, indentationLevel); - m_outStream << "\n"; - m_outStream.flush(); + d->outStream << "\n"; + d->outStream.flush(); } -void State::printError(const QString &errorMessage, const QString &errorCode) +void State::printError(const QString &errorMessage, const QString &errorCode) const { printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage); } @@ -51,12 +65,27 @@ void State::printError(const QString &errorMessage, const QString &errorCode) void State::setDebugLevel(unsigned int level) { if (level < 7) { - m_debugLevel = level; + d->debugLevel = level; } } unsigned int State::debugLevel() const { - return m_debugLevel; + return d->debugLevel; +} + +int State::commandStarted() const +{ + if (!d->eventLoop.isRunning()) { + qDebug() << "RUNNING THE EVENT LOOP!"; + return d->eventLoop.exec(); + } + + return 0; +} + +void State::commandFinished(int returnCode) const +{ + d->eventLoop.exit(returnCode); } -- cgit v1.2.3