[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [akonadi-next/feature/new_cli] akonadi2_cli: get around const'ness with a dptr and introduce an even
From: Aaron Seigo <aseigo () kde ! org>
Date: 2015-12-23 19:28:37
Message-ID: E1aBp5R-0002QW-4Q () scm ! kde ! org
[Download RAW message or body]
Git commit 109fa78cd929b134e8fa826ec5c64b09dc88c3b7 by Aaron Seigo.
Committed on 23/12/2015 at 19:22.
Pushed by aseigo into branch 'feature/new_cli'.
get around const'ness with a dptr and introduce an event loop
M +39 -10 akonadi2_cli/state.cpp
M +8 -5 akonadi2_cli/state.h
http://commits.kde.org/akonadi-next/109fa78cd929b134e8fa826ec5c64b09dc88c3b7
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 <QDebug>
+#include <QEventLoop>
#include <QTextStream>
+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);
}
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
public:
State();
- void print(const QString &message, unsigned int indentationLevel = 0);
- void printLine(const QString &message = QString(), unsigned int indentationLevel = 0);
- void printError(const QString &errorMessage, const QString &errorCode = QString());
+ void print(const QString &message, unsigned int indentationLevel = 0) const;
+ void printLine(const QString &message = QString(), unsigned int indentationLevel = 0) const;
+ void printError(const QString &errorMessage, const QString &errorCode = QString()) const;
void setDebugLevel(unsigned int level);
unsigned int debugLevel() const;
+ int commandStarted() const;
+ void commandFinished(int returnCode = 0) const;
+
private:
- int m_debugLevel = 0;
- QTextStream m_outStream;
+ class Private;
+ Private * const d;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic