[tor-commits] [vidalia/alpha] Provide more useful output
chiiph at torproject.org
chiiph at torproject.org
Sat Jul 2 21:53:47 UTC 2011
commit db3a4f43ed310b5e1e1fe778dfe8d6cf3c405ead
Author: Tomas Touceda <chiiph at gentoo.org>
Date: Thu Jun 2 14:02:26 2011 -0300
Provide more useful output
---
src/vidalia/plugin/DebugDialog.cpp | 41 +++++++++++++---
src/vidalia/plugin/DebugDialog.h | 11 ++++-
src/vidalia/plugin/DebugDialog.ui | 38 +++++++++++++++-
src/vidalia/plugin/PluginEngine.cpp | 24 ++++++----
src/vidalia/plugin/PluginWrapper.cpp | 83 ++++++++++++++++++++++++++-------
src/vidalia/plugin/PluginWrapper.h | 1 +
6 files changed, 159 insertions(+), 39 deletions(-)
diff --git a/src/vidalia/plugin/DebugDialog.cpp b/src/vidalia/plugin/DebugDialog.cpp
index b05fbe0..df2aa1e 100644
--- a/src/vidalia/plugin/DebugDialog.cpp
+++ b/src/vidalia/plugin/DebugDialog.cpp
@@ -1,28 +1,53 @@
#include "DebugDialog.h"
-QStringList DebugDialog::buffer;
+QStringList DebugDialog::outputBuffer;
+QStringList DebugDialog::syntaxBuffer;
+QStringList DebugDialog::exceptBuffer;
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));
+ fillText(ui.tedOutput, outputBuffer);
+ fillText(ui.tedSyntax, syntaxBuffer);
+ fillText(ui.tedExceptions, exceptBuffer);
}
DebugDialog::~DebugDialog() {}
void
-DebugDialog::pDebug(const QString &msg)
+DebugDialog::fillText(QTextEdit *tedit, QStringList buffer)
+{
+ foreach(QString line, buffer) {
+ tedit->setPlainText(QString("%1\n%2")
+ .arg(tedit->toPlainText())
+ .arg(line));
+ }
+}
+
+void
+DebugDialog::outputDebug(const QString &msg)
+{
+ outputBuffer << msg;
+}
+
+void
+DebugDialog::syntaxDebug(const QString &msg)
+{
+ syntaxBuffer << msg;
+}
+
+void
+DebugDialog::exceptDebug(const QString &msg)
{
- buffer << msg;
+ exceptBuffer << msg;
}
void
DebugDialog::clear()
{
- buffer.clear();
+ outputBuffer.clear();
+ syntaxBuffer.clear();
+ exceptBuffer.clear();
}
diff --git a/src/vidalia/plugin/DebugDialog.h b/src/vidalia/plugin/DebugDialog.h
index ec69c3e..76b3bb6 100644
--- a/src/vidalia/plugin/DebugDialog.h
+++ b/src/vidalia/plugin/DebugDialog.h
@@ -13,11 +13,18 @@ class DebugDialog : public QDialog
DebugDialog(QWidget *parent = 0);
~DebugDialog();
- static void pDebug(const QString &msg);
+ void fillText(QTextEdit *tedit, QStringList buffer);
+
+ static void outputDebug(const QString &msg);
+ static void syntaxDebug(const QString &msg);
+ static void exceptDebug(const QString &msg);
+
static void clear();
private:
- static QStringList buffer;
+ static QStringList outputBuffer;
+ static QStringList syntaxBuffer;
+ static QStringList exceptBuffer;
Ui::DebugDialog ui;
};
diff --git a/src/vidalia/plugin/DebugDialog.ui b/src/vidalia/plugin/DebugDialog.ui
index 1ad0d2f..1107c3a 100644
--- a/src/vidalia/plugin/DebugDialog.ui
+++ b/src/vidalia/plugin/DebugDialog.ui
@@ -18,8 +18,42 @@
<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 row="0" column="0">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="outputTab">
+ <attribute name="title">
+ <string>Plugin Output</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTextEdit" name="tedOutput"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="syntaxTab">
+ <attribute name="title">
+ <string>Syntax Errors</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QTextEdit" name="tedSyntax"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="errorTab">
+ <attribute name="title">
+ <string>Exceptions</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QTextEdit" name="tedExceptions"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
</item>
</layout>
</widget>
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index bad9c65..883dc24 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -21,16 +21,18 @@ PluginEngine::~PluginEngine()
void
PluginEngine::loadAllPlugins()
{
- DebugDialog::pDebug("loadAllPlugins()");
+ DebugDialog::outputDebug("Loading all plugins...");
VidaliaSettings settings;
QDir path = QDir(settings.pluginPath());
- qWarning() << "PluginPath" << path.absolutePath();
+ DebugDialog::outputDebug(QString("PluginPath=%1").arg(path.absolutePath()));
foreach(QString pdir, path.entryList(QDir::NoDotAndDotDot|QDir::AllDirs)) {
- qWarning() << "pdir" << pdir;
- QFileInfo finfo(QString("%1%2%3").arg(path.absolutePath()).arg(QDir::separator()).arg(pdir));
+ QFileInfo finfo(QString("%1%2%3")
+ .arg(path.absolutePath())
+ .arg(QDir::separator())
+ .arg(pdir));
if(finfo.isDir()) {
tryLoadPlugin(finfo.filePath());
@@ -41,18 +43,22 @@ PluginEngine::loadAllPlugins()
void
PluginEngine::tryLoadPlugin(QDir path)
{
- qWarning() << "tryLoadPlugin()" << path.absolutePath();
-
QStringList files = path.entryList();
- if(!files.contains("info.xml"))
+ if(!files.contains("info.xml")) {
+ DebugDialog::outputDebug(tr("WARNING: %1 doesn't have an info file.")
+ .arg(path.absolutePath()));
return;
+ }
- PluginWrapper *wrapper = new PluginWrapper(QString("%1%2info.xml").arg(path.absolutePath()).arg(QDir::separator()), this);
+ PluginWrapper *wrapper = new PluginWrapper(QString("%1%2info.xml")
+ .arg(path.absolutePath())
+ .arg(QDir::separator()), this);
// if it's persistent, start it right away
- if(wrapper->isPersistent())
+ if(wrapper->isPersistent()) {
wrapper->start();
+ }
wrappers << wrapper;
diff --git a/src/vidalia/plugin/PluginWrapper.cpp b/src/vidalia/plugin/PluginWrapper.cpp
index 8e839fa..2736dbc 100644
--- a/src/vidalia/plugin/PluginWrapper.cpp
+++ b/src/vidalia/plugin/PluginWrapper.cpp
@@ -1,5 +1,6 @@
#include "PluginWrapper.h"
#include "PluginEngine.h"
+#include "DebugDialog.h"
#include <QtXml>
@@ -12,13 +13,25 @@ PluginWrapper::PluginWrapper(const QString &info_path, PluginEngine *engine, QOb
processInfo(info_path);
foreach(QString path, _files) {
- qWarning() << path;
+ DebugDialog::outputDebug(tr("%1: Processing...").arg(name()));
+
QFile file(path);
if(file.open(QIODevice::ReadOnly)) {
- _engine->evaluate(file.readAll());
- qWarning() << "evaluated";
+ QString contents = file.readAll();
+ QScriptSyntaxCheckResult res = QScriptEngine::checkSyntax(contents);
+ if(res.state() == QScriptSyntaxCheckResult::Valid) {
+ DebugDialog::outputDebug("Everything's ok, evaluating...");
+ _engine->evaluate(contents);
+ } else {
+ DebugDialog::syntaxDebug(tr("%4: ERROR: Line: %1 - Column: %2\n%3")
+ .arg(res.errorLineNumber())
+ .arg(res.errorColumnNumber())
+ .arg(res.errorMessage())
+ .arg(name()));
+ }
} else
- qWarning() << "Error opening file";
+ DebugDialog::outputDebug(tr("%1: Error opening file %2")
+ .arg(name()).arg(path));
}
}
@@ -27,17 +40,23 @@ PluginWrapper::~PluginWrapper() {}
void
PluginWrapper::processInfo(const QString &path)
{
- qWarning() << "processInfo()";
-
QDomDocument info("Plugin Info");
QFile file(path);
if(!file.open(QIODevice::ReadOnly)) {
- qWarning() << "Problem opening xml file";
+ DebugDialog::outputDebug(tr("%2: ERROR: Cannot open %1")
+ .arg(path).arg(name()));
return;
}
- if(!info.setContent(&file)) {
- qWarning() << "Problem setting contents";
+ QString errMsg;
+ int errLine, errCol;
+
+ if(!info.setContent(&file, false, &errMsg, &errLine, &errCol)) {
+ DebugDialog::syntaxDebug(tr("%2: ERROR: Parsing %1")
+ .arg(file.fileName()).arg(name()));
+ DebugDialog::syntaxDebug(tr("Line: %1 - Column: %2\nMessage: %3")
+ .arg(errLine).arg(errCol).arg(errMsg));
+
file.close();
return;
}
@@ -82,29 +101,55 @@ PluginWrapper::processInfo(const QString &path)
void
PluginWrapper::start()
{
+ DebugDialog::outputDebug(tr("%1: Starting...").arg(name()));
_engine->evaluate(QString("%1.start()").arg(nspace()));
+ checkExceptions();
}
void
PluginWrapper::stop()
{
+ DebugDialog::outputDebug(tr("%1: Stoping...").arg(name()));
_engine->evaluate(QString("%1.stop()").arg(nspace()));
+ checkExceptions();
}
VidaliaTab *
PluginWrapper::buildGUI()
{
- if(!hasGUI())
+ if(!hasGUI()) {
+ DebugDialog::outputDebug(tr("%1: WARNING: doesn't have a GUI, and buildGUI() was called")
+ .arg(name()));
+ if(checkExceptions())
+ return NULL;
+ }
+
+ VidaliaTab *tab = qscriptvalue_cast<VidaliaTab *>(
+ _engine->evaluate(QString("%1.buildGUI()").arg(nspace())));
+
+ if(checkExceptions())
return NULL;
- VidaliaTab *tab = qscriptvalue_cast<VidaliaTab *>(_engine->evaluate(QString("%1.buildGUI()").arg(nspace())));
+
+ return tab;
+}
+
+bool
+PluginWrapper::checkExceptions()
+{
if(_engine->hasUncaughtException()) {
- qWarning() << "Exception:";
- qWarning() << _engine->uncaughtExceptionLineNumber();
+ DebugDialog::exceptDebug(tr("%2:\n*** Exception in line %1")
+ .arg(_engine->uncaughtExceptionLineNumber())
+ .arg(name()));
+ DebugDialog::exceptDebug(tr("*** Backtrace:"));
+ foreach(QString line, _engine->uncaughtExceptionBacktrace())
+ DebugDialog::exceptDebug(line);
- return NULL;
+ _engine->clearExceptions();
+
+ return true;
}
- qWarning() << "Casted tab:" << tab << nspace();
- return tab;
+
+ return false;
}
bool
@@ -122,6 +167,8 @@ PluginWrapper::isPersistent()
QString
PluginWrapper::name() const
{
+ if(_name.isEmpty())
+ return tr("(untitled)");
return _name;
}
@@ -173,6 +220,6 @@ PluginWrapper::emitPluginTab()
if(tab)
emit pluginTab(tab);
else
- // TODO: make this more than a console print
- qWarning() << "Error: buildGUI() failed for plugin" << name();
+ DebugDialog::exceptDebug(tr("Error: buildGUI() failed for plugin %1")
+ .arg(name()));
}
diff --git a/src/vidalia/plugin/PluginWrapper.h b/src/vidalia/plugin/PluginWrapper.h
index d99538c..15f7853 100644
--- a/src/vidalia/plugin/PluginWrapper.h
+++ b/src/vidalia/plugin/PluginWrapper.h
@@ -38,6 +38,7 @@ class PluginWrapper : public QObject {
protected:
void processInfo(const QString &path);
+ bool checkExceptions();
PluginEngine *_engine;
QString _name, _date, _author;
More information about the tor-commits
mailing list