From: Christoph Egger Date: Wed, 11 Mar 2015 15:47:05 +0000 (+0100) Subject: Add log widget to lower dock X-Git-Tag: v0.1~48 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=5514e0b76ec9af2fa67abebe77cfe26052f2326f;p=frida%2Ffrida.git Add log widget to lower dock 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 --- diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 2036c48..269f3e7 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -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(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, diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 8b46404..cfdbaaa 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -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 index 0000000..eef1c87 --- /dev/null +++ b/src/gui/widgets/FridaDock.cxx @@ -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 index 0000000..4f81e85 --- /dev/null +++ b/src/gui/widgets/FridaDock.hxx @@ -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 index 0000000..b8b9214 --- /dev/null +++ b/src/gui/widgets/LogDock.cxx @@ -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 index 0000000..bda8203 --- /dev/null +++ b/src/gui/widgets/LogDock.hxx @@ -0,0 +1,21 @@ +#ifndef INCLUDE__LogDock_hxx_ +#define INCLUDE__LogDock_hxx_ + +#include "gui/qt.hxx" +#include + +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 index 0000000..f6419c2 --- /dev/null +++ b/src/gui/widgets/LogDockAppender.cxx @@ -0,0 +1,52 @@ +#include "LogDockAppender.hxx" +#include "LogDock.hxx" + +#include + +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 index 0000000..bfe702f --- /dev/null +++ b/src/gui/widgets/LogDockAppender.hxx @@ -0,0 +1,33 @@ +#ifndef INCLUDE__LogDockAppender_hxx_ +#define INCLUDE__LogDockAppender_hxx_ + +#include +#include +#include + +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_ */ diff --git a/src/gui/widgets/ScriptingDock.cxx b/src/gui/widgets/ScriptingDock.cxx index b334d71..8e5f3cf 100644 --- a/src/gui/widgets/ScriptingDock.cxx +++ b/src/gui/widgets/ScriptingDock.cxx @@ -1,20 +1,18 @@ #include "ScriptingDock.hxx" +#include "FridaDock.hxx" + #include "bindings/Interpreter.hxx" #include -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())); } diff --git a/src/gui/widgets/ScriptingDock.hxx b/src/gui/widgets/ScriptingDock.hxx index a49dc3e..094e520 100644 --- a/src/gui/widgets/ScriptingDock.hxx +++ b/src/gui/widgets/ScriptingDock.hxx @@ -5,11 +5,12 @@ #include 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;