summaryrefslogtreecommitdiffstats
path: root/akonadi2_cli/state.cpp
diff options
context:
space:
mode:
authorAaron Seigo <aseigo@kde.org>2015-12-23 20:22:15 +0100
committerAaron Seigo <aseigo@kde.org>2015-12-23 20:22:15 +0100
commit109fa78cd929b134e8fa826ec5c64b09dc88c3b7 (patch)
tree141a5aa76e4339807f68b6ec73295cd9b8ee0d3d /akonadi2_cli/state.cpp
parent25a17e16901590a9400deef9e2feb5423df84b59 (diff)
downloadsink-109fa78cd929b134e8fa826ec5c64b09dc88c3b7.tar.gz
sink-109fa78cd929b134e8fa826ec5c64b09dc88c3b7.zip
get around const'ness with a dptr and introduce an event loop
Diffstat (limited to 'akonadi2_cli/state.cpp')
-rw-r--r--akonadi2_cli/state.cpp49
1 files changed, 39 insertions, 10 deletions
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 @@
20#include "state.h" 20#include "state.h"
21 21
22#include <QDebug> 22#include <QDebug>
23#include <QEventLoop>
23#include <QTextStream> 24#include <QTextStream>
24 25
26class State::Private
27{
28public:
29 Private()
30 : outStream(stdout)
31 {
32 }
33
34 int debugLevel = 0;
35 QEventLoop eventLoop;
36 QTextStream outStream;
37};
38
25State::State() 39State::State()
26 : m_outStream(stdout) 40 : d(new Private)
27{ 41{
28} 42}
29 43
30void State::print(const QString &message, unsigned int indentationLevel) 44void State::print(const QString &message, unsigned int indentationLevel) const
31{ 45{
32 for (unsigned int i = 0; i < indentationLevel; ++i) { 46 for (unsigned int i = 0; i < indentationLevel; ++i) {
33 m_outStream << "\t"; 47 d->outStream << "\t";
34 } 48 }
35 49
36 m_outStream << message; 50 d->outStream << message;
37} 51}
38 52
39void State::printLine(const QString &message, unsigned int indentationLevel) 53void State::printLine(const QString &message, unsigned int indentationLevel) const
40{ 54{
41 print(message, indentationLevel); 55 print(message, indentationLevel);
42 m_outStream << "\n"; 56 d->outStream << "\n";
43 m_outStream.flush(); 57 d->outStream.flush();
44} 58}
45 59
46void State::printError(const QString &errorMessage, const QString &errorCode) 60void State::printError(const QString &errorMessage, const QString &errorCode) const
47{ 61{
48 printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage); 62 printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage);
49} 63}
@@ -51,12 +65,27 @@ void State::printError(const QString &errorMessage, const QString &errorCode)
51void State::setDebugLevel(unsigned int level) 65void State::setDebugLevel(unsigned int level)
52{ 66{
53 if (level < 7) { 67 if (level < 7) {
54 m_debugLevel = level; 68 d->debugLevel = level;
55 } 69 }
56} 70}
57 71
58unsigned int State::debugLevel() const 72unsigned int State::debugLevel() const
59{ 73{
60 return m_debugLevel; 74 return d->debugLevel;
75}
76
77int State::commandStarted() const
78{
79 if (!d->eventLoop.isRunning()) {
80 qDebug() << "RUNNING THE EVENT LOOP!";
81 return d->eventLoop.exec();
82 }
83
84 return 0;
85}
86
87void State::commandFinished(int returnCode) const
88{
89 d->eventLoop.exit(returnCode);
61} 90}
62 91