summaryrefslogtreecommitdiffstats
path: root/akonadish/state.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'akonadish/state.cpp')
-rw-r--r--akonadish/state.cpp91
1 files changed, 91 insertions, 0 deletions
diff --git a/akonadish/state.cpp b/akonadish/state.cpp
new file mode 100644
index 0000000..84bce13
--- /dev/null
+++ b/akonadish/state.cpp
@@ -0,0 +1,91 @@
1/*
2 * Copyright (C) 2014 Aaron Seigo <aseigo@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include "state.h"
21
22#include <QDebug>
23#include <QEventLoop>
24#include <QTextStream>
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
39State::State()
40 : d(new Private)
41{
42}
43
44void State::print(const QString &message, unsigned int indentationLevel) const
45{
46 for (unsigned int i = 0; i < indentationLevel; ++i) {
47 d->outStream << "\t";
48 }
49
50 d->outStream << message;
51}
52
53void State::printLine(const QString &message, unsigned int indentationLevel) const
54{
55 print(message, indentationLevel);
56 d->outStream << "\n";
57 d->outStream.flush();
58}
59
60void State::printError(const QString &errorMessage, const QString &errorCode) const
61{
62 printLine("ERROR" + (errorCode.isEmpty() ? "" : " " + errorCode) + ": " + errorMessage);
63}
64
65void State::setDebugLevel(unsigned int level)
66{
67 if (level < 7) {
68 d->debugLevel = level;
69 }
70}
71
72unsigned int State::debugLevel() const
73{
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);
90}
91