]> git.siccegge.de Git - frida/frida.git/commitdiff
Make LogDock and LogDockAppender communicate by signals
authorChristoph Egger <christoph@christoph-egger.org>
Tue, 2 Jun 2015 21:11:18 +0000 (23:11 +0200)
committerChristoph Egger <christoph@christoph-egger.org>
Tue, 2 Jun 2015 21:11:18 +0000 (23:11 +0200)
This way the Appender can work in a different thread from the gui dock
without causing problems. Also we no longer need to make the Appender
a friend of the gui dock and instead make the dock handle it's own
affairs

src/gui/widgets/LogDock.cxx
src/gui/widgets/LogDock.hxx
src/gui/widgets/LogDockAppender.cxx
src/gui/widgets/LogDockAppender.hxx

index b8b92147ccb19158cc4bd6f4ba00654bcd989d8e..b4efc1d4d5ae6726f4bfe91d8061189def6046bd 100644 (file)
@@ -11,10 +11,31 @@ LogDock::LogDock(FridaDock* parent)
        horizontalHeader()->setStretchLastSection(true);
        verticalHeader()->setDefaultSectionSize(18);
        appender = new LogDockAppender;
-       appender->setTarget(this);
+       connect(appender, &LogDockAppender::newLogEntry,
+               this, &LogDock::handleNewLogEntry);
        log4cxx::BasicConfigurator::configure(appender);
 }
 
 LogDock::~LogDock() {
        delete appender;
 }
+
+void LogDock::handleNewLogEntry(QColor color, QString timestamp, QString level, QString message) {
+       int rowcount = rowCount();
+       insertRow(rowcount);
+       setItem(rowcount, 0, new QTableWidgetItem(timestamp));
+       setItem(rowcount, 1, new QTableWidgetItem(level));
+       setItem(rowcount, 2, new QTableWidgetItem(message));
+       item(rowcount, 0)->setBackground(color);
+       item(rowcount, 1)->setBackground(color);
+       item(rowcount, 2)->setBackground(color);
+       resizeColumnsToContents();
+
+       QTimer *timer = new QTimer(this);
+       timer->setSingleShot(true);
+
+       QObject::connect(timer, &QTimer::timeout, [=]() {
+                       scrollToItem(item(rowcount, 2), QAbstractItemView::PositionAtTop);
+               });
+       timer->start(2);
+}
index e71063530c4494144e54759d6844d573ca210eff..7845764d22c948b8f4c322be896754fc13b1dfcd 100644 (file)
@@ -15,6 +15,7 @@ public:
        log4cxx::Appender* getAppender();
 private:
        LogDockAppender* appender;
+       void handleNewLogEntry(QColor color, QString timestamp, QString level, QString message);
        friend class LogDockAppender;
 };
 
index 321860afb3313126060f68399d8b41987eb1bf5f..a0db7a4140f8fe9319706e681c4bd32ebef26ef7 100644 (file)
@@ -42,28 +42,9 @@ void LogDockAppender::append(const spi::LoggingEventPtr& event, Pool& p) {
        } else if (log4cxx::Level::getTrace() == event->getLevel()) {
                rowcolor.setRgb(0xee, 0xff, 0xee);
        }
-
-       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->item(rowcount, 0)->setBackground(rowcolor);
-       target->item(rowcount, 1)->setBackground(rowcolor);
-       target->item(rowcount, 2)->setBackground(rowcolor);
-       target->resizeColumnsToContents();
-
-       QTimer *timer = new QTimer(target);
-       timer->setSingleShot(true);
-
-       QObject::connect(timer, &QTimer::timeout, [=]() {
-                       target->scrollToItem(target->item(rowcount, 2), QAbstractItemView::PositionAtTop);
-               });
-       timer->start(10);
-}
-
-void LogDockAppender::setTarget(LogDock *target) {
-       this->target = target;
+       emit newLogEntry(rowcolor, timestampencode.c_str(),
+                        event->getLevel()->toString().c_str(),
+                        messageencode.c_str());
 }
 
 void LogDockAppender::close() {
index bfe702fb282070e854b74aeca1e9949034be37fa..4acf4f473e5a4b0e77b23eb979aa66365cd603f5 100644 (file)
@@ -4,16 +4,19 @@
 #include <log4cxx/appenderskeleton.h>
 #include <log4cxx/spi/loggingevent.h>
 #include <log4cxx/helpers/strftimedateformat.h>
+#include <QObject>
 
 class LogDock;
 
 using namespace log4cxx;
 
-class LogDockAppender : public AppenderSkeleton {
+class LogDockAppender : public QObject, public AppenderSkeleton {
+       Q_OBJECT
+signals:
+       void newLogEntry(QColor color, QString timestamp, QString level, QString message);
 public:
        LogDockAppender();
 
-       void setTarget(LogDock* target);
        void append(const spi::LoggingEventPtr& event, helpers::Pool& p);
        void close();
        bool requiresLayout() const;
@@ -24,7 +27,6 @@ public:
        LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
        END_LOG4CXX_CAST_MAP()
 private:
-       LogDock* target;
        helpers::StrftimeDateFormat timeformat;
 };