]> Some of my projects - localmylist.git/commitdiff
Add simple client log tab.
authorAPTX <marek321@gmail.com>
Tue, 4 Jun 2013 17:50:07 +0000 (19:50 +0200)
committerAPTX <marek321@gmail.com>
Tue, 4 Jun 2013 17:50:07 +0000 (19:50 +0200)
Displays whatever gets printed to (usually) stderr starting from the time the tab was opened.

localmylist-management/localmylist-management.pro
localmylist-management/registertabs.cpp
localmylist-management/tabs/clientlogtab.cpp [new file with mode: 0644]
localmylist-management/tabs/clientlogtab.h [new file with mode: 0644]
localmylist-management/tabs/clientlogtab.ui [new file with mode: 0644]
localmylist/messagehandler.cpp
localmylist/mylist.h

index 6801dbc7b576333f27ef0cd3a356ffe03f106c20..d4b045d8e11f147f691a546b718a417177bcb3f1 100644 (file)
@@ -26,7 +26,8 @@ SOURCES += main.cpp\
        tabs/unknownfilestab.cpp \
        tabs/pendingrequesttab.cpp \
        registertabs.cpp \
-       tabs/databaselogtab.cpp
+       tabs/databaselogtab.cpp \
+       tabs/clientlogtab.cpp
 
 HEADERS += mainwindow.h \
        databaseconnectiondialog.h \
@@ -43,7 +44,8 @@ HEADERS += mainwindow.h \
        tabs/reportstab.h \
        tabs/unknownfilestab.h \
        tabs/pendingrequesttab.h \
-       tabs/databaselogtab.h
+       tabs/databaselogtab.h \
+       tabs/clientlogtab.h
 
 FORMS += mainwindow.ui \
        databaseconnectiondialog.ui \
@@ -52,7 +54,8 @@ FORMS += mainwindow.ui \
        tabs/reportstab.ui \
        tabs/unknownfilestab.ui \
        tabs/pendingrequesttab.ui \
-       tabs/databaselogtab.ui
+       tabs/databaselogtab.ui \
+       tabs/clientlogtab.ui
 
 include(../localmylist.pri)
 include(qtsingleapplication/qtsingleapplication.pri)
index bae47ec6b7c7587f637b82b17332746d6ec9ccf8..8e0ea67fddb7440da06e5d80e2e3b667833eebcd 100644 (file)
@@ -5,6 +5,7 @@
 #include "tabs/unknownfilestab.h"
 #include "tabs/pendingrequesttab.h"
 #include "tabs/databaselogtab.h"
+#include "tabs/clientlogtab.h"
 
 void registerTabs()
 {
@@ -14,4 +15,5 @@ void registerTabs()
        TabWidget::registerTab<UnknownFilesTab>();
        TabWidget::registerTab<PendingRequestTab>();
        TabWidget::registerTab<DatabaseLogTab>();
+       TabWidget::registerTab<ClientLogTab>();
 }
diff --git a/localmylist-management/tabs/clientlogtab.cpp b/localmylist-management/tabs/clientlogtab.cpp
new file mode 100644 (file)
index 0000000..71ccb51
--- /dev/null
@@ -0,0 +1,43 @@
+#include "clientlogtab.h"
+#include "ui_clientlogtab.h"
+
+#include <QDateTime>
+
+#include "mylist.h"
+
+ClientLogTab::ClientLogTab(QWidget *parent) :
+       AbstractTabBase(parent),
+       ui(new Ui::ClientLogTab)
+{
+       ui->setupUi(this);
+       setLabel(name());
+}
+
+ClientLogTab::~ClientLogTab()
+{
+       delete ui;
+}
+
+QString ClientLogTab::staticId()
+{
+       return "client_log";
+}
+
+QString ClientLogTab::name()
+{
+       return tr("Client Log");
+}
+
+void ClientLogTab::init()
+{
+       connect(LocalMyList::instance(), SIGNAL(debugMessage(QString)), this, SLOT(appendMessage(QString)));
+       QString message = tr("Logging started at %1.").arg(
+                               QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"));
+       ui->textBox->appendPlainText(message);
+}
+
+
+void ClientLogTab::appendMessage(const QString &message)
+{
+       ui->textBox->appendPlainText(message);
+}
diff --git a/localmylist-management/tabs/clientlogtab.h b/localmylist-management/tabs/clientlogtab.h
new file mode 100644 (file)
index 0000000..65be1ed
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef CLIENTLOGTAB_H
+#define CLIENTLOGTAB_H
+
+#include "abstracttab.h"
+
+#include <QString>
+
+namespace Ui {
+class ClientLogTab;
+}
+
+class ClientLogTab : public AbstractTabBase<ClientLogTab>
+{
+       Q_OBJECT
+
+public:
+       explicit ClientLogTab(QWidget *parent = 0);
+       ~ClientLogTab();
+
+       static QString staticId();
+       static QString name();
+
+       void init();
+
+public slots:
+       void appendMessage(const QString &message);
+
+private:
+       Ui::ClientLogTab *ui;
+};
+
+#endif // CLIENTLOGTAB_H
diff --git a/localmylist-management/tabs/clientlogtab.ui b/localmylist-management/tabs/clientlogtab.ui
new file mode 100644 (file)
index 0000000..8542d67
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ClientLogTab</class>
+ <widget class="QWidget" name="ClientLogTab">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>559</width>
+    <height>382</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="leftMargin">
+    <number>0</number>
+   </property>
+   <property name="rightMargin">
+    <number>0</number>
+   </property>
+   <item>
+    <widget class="QPlainTextEdit" name="textBox">
+     <property name="readOnly">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
index cffdcbd6ce56e2a75004196d9c87a00bc16170e0..874d4e91b0dd5b0db32ca8cc12c30baa2804c852 100644 (file)
@@ -5,6 +5,8 @@
 #include <QByteArray>
 #include <QDateTime>
 
+#include "mylist.h"
+
 namespace LocalMyList {
 
 /*
@@ -29,6 +31,11 @@ const char *messageType2Str(QtMsgType type)
        }
 }
 
+auto debugMessageSignal = [](const QString &message)
+{
+       emit MyList::instance()->debugMessage(message);
+};
+
 /*
  * messageHandler will try to format the debug message
  * and use Qt's default handlerto print it.
@@ -64,6 +71,8 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
                                ctx);
 
        qtMessageHandler(type, context, message);
+
+       debugMessageSignal(message);
 }
 #else
 void messageHandler(QtMsgType type, const char *msg)
@@ -81,6 +90,8 @@ void messageHandler(QtMsgType type, const char *msg)
        // actually printing the message.
        qt_message_output(type, buf.constData());
        qInstallMsgHandler(messageHandler);
+
+       debugMessageSignal(message);
 }
 #endif
 
index 31107d45b5d8b3d9b406ba739e6355622943b2b1..bf7a417293342cdfb6f11d03832cd267c3213e08 100644 (file)
@@ -87,6 +87,7 @@ private slots:
 signals:
        void taskCountChanged();
        void allTasksFinished();
+       void debugMessage(const QString &message);
 
 private:
        DatabaseConnectionSettings dbs;