Add log widget to lower dock
authorChristoph Egger <Christoph.Egger@fau.de>
Wed, 11 Mar 2015 15:47:05 +0000 (16:47 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Wed, 11 Mar 2015 15:47:05 +0000 (16:47 +0100)
Make the lower dock container agnostic the former ScriptingDock now is
just taking care of the content inside one of the tabs and the FridaDock
is managing the Dock and TabWidget stuff.

Add a Logging Tab that outputs messages from the logging system for
inspection. Could well be improved (T12 T13 T14).

Closes T11

src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx
src/gui/widgets/FridaDock.cxx [new file with mode: 0644]
src/gui/widgets/FridaDock.hxx [new file with mode: 0644]
src/gui/widgets/LogDock.cxx [new file with mode: 0644]
src/gui/widgets/LogDock.hxx [new file with mode: 0644]
src/gui/widgets/LogDockAppender.cxx [new file with mode: 0644]
src/gui/widgets/LogDockAppender.hxx [new file with mode: 0644]
src/gui/widgets/ScriptingDock.cxx
src/gui/widgets/ScriptingDock.hxx

index 2036c486b705bb872ba51e037deeb3bb1cfb649b..269f3e7359d7c82b89e613c011d6f614097cee0a 100644 (file)
@@ -6,6 +6,9 @@
 #include "core/BasicBlock.hxx"
 #include "core/InformationManager.hxx"
 #include "core/events/RenameFunctionEvent.hxx"
+
+#include "widgets/FridaDock.hxx"
+#include "widgets/LogDock.hxx"
 #include "widgets/ScriptingDock.hxx"
 #include "widgets/CFGScene.hxx"
 #include "widgets/FunctionWidget.hxx"
@@ -44,9 +47,13 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        if (!loader->load())
                LOG4CXX_ERROR(logger, "Loading plugin failed: " << loader->errorString().toStdString());
        interpreter["GUILE"] = qobject_cast<Interpreter*>(loader->instance());
-       scripting = new ScriptingDock(interpreter["GUILE"], tr("Scripting"), this);
-       scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
-       addDockWidget(Qt::BottomDockWidgetArea, scripting);
+       fdock = new FridaDock(tr("Frida Dock"), this);
+
+       fdock->addTab(new LogDock(fdock), "Log");
+
+       fdock->addTab(new ScriptingDock(interpreter["GUILE"], fdock), "guile");
+       fdock->setAllowedAreas(Qt::BottomDockWidgetArea);
+       addDockWidget(Qt::BottomDockWidgetArea, fdock);
        QAction* guileLoad = new QAction(tr("&GUILE"), this);
        interpretermenu->addAction(guileLoad);
        connect(guileLoad, &QAction::triggered,
index 8b46404b3a8331330177795188dbfb3205fb74b3..cfdbaaa152e21ccb124d261e477db4604c30c70c 100644 (file)
@@ -19,7 +19,7 @@ class Function;
 class InformationManager;
 class FunctionWidget;
 class BasicBlockWidget;
-class ScriptingDock;
+class FridaDock;
 class Interpreter;
 
 class Mainwindow : public QMainWindow {
@@ -43,7 +43,7 @@ private:
        QTreeWidget * listWidget;
        QStackedWidget * stackedWidget;
        QDockWidget * dockWidget;
-       ScriptingDock * scripting;
+       FridaDock * fdock;
 
        QAction *exitAction;
        QAction *openAction;
diff --git a/src/gui/widgets/FridaDock.cxx b/src/gui/widgets/FridaDock.cxx
new file mode 100644 (file)
index 0000000..eef1c87
--- /dev/null
@@ -0,0 +1,12 @@
+#include "FridaDock.hxx"
+
+FridaDock::FridaDock(const QString& title, QWidget * parent)
+       : QDockWidget(title, parent)
+       , tabWidget(new QTabWidget) {
+
+       setWidget(tabWidget);
+}
+
+void FridaDock::addTab(QWidget* widget, const QString& name) {
+       tabWidget->addTab(widget, name);
+}
diff --git a/src/gui/widgets/FridaDock.hxx b/src/gui/widgets/FridaDock.hxx
new file mode 100644 (file)
index 0000000..4f81e85
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef INCLUDE__FridaDock_hxx_
+#define INCLUDE__FridaDock_hxx_
+
+#include "gui/qt.hxx"
+
+class FridaDock : public QDockWidget {
+       Q_OBJECT
+public:
+       FridaDock(const QString& title, QWidget * parent = 0);
+
+       void addTab(QWidget* widget, const QString& name);
+
+private:
+       QTabWidget* tabWidget;
+};
+
+#endif /* INCLUDE__FridaDock_hxx_ */
diff --git a/src/gui/widgets/LogDock.cxx b/src/gui/widgets/LogDock.cxx
new file mode 100644 (file)
index 0000000..b8b9214
--- /dev/null
@@ -0,0 +1,20 @@
+#include "LogDock.hxx"
+#include "FridaDock.hxx"
+#include "LogDockAppender.hxx"
+
+#include "log4cxx/basicconfigurator.h"
+
+LogDock::LogDock(FridaDock* parent)
+       : QTableWidget(0, 3, parent) {
+       verticalHeader()->hide();
+       horizontalHeader()->hide();
+       horizontalHeader()->setStretchLastSection(true);
+       verticalHeader()->setDefaultSectionSize(18);
+       appender = new LogDockAppender;
+       appender->setTarget(this);
+       log4cxx::BasicConfigurator::configure(appender);
+}
+
+LogDock::~LogDock() {
+       delete appender;
+}
diff --git a/src/gui/widgets/LogDock.hxx b/src/gui/widgets/LogDock.hxx
new file mode 100644 (file)
index 0000000..bda8203
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef INCLUDE__LogDock_hxx_
+#define INCLUDE__LogDock_hxx_
+
+#include "gui/qt.hxx"
+#include <log4cxx/appenderskeleton.h>
+
+class FridaDock;
+class LogDockAppender;
+
+class LogDock : public QTableWidget {
+       Q_OBJECT
+public:
+       LogDock(FridaDock* parent);
+       virtual ~LogDock();
+       log4cxx::Appender* getAppender();
+private:
+       LogDockAppender* appender;
+       friend class LogDockAppender;
+};
+
+#endif /* INCLUDE__LogDock_hxx_ */
diff --git a/src/gui/widgets/LogDockAppender.cxx b/src/gui/widgets/LogDockAppender.cxx
new file mode 100644 (file)
index 0000000..f6419c2
--- /dev/null
@@ -0,0 +1,52 @@
+#include "LogDockAppender.hxx"
+#include "LogDock.hxx"
+
+#include <log4cxx/patternlayout.h>
+
+using namespace log4cxx::helpers;
+
+IMPLEMENT_LOG4CXX_OBJECT(LogDockAppender)
+
+LogDockAppender::LogDockAppender()
+: timeformat("%T") {
+       layout = new PatternLayout("%d{MMM dd yyyy HH:mm:ss,SSS} - %m %n");
+}
+
+void LogDockAppender::append(const spi::LoggingEventPtr& event, Pool& p) {
+       log4cxx::LogString message, timestamp;
+
+       if ( this->layout == NULL ) {
+             LOG4CXX_ENCODE_CHAR(nameStr, name);
+             std::string msg("No Layout set for the appender named [ ");
+             msg.append(nameStr);
+             msg.append(" ].");
+
+             LOG4CXX_DECODE_CHAR(msgL, msg);
+             errorHandler->error(msgL);
+           return;
+       }
+
+       layout->format(message, event, p);
+       timeformat.format(timestamp, event->getTimeStamp(), p);
+       LOG4CXX_ENCODE_CHAR(messageencode, message);
+       LOG4CXX_ENCODE_CHAR(timestampencode, timestamp);
+
+       int rowcount = target->rowCount();
+       target->insertRow(rowcount);
+       target->setItem(rowcount, 0, new QTableWidgetItem(timestampencode.c_str()));
+       target->setItem(rowcount, 1, new QTableWidgetItem(event->getLevel()->toString().c_str()));
+       target->setItem(rowcount, 2, new QTableWidgetItem(messageencode.c_str()));
+       target->resizeColumnsToContents();
+}
+
+void LogDockAppender::setTarget(LogDock *target) {
+       this->target = target;
+}
+
+void LogDockAppender::close() {
+
+}
+
+bool LogDockAppender::requiresLayout() const {
+       return true;
+}
diff --git a/src/gui/widgets/LogDockAppender.hxx b/src/gui/widgets/LogDockAppender.hxx
new file mode 100644 (file)
index 0000000..bfe702f
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef INCLUDE__LogDockAppender_hxx_
+#define INCLUDE__LogDockAppender_hxx_
+
+#include <log4cxx/appenderskeleton.h>
+#include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/helpers/strftimedateformat.h>
+
+class LogDock;
+
+using namespace log4cxx;
+
+class LogDockAppender : public AppenderSkeleton {
+public:
+       LogDockAppender();
+
+       void setTarget(LogDock* target);
+       void append(const spi::LoggingEventPtr& event, helpers::Pool& p);
+       void close();
+       bool requiresLayout() const;
+
+       DECLARE_LOG4CXX_OBJECT(LogDockAppender)
+       BEGIN_LOG4CXX_CAST_MAP()
+       LOG4CXX_CAST_ENTRY(LogDockAppender)
+       LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
+       END_LOG4CXX_CAST_MAP()
+private:
+       LogDock* target;
+       helpers::StrftimeDateFormat timeformat;
+};
+
+LOG4CXX_PTR_DEF(LogDockAppender);
+
+#endif /* INCLUDE__LogDockAppender_hxx_ */
index b334d712a1f20f552b6dab689fa57bc26e457c08..8e5f3cf38f4a44a0f60d00dfae0c6e743a8c9fbc 100644 (file)
@@ -1,20 +1,18 @@
 #include "ScriptingDock.hxx"
+#include "FridaDock.hxx"
+
 #include "bindings/Interpreter.hxx"
 
 #include <sstream>
 
-ScriptingDock::ScriptingDock(Interpreter* interpreter, const QString& title, QWidget * parent)
-       : QDockWidget(title, parent)
+ScriptingDock::ScriptingDock(Interpreter* interpreter, FridaDock* parent)
+       : QWidget(parent)
        , logger(log4cxx::Logger::getLogger("ScriptingDock"))
        , interpreter(interpreter) {
-       QTabWidget * tab = new QTabWidget;
-       QWidget * widget = new QWidget;
-       widget->setLayout(layout = new QGridLayout);
+       setLayout(layout = new QGridLayout);
        layout->addWidget(browser = new QTextBrowser, 0, 0, 1, 0);
        layout->addWidget(line = new QLineEdit, 1, 0);
        layout->addWidget(button = new QPushButton(tr("Evaluate")), 1, 1);
-       tab->addTab(widget, "GUILE");
-       ((QDockWidget*)this)->setWidget(tab);
        connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
        connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
 }
index a49dc3eaeadf6a8e061bc78b36c7917d024c6c99..094e52011ecf9f8dacaec7a3b932223bc0b80409 100644 (file)
@@ -5,11 +5,12 @@
 #include <log4cxx/logger.h>
 
 class Interpreter;
+class FridaDock;
 
-class ScriptingDock : public QDockWidget {
+class ScriptingDock : public QWidget {
        Q_OBJECT
 public:
-       ScriptingDock(Interpreter* interpreter, const QString& title, QWidget * parent = 0);
+       ScriptingDock(Interpreter* interpreter, FridaDock* parent);
 
 private:
        log4cxx::LoggerPtr logger;