summaryrefslogtreecommitdiffstats
path: root/src/trace.cpp
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2013-07-05 19:06:59 +0200
committerSlávek Banko <slavek.banko@axis.cz>2013-07-05 19:06:59 +0200
commit14286a0eb6ec163c90e3d13c27fea147dbb82481 (patch)
treea5d70bd732b00ec833525dc1d25abc80f2d49144 /src/trace.cpp
downloadtdedocker-14286a0eb6ec163c90e3d13c27fea147dbb82481.tar.gz
tdedocker-14286a0eb6ec163c90e3d13c27fea147dbb82481.zip
Initial import
Diffstat (limited to 'src/trace.cpp')
-rw-r--r--src/trace.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/trace.cpp b/src/trace.cpp
new file mode 100644
index 0000000..c41247e
--- /dev/null
+++ b/src/trace.cpp
@@ -0,0 +1,44 @@
+#ifdef ENABLE_TRACING
+#include <qapplication.h>
+#include <qtextedit.h>
+#include <qfile.h>
+#include <stdio.h>
+
+static QTextEdit *tracer = NULL;
+
+void TRACER(QtMsgType, const char *msg)
+{
+ tracer->append(&msg[*msg == '~' ? 1 : 0]);
+ if (msg[0] != '~')
+ {
+ fprintf(stderr, msg);
+ fprintf(stderr, "\r\n");
+ }
+}
+
+void INIT_TRACE()
+{
+ if (tracer) return; // de javu
+ tracer = new QTextEdit();
+ tracer->setTextFormat(Qt::LogText);
+ tracer->setMaxLogLines(10000);
+ tracer->resize(750, 300);
+ qInstallMsgHandler(TRACER);
+}
+
+void SHOW_TRACE()
+{
+ tracer->show();
+}
+
+void DUMP_TRACE(const char *f)
+{
+ QFile file(f); // Write the text to a file
+ if (file.open(IO_WriteOnly))
+ {
+ QTextStream stream(&file);
+ stream << tracer->text();
+ }
+}
+
+#endif // ENABLE_TRACER