[tor-commits] [vidalia/alpha] Creates a simple debug output dialog

chiiph at torproject.org chiiph at torproject.org
Sat Jul 2 21:53:47 UTC 2011


commit 1f6d58a5568782e79fdbb17a6c73a20f1ea91075
Author: Tomas Touceda <chiiph at gentoo.org>
Date:   Thu Jun 2 00:23:20 2011 -0300

    Creates a simple debug output dialog
    
    Every problem, whether exception or syntax problem, will be displayed in here.
---
 src/vidalia/CMakeLists.txt          |    3 +++
 src/vidalia/MainWindow.cpp          |   13 +++++++++++++
 src/vidalia/MainWindow.h            |    4 ++++
 src/vidalia/plugin/DebugDialog.cpp  |   28 ++++++++++++++++++++++++++++
 src/vidalia/plugin/DebugDialog.h    |   26 ++++++++++++++++++++++++++
 src/vidalia/plugin/DebugDialog.ui   |   30 ++++++++++++++++++++++++++++++
 src/vidalia/plugin/PluginEngine.cpp |    3 ++-
 7 files changed, 106 insertions(+), 1 deletions(-)

diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 4cbe458..7dac60e 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -86,11 +86,13 @@ qt4_wrap_cpp(vidalia_SRCS
 set(vidalia_SRCS ${vidalia_SRCS}
   plugin/PluginEngine.cpp
   plugin/PluginWrapper.cpp
+  plugin/DebugDialog.cpp
   plugin/prototypes/VidaliaTabPrototype.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
   plugin/PluginEngine.h
   plugin/PluginWrapper.h
+  plugin/DebugDialog.h
   plugin/prototypes/VidaliaTabPrototype.h
 )
 
@@ -216,6 +218,7 @@ qt4_wrap_ui(vidalia_SRCS
   help/browser/HelpBrowser.ui
   network/NetViewer.ui
   network/RouterInfoDialog.ui
+  plugin/DebugDialog.ui
 )
 
 ## Add the resource files (icons, etc.)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index bd72346..bcc3538 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -38,6 +38,7 @@
 #include "procutil.h"
 
 #include "PluginWrapper.h"
+#include "DebugDialog.h"
 
 #include <QtGui>
 
@@ -153,6 +154,7 @@ MainWindow::createActions()
   _actionAbout = new QAction(QIcon(IMG_ABOUT), tr("About"), this);
   _actionStartStopTor = new QAction(QIcon(IMG_START_TOR_16), tr("Start Tor"), this);
   _actionExit = new QAction(QIcon(IMG_EXIT), tr("Exit"), this);
+  _actionDebugDialog = new QAction(tr("Debug output"), this);
 }
 
 /** Creates the menu bar */
@@ -184,6 +186,8 @@ MainWindow::createMenuBar()
   foreach(QAction *action, _engine->getAllActions()) {
     pluginsMenu->addAction(action);
   }
+  pluginsMenu->addSeparator();
+  pluginsMenu->addAction(_actionDebugDialog);
 
   QMenu *helpMenu = menu->addMenu(tr("Help"));
   helpMenu->addAction(_actionVidaliaHelp);
@@ -334,6 +338,8 @@ MainWindow::createConnections()
   connect(_actionStatus, SIGNAL(triggered()), this, SLOT(showStatusTab()));
   connect(_actionNetworkMap, SIGNAL(triggered()), this, SLOT(showNetViewerTab()));
 
+  connect(_actionDebugDialog, SIGNAL(triggered()), this, SLOT(showDebugDialog()));
+
   /* Catch signals when the application is running or shutting down */
   connect(vApp, SIGNAL(running()), this, SLOT(running()));
   connect(vApp, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
@@ -1644,6 +1650,13 @@ MainWindow::showNetViewerTab()
   addTab(&_netViewer);
 }
 
+void
+MainWindow::showDebugDialog()
+{
+  DebugDialog dlg;
+  dlg.exec();
+}
+
 #if defined(USE_MINIUPNPC)
 /** Called when a UPnP error occurs. */
 void
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 8172f71..21ab1a2 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -138,6 +138,9 @@ private slots:
   void showHelpDialog();
   /** Called when a child window requests the given help <b>topic</b>. */
   void showHelpDialog(const QString &topic);
+
+  /** Displays the debug output dialog for plugins */
+  void showDebugDialog();
   
   /** Adds a new tab to the MainWindow */
   void addTab(VidaliaTab *tab);
@@ -301,6 +304,7 @@ private:
   QAction *_actionVidaliaHelp;
   QAction *_actionAbout;
   QAction *_actionExit;
+  QAction *_actionDebugDialog;
 
   Ui::MainWindow ui; /**< Qt Designer generated object. */
 
diff --git a/src/vidalia/plugin/DebugDialog.cpp b/src/vidalia/plugin/DebugDialog.cpp
new file mode 100644
index 0000000..b05fbe0
--- /dev/null
+++ b/src/vidalia/plugin/DebugDialog.cpp
@@ -0,0 +1,28 @@
+#include "DebugDialog.h"
+
+QStringList DebugDialog::buffer;
+
+DebugDialog::DebugDialog(QWidget *parent)
+  : QDialog(parent)
+{
+  ui.setupUi(this);
+
+  foreach(QString line, buffer)
+    ui.textEdit->setPlainText(QString("%1\n%2")
+        .arg(ui.textEdit->toPlainText())
+        .arg(line));
+}
+
+DebugDialog::~DebugDialog() {}
+
+void
+DebugDialog::pDebug(const QString &msg)
+{
+  buffer << msg;
+}
+
+void
+DebugDialog::clear()
+{
+  buffer.clear();
+}
diff --git a/src/vidalia/plugin/DebugDialog.h b/src/vidalia/plugin/DebugDialog.h
new file mode 100644
index 0000000..ec69c3e
--- /dev/null
+++ b/src/vidalia/plugin/DebugDialog.h
@@ -0,0 +1,26 @@
+#ifndef DEBUGDIALOG_H
+#define DEBUGDIALOG_H
+
+#include <QtGui>
+
+#include "ui_DebugDialog.h"
+
+class DebugDialog : public QDialog
+{
+  Q_OBJECT
+
+  public:
+    DebugDialog(QWidget *parent = 0);
+    ~DebugDialog();
+
+    static void pDebug(const QString &msg);
+    static void clear();
+
+  private:
+    static QStringList buffer;
+
+    Ui::DebugDialog ui;
+};
+
+#endif
+
diff --git a/src/vidalia/plugin/DebugDialog.ui b/src/vidalia/plugin/DebugDialog.ui
new file mode 100644
index 0000000..1ad0d2f
--- /dev/null
+++ b/src/vidalia/plugin/DebugDialog.ui
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>DebugDialog</class>
+ <widget class="QDialog" name="DebugDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>491</width>
+    <height>254</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Plugin debug output</string>
+  </property>
+  <property name="windowIcon">
+   <iconset resource="../res/vidalia.qrc">
+    <normaloff>:/images/16x16/applications-system.png</normaloff>:/images/16x16/applications-system.png</iconset>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="1" rowspan="2">
+    <widget class="QTextEdit" name="textEdit"/>
+   </item>
+  </layout>
+ </widget>
+ <resources>
+  <include location="../res/vidalia.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index c7b74ea..bad9c65 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -1,6 +1,7 @@
 #include "PluginEngine.h"
 #include "VidaliaSettings.h"
 #include "PluginWrapper.h"
+#include "DebugDialog.h"
 
 PluginEngine::PluginEngine(QObject *parent)
   : QScriptEngine(parent)
@@ -20,7 +21,7 @@ PluginEngine::~PluginEngine()
 void
 PluginEngine::loadAllPlugins()
 {
-  qWarning() << "loadAllPlugins()";
+  DebugDialog::pDebug("loadAllPlugins()");
 
   VidaliaSettings settings;
   QDir path = QDir(settings.pluginPath());





More information about the tor-commits mailing list