diff options
Diffstat (limited to 'akonadi2_cli')
-rw-r--r-- | akonadi2_cli/state.cpp | 49 | ||||
-rw-r--r-- | akonadi2_cli/state.h | 13 |
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 | ||
26 | class State::Private | ||
27 | { | ||
28 | public: | ||
29 | Private() | ||
30 | : outStream(stdout) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | int debugLevel = 0; | ||
35 | QEventLoop eventLoop; | ||
36 | QTextStream outStream; | ||
37 | }; | ||
38 | |||
25 | State::State() | 39 | State::State() |
26 | : m_outStream(stdout) | 40 | : d(new Private) |
27 | { | 41 | { |
28 | } | 42 | } |
29 | 43 | ||
30 | void State::print(const QString &message, unsigned int indentationLevel) | 44 | void 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 | ||
39 | void State::printLine(const QString &message, unsigned int indentationLevel) | 53 | void 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 | ||
46 | void State::printError(const QString &errorMessage, const QString &errorCode) | 60 | void 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) | |||
51 | void State::setDebugLevel(unsigned int level) | 65 | void 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 | ||
58 | unsigned int State::debugLevel() const | 72 | unsigned int State::debugLevel() const |
59 | { | 73 | { |
60 | return m_debugLevel; | 74 | return d->debugLevel; |
75 | } | ||
76 | |||
77 | int 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 | |||
87 | void 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 | |||
26 | public: | 26 | public: |
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 | |||
36 | private: | 39 | private: |
37 | int m_debugLevel = 0; | 40 | class Private; |
38 | QTextStream m_outStream; | 41 | Private * const d; |
39 | }; | 42 | }; |
40 | 43 | ||