summaryrefslogtreecommitdiffstats
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
parent25a17e16901590a9400deef9e2feb5423df84b59 (diff)
downloadsink-109fa78cd929b134e8fa826ec5c64b09dc88c3b7.tar.gz
sink-109fa78cd929b134e8fa826ec5c64b09dc88c3b7.zip
get around const'ness with a dptr and introduce an event loop
-rw-r--r--akonadi2_cli/state.cpp49
-rw-r--r--akonadi2_cli/state.h13
2 files changed, 47 insertions, 15 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
diff --git a/akonadi2_cli/state.h b/akonadi2_cli/state.h
index 2f13166..eb07f56 100644
--- a/akonadi2_cli/state.h
+++ b/akonadi2_cli/state.h
@@ -26,15 +26,18 @@ class State
26public: 26public:
27 State(); 27 State();
28 28
29 void print(const QString &message, unsigned int indentationLevel = 0); 29 void print(const QString &message, unsigned int indentationLevel = 0) const;
30 void printLine(const QString &message = QString(), unsigned int indentationLevel = 0); 30 void printLine(const QString &message = QString(), unsigned int indentationLevel = 0) const;
31 void printError(const QString &errorMessage, const QString &errorCode = QString()); 31 void printError(const QString &errorMessage, const QString &errorCode = QString()) const;
32 32
33 void setDebugLevel(unsigned int level); 33 void setDebugLevel(unsigned int level);
34 unsigned int debugLevel() const; 34 unsigned int debugLevel() const;
35 35
36 int commandStarted() const;
37 void commandFinished(int returnCode = 0) const;
38
36private: 39private:
37 int m_debugLevel = 0; 40 class Private;
38 QTextStream m_outStream; 41 Private * const d;
39}; 42};
40 43