aboutsummaryrefslogtreecommitdiffstats
path: root/reporthandler.cpp
diff options
context:
space:
mode:
authorHugo Lima <hugo.lima@openbossa.org>2009-11-20 14:56:35 -0200
committerHugo Lima <hugo.lima@openbossa.org>2009-11-20 14:56:35 -0200
commita7fdd58a4312b60d2bc2aeaf49216b74c4237e65 (patch)
treeff54e46b354e55079b86d0ea88850611eda1aae3 /reporthandler.cpp
parent8f8de4e763269b57c57eb4d5047139177d7fd1a8 (diff)
Export a minimal set of classes in ReportHandler interface, to speep up
compilation and avoid link errors on windows.
Diffstat (limited to 'reporthandler.cpp')
-rw-r--r--reporthandler.cpp126
1 files changed, 107 insertions, 19 deletions
diff --git a/reporthandler.cpp b/reporthandler.cpp
index 18a9a9c1..a311b53c 100644
--- a/reporthandler.cpp
+++ b/reporthandler.cpp
@@ -23,7 +23,10 @@
#include "reporthandler.h"
#include "typesystem.h"
+#include <QtCore/QSet>
#include <cstring>
+#include <cstdarg>
+#include <cstdio>
#ifndef NOCOLOR
#define COLOR_END "\033[0m"
@@ -37,16 +40,108 @@
#define COLOR_GREEN ""
#endif
+class ProgressAnimation
+{
+ public:
+ ProgressAnimation()
+ {
+ anim_data = "|/-\\";
+ anim_frame = anim_data;
+ std::strcpy(anim_string, "[ ]");
+ m_current = m_max = 0;
+ }
+ const char* toString()
+ {
+ step();
+ return anim_string;
+ }
+
+ void reset(int max)
+ {
+ m_current = 1;
+ m_max = max;
+ }
+
+ int current() const
+ {
+ return m_current;
+ }
+ int max() const
+ {
+ return m_max;
+ }
+
+ private:
+ const char* anim_data;
+ char anim_string[4];
+ const char* anim_frame;
+ int m_max;
+ int m_current;
+
+ void step()
+ {
+ if (!*(++anim_frame))
+ anim_frame = anim_data;
+ anim_string[1] = *anim_frame;
+ m_current++;
+ }
+};
+
+
+static bool m_silent = false;
+static int m_warningCount = 0;
+static int m_suppressedCount = 0;
+static QString m_context;
+static ReportHandler::DebugLevel m_debugLevel = ReportHandler::NoDebug;
+static QSet<QString> m_reportedWarnings;
+static char m_progressBuffer[1024] = {0};
+static ProgressAnimation m_anim;
+
+static void printProgress()
+{
+ std::printf("%s", m_progressBuffer);
+ std::fflush(stdout);
+}
+
+ReportHandler::DebugLevel ReportHandler::debugLevel()
+{
+ return m_debugLevel;
+}
+
+void ReportHandler::setDebugLevel(ReportHandler::DebugLevel level)
+{
+ m_debugLevel = level;
+}
+
+void ReportHandler::setContext(const QString& context)
+{
+ m_context = context;
+}
+
+int ReportHandler::suppressedCount()
+{
+ return m_suppressedCount;
+}
+
+int ReportHandler::warningCount()
+{
+ return m_warningCount;
+}
+
+void ReportHandler::setProgressReference(int max)
+{
+ m_anim.reset(max);
+}
-bool ReportHandler::m_silent = false;
-int ReportHandler::m_warningCount = 0;
-int ReportHandler::m_suppressedCount = 0;
-QString ReportHandler::m_context;
-ReportHandler::DebugLevel ReportHandler::m_debugLevel = NoDebug;
-QSet<QString> ReportHandler::m_reportedWarnings;
-char ReportHandler::m_progressBuffer[1024] = {0};
-ProgressAnimation ReportHandler::m_anim;
+bool ReportHandler::isSilent()
+{
+ return m_silent;
+}
+void ReportHandler::setSilent(bool silent)
+{
+ m_silent = silent;
+}
void ReportHandler::warning(const QString &text)
{
@@ -61,7 +156,7 @@ void ReportHandler::warning(const QString &text)
if (db && db->isSuppressedWarning(text)) {
++m_suppressedCount;
} else if (!m_reportedWarnings.contains(text)) {
- puts(qPrintable(warningText));
+ std::puts(qPrintable(warningText));
printProgress();
++m_warningCount;
@@ -74,27 +169,20 @@ void ReportHandler::progress(const QString& str, ...)
if (m_silent)
return;
QString msg = QString("\033[1K\r" COLOR_WHITE "%1 (%2/%3) " COLOR_END).arg(m_anim.toString()).arg(m_anim.current()).arg(m_anim.max()) + str;
- va_list argp;
+ std::va_list argp;
va_start(argp, str);
- vsnprintf(m_progressBuffer, sizeof(m_progressBuffer), msg.toLocal8Bit().constData(), argp);
+ std::vsnprintf(m_progressBuffer, sizeof(m_progressBuffer), msg.toLocal8Bit().constData(), argp);
va_end(argp);
printProgress();
}
-void ReportHandler::printProgress()
-{
- printf("%s", m_progressBuffer);
- fflush(stdout);
-}
-
-
void ReportHandler::debug(DebugLevel level, const QString &text)
{
if (m_debugLevel == NoDebug)
return;
if (level <= m_debugLevel) {
- printf("\r" COLOR_GREEN "DEBUG" COLOR_END " :: %-70s\n", qPrintable(text));
+ std::printf("\r" COLOR_GREEN "DEBUG" COLOR_END " :: %-70s\n", qPrintable(text));
printProgress();
}
}