tor-commits
Threads by month
- ----- 2025 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- 213386 discussions
commit 1f6d58a5568782e79fdbb17a6c73a20f1ea91075
Author: Tomas Touceda <chiiph(a)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());
1
0
commit db3a4f43ed310b5e1e1fe778dfe8d6cf3c405ead
Author: Tomas Touceda <chiiph(a)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;
1
0
commit 2de86992bd17a018a3d6efc80944259ffb2d1885
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Mon Jun 13 11:02:45 2011 -0300
First part of interfacing TorControl
---
.../plugin/prototypes/TorControlPrototype.cpp | 463 ++++++++++++++++++++
.../plugin/prototypes/TorControlPrototype.h | 350 +++++++++++++++
2 files changed, 813 insertions(+), 0 deletions(-)
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
new file mode 100644
index 0000000..75e08d5
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
@@ -0,0 +1,463 @@
+#include "TorControlPrototype.h"
+
+TorControlPrototype::TorControlPrototype()
+ : QObject(), QScriptable() {}
+
+void
+TorControlPrototype::start(const QString &tor, const QStringList &args)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ obj->start(tor, args);
+}
+
+bool
+TorControlPrototype::stop(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->stop(errmsg);
+}
+
+bool
+TorControlPrototype::isRunning()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->isRunning();
+}
+
+bool
+TorControlPrototype::isVidaliaRunningTor()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->isVidaliaRunningTor();
+}
+
+void
+TorControlPrototype::closeTorStdout()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ obj->closeTorStdout();
+}
+
+void
+TorControlPrototype::connect(const QHostAddress &address, quint16 port)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ obj->connect(address, port);
+}
+
+void
+TorControlPrototype::connect(const QString &path)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ obj->connect(path);
+}
+
+void
+TorControlPrototype::disconnect()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ obj->disconnect();
+}
+
+bool
+TorControlPrototype::isConnected()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->isConnected();
+}
+
+bool
+TorControlPrototype::authenticate(const QByteArray cookie, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->authenticate(cookie, errmsg);
+}
+
+bool
+TorControlPrototype::authenticate(const QString &password = QString(), QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->authenticate(password, errmsg);
+}
+
+ProtocolInfo
+TorControlPrototype::protocolInfo(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->protocolInfo(errmsg);
+}
+
+BootstrapStatus
+TorControlPrototype::bootstrapStatus(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->bootstrapStatus(errmsg);
+}
+
+bool
+TorControlPrototype::isCircuitEstablished()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->isCircuitEstablished();
+}
+
+bool
+TorControlPrototype::getInfo(QHash<QString,QString> &map, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getInfo(map, errmsg);
+}
+
+bool
+TorControlPrototype::getInfo(QString key, QString &val, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getInfo(key, val, errmsg);
+}
+
+QVariantMap
+TorControlPrototype::getInfo(const QStringList &keys, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getInfo(keys, errmsg);
+}
+
+QVariant
+TorControlPrototype::getInfo(const QString &key, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getInfo(key, errmsg);
+}
+
+bool
+TorControlPrototype::signal(TorSignal::Signal sig, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->signal(sig, errmsg);
+}
+
+QHostAddress
+TorControlPrototype::getSocksAddress(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getSocksAddress(errmsg);
+}
+
+QStringList
+TorControlPrototype::getSocksAddressList(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getSocksAddressList(errmsg);
+}
+
+quint16
+TorControlPrototype::getSocksPort(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getSocksPort(errmsg);
+}
+
+QList
+TorControlPrototype::<quint16> getSocksPortList(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->quint16> getSocksPortList(errmsg);
+}
+
+QString
+TorControlPrototype::getTorVersionString()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getTorVersionString();
+}
+
+quint32
+TorControlPrototype::getTorVersion()
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getTorVersion();
+}
+
+bool
+TorControlPrototype::setEvent(TorEvents::Event e, bool add = true, bool set = true, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->setEvent(e, add, set, errmsg);
+}
+
+bool
+TorControlPrototype::setEvents(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->setEvents(errmsg);
+}
+
+bool
+TorControlPrototype::setConf(QHash<QString,QString> map, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->setConf(map, errmsg);
+}
+
+bool
+TorControlPrototype::setConf(QString key, QString value, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ returb obj->setConf(key, value, errmsg);
+}
+
+bool
+TorControlPrototype::setConf(QString keyAndValue, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->setConf(keyAndValue, errmsg);
+}
+
+bool
+TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(map, errmsg);
+}
+
+bool
+TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(map, errmsg);
+}
+
+bool
+TorControlPrototype::getConf(QString key, QString &value, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(key, value, errmsg);
+}
+
+bool
+TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(key, value, errmsg);
+}
+
+QVariantMap
+TorControlPrototype::getConf(const QStringList &keys, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(keys, errmsg);
+}
+
+QVariant
+TorControlPrototype::getConf(const QString &key, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getConf(key, errmsg);
+}
+
+QString
+TorControlPrototype::getHiddenServiceConf(const QString &key, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getHiddenServiceConf(key, errmsg);
+}
+
+bool
+TorControlPrototype::saveConf(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->saveConf(errmsg);
+}
+
+bool
+TorControlPrototype::resetConf(QStringList keys, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->resetConf(keys, errmsg);
+}
+
+bool
+TorControlPrototype::resetConf(QString key, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->resetConf(key, errmsg);
+}
+
+QStringList
+TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getRouterDescriptorText(id, errmsg);
+}
+
+RouterDescriptor
+TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getRouterDescriptor(id, errmsg);
+}
+
+RouterStatus
+TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getRouterStatus(id, errmsg);
+}
+
+NetworkStatus
+TorControlPrototype::getNetworkStatus(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getNetworkStatus(errmsg);
+}
+
+DescriptorAnnotations
+TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getDescriptorAnnotations(id, errmsg);
+}
+
+CircuitList
+TorControlPrototype::getCircuits(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getCircuits(errmsg);
+}
+
+StreamList
+TorControlPrototype::getStreams(QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getStreams(errmsg);
+}
+
+AddressMap
+TorControlPrototype::getAddressMap(AddressMap::AddressMapType type = AddressMap::AddressMapAll, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->getAddressMap(type, errmsg);
+}
+
+QString
+TorControlPrototype::ipToCountry(const QHostAddress &ip, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->ipToCountry(ip, errmsg);
+}
+
+bool
+TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused = false, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->closeCircuit(circId, ifUnused, errmsg);
+}
+
+bool
+TorControlPrototype::closeStream(const StreamId &streamId, QString *errmsg = 0)
+{
+ TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+
+ if(obj)
+ return obj->closeStream(streamId, errmsg);
+}
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
new file mode 100644
index 0000000..0327b74
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.h
@@ -0,0 +1,350 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file TorControlPrototype.h
+** \brief Object for interacting with the Tor process and control interface
+*/
+
+#ifndef _TORCONTROLPROTO_H
+#define _TORCONTROLPROTO_H
+
+#include <QtScript>
+
+#include "TorControl.h"
+
+class TorControlPrototype : public QObject, QScriptable
+{
+ Q_OBJECT
+
+public:
+ TorControlPrototype();
+
+ /** Start the Tor process */
+ Q_INVOKABLE void start(const QString &tor, const QStringList &args);
+ /** Stop the Tor process */
+ Q_INVOKABLE bool stop(QString *errmsg = 0);
+ /** Detect if the Tor process is running */
+ Q_INVOKABLE bool isRunning();
+ /** Detects if the Tor process is running under Vidalia. */
+ Q_INVOKABLE bool isVidaliaRunningTor();
+ /** Stops reading log messages from the Tor process's stdout. This has no
+ * effect if isVidaliaRunningTor() is false. */
+ Q_INVOKABLE void closeTorStdout();
+
+ /** Connect to Tor's control socket */
+ Q_INVOKABLE void connect(const QHostAddress &address, quint16 port);
+ Q_INVOKABLE void connect(const QString &path);
+ /** Disconnect from Tor's control socket */
+ Q_INVOKABLE void disconnect();
+ /** Check if we're connected to Tor's control socket */
+ Q_INVOKABLE bool isConnected();
+ /** Sends an authentication cookie to Tor. */
+ Q_INVOKABLE bool authenticate(const QByteArray cookie, QString *errmsg = 0);
+ /** Sends an authentication password to Tor. */
+ Q_INVOKABLE bool authenticate(const QString &password = QString(), QString *errmsg = 0);
+
+ /** Sends a PROTOCOLINFO command to Tor and parses the response. */
+ Q_INVOKABLE ProtocolInfo protocolInfo(QString *errmsg = 0);
+
+ /** Returns the Tor software's current bootstrap phase and status. */
+ Q_INVOKABLE BootstrapStatus bootstrapStatus(QString *errmsg = 0);
+
+ /** Returns true if Tor either has an open circuit or (on Tor >=
+ * 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
+ Q_INVOKABLE bool isCircuitEstablished();
+
+ /** Sends a GETINFO message to Tor based on the given keys */
+ Q_INVOKABLE bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
+ /** Sends a GETINFO message for a single info value to Tor */
+ Q_INVOKABLE bool getInfo(QString key, QString &val, QString *errmsg = 0);
+
+ /** Sends a GETINFO message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+ Q_INVOKABLE QVariantMap getInfo(const QStringList &keys, QString *errmsg = 0);
+ /** Sends a GETINFO message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+ Q_INVOKABLE QVariant getInfo(const QString &key, QString *errmsg = 0);
+
+ /** Sends a signal to Tor */
+ Q_INVOKABLE bool signal(TorSignal::Signal sig, QString *errmsg = 0);
+
+ /** Returns an address on which Tor is listening for application
+ * requests. If none are available, a null QHostAddress is returned. */
+ Q_INVOKABLE QHostAddress getSocksAddress(QString *errmsg = 0);
+ /** Returns a (possibly empty) list of all currently configured
+ * SocksListenAddress entries. */
+ Q_INVOKABLE QStringList getSocksAddressList(QString *errmsg = 0);
+ /** Returns a valid SOCKS port for Tor, or 0 if Tor is not accepting
+ * application requests. */
+ Q_INVOKABLE quint16 getSocksPort(QString *errmsg = 0);
+ /** Returns a list of all currently configured SOCKS ports. If Tor is not
+ * accepting any application connections, an empty list will be returned. */
+ Q_INVOKABLE QList<quint16> getSocksPortList(QString *errmsg = 0);
+
+ /** Returns Tor's version as a string. */
+ Q_INVOKABLE QString getTorVersionString();
+ /** Returns Tor's version as a numeric value. */
+ Q_INVOKABLE quint32 getTorVersion();
+
+ /** Sets an event and its handler. If add is true, then the event is added,
+ * otherwise it is removed. If set is true, then the given event will be
+ * registered with Tor. */
+ Q_INVOKABLE bool setEvent(TorEvents::Event e, bool add = true, bool set = true,
+ QString *errmsg = 0);
+ /** Register events of interest with Tor */
+ Q_INVOKABLE bool setEvents(QString *errmsg = 0);
+
+ /** Sets each configuration key in <b>map</b> to the value associated with its key. */
+ Q_INVOKABLE bool setConf(QHash<QString,QString> map, QString *errmsg = 0);
+ /** Sets a single configuration key to the given value. */
+ Q_INVOKABLE bool setConf(QString key, QString value, QString *errmsg = 0);
+ /** Sets a single configuration string that is formatted <key=escaped value>. */
+ Q_INVOKABLE bool setConf(QString keyAndValue, QString *errmsg = 0);
+ /** Gets values for a set of configuration keys, each of which has a single
+ * value. */
+ Q_INVOKABLE bool getConf(QHash<QString,QString> &map, QString *errmsg = 0);
+ /** Gets a set of configuration keyvalues and stores them in <b>map</b>. */
+ Q_INVOKABLE bool getConf(QHash<QString,QStringList> &map, QString *errmsg = 0);
+ /** Gets a single configuration value for <b>key</b>. */
+ Q_INVOKABLE bool getConf(QString key, QString &value, QString *errmsg = 0);
+ /** Gets a list of configuration values for <b>key</b>. */
+ Q_INVOKABLE bool getConf(QString key, QStringList &value, QString *errmsg = 0);
+
+ /** Sends a GETCONF message to Tor using the given list of <b>keys</b> and
+ * returns a QVariantMap containing the specified keys and their values as
+ * returned by Tor. Returns a default constructed QVariantMap on failure. */
+ Q_INVOKABLE QVariantMap getConf(const QStringList &keys, QString *errmsg = 0);
+ /** Sends a GETCONF message to Tor with a single <b>key</b> and returns a
+ * QVariant containing the value returned by Tor. Returns a default
+ * constructed QVariant on failure. */
+ Q_INVOKABLE QVariant getConf(const QString &key, QString *errmsg = 0);
+ /** Sends a GETCONF message to Tor with the single key and returns a QString
+ * containing the value returned by Tor */
+ Q_INVOKABLE QString getHiddenServiceConf(const QString &key, QString *errmsg = 0);
+
+ /** Asks Tor to save the current configuration to its torrc */
+ Q_INVOKABLE bool saveConf(QString *errmsg = 0);
+ /** Tells Tor to reset the given configuration keys back to defaults. */
+ Q_INVOKABLE bool resetConf(QStringList keys, QString *errmsg = 0);
+ /** Tells Tor to reset a configuration key back to its default value. */
+ Q_INVOKABLE bool resetConf(QString key, QString *errmsg = 0);
+
+ /** Returns an unparsed router descriptor for the router whose fingerprint
+ * matches <b>id</b>. The returned text can later be parsed by the
+ * RouterDescriptor class. If <b>id</b> is invalid, then an empty
+ * QStringList is returned. */
+ Q_INVOKABLE QStringList getRouterDescriptorText(const QString &id, QString *errmsg = 0);
+ /** Returns the descriptor for the router whose fingerprint matches
+ * <b>id</b>. If <b>id</b> is invalid or the router's descriptor cannot be
+ * parsed, then an invalid RouterDescriptor is returned. */
+ Q_INVOKABLE RouterDescriptor getRouterDescriptor(const QString &id, QString *errmsg = 0);
+ /** Returns the status of the router whose fingerprint matches <b>id</b>. If
+ * <b>id</b> is invalid or the router's status cannot be parsed, then an
+ * invalid RouterStatus is returned. */
+ Q_INVOKABLE RouterStatus getRouterStatus(const QString &id, QString *errmsg = 0);
+ /** Returns a RouterStatus object for every known router in the network. If
+ * the network status document cannot be parsed, then an empty NetworkStatus
+ * is returned. */
+ Q_INVOKABLE NetworkStatus getNetworkStatus(QString *errmsg = 0);
+ /** Returns the annotations for the router whose fingerprint matches
+ * <b>id</b>. If <b>id</b> is invalid or the router's descriptor cannot be
+ * parsed, then an empty DescriptorAnnotations is returned and
+ * <b>errmsg</b> is set if it's not NULL. (Tor >= 0.2.0.13-alpha only) */
+ Q_INVOKABLE DescriptorAnnotations getDescriptorAnnotations(const QString &id,
+ QString *errmsg = 0);
+
+ /** Gets a list of current circuits. */
+ Q_INVOKABLE CircuitList getCircuits(QString *errmsg = 0);
+ /** Gets a list of current streams. */
+ Q_INVOKABLE StreamList getStreams(QString *errmsg = 0);
+
+ /** Gets a list of address mappings of the type specified by <b>type</b>
+ * (defaults to <i>AddressMapAll</i>. */
+ Q_INVOKABLE AddressMap getAddressMap(
+ AddressMap::AddressMapType type = AddressMap::AddressMapAll,
+ QString *errmsg = 0);
+
+ /** Gets the ISO-3166 two-letter country code for <b>ip</b> from Tor.
+ * Returns a default-constructed QString on failure or if a country code
+ * is not known for <b>ip</b>. On failure, <b>errmsg</b> will be set if
+ * it's not NULL. */
+ Q_INVOKABLE QString ipToCountry(const QHostAddress &ip, QString *errmsg = 0);
+
+public slots:
+ /** Closes the circuit specified by <b>circId</b>. If <b>ifUnused</b> is
+ * true, then the circuit will not be closed unless it is unused. */
+ bool closeCircuit(const CircuitId &circId, bool ifUnused = false,
+ QString *errmsg = 0);
+ /** Closes the stream specified by <b>streamId</b>. */
+ bool closeStream(const StreamId &streamId, QString *errmsg = 0);
+
+signals:
+ /** Emitted when the Tor process has started */
+ void started();
+ /** Emitted when the Tor process fails to start. */
+ void startFailed(QString errmsg);
+ /** Emitted when the Tor process has stopped */
+ void stopped(int exitCode, QProcess::ExitStatus exitStatus);
+ /** Emitted when the Tor process has stopped. */
+ void stopped();
+ /** Emitted when the controller has connected to Tor */
+ void connected();
+ /** Emitted when the controller failed to connect to Tor. */
+ void connectFailed(QString errmsg);
+ /** Emitted when the controller has disconnected from Tor */
+ void disconnected();
+ /** Emitted when the control socket is connected and authenticated. */
+ void authenticated();
+ /** Emitted when Tor rejects our authentication attempt. */
+ void authenticationFailed(QString errmsg);
+
+ /** Emitted when Tor writes the message <b>msg</b> to the control port
+ * with message severity <b>level</b>.
+ */
+ void logMessage(tc::Severity level, const QString &msg);
+
+ /** Emitted when Tor sends a bandwidth usage update (roughly once every
+ * second). <b>bytesReceived</b> is the number of bytes read by Tor over
+ * the previous second and <b>bytesWritten</b> is the number of bytes
+ * sent over the same interval.
+ */
+ void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent);
+
+ /** Emitted when the stream status of <b>stream</b> has changed.
+ */
+ void streamStatusChanged(const Stream &stream);
+
+ /** Emitted when the circuit status of <b>circuit</b> has changed.
+ */
+ void circuitStatusChanged(const Circuit &circuit);
+
+ /** Emitted when Tor has mapped the address <b>from</b> to the address
+ * <b>to</b>. <b>expires</b> indicates the time at which when the address
+ * mapping will no longer be considered valid.
+ */
+ void addressMapped(const QString &from, const QString &to,
+ const QDateTime &expires);
+
+ /** Emitted when Tor has received one or more new router descriptors.
+ * <b>ids</b> contains a list of digests of the new descriptors.
+ */
+ void newDescriptors(const QStringList &ids);
+
+ /** Indicates Tor has been able to successfully establish one or more
+ * circuits.
+ */
+ void circuitEstablished();
+
+ /** Indicates that Tor has decided the user's Tor software <b>version</b>
+ * is no longer recommended for some <b>reason</b>. <b>recommended</b> is
+ * a list of Tor software versions that are considered current.
+ */
+ void dangerousTorVersion(tc::TorVersionStatus reason,
+ const QString &version,
+ const QStringList &recommended);
+
+ /** Emitted during Tor's startup process to indicate how far in its
+ * bootstrapping process it has progressed. <b>status</b> may indicate
+ * the current bootstrapping stage or an error during bootstrapping.
+ */
+ void bootstrapStatusChanged(const BootstrapStatus &status);
+
+ /** Emitted when the user attempts to establish a connection to some
+ * destination on port <b>port</b>, which is a port known to use
+ * plaintext connections (as determined by Tor's WarnPlaintextPorts and
+ * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether
+ * Tor rejected the connection or permitted it to connect anyway.
+ */
+ void dangerousPort(quint16 port, bool rejected);
+
+ /** Emitted when Tor detects a problem with a SOCKS connection from the
+ * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad
+ * hostname. <b>type</b> indicates the type of error encountered and
+ * <b>destination</b> (if non-empty) specifies the attempted connection
+ * destination address or hostname.
+ */
+ void socksError(tc::SocksError type, const QString &destination);
+
+ /** Emitted when Tor decides the client's external IP address has changed
+ * to <b>ip</b>. If <b>hostname</b> is non-empty, Tor obtained the new
+ * value for <b>ip</b> by resolving <b>hostname</b>.
+ */
+ void externalAddressChanged(const QHostAddress &ip, const QString &hostname);
+
+ /** Indicates that Tor has determined the client's clock is potentially
+ * skewed by <b>skew</b> seconds relative to <b>source</b>.
+ */
+ void clockSkewed(int skew, const QString &source);
+
+ /** Emitted when Tor has encountered an internal bug. <b>reason</b> is
+ * Tor's description of the bug.
+ */
+ void bug(const QString &reason);
+
+ /** Emitted when Tor determines that the user's DNS provider is providing
+ * an address for non-existent domains when it should really be saying
+ * "NXDOMAIN".
+ */
+ void dnsHijacked();
+
+ /** Emitted when Tor determines that the user's DNS provider is providing
+ * a hijacked address even for well-known websites.
+ */
+ void dnsUseless();
+
+ /** Indicates Tor has started testing the reachability of its OR port
+ * using the IP address <b>ip</b> and port <b>port</b>.
+ */
+ void checkingOrPortReachability(const QHostAddress &ip, quint16 port);
+
+ /** Tor has completed testing the reachability of its OR port using
+ * the IP address <b>ip</b> and port <b>port</b>. If the user's OR port
+ * was reachable, <b>reachable</b> will be set to true.
+ */
+ void orPortReachabilityFinished(const QHostAddress &ip, quint16 port,
+ bool reachable);
+
+ /** Indicates Tor has started testing the reachability of its directory
+ * port using the IP address <b>ip</b> and port <b>port</b>.
+ */
+ void checkingDirPortReachability(const QHostAddress &ip, quint16 port);
+
+ /** Tor has completed testing the reachability of its directory port using
+ * the IP address <b>ip</b> and port <b>port</b>. If the user's directory
+ * port was reachable, <b>reachable</b> will be set to true.
+ */
+ void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port,
+ bool reachable);
+
+ /** Emitted when the directory authority with IP address <b>ip</b> and
+ * port <b>port</b> rejected the user's server descriptor. <b>reason</b>
+ * describes why the descriptor was rejected (e.g., malformed, skewed
+ * clock, etc.).
+ */
+ void serverDescriptorRejected(const QHostAddress &ip, quint16 port,
+ const QString &reason);
+
+ /** Emitted when the directory authority with IP address <b>ip</b> and
+ * port <b>port</b> accepted the user's server descriptor.
+ */
+ void serverDescriptorAccepted(const QHostAddress &ip, quint16 port);
+
+ /** Emitted when at least one directory authority has accepted the user's
+ * server descriptor.
+ */
+ void serverDescriptorAccepted();
+};
+
+#endif
+
+
1
0
commit 6bae6e29816be171462ae028a9adc1dcaab778d6
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Mon Jun 13 01:56:37 2011 -0300
Improve the engine
- Add include and importExtension functions from qtscriptgenerator.
- Improve the ADD_CLASS macro
- Add a way to access the settings that belong to a tab from inside
a plugin.
---
src/vidalia/plugin/PluginEngine.cpp | 86 +++++++++++++++++++-
src/vidalia/plugin/PluginEngine.h | 15 ++--
.../plugin/prototypes/VidaliaTabPrototype.cpp | 52 +++++++++++-
.../plugin/prototypes/VidaliaTabPrototype.h | 6 ++
4 files changed, 149 insertions(+), 10 deletions(-)
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 883dc24..9604b8d 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -6,8 +6,14 @@
PluginEngine::PluginEngine(QObject *parent)
: QScriptEngine(parent)
{
- ADD_CLASS("VidaliaTab", VidaliaTabPrototype, VidaliaTab *,
- VidaliaTabPrototype::constructor)
+ ADD_CLASS(VidaliaTabPrototype)
+
+ globalObject().setProperty("include", newFunction(includeScript));
+ globalObject().setProperty("importExtension", newFunction(importExtension));
+
+ DebugDialog::outputDebug("Available extensions:");
+ foreach(QString ext, availableExtensions())
+ DebugDialog::outputDebug(QString(" %1").arg(ext));
loadAllPlugins();
}
@@ -74,3 +80,79 @@ PluginEngine::getAllActions()
return actions;
}
+
+QScriptValue
+PluginEngine::importExtension(QScriptContext *context, QScriptEngine *engine)
+{
+ return engine->importExtension(context->argument(0).toString());
+}
+
+QScriptValue
+PluginEngine::includeScript(QScriptContext *context, QScriptEngine *engine)
+{
+ QString currentFileName = engine->globalObject().property("qs").property("script").property("absoluteFilePath").toString();
+ QFileInfo currentFileInfo(currentFileName);
+ QString path = currentFileInfo.path();
+ QString importFile = context->argument(0).toString();
+ QFileInfo importInfo(importFile);
+ if (importInfo.isRelative()) {
+ importFile = path + "/" + importInfo.filePath();
+ }
+ if (!loadFile(importFile, engine)) {
+ return context->throwError(QString("Failed to resolve include: %1").arg(importFile));
+ }
+ return engine->toScriptValue(true);
+}
+
+bool
+PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
+{
+ // avoid loading files more than once
+ static QSet<QString> loadedFiles;
+ QFileInfo fileInfo(fileName);
+ QString absoluteFileName = fileInfo.absoluteFilePath();
+ QString absolutePath = fileInfo.absolutePath();
+ QString canonicalFileName = fileInfo.canonicalFilePath();
+ if (loadedFiles.contains(canonicalFileName)) {
+ return true;
+ }
+ loadedFiles.insert(canonicalFileName);
+ QString path = fileInfo.path();
+
+ // load the file
+ QFile file(fileName);
+ if (file.open(QFile::ReadOnly)) {
+ QTextStream stream(&file);
+ QString contents = stream.readAll();
+ file.close();
+
+ int endlineIndex = contents.indexOf('\n');
+ QString line = contents.left(endlineIndex);
+ int lineNumber = 1;
+
+ // strip off #!/usr/bin/env qscript line
+ if (line.startsWith("#!")) {
+ contents.remove(0, endlineIndex+1);
+ ++lineNumber;
+ }
+
+ // set qt.script.absoluteFilePath
+ QScriptValue script = engine->globalObject().property("qs").property("script");
+ QScriptValue oldFilePathValue = script.property("absoluteFilePath");
+ QScriptValue oldPathValue = script.property("absolutePath");
+ script.setProperty("absoluteFilePath", engine->toScriptValue(absoluteFileName));
+ script.setProperty("absolutePath", engine->toScriptValue(absolutePath));
+
+ QScriptValue r = engine->evaluate(contents, fileName, lineNumber);
+ if (engine->hasUncaughtException()) {
+ QStringList backtrace = engine->uncaughtExceptionBacktrace();
+ qDebug() << QString(" %1\n%2\n\n").arg(r.toString()).arg(backtrace.join("\n"));
+ return true;
+ }
+ script.setProperty("absoluteFilePath", oldFilePathValue); // if we come from includeScript(), or whereever
+ script.setProperty("absolutePath", oldPathValue); // if we come from includeScript(), or whereever
+ } else {
+ return false;
+ }
+ return true;
+}
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 7876803..6496ca6 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -8,12 +8,11 @@
class PluginWrapper;
-#define ADD_CLASS(name, protoType, absType, ctor) \
- protoType __proto; \
- QScriptValue __script = newQObject(&__proto, QScriptEngine::ScriptOwnership); \
- setDefaultPrototype(qMetaTypeId<absType>(), __script); \
- QScriptValue __ctor = newFunction(ctor, __script); \
- globalObject().setProperty(name, __ctor);
+#define ADD_CLASS(protoType) \
+ QScriptValue __script##protoType = newQObject(new protoType); \
+ setDefaultPrototype(protoType::metaTypeId(), __script##protoType); \
+ globalObject().setProperty(protoType::name(), newFunction(protoType::constructor, __script##protoType));
+
class PluginEngine : public QScriptEngine {
Q_OBJECT
@@ -28,6 +27,10 @@ class PluginEngine : public QScriptEngine {
void pluginTab(VidaliaTab *);
protected:
+ static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine);
+ static bool loadFile(QString fileName, QScriptEngine *engine);
+ static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
+
void loadAllPlugins();
void tryLoadPlugin(QDir path);
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
index 58170ef..52b8fef 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
@@ -4,7 +4,55 @@ VidaliaTabPrototype::VidaliaTabPrototype(QObject *parent)
: QObject(parent)
{}
-QScriptValue VidaliaTabPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
+QScriptValue
+VidaliaTabPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
{
- return engine->newQObject(new VidaliaTab(QString("titulooo"), QString("nombreee")), QScriptEngine::ScriptOwnership);
+ if((context->argumentCount() > 2) or (context->argumentCount() < 1))
+ return QScriptValue(QScriptValue::NullValue);
+
+ QString title = "";
+ QString name = "";
+
+ title = qscriptvalue_cast<QString>(context->argument(0));
+ if(context->argumentCount() > 1)
+ name = qscriptvalue_cast<QString>(context->argument(1));
+
+ return engine->newQObject(new VidaliaTab(title, name), QScriptEngine::ScriptOwnership);
+}
+
+int
+VidaliaTabPrototype::metaTypeId() {
+ return qMetaTypeId<VidaliaTab *>();
+}
+
+QString
+VidaliaTabPrototype::name() {
+ return QString("VidaliaTab");
+}
+
+void
+VidaliaTabPrototype::setLayout(QLayout *layout)
+{
+ VidaliaTab *obj = qscriptvalue_cast<VidaliaTab *>(thisObject());
+
+ if(obj)
+ obj->setLayout(layout);
+}
+
+QVariant
+VidaliaTabPrototype::getSetting(QString name, QVariant defaultValue)
+{
+ VidaliaTab *obj = qscriptvalue_cast<VidaliaTab *>(thisObject());
+
+ if(obj)
+ return obj->getSetting(name, defaultValue);
+}
+
+void
+VidaliaTabPrototype::saveSetting(QString name, QVariant value)
+{
+ VidaliaTab *obj = qscriptvalue_cast<VidaliaTab *>(thisObject());
+
+ if(obj)
+ obj->saveSetting(name, value);
}
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
index dbd89cd..59d640d 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
@@ -13,6 +13,12 @@ class VidaliaTabPrototype : public QObject, public QScriptable
public:
VidaliaTabPrototype(QObject *parent = 0);
static QScriptValue constructor(QScriptContext *context, QScriptEngine *engine);
+ static int metaTypeId();
+ static QString name();
+
+ Q_INVOKABLE void setLayout(QLayout *layout);
+ Q_INVOKABLE QVariant getSetting(QString name, QVariant defaultValue);
+ Q_INVOKABLE void saveSetting(QString name, QVariant value);
};
Q_DECLARE_METATYPE(VidaliaTab *);
1
0

[vidalia/alpha] Improve engine, add HelperProcess and work a bit more with TorControl
by chiiph@torproject.org 02 Jul '11
by chiiph@torproject.org 02 Jul '11
02 Jul '11
commit 9e2bfe1cab863674e4e1d1b757c924d5b3eaebb2
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Mon Jun 13 16:22:07 2011 -0300
Improve engine, add HelperProcess and work a bit more with TorControl
- Added HelperProcess since we need it to take the TBB functionality out of
Vidalia.
- Break the ADD_CLASS macro into ADD_PROTOTYPE and MAKE_CREATABLE to be
able to handle static objects without constructors.
- Fix a bit more TorControl, but it's not ready yet.
---
src/vidalia/CMakeLists.txt | 2 +
src/vidalia/plugin/PluginEngine.cpp | 9 ++-
src/vidalia/plugin/PluginEngine.h | 7 +-
.../plugin/prototypes/HelperProcessPrototype.cpp | 49 ++++++++++
.../plugin/prototypes/HelperProcessPrototype.h | 28 ++++++
.../plugin/prototypes/TorControlPrototype.cpp | 93 +++++++++++---------
.../plugin/prototypes/TorControlPrototype.h | 7 ++
7 files changed, 151 insertions(+), 44 deletions(-)
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 7dac60e..380b9e8 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -88,12 +88,14 @@ set(vidalia_SRCS ${vidalia_SRCS}
plugin/PluginWrapper.cpp
plugin/DebugDialog.cpp
plugin/prototypes/VidaliaTabPrototype.cpp
+ plugin/prototypes/HelperProcessPrototype.cpp
)
qt4_wrap_cpp(vidalia_SRCS
plugin/PluginEngine.h
plugin/PluginWrapper.h
plugin/DebugDialog.h
plugin/prototypes/VidaliaTabPrototype.h
+ plugin/prototypes/HelperProcessPrototype.h
)
## Configuration dialog sources
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 9604b8d..3f99025 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -6,11 +6,18 @@
PluginEngine::PluginEngine(QObject *parent)
: QScriptEngine(parent)
{
- ADD_CLASS(VidaliaTabPrototype)
+ ADD_PROTOTYPE(VidaliaTabPrototype)
+ MAKE_CREATABLE(VidaliaTabPrototype)
+ ADD_PROTOTYPE(HelperProcessPrototype)
+ MAKE_CREATABLE(HelperProcessPrototype)
+// ADD_PROTOTYPE(TorControlPrototype)
globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
+ VidaliaSettings settings;
+ globalObject().setProperty("pluginPath", QScriptValue(settings.pluginPath()));
+
DebugDialog::outputDebug("Available extensions:");
foreach(QString ext, availableExtensions())
DebugDialog::outputDebug(QString(" %1").arg(ext));
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 6496ca6..5b4cc25 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -5,14 +5,17 @@
#include <QtScript>
#include "VidaliaTabPrototype.h"
+#include "HelperProcessPrototype.h"
+//#include "TorControlPrototype.h"
class PluginWrapper;
-#define ADD_CLASS(protoType) \
+#define ADD_PROTOTYPE(protoType) \
QScriptValue __script##protoType = newQObject(new protoType); \
setDefaultPrototype(protoType::metaTypeId(), __script##protoType); \
- globalObject().setProperty(protoType::name(), newFunction(protoType::constructor, __script##protoType));
+#define MAKE_CREATABLE(protoType) \
+ globalObject().setProperty(protoType::name(), newFunction(protoType::constructor, __script##protoType));
class PluginEngine : public QScriptEngine {
Q_OBJECT
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
new file mode 100644
index 0000000..81d4d94
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
@@ -0,0 +1,49 @@
+#include "HelperProcessPrototype.h"
+
+HelperProcessPrototype::HelperProcessPrototype(QObject *parent)
+ : QObject(parent)
+{}
+
+QScriptValue
+HelperProcessPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
+{
+ return engine->newQObject(new HelperProcess(), QScriptEngine::ScriptOwnership);
+}
+
+int
+HelperProcessPrototype::metaTypeId() {
+ return qMetaTypeId<HelperProcess *>();
+}
+
+QString
+HelperProcessPrototype::name() {
+ return QString("HelperProcess");
+}
+
+void
+HelperProcessPrototype::start(const QString &app, const QString &args)
+{
+ HelperProcess *obj = qscriptvalue_cast<HelperProcess *>(thisObject());
+
+ if(obj)
+ obj->start(app, args);
+}
+
+void
+HelperProcessPrototype::start(const QString &app, const QStringList &args)
+{
+ HelperProcess *obj = qscriptvalue_cast<HelperProcess *>(thisObject());
+
+ if(obj)
+ obj->start(app, args);
+}
+
+bool
+HelperProcessPrototype::isDone() const
+{
+ HelperProcess *obj = qscriptvalue_cast<HelperProcess *>(thisObject());
+
+ if(obj)
+ return obj->isDone();
+}
+
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.h b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
new file mode 100644
index 0000000..b64a27c
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
@@ -0,0 +1,28 @@
+#ifndef HELPERPROCESSPROT_H
+#define HELPERPROCESSPROT_H
+
+#include <QtGui>
+#include <QtScript>
+
+#include "HelperProcess.h"
+
+class HelperProcessPrototype : public QObject, public QScriptable
+{
+ Q_OBJECT
+
+ public:
+ HelperProcessPrototype(QObject *parent = 0);
+ static QScriptValue constructor(QScriptContext *context, QScriptEngine *engine);
+ static int metaTypeId();
+ static QString name();
+
+ Q_INVOKABLE void start(const QString &app, const QString &args);
+ Q_INVOKABLE void start(const QString &app, const QStringList &args);
+ Q_INVOKABLE bool isDone() const;
+};
+
+Q_DECLARE_METATYPE(HelperProcess *);
+
+#endif
+
+
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
index 75e08d5..972d100 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
@@ -3,6 +3,17 @@
TorControlPrototype::TorControlPrototype()
: QObject(), QScriptable() {}
+int
+TorControlPrototype::metaTypeId() {
+ return qMetaTypeId<TorControl *>();
+}
+
+QString
+TorControlPrototype::name() {
+ return QString("TorControl");
+}
+
+
void
TorControlPrototype::start(const QString &tor, const QStringList &args)
{
@@ -13,7 +24,7 @@ TorControlPrototype::start(const QString &tor, const QStringList &args)
}
bool
-TorControlPrototype::stop(QString *errmsg = 0)
+TorControlPrototype::stop(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -85,7 +96,7 @@ TorControlPrototype::isConnected()
}
bool
-TorControlPrototype::authenticate(const QByteArray cookie, QString *errmsg = 0)
+TorControlPrototype::authenticate(const QByteArray cookie, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -94,7 +105,7 @@ TorControlPrototype::authenticate(const QByteArray cookie, QString *errmsg = 0)
}
bool
-TorControlPrototype::authenticate(const QString &password = QString(), QString *errmsg = 0)
+TorControlPrototype::authenticate(const QString &password, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -103,7 +114,7 @@ TorControlPrototype::authenticate(const QString &password = QString(), QString *
}
ProtocolInfo
-TorControlPrototype::protocolInfo(QString *errmsg = 0)
+TorControlPrototype::protocolInfo(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -112,7 +123,7 @@ TorControlPrototype::protocolInfo(QString *errmsg = 0)
}
BootstrapStatus
-TorControlPrototype::bootstrapStatus(QString *errmsg = 0)
+TorControlPrototype::bootstrapStatus(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -130,7 +141,7 @@ TorControlPrototype::isCircuitEstablished()
}
bool
-TorControlPrototype::getInfo(QHash<QString,QString> &map, QString *errmsg = 0)
+TorControlPrototype::getInfo(QHash<QString,QString> &map, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -139,7 +150,7 @@ TorControlPrototype::getInfo(QHash<QString,QString> &map, QString *errmsg = 0)
}
bool
-TorControlPrototype::getInfo(QString key, QString &val, QString *errmsg = 0)
+TorControlPrototype::getInfo(QString key, QString &val, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -148,7 +159,7 @@ TorControlPrototype::getInfo(QString key, QString &val, QString *errmsg = 0)
}
QVariantMap
-TorControlPrototype::getInfo(const QStringList &keys, QString *errmsg = 0)
+TorControlPrototype::getInfo(const QStringList &keys, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -157,7 +168,7 @@ TorControlPrototype::getInfo(const QStringList &keys, QString *errmsg = 0)
}
QVariant
-TorControlPrototype::getInfo(const QString &key, QString *errmsg = 0)
+TorControlPrototype::getInfo(const QString &key, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -166,7 +177,7 @@ TorControlPrototype::getInfo(const QString &key, QString *errmsg = 0)
}
bool
-TorControlPrototype::signal(TorSignal::Signal sig, QString *errmsg = 0)
+TorControlPrototype::signal(TorSignal::Signal sig, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -175,7 +186,7 @@ TorControlPrototype::signal(TorSignal::Signal sig, QString *errmsg = 0)
}
QHostAddress
-TorControlPrototype::getSocksAddress(QString *errmsg = 0)
+TorControlPrototype::getSocksAddress(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -184,7 +195,7 @@ TorControlPrototype::getSocksAddress(QString *errmsg = 0)
}
QStringList
-TorControlPrototype::getSocksAddressList(QString *errmsg = 0)
+TorControlPrototype::getSocksAddressList(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -193,7 +204,7 @@ TorControlPrototype::getSocksAddressList(QString *errmsg = 0)
}
quint16
-TorControlPrototype::getSocksPort(QString *errmsg = 0)
+TorControlPrototype::getSocksPort(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -201,8 +212,8 @@ TorControlPrototype::getSocksPort(QString *errmsg = 0)
return obj->getSocksPort(errmsg);
}
-QList
-TorControlPrototype::<quint16> getSocksPortList(QString *errmsg = 0)
+QList<quint16>
+TorControlPrototype::getSocksPortList(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -229,7 +240,7 @@ TorControlPrototype::getTorVersion()
}
bool
-TorControlPrototype::setEvent(TorEvents::Event e, bool add = true, bool set = true, QString *errmsg = 0)
+TorControlPrototype::setEvent(TorEvents::Event e, bool add, bool set, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -238,7 +249,7 @@ TorControlPrototype::setEvent(TorEvents::Event e, bool add = true, bool set = tr
}
bool
-TorControlPrototype::setEvents(QString *errmsg = 0)
+TorControlPrototype::setEvents(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -247,7 +258,7 @@ TorControlPrototype::setEvents(QString *errmsg = 0)
}
bool
-TorControlPrototype::setConf(QHash<QString,QString> map, QString *errmsg = 0)
+TorControlPrototype::setConf(QHash<QString,QString> map, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -256,7 +267,7 @@ TorControlPrototype::setConf(QHash<QString,QString> map, QString *errmsg = 0)
}
bool
-TorControlPrototype::setConf(QString key, QString value, QString *errmsg = 0)
+TorControlPrototype::setConf(QString key, QString value, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -265,7 +276,7 @@ TorControlPrototype::setConf(QString key, QString value, QString *errmsg = 0)
}
bool
-TorControlPrototype::setConf(QString keyAndValue, QString *errmsg = 0)
+TorControlPrototype::setConf(QString keyAndValue, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -274,7 +285,7 @@ TorControlPrototype::setConf(QString keyAndValue, QString *errmsg = 0)
}
bool
-TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg = 0)
+TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -283,7 +294,7 @@ TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg = 0)
}
bool
-TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg = 0)
+TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -292,7 +303,7 @@ TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg =
}
bool
-TorControlPrototype::getConf(QString key, QString &value, QString *errmsg = 0)
+TorControlPrototype::getConf(QString key, QString &value, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -301,7 +312,7 @@ TorControlPrototype::getConf(QString key, QString &value, QString *errmsg = 0)
}
bool
-TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg = 0)
+TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -310,7 +321,7 @@ TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg =
}
QVariantMap
-TorControlPrototype::getConf(const QStringList &keys, QString *errmsg = 0)
+TorControlPrototype::getConf(const QStringList &keys, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -319,7 +330,7 @@ TorControlPrototype::getConf(const QStringList &keys, QString *errmsg = 0)
}
QVariant
-TorControlPrototype::getConf(const QString &key, QString *errmsg = 0)
+TorControlPrototype::getConf(const QString &key, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -328,7 +339,7 @@ TorControlPrototype::getConf(const QString &key, QString *errmsg = 0)
}
QString
-TorControlPrototype::getHiddenServiceConf(const QString &key, QString *errmsg = 0)
+TorControlPrototype::getHiddenServiceConf(const QString &key, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -337,7 +348,7 @@ TorControlPrototype::getHiddenServiceConf(const QString &key, QString *errmsg =
}
bool
-TorControlPrototype::saveConf(QString *errmsg = 0)
+TorControlPrototype::saveConf(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -346,7 +357,7 @@ TorControlPrototype::saveConf(QString *errmsg = 0)
}
bool
-TorControlPrototype::resetConf(QStringList keys, QString *errmsg = 0)
+TorControlPrototype::resetConf(QStringList keys, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -355,7 +366,7 @@ TorControlPrototype::resetConf(QStringList keys, QString *errmsg = 0)
}
bool
-TorControlPrototype::resetConf(QString key, QString *errmsg = 0)
+TorControlPrototype::resetConf(QString key, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -364,7 +375,7 @@ TorControlPrototype::resetConf(QString key, QString *errmsg = 0)
}
QStringList
-TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg = 0)
+TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -373,7 +384,7 @@ TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg
}
RouterDescriptor
-TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg = 0)
+TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -382,7 +393,7 @@ TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg = 0)
}
RouterStatus
-TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg = 0)
+TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -391,7 +402,7 @@ TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg = 0)
}
NetworkStatus
-TorControlPrototype::getNetworkStatus(QString *errmsg = 0)
+TorControlPrototype::getNetworkStatus(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -400,7 +411,7 @@ TorControlPrototype::getNetworkStatus(QString *errmsg = 0)
}
DescriptorAnnotations
-TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg = 0)
+TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -409,7 +420,7 @@ TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg
}
CircuitList
-TorControlPrototype::getCircuits(QString *errmsg = 0)
+TorControlPrototype::getCircuits(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -418,7 +429,7 @@ TorControlPrototype::getCircuits(QString *errmsg = 0)
}
StreamList
-TorControlPrototype::getStreams(QString *errmsg = 0)
+TorControlPrototype::getStreams(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -427,7 +438,7 @@ TorControlPrototype::getStreams(QString *errmsg = 0)
}
AddressMap
-TorControlPrototype::getAddressMap(AddressMap::AddressMapType type = AddressMap::AddressMapAll, QString *errmsg = 0)
+TorControlPrototype::getAddressMap(AddressMap::AddressMapType type, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -436,7 +447,7 @@ TorControlPrototype::getAddressMap(AddressMap::AddressMapType type = AddressMap:
}
QString
-TorControlPrototype::ipToCountry(const QHostAddress &ip, QString *errmsg = 0)
+TorControlPrototype::ipToCountry(const QHostAddress &ip, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -445,7 +456,7 @@ TorControlPrototype::ipToCountry(const QHostAddress &ip, QString *errmsg = 0)
}
bool
-TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused = false, QString *errmsg = 0)
+TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
@@ -454,7 +465,7 @@ TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused = false
}
bool
-TorControlPrototype::closeStream(const StreamId &streamId, QString *errmsg = 0)
+TorControlPrototype::closeStream(const StreamId &streamId, QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
index 0327b74..196a378 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.h
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.h
@@ -16,9 +16,11 @@
#ifndef _TORCONTROLPROTO_H
#define _TORCONTROLPROTO_H
+#include <QtGui>
#include <QtScript>
#include "TorControl.h"
+#include "ProtocolInfo.h"
class TorControlPrototype : public QObject, QScriptable
{
@@ -27,6 +29,9 @@ class TorControlPrototype : public QObject, QScriptable
public:
TorControlPrototype();
+ static int metaTypeId();
+ static QString name();
+
/** Start the Tor process */
Q_INVOKABLE void start(const QString &tor, const QStringList &args);
/** Stop the Tor process */
@@ -345,6 +350,8 @@ signals:
void serverDescriptorAccepted();
};
+Q_DECLARE_METATYPE(TorControl *);
+
#endif
1
0

[vidalia/alpha] First rusty working version of TorControlPrototype
by chiiph@torproject.org 02 Jul '11
by chiiph@torproject.org 02 Jul '11
02 Jul '11
commit ccbc7388fb15d808e5c90aa9d30cd9af48b1f1cf
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Wed Jun 15 00:24:14 2011 -0300
First rusty working version of TorControlPrototype
It needs work mainly in all the types that aren't automatically cohersed to
QVariant or something that javascript understands
---
src/vidalia/CMakeLists.txt | 2 +
src/vidalia/plugin/PluginEngine.cpp | 22 +-
src/vidalia/plugin/PluginEngine.h | 3 +-
.../plugin/prototypes/TorControlPrototype.cpp | 475 +++++++++-----------
.../plugin/prototypes/TorControlPrototype.h | 49 +-
5 files changed, 256 insertions(+), 295 deletions(-)
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 380b9e8..f340b65 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -89,6 +89,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
plugin/DebugDialog.cpp
plugin/prototypes/VidaliaTabPrototype.cpp
plugin/prototypes/HelperProcessPrototype.cpp
+ plugin/prototypes/TorControlPrototype.cpp
)
qt4_wrap_cpp(vidalia_SRCS
plugin/PluginEngine.h
@@ -96,6 +97,7 @@ qt4_wrap_cpp(vidalia_SRCS
plugin/DebugDialog.h
plugin/prototypes/VidaliaTabPrototype.h
plugin/prototypes/HelperProcessPrototype.h
+ plugin/prototypes/TorControlPrototype.h
)
## Configuration dialog sources
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 3f99025..4d6d745 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -3,6 +3,8 @@
#include "PluginWrapper.h"
#include "DebugDialog.h"
+#include "Vidalia.h"
+
PluginEngine::PluginEngine(QObject *parent)
: QScriptEngine(parent)
{
@@ -10,10 +12,13 @@ PluginEngine::PluginEngine(QObject *parent)
MAKE_CREATABLE(VidaliaTabPrototype)
ADD_PROTOTYPE(HelperProcessPrototype)
MAKE_CREATABLE(HelperProcessPrototype)
-// ADD_PROTOTYPE(TorControlPrototype)
+ ADD_PROTOTYPE(TorControlPrototype)
+
+ globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
+ globalObject().setProperty("vdebug", newFunction(vdebug));
VidaliaSettings settings;
globalObject().setProperty("pluginPath", QScriptValue(settings.pluginPath()));
@@ -163,3 +168,18 @@ PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
}
return true;
}
+
+QScriptValue
+PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
+{
+ QString result;
+ for(int i = 0; i<context->argumentCount(); i++) {
+ if(i>0)
+ result.append(" ");
+ result.append(context->argument(i).toString());
+ }
+
+ qWarning() << result;
+
+ return engine->undefinedValue();
+}
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 5b4cc25..13890f6 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -6,7 +6,7 @@
#include "VidaliaTabPrototype.h"
#include "HelperProcessPrototype.h"
-//#include "TorControlPrototype.h"
+#include "TorControlPrototype.h"
class PluginWrapper;
@@ -33,6 +33,7 @@ class PluginEngine : public QScriptEngine {
static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine);
static bool loadFile(QString fileName, QScriptEngine *engine);
static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
+ static QScriptValue vdebug(QScriptContext *context, QScriptEngine *engine);
void loadAllPlugins();
void tryLoadPlugin(QDir path);
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
index 972d100..56bccc0 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
@@ -1,5 +1,55 @@
#include "TorControlPrototype.h"
+#define GET_AND_CALL(type, func, res) \
+ type obj = qscriptvalue_cast<type>(thisObject()); \
+ if(obj) \
+ res = obj->func;
+
+#define MERGE2(result, errmsg) \
+ QVariant(QList<QVariant>() << result << errmsg);
+
+#define DEF_TYPE0(type, retType, func, call) \
+retType \
+type##Prototype::func \
+{ \
+ type *obj = qscriptvalue_cast<type *>(thisObject()); \
+ if(obj) \
+ return obj->call; \
+}
+
+#define DEF_TYPE1(type, resType, func, call) \
+QVariant \
+type##Prototype::func \
+{ \
+ resType res; \
+ QString errmsg; \
+\
+ type *obj = qscriptvalue_cast<type *>(thisObject()); \
+ if(obj) \
+ res = obj->call; \
+ QList<QVariant> vals; \
+ vals << res << QVariant(errmsg); \
+\
+ return vals; \
+}
+
+#define DEF_TYPE2(type, resType, ansType, func, call) \
+QVariant \
+type##Prototype::func \
+{ \
+ resType res; \
+ ansType ans; \
+ QString errmsg; \
+\
+ type *obj = qscriptvalue_cast<type *>(thisObject()); \
+ if(obj) \
+ res = obj->call; \
+ QList<QVariant> vals; \
+ vals << QVariant(ans) << res << QVariant(errmsg); \
+\
+ return vals; \
+}
+
TorControlPrototype::TorControlPrototype()
: QObject(), QScriptable() {}
@@ -13,187 +63,120 @@ TorControlPrototype::name() {
return QString("TorControl");
}
+DEF_TYPE0(TorControl, void,
+ start(const QString &tor, const QStringList &args),
+ start(tor, args))
-void
-TorControlPrototype::start(const QString &tor, const QStringList &args)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- obj->start(tor, args);
-}
-
-bool
-TorControlPrototype::stop(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->stop(errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ stop(),
+ stop(&errmsg))
-bool
-TorControlPrototype::isRunning()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE0(TorControl, bool,
+ isRunning(),
+ isRunning())
- if(obj)
- return obj->isRunning();
-}
+DEF_TYPE0(TorControl, bool,
+ isVidaliaRunningTor(),
+ isVidaliaRunningTor())
-bool
-TorControlPrototype::isVidaliaRunningTor()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE0(TorControl, void,
+ closeTorStdout(),
+ closeTorStdout())
- if(obj)
- return obj->isVidaliaRunningTor();
-}
-
-void
-TorControlPrototype::closeTorStdout()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- obj->closeTorStdout();
-}
-
-void
-TorControlPrototype::connect(const QHostAddress &address, quint16 port)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- obj->connect(address, port);
-}
-
-void
-TorControlPrototype::connect(const QString &path)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- obj->connect(path);
-}
-
-void
-TorControlPrototype::disconnect()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- obj->disconnect();
-}
+DEF_TYPE0(TorControl, void,
+ connect(const QHostAddress &address, quint16 port),
+ connect(address, port))
-bool
-TorControlPrototype::isConnected()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE0(TorControl, void,
+ connect(const QString &path),
+ connect(path))
- if(obj)
- return obj->isConnected();
-}
+DEF_TYPE0(TorControl, void,
+ disconnect(),
+ disconnect())
-bool
-TorControlPrototype::authenticate(const QByteArray cookie, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE0(TorControl, bool,
+ isConnected(),
+ isConnected())
- if(obj)
- return obj->authenticate(cookie, errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ authenticate(const QByteArray cookie),
+ authenticate(cookie, &errmsg))
-bool
-TorControlPrototype::authenticate(const QString &password, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE1(TorControl, bool,
+ authenticate(const QString &password),
+ authenticate(password, &errmsg))
- if(obj)
- return obj->authenticate(password, errmsg);
-}
+// TODO: make a QVariant for this two
+//QVariant
+//TorControlPrototype::protocolInfo()
+//{
+// ProtocolInfo info;
+// QString errmsg;
-ProtocolInfo
-TorControlPrototype::protocolInfo(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// GET_AND_CALL(TorControl *, protocolInfo(&errmsg), info)
- if(obj)
- return obj->protocolInfo(errmsg);
-}
+// return MERGE2(info, errmsg);
+//}
-BootstrapStatus
-TorControlPrototype::bootstrapStatus(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+//BootstrapStatus
+//TorControlPrototype::bootstrapStatus(QString *errmsg)
+//{
+// BootstrapStatus status;
+// QString errmsg;
- if(obj)
- return obj->bootstrapStatus(errmsg);
-}
+// GET_AND_CALL(TorControl *, protocolInfo(&errmsg), status)
-bool
-TorControlPrototype::isCircuitEstablished()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// return MERGE2(status, errmsg);
+//}
- if(obj)
- return obj->isCircuitEstablished();
-}
+DEF_TYPE0(TorControl, bool,
+ isCircuitEstablished(),
+ isCircuitEstablished())
-bool
-TorControlPrototype::getInfo(QHash<QString,QString> &map, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE1(TorControl, bool,
+ getInfo(QHash<QString,QString> &map),
+ getInfo(map, &errmsg))
- if(obj)
- return obj->getInfo(map, errmsg);
-}
+// TODO: this one may be useless
+//QVariant
+//TorControlPrototype::getInfo(QString key)
+//{
+// TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// QString val, *errmsg = new QString();
+// bool res = false;
+// QList<QVariant> vals;
-bool
-TorControlPrototype::getInfo(QString key, QString &val, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// if(obj)
+// res = obj->getInfo(key, val, errmsg);
- if(obj)
- return obj->getInfo(key, val, errmsg);
-}
+// vals.append(QVariant(res));
+// vals.append(QVariant(val));
+// vals.append(QVariant(*errmsg));
-QVariantMap
-TorControlPrototype::getInfo(const QStringList &keys, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// return QVariant(vals);
+//}
- if(obj)
- return obj->getInfo(keys, errmsg);
-}
+// TODO: There is no StringList, this may be useless
+//DEF_TYPE1(TorControl, QVariantMap,
+// getInfo(const QStringList &keys),
+// getInfo(keys, &errmsg))
-QVariant
-TorControlPrototype::getInfo(const QString &key, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getInfo(key, errmsg);
-}
-
-bool
-TorControlPrototype::signal(TorSignal::Signal sig, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->signal(sig, errmsg);
-}
-
-QHostAddress
-TorControlPrototype::getSocksAddress(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getSocksAddress(errmsg);
-}
+DEF_TYPE1(TorControl, QVariant,
+ getInfo(const QString &key),
+ getInfo(key, &errmsg))
+
+DEF_TYPE1(TorControl, bool,
+ signal(TorSignal::Signal sig),
+ signal(sig, &errmsg))
+
+// TODO: QVariant don't like QHostAddress
+//DEF_TYPE1(TorControl, QHostAddress,
+// getSocksAddress(),
+// getSocksAddress(&errmsg))
+// TODO: make it a QVariant(QList<QVariant>() << QVariant(QString) <<
+// QVariant(QString) ...
QStringList
TorControlPrototype::getSocksAddressList(QString *errmsg)
{
@@ -203,87 +186,53 @@ TorControlPrototype::getSocksAddressList(QString *errmsg)
return obj->getSocksAddressList(errmsg);
}
-quint16
-TorControlPrototype::getSocksPort(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getSocksPort(errmsg);
-}
+DEF_TYPE1(TorControl, quint16,
+ getSocksPort(),
+ getSocksPort(&errmsg))
+// TODO: same as getSocksAddressList but with quint16
QList<quint16>
TorControlPrototype::getSocksPortList(QString *errmsg)
{
TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
if(obj)
- return obj->quint16> getSocksPortList(errmsg);
+ return obj->getSocksPortList(errmsg);
}
-QString
-TorControlPrototype::getTorVersionString()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE0(TorControl, QString,
+ getTorVersionString(),
+ getTorVersionString())
- if(obj)
- return obj->getTorVersionString();
-}
+DEF_TYPE0(TorControl, quint32,
+ getTorVersion(),
+ getTorVersion())
-quint32
-TorControlPrototype::getTorVersion()
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE1(TorControl, bool,
+ setEvent(TorEvents::Event e, bool add, bool set),
+ setEvent(e, add, set, &errmsg))
- if(obj)
- return obj->getTorVersion();
-}
+DEF_TYPE1(TorControl, bool,
+ setEvents(),
+ setEvents(&errmsg))
-bool
-TorControlPrototype::setEvent(TorEvents::Event e, bool add, bool set, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE1(TorControl, bool,
+ setConf(QHash<QString,QString> map),
+ setConf(map, &errmsg))
- if(obj)
- return obj->setEvent(e, add, set, errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ setConf(QString key, QString value),
+ setConf(key, value, &errmsg))
-bool
-TorControlPrototype::setEvents(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->setEvents(errmsg);
-}
-
-bool
-TorControlPrototype::setConf(QHash<QString,QString> map, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->setConf(map, errmsg);
-}
-
-bool
-TorControlPrototype::setConf(QString key, QString value, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- returb obj->setConf(key, value, errmsg);
-}
-
-bool
-TorControlPrototype::setConf(QString keyAndValue, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->setConf(keyAndValue, errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ setConf(QString keyAndValue),
+ setConf(keyAndValue, &errmsg))
+// TODO: macros don't like template variables
+// do this one by hand
+//DEF_TYPE2(TorControl, bool, QHash<QString,QString>,
+// getConf(QHash<QString,QString> &map),
+// getConf(map, &errmsg))
bool
TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg)
{
@@ -293,6 +242,7 @@ TorControlPrototype::getConf(QHash<QString,QString> &map, QString *errmsg)
return obj->getConf(map, errmsg);
}
+// TODO: this one too
bool
TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg)
{
@@ -302,15 +252,11 @@ TorControlPrototype::getConf(QHash<QString,QStringList> &map, QString *errmsg)
return obj->getConf(map, errmsg);
}
-bool
-TorControlPrototype::getConf(QString key, QString &value, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(key, value, errmsg);
-}
+DEF_TYPE2(TorControl, bool, QString,
+ getConf(QString key),
+ getConf(key, ans, &errmsg))
+// TODO: same as the last one with StringList
bool
TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg)
{
@@ -320,6 +266,7 @@ TorControlPrototype::getConf(QString key, QStringList &value, QString *errmsg)
return obj->getConf(key, value, errmsg);
}
+// TODO: idem
QVariantMap
TorControlPrototype::getConf(const QStringList &keys, QString *errmsg)
{
@@ -329,33 +276,25 @@ TorControlPrototype::getConf(const QStringList &keys, QString *errmsg)
return obj->getConf(keys, errmsg);
}
-QVariant
-TorControlPrototype::getConf(const QString &key, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->getConf(key, errmsg);
-}
-
-QString
-TorControlPrototype::getHiddenServiceConf(const QString &key, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+// TODO: possibly useless
+//QVariant
+//TorControlPrototype::getConf(const QString &key, QString *errmsg)
+//{
+// TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
- if(obj)
- return obj->getHiddenServiceConf(key, errmsg);
-}
+// if(obj)
+// return obj->getConf(key, errmsg);
+//}
-bool
-TorControlPrototype::saveConf(QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
+DEF_TYPE1(TorControl, QString,
+ getHiddenServiceConf(const QString &key),
+ getHiddenServiceConf(key, &errmsg))
- if(obj)
- return obj->saveConf(errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ saveConf(),
+ saveConf(&errmsg))
+// TODO: another stringlist one
bool
TorControlPrototype::resetConf(QStringList keys, QString *errmsg)
{
@@ -365,15 +304,11 @@ TorControlPrototype::resetConf(QStringList keys, QString *errmsg)
return obj->resetConf(keys, errmsg);
}
-bool
-TorControlPrototype::resetConf(QString key, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->resetConf(key, errmsg);
-}
+DEF_TYPE1(TorControl, bool,
+ resetConf(QString key),
+ resetConf(key, &errmsg))
+// TODO: you know
QStringList
TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg)
{
@@ -383,6 +318,7 @@ TorControlPrototype::getRouterDescriptorText(const QString &id, QString *errmsg)
return obj->getRouterDescriptorText(id, errmsg);
}
+// TODO: QVariantize RouterDescriptor
RouterDescriptor
TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg)
{
@@ -392,6 +328,7 @@ TorControlPrototype::getRouterDescriptor(const QString &id, QString *errmsg)
return obj->getRouterDescriptor(id, errmsg);
}
+// TODO: QVariantize RouterStatus
RouterStatus
TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg)
{
@@ -401,6 +338,7 @@ TorControlPrototype::getRouterStatus(const QString &id, QString *errmsg)
return obj->getRouterStatus(id, errmsg);
}
+// TODO: QVariantize NetworkStatus
NetworkStatus
TorControlPrototype::getNetworkStatus(QString *errmsg)
{
@@ -410,6 +348,7 @@ TorControlPrototype::getNetworkStatus(QString *errmsg)
return obj->getNetworkStatus(errmsg);
}
+// TODO: QVariantize DescriptorAnnotations
DescriptorAnnotations
TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg)
{
@@ -419,6 +358,7 @@ TorControlPrototype::getDescriptorAnnotations(const QString &id, QString *errmsg
return obj->getDescriptorAnnotations(id, errmsg);
}
+// TODO: QVariantize CircuitList
CircuitList
TorControlPrototype::getCircuits(QString *errmsg)
{
@@ -428,6 +368,7 @@ TorControlPrototype::getCircuits(QString *errmsg)
return obj->getCircuits(errmsg);
}
+// TODO: QVariantize StreamList
StreamList
TorControlPrototype::getStreams(QString *errmsg)
{
@@ -437,6 +378,7 @@ TorControlPrototype::getStreams(QString *errmsg)
return obj->getStreams(errmsg);
}
+// TODO: QVariantize AddressMap
AddressMap
TorControlPrototype::getAddressMap(AddressMap::AddressMapType type, QString *errmsg)
{
@@ -446,15 +388,11 @@ TorControlPrototype::getAddressMap(AddressMap::AddressMapType type, QString *err
return obj->getAddressMap(type, errmsg);
}
-QString
-TorControlPrototype::ipToCountry(const QHostAddress &ip, QString *errmsg)
-{
- TorControl *obj = qscriptvalue_cast<TorControl *>(thisObject());
-
- if(obj)
- return obj->ipToCountry(ip, errmsg);
-}
+DEF_TYPE1(TorControl, QString,
+ ipToCountry(const QHostAddress &ip),
+ ipToCountry(ip, &errmsg))
+// TODO: migrate CircuitId
bool
TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused, QString *errmsg)
{
@@ -464,6 +402,7 @@ TorControlPrototype::closeCircuit(const CircuitId &circId, bool ifUnused, QStrin
return obj->closeCircuit(circId, ifUnused, errmsg);
}
+// TODO: migrate StreamId
bool
TorControlPrototype::closeStream(const StreamId &streamId, QString *errmsg)
{
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
index 196a378..8127c76 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.h
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.h
@@ -35,7 +35,7 @@ public:
/** Start the Tor process */
Q_INVOKABLE void start(const QString &tor, const QStringList &args);
/** Stop the Tor process */
- Q_INVOKABLE bool stop(QString *errmsg = 0);
+ Q_INVOKABLE QVariant stop();
/** Detect if the Tor process is running */
Q_INVOKABLE bool isRunning();
/** Detects if the Tor process is running under Vidalia. */
@@ -52,46 +52,46 @@ public:
/** Check if we're connected to Tor's control socket */
Q_INVOKABLE bool isConnected();
/** Sends an authentication cookie to Tor. */
- Q_INVOKABLE bool authenticate(const QByteArray cookie, QString *errmsg = 0);
+ Q_INVOKABLE QVariant authenticate(const QByteArray cookie);
/** Sends an authentication password to Tor. */
- Q_INVOKABLE bool authenticate(const QString &password = QString(), QString *errmsg = 0);
+ Q_INVOKABLE QVariant authenticate(const QString &password = QString());
/** Sends a PROTOCOLINFO command to Tor and parses the response. */
- Q_INVOKABLE ProtocolInfo protocolInfo(QString *errmsg = 0);
+// Q_INVOKABLE QVariant protocolInfo();
/** Returns the Tor software's current bootstrap phase and status. */
- Q_INVOKABLE BootstrapStatus bootstrapStatus(QString *errmsg = 0);
+// Q_INVOKABLE BootstrapStatus bootstrapStatus(QString *errmsg = 0);
/** Returns true if Tor either has an open circuit or (on Tor >=
* 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
Q_INVOKABLE bool isCircuitEstablished();
/** Sends a GETINFO message to Tor based on the given keys */
- Q_INVOKABLE bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
+ Q_INVOKABLE QVariant getInfo(QHash<QString,QString> &map);
/** Sends a GETINFO message for a single info value to Tor */
- Q_INVOKABLE bool getInfo(QString key, QString &val, QString *errmsg = 0);
+// Q_INVOKABLE QVariant getInfo(QString key);
/** Sends a GETINFO message to Tor using the given list of <b>keys</b> and
* returns a QVariantMap containing the specified keys and their values as
* returned by Tor. Returns a default constructed QVariantMap on failure. */
- Q_INVOKABLE QVariantMap getInfo(const QStringList &keys, QString *errmsg = 0);
+// Q_INVOKABLE QVariantMap getInfo(const QStringList &keys, QString *errmsg = 0);
/** Sends a GETINFO message to Tor with a single <b>key</b> and returns a
* QVariant containing the value returned by Tor. Returns a default
* constructed QVariant on failure. */
- Q_INVOKABLE QVariant getInfo(const QString &key, QString *errmsg = 0);
+ Q_INVOKABLE QVariant getInfo(const QString &key);
/** Sends a signal to Tor */
- Q_INVOKABLE bool signal(TorSignal::Signal sig, QString *errmsg = 0);
+ Q_INVOKABLE QVariant signal(TorSignal::Signal sig);
/** Returns an address on which Tor is listening for application
* requests. If none are available, a null QHostAddress is returned. */
- Q_INVOKABLE QHostAddress getSocksAddress(QString *errmsg = 0);
+// Q_INVOKABLE QVariant getSocksAddress();
/** Returns a (possibly empty) list of all currently configured
* SocksListenAddress entries. */
Q_INVOKABLE QStringList getSocksAddressList(QString *errmsg = 0);
/** Returns a valid SOCKS port for Tor, or 0 if Tor is not accepting
* application requests. */
- Q_INVOKABLE quint16 getSocksPort(QString *errmsg = 0);
+ Q_INVOKABLE QVariant getSocksPort();
/** Returns a list of all currently configured SOCKS ports. If Tor is not
* accepting any application connections, an empty list will be returned. */
Q_INVOKABLE QList<quint16> getSocksPortList(QString *errmsg = 0);
@@ -104,24 +104,23 @@ public:
/** Sets an event and its handler. If add is true, then the event is added,
* otherwise it is removed. If set is true, then the given event will be
* registered with Tor. */
- Q_INVOKABLE bool setEvent(TorEvents::Event e, bool add = true, bool set = true,
- QString *errmsg = 0);
+ Q_INVOKABLE QVariant setEvent(TorEvents::Event e, bool add = true, bool set = true);
/** Register events of interest with Tor */
- Q_INVOKABLE bool setEvents(QString *errmsg = 0);
+ Q_INVOKABLE QVariant setEvents();
/** Sets each configuration key in <b>map</b> to the value associated with its key. */
- Q_INVOKABLE bool setConf(QHash<QString,QString> map, QString *errmsg = 0);
+ Q_INVOKABLE QVariant setConf(QHash<QString,QString> map);
/** Sets a single configuration key to the given value. */
- Q_INVOKABLE bool setConf(QString key, QString value, QString *errmsg = 0);
+ Q_INVOKABLE QVariant setConf(QString key, QString value);
/** Sets a single configuration string that is formatted <key=escaped value>. */
- Q_INVOKABLE bool setConf(QString keyAndValue, QString *errmsg = 0);
+ Q_INVOKABLE QVariant setConf(QString keyAndValue);
/** Gets values for a set of configuration keys, each of which has a single
* value. */
- Q_INVOKABLE bool getConf(QHash<QString,QString> &map, QString *errmsg = 0);
+ Q_INVOKABLE bool getConf(QHash<QString,QString> &map, QString *errmsg);
/** Gets a set of configuration keyvalues and stores them in <b>map</b>. */
Q_INVOKABLE bool getConf(QHash<QString,QStringList> &map, QString *errmsg = 0);
/** Gets a single configuration value for <b>key</b>. */
- Q_INVOKABLE bool getConf(QString key, QString &value, QString *errmsg = 0);
+ Q_INVOKABLE QVariant getConf(QString key);
/** Gets a list of configuration values for <b>key</b>. */
Q_INVOKABLE bool getConf(QString key, QStringList &value, QString *errmsg = 0);
@@ -132,17 +131,17 @@ public:
/** Sends a GETCONF message to Tor with a single <b>key</b> and returns a
* QVariant containing the value returned by Tor. Returns a default
* constructed QVariant on failure. */
- Q_INVOKABLE QVariant getConf(const QString &key, QString *errmsg = 0);
+// Q_INVOKABLE QVariant getConf(const QString &key, QString *errmsg = 0);
/** Sends a GETCONF message to Tor with the single key and returns a QString
* containing the value returned by Tor */
- Q_INVOKABLE QString getHiddenServiceConf(const QString &key, QString *errmsg = 0);
+ Q_INVOKABLE QVariant getHiddenServiceConf(const QString &key);
/** Asks Tor to save the current configuration to its torrc */
- Q_INVOKABLE bool saveConf(QString *errmsg = 0);
+ Q_INVOKABLE QVariant saveConf();
/** Tells Tor to reset the given configuration keys back to defaults. */
Q_INVOKABLE bool resetConf(QStringList keys, QString *errmsg = 0);
/** Tells Tor to reset a configuration key back to its default value. */
- Q_INVOKABLE bool resetConf(QString key, QString *errmsg = 0);
+ Q_INVOKABLE QVariant resetConf(QString key);
/** Returns an unparsed router descriptor for the router whose fingerprint
* matches <b>id</b>. The returned text can later be parsed by the
@@ -183,7 +182,7 @@ public:
* Returns a default-constructed QString on failure or if a country code
* is not known for <b>ip</b>. On failure, <b>errmsg</b> will be set if
* it's not NULL. */
- Q_INVOKABLE QString ipToCountry(const QHostAddress &ip, QString *errmsg = 0);
+ Q_INVOKABLE QVariant ipToCountry(const QHostAddress &ip);
public slots:
/** Closes the circuit specified by <b>circId</b>. If <b>ifUnused</b> is
1
0
commit d6416b36e8378de1e59ad7532f9d44e8a9539364
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sun Jun 26 19:17:08 2011 -0300
Improve engine and clean some code
Removes all TBB related code, since it's now in a plugin.
Adds minor improvements to the engine, and the possibility of having a real
debugger.
---
src/vidalia/MainWindow.cpp | 241 --------------------
src/vidalia/MainWindow.h | 29 ---
src/vidalia/plugin/PluginEngine.cpp | 26 ++
src/vidalia/plugin/PluginEngine.h | 4 +
.../plugin/prototypes/HelperProcessPrototype.cpp | 14 ++
.../plugin/prototypes/HelperProcessPrototype.h | 2 +
6 files changed, 46 insertions(+), 270 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index bcc3538..56b24c7 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -401,24 +401,6 @@ MainWindow::createConnections()
connect(UPNPControl::instance(), SIGNAL(error(UPNPControl::UPNPError)),
this, SLOT(upnpError(UPNPControl::UPNPError)));
#endif
- /* Create a new HelperProcess object, used to start the web browser */
- _browserProcess = new HelperProcess(this);
- connect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(onSubprocessFinished(int, QProcess::ExitStatus)));
- connect(_browserProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onBrowserFailed(QString)));
-
- /* Create a new HelperProcess object, used to start the IM client */
- _imProcess = new HelperProcess(this);
- connect(_imProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(onSubprocessFinished(int, QProcess::ExitStatus)));
- connect(_imProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onIMFailed(QString)));
-
- /* Create a new HelperProcess object, used to start the proxy server */
- _proxyProcess = new HelperProcess(this);
- connect(_proxyProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onProxyFailed(QString)));
connect(_engine, SIGNAL(pluginTab(VidaliaTab *)),
this, SLOT(addTab(VidaliaTab *)));
@@ -470,10 +452,6 @@ MainWindow::running()
start();
}
- /* Start the proxy server, if configured */
- if (settings.runProxyAtStart())
- startProxy();
-
#if defined(USE_AUTOUPDATE)
if (settings.isAutoUpdateEnabled()) {
QDateTime lastCheckedAt = settings.lastCheckedForUpdates();
@@ -519,33 +497,6 @@ MainWindow::aboutToQuit()
ServerSettings settings(_torControl);
settings.cleanupPortForwarding();
- if (_proxyProcess->state() != QProcess::NotRunning) {
- /* Close the proxy server (Polipo ignores the WM_CLOSE event sent by
- * terminate() so we have to kill() it) */
- _proxyProcess->kill();
- }
-
- /* Kill the browser and IM client if using the new launcher */
- VidaliaSettings vidalia_settings;
-
- if (! vidalia_settings.getBrowserDirectory().isEmpty()) {
- /* Disconnect the finished signals so that we won't try to exit Vidalia again */
- QObject::disconnect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)), 0, 0);
- QObject::disconnect(_imProcess, SIGNAL(finished(int, QProcess::ExitStatus)), 0, 0);
-
- /* Use QProcess terminate function */
- if (_browserProcess->state() == QProcess::Running)
- _browserProcess->terminate();
-
-#if defined(Q_OS_WIN)
- /* Kill any processes which might have been forked off */
- win32_end_process_by_filename(vidalia_settings.getBrowserExecutable());
-#endif
-
- if (_imProcess->state() == QProcess::Running)
- _imProcess->terminate();
- }
-
/* Disconnect all of the TorControl object's signals */
QObject::disconnect(_torControl, 0, 0, 0);
}
@@ -1061,7 +1012,6 @@ MainWindow::circuitEstablished()
// TODO: fix hardcoded total length
setStartupProgress(130,
tr("Connected to the Tor network!"));
- startSubprocesses();
#if defined(USE_AUTOUPDATE)
VidaliaSettings settings;
@@ -1346,7 +1296,6 @@ MainWindow::updateTorStatus(TorStatus status)
trayIconFile = IMG_TOR_STOPPING;
statusIconFile = IMG_TOR_STOPPING_48;
-// ui.btnStartStopTor->setStatusTip(tr("Stop Tor Now"));
} else if (status == Started) {
actionText = tr("Stop Tor");
_actionRestartTor->setEnabled(true);
@@ -1512,7 +1461,6 @@ MainWindow::newIdentity()
/* Disable the New Identity button for MIN_NEWIDENTITY_INTERVAL */
_actionNewIdentity->setEnabled(false);
-// ui.lblNewIdentity->setEnabled(false);
QTimer::singleShot(MIN_NEWIDENTITY_INTERVAL,
this, SLOT(enableNewIdentity()));
@@ -1817,192 +1765,3 @@ MainWindow::installUpdatesFailed(const QString &errmsg)
#endif
-/** Called when browser or IM client have exited */
-void
-MainWindow::onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus)
-{
- Q_UNUSED(exitCode)
- Q_UNUSED(exitStatus)
-
- /* Get path to browser and IM client */
- VidaliaSettings settings;
- QString browserExecutable = settings.getBrowserExecutable();
- QString browserDirectory = settings.getBrowserDirectory();
- QString imExecutable = settings.getIMExecutable();
-
- /* A subprocess is finished if it successfully exited or was never asked to start */
- bool browserDone = (browserExecutable.isEmpty()
- && browserDirectory.isEmpty())
- || _browserProcess->isDone();
- bool imDone = imExecutable.isEmpty() || _imProcess->isDone();
-
- /* Exit if both subprocesses are finished */
- if (browserDone && imDone) {
- if (browserDirectory.isEmpty()) {
- /* We are using the standard launcher, exit immediately */
- vApp->quit();
- } else {
- /* We are using the alternate launcher, wait until the browser has really died */
- QTimer *browserWatcher = new QTimer(this);
- connect(browserWatcher, SIGNAL(timeout()), this, SLOT(onCheckForBrowser()));
- browserWatcher->start(2000);
- }
- }
-}
-
-/** Called periodically to check if the browser is running. If it is not,
- * exit Vidalia cleanly */
-void
-MainWindow::onCheckForBrowser()
-{
-/* This only works on Windows for now */
-#if defined(Q_OS_WIN)
-
- VidaliaSettings settings;
- QString browserDirectoryFilename = settings.getBrowserExecutable();
-
- /* Get list of running processes */
- QHash<qint64, QString> procList = win32_process_list();
-
- /* On old versions of Windows win32_process_list() will return
- an empty list. In this case, just keep Vidalia open */
- if (procList.isEmpty()) {
- return;
- }
-
- /* Loop over all processes or until we find <browserDirectoryFilename> */
- QHashIterator<qint64, QString> i(procList);
- while (i.hasNext()) {
- i.next();
- if (i.value().toLower() == browserDirectoryFilename) {
- /* The browser is still running, so Vidalia should keep running too */
- return;
- }
- }
-
- /* The browser isn't running, exit Vidalia */
- vApp->quit();
-#endif
-}
-
-/** Called when the web browser failed to start, for example, because the path
- * specified to the web browser executable didn't lead to an executable. */
-void
-MainWindow::onBrowserFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting web browser"),
- tr("Vidalia was unable to start the configured web browser"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Called when the IM client failed to start, for example, because the path
- * specified to the IM client executable didn't lead to an executable. */
-void
-MainWindow::onIMFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting IM client"),
- tr("Vidalia was unable to start the configured IM client"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Starts the proxy server, if appropriately configured */
-void
-MainWindow::startProxy()
-{
- VidaliaSettings settings;
- QString executable = settings.getProxyExecutable();
- _proxyProcess->start(executable, settings.getProxyExecutableArguments());
-}
-
-/** Called when the proxy server fails to start, for example, because
- * the path specified didn't lead to an executable. */
-void
-MainWindow::onProxyFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting proxy server"),
- tr("Vidalia was unable to start the configured proxy server"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Start a web browser when given the directory containing the executable and profile */
-void
-MainWindow::launchBrowserFromDirectory()
-{
- VidaliaSettings settings;
-
- QString browserDirectory = settings.getBrowserDirectory();
- QString browserDirectoryFilename = settings.getBrowserExecutable();
-
- /* Set TZ=UTC (to stop leaking timezone information) and
- * MOZ_NO_REMOTE=1 (to allow multiple instances of Firefox */
- QStringList env = QProcess::systemEnvironment();
- env << "TZ=UTC";
- env << "MOZ_NO_REMOTE=1";
- _browserProcess->setEnvironment(env);
-
- /* The browser is in <browserDirectory>/App/Firefox/<browserDirectoryFilename> */
- QString browserExecutable =
- QDir::toNativeSeparators(browserDirectory + "/App/Firefox/" + browserDirectoryFilename);
- /* The profile is in <browserDirectory>/Data/profile */
- QString profileDir =
- QDir::toNativeSeparators(browserDirectory + "/Data/profile");
-
- /* Copy the profile directory if it's not already there */
- QDir browserDirObj = QDir(browserDirectory);
-
- /* Copy the profile directory if it's not already there */
- if (!browserDirObj.exists("Data/profile")) {
- browserDirObj.mkdir("Data/profile");
- copy_dir(browserDirectory + "/App/DefaultData/profile", browserDirectory + "/Data/profile");
- }
-
- /* Copy the plugins directory if it's not already there */
- if (!browserDirObj.exists("Data/plugins")) {
- browserDirObj.mkdir("Data/plugins");
- copy_dir(browserDirectory + "/App/DefaultData/plugins", browserDirectory + "/Data/plugins");
- }
-
- /* Build the command line arguments */
- QStringList commandLine;
- // Is this better or worse than MOZ_NO_REMOTE?
- commandLine << "-no-remote";
- commandLine << "-profile";
- commandLine << profileDir;
-
- /* Launch the browser */
- _browserProcess->start(browserExecutable, commandLine);
-}
-
-/** Starts the web browser and IM client, if appropriately configured */
-void
-MainWindow::startSubprocesses()
-{
- VidaliaSettings settings;
- QString subprocess;
-
- /* Launch the web browser */
- if (!(subprocess = settings.getBrowserDirectory()).isEmpty()) {
- /* The user has set BrowserDirectory; use this */
- launchBrowserFromDirectory();
- } else if (!(subprocess = settings.getBrowserExecutable()).isEmpty()) {
- /* BrowserDirectory is not set, but BrowserExecutable is; use this */
- _browserProcess->setEnvironment(QProcess::systemEnvironment() << "TZ=UTC");
- _browserProcess->start(subprocess, QStringList());
- }
-
- /* Launch the IM client */
- subprocess = settings.getIMExecutable();
-
- if (!subprocess.isEmpty())
- _imProcess->start(subprocess, QStringList());
-}
-
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 21ab1a2..3b7d544 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -147,21 +147,6 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
-// /** Handles adding a new tab corresponding to a plugin */
-// void showPluginTab();
-
- /** Called when the web browser or IM client have stopped */
- void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
- /** Called periodically to check if the browser is running. If it is not,
- * exit Vidalia cleanly */
- void onCheckForBrowser();
- /** Called web the web browser failed to start */
- void onBrowserFailed(QString errmsg);
- /** Called web the IM client failed to start */
- void onIMFailed(QString errmsg);
- /** Called when the proxy server fails to start */
- void onProxyFailed(QString errmsg);
-
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -264,20 +249,6 @@ private:
/** The Vidalia icon that sits in the tray. */
QSystemTrayIcon _trayIcon;
- /** Start a web browser when given the directory containing the executable and profile */
- void launchBrowserFromDirectory();
- /** Starts the web browser, if appropriately configured */
- void startSubprocesses();
- /** Starts the proxy server, if appropriately configured */
- void startProxy();
-
- /** A HelperProcess object that manages the web browser */
- HelperProcess* _browserProcess;
- /** A HelperProcess object that manages the IM client */
- HelperProcess* _imProcess;
- /** A HelperProcess object that manages the proxy server */
- HelperProcess* _proxyProcess;
-
#if defined(USE_AUTOUPDATE)
/** Timer used to remind us to check for software updates. */
QTimer _updateTimer;
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 4d6d745..f51607e 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -15,10 +15,12 @@ PluginEngine::PluginEngine(QObject *parent)
ADD_PROTOTYPE(TorControlPrototype)
globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
+ globalObject().setProperty("vidaliaApp", newQObject(vApp));
globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
globalObject().setProperty("vdebug", newFunction(vdebug));
+ globalObject().setProperty("findWidget", newFunction(findWidget));
VidaliaSettings settings;
globalObject().setProperty("pluginPath", QScriptValue(settings.pluginPath()));
@@ -28,6 +30,9 @@ PluginEngine::PluginEngine(QObject *parent)
DebugDialog::outputDebug(QString(" %1").arg(ext));
loadAllPlugins();
+
+// debugger.attachTo(this);
+// debugger.standardWindow()->show();
}
PluginEngine::~PluginEngine()
@@ -183,3 +188,24 @@ PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
return engine->undefinedValue();
}
+
+QScriptValue
+PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine) {
+ if(context->argumentCount() != 2)
+ return context->throwError(QString("findWidget called with the wrong argument count. Expected 2."));
+
+ QWidget *widget = qscriptvalue_cast<QWidget *>(context->argument(0));
+ QString name = context->argument(1).toString();
+
+ QObjectList list = widget->children();
+ QScriptValue ret = engine->nullValue();
+
+ for(int i = 0; i < list.length(); i++) {
+ if(list[i]->objectName() == name) {
+ ret = QScriptValue(i);
+ break;
+ }
+ }
+
+ return ret;
+}
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 13890f6..854ed15 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -3,6 +3,7 @@
#include <QtGui>
#include <QtScript>
+#include <QScriptEngineDebugger>
#include "VidaliaTabPrototype.h"
#include "HelperProcessPrototype.h"
@@ -34,11 +35,14 @@ class PluginEngine : public QScriptEngine {
static bool loadFile(QString fileName, QScriptEngine *engine);
static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
static QScriptValue vdebug(QScriptContext *context, QScriptEngine *engine);
+ static QScriptValue findWidget(QScriptContext *context, QScriptEngine *engine);
void loadAllPlugins();
void tryLoadPlugin(QDir path);
QList<PluginWrapper *> wrappers;
+
+ QScriptEngineDebugger debugger;
};
#endif
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
index 81d4d94..c2232e1 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
@@ -47,3 +47,17 @@ HelperProcessPrototype::isDone() const
return obj->isDone();
}
+QStringList
+HelperProcessPrototype::systemEnvironment()
+{
+ return HelperProcess::systemEnvironment();
+}
+
+void
+HelperProcessPrototype::setEnvironment(const QStringList &env)
+{
+ HelperProcess *obj = qscriptvalue_cast<HelperProcess *>(thisObject());
+
+ if(obj)
+ obj->setEnvironment(env);
+}
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.h b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
index b64a27c..1751347 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
@@ -19,6 +19,8 @@ class HelperProcessPrototype : public QObject, public QScriptable
Q_INVOKABLE void start(const QString &app, const QString &args);
Q_INVOKABLE void start(const QString &app, const QStringList &args);
Q_INVOKABLE bool isDone() const;
+ Q_INVOKABLE QStringList systemEnvironment();
+ Q_INVOKABLE void setEnvironment(const QStringList &env);
};
Q_DECLARE_METATYPE(HelperProcess *);
1
0
commit 1ac1c1746a3fe63bb9ba32f2ed1c1e13b12cda02
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sat Jul 2 18:46:57 2011 -0300
Remove debugger for now
---
src/vidalia/plugin/PluginEngine.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index d8dc273..2251e6c 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -57,7 +57,7 @@ class PluginEngine : public QScriptEngine {
QList<PluginWrapper *> wrappers;
- QScriptEngineDebugger debugger;
+// QScriptEngineDebugger debugger;
};
#endif
1
0

[vidalia/alpha] Add headers and temporary disable the include function
by chiiph@torproject.org 02 Jul '11
by chiiph@torproject.org 02 Jul '11
02 Jul '11
commit bad8cdb7ad327116311daca0c102c747aa0de568
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sat Jul 2 18:12:16 2011 -0300
Add headers and temporary disable the include function
The include function won't be on the 0.3.1 release, it doesn't work as of
today, so I'm disabling it.
---
src/vidalia/plugin/DebugDialog.cpp | 16 +++
src/vidalia/plugin/DebugDialog.h | 16 +++
src/vidalia/plugin/PluginEngine.cpp | 142 +++++++++----------
src/vidalia/plugin/PluginEngine.h | 19 +++-
src/vidalia/plugin/PluginWrapper.cpp | 15 ++
src/vidalia/plugin/PluginWrapper.h | 15 ++
.../plugin/prototypes/HelperProcessPrototype.cpp | 21 +++-
.../plugin/prototypes/TorControlPrototype.cpp | 15 ++
.../plugin/prototypes/TorControlPrototype.h | 10 +-
.../plugin/prototypes/VidaliaTabPrototype.cpp | 21 +++-
.../plugin/prototypes/VidaliaTabPrototype.h | 15 ++
11 files changed, 219 insertions(+), 86 deletions(-)
diff --git a/src/vidalia/plugin/DebugDialog.cpp b/src/vidalia/plugin/DebugDialog.cpp
index df2aa1e..683ed6a 100644
--- a/src/vidalia/plugin/DebugDialog.cpp
+++ b/src/vidalia/plugin/DebugDialog.cpp
@@ -1,3 +1,19 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file DebugDialog.cpp
+** \brief Simple dialog to see exceptions, syntaxis problems, and general
+** output for pluging
+*/
+
#include "DebugDialog.h"
QStringList DebugDialog::outputBuffer;
diff --git a/src/vidalia/plugin/DebugDialog.h b/src/vidalia/plugin/DebugDialog.h
index 76b3bb6..7f6ff0a 100644
--- a/src/vidalia/plugin/DebugDialog.h
+++ b/src/vidalia/plugin/DebugDialog.h
@@ -1,3 +1,19 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file DebugDialog.h
+** \brief Simple dialog to see exceptions, syntaxis problems, and general
+** output for pluging
+*/
+
#ifndef DEBUGDIALOG_H
#define DEBUGDIALOG_H
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index f51607e..41f9712 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginEngine.cpp
+** \brief Engine that handles all plugin related features
+*/
+
#include "PluginEngine.h"
#include "VidaliaSettings.h"
#include "PluginWrapper.h"
@@ -17,7 +32,7 @@ PluginEngine::PluginEngine(QObject *parent)
globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
globalObject().setProperty("vidaliaApp", newQObject(vApp));
- globalObject().setProperty("include", newFunction(includeScript));
+// globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
globalObject().setProperty("vdebug", newFunction(vdebug));
globalObject().setProperty("findWidget", newFunction(findWidget));
@@ -30,9 +45,6 @@ PluginEngine::PluginEngine(QObject *parent)
DebugDialog::outputDebug(QString(" %1").arg(ext));
loadAllPlugins();
-
-// debugger.attachTo(this);
-// debugger.standardWindow()->show();
}
PluginEngine::~PluginEngine()
@@ -104,75 +116,54 @@ PluginEngine::importExtension(QScriptContext *context, QScriptEngine *engine)
return engine->importExtension(context->argument(0).toString());
}
-QScriptValue
-PluginEngine::includeScript(QScriptContext *context, QScriptEngine *engine)
-{
- QString currentFileName = engine->globalObject().property("qs").property("script").property("absoluteFilePath").toString();
- QFileInfo currentFileInfo(currentFileName);
- QString path = currentFileInfo.path();
- QString importFile = context->argument(0).toString();
- QFileInfo importInfo(importFile);
- if (importInfo.isRelative()) {
- importFile = path + "/" + importInfo.filePath();
- }
- if (!loadFile(importFile, engine)) {
- return context->throwError(QString("Failed to resolve include: %1").arg(importFile));
- }
- return engine->toScriptValue(true);
-}
-
-bool
-PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
-{
- // avoid loading files more than once
- static QSet<QString> loadedFiles;
- QFileInfo fileInfo(fileName);
- QString absoluteFileName = fileInfo.absoluteFilePath();
- QString absolutePath = fileInfo.absolutePath();
- QString canonicalFileName = fileInfo.canonicalFilePath();
- if (loadedFiles.contains(canonicalFileName)) {
- return true;
- }
- loadedFiles.insert(canonicalFileName);
- QString path = fileInfo.path();
-
- // load the file
- QFile file(fileName);
- if (file.open(QFile::ReadOnly)) {
- QTextStream stream(&file);
- QString contents = stream.readAll();
- file.close();
-
- int endlineIndex = contents.indexOf('\n');
- QString line = contents.left(endlineIndex);
- int lineNumber = 1;
-
- // strip off #!/usr/bin/env qscript line
- if (line.startsWith("#!")) {
- contents.remove(0, endlineIndex+1);
- ++lineNumber;
- }
-
- // set qt.script.absoluteFilePath
- QScriptValue script = engine->globalObject().property("qs").property("script");
- QScriptValue oldFilePathValue = script.property("absoluteFilePath");
- QScriptValue oldPathValue = script.property("absolutePath");
- script.setProperty("absoluteFilePath", engine->toScriptValue(absoluteFileName));
- script.setProperty("absolutePath", engine->toScriptValue(absolutePath));
-
- QScriptValue r = engine->evaluate(contents, fileName, lineNumber);
- if (engine->hasUncaughtException()) {
- QStringList backtrace = engine->uncaughtExceptionBacktrace();
- qDebug() << QString(" %1\n%2\n\n").arg(r.toString()).arg(backtrace.join("\n"));
- return true;
- }
- script.setProperty("absoluteFilePath", oldFilePathValue); // if we come from includeScript(), or whereever
- script.setProperty("absolutePath", oldPathValue); // if we come from includeScript(), or whereever
- } else {
- return false;
- }
- return true;
-}
+//QScriptValue
+//PluginEngine::includeScript(QScriptContext *context, QScriptEngine *engine)
+//{
+// VidaliaSettings settings;
+// QString path = settings.pluginPath();
+// QString importFile = context->argument(0).toString();
+// QFileInfo importInfo(importFile);
+// if (importInfo.isRelative()) {
+// importFile = path + "/" + importInfo.filePath();
+// }
+
+// if (!loadFile(importFile, engine)) {
+// return context->throwError(QString("Failed to resolve include: %1").arg(importFile));
+// }
+// return engine->toScriptValue(true);
+//}
+
+//bool
+//PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
+//{
+// static QSet<QString> loadedFiles;
+// QFileInfo fileInfo(fileName);
+// QString absoluteFileName = fileInfo.absoluteFilePath();
+// QString absolutePath = fileInfo.absolutePath();
+// QString canonicalFileName = fileInfo.canonicalFilePath();
+// if (loadedFiles.contains(canonicalFileName)) {
+// return true;
+// }
+// loadedFiles.insert(canonicalFileName);
+// QString path = fileInfo.path();
+
+// QFile file(fileName);
+// if (file.open(QFile::ReadOnly)) {
+// QTextStream stream(&file);
+// QString contents = stream.readAll();
+// file.close();
+
+// QScriptValue r = engine->evaluate(contents);
+// if (engine->hasUncaughtException()) {
+// QStringList backtrace = engine->uncaughtExceptionBacktrace();
+// qDebug() << QString(" %1\n%2\n\n").arg(r.toString()).arg(backtrace.join("\n"));
+// return true;
+// }
+// } else {
+// return false;
+// }
+// return true;
+//}
QScriptValue
PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
@@ -184,13 +175,14 @@ PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
result.append(context->argument(i).toString());
}
- qWarning() << result;
+ vInfo(result);
return engine->undefinedValue();
}
QScriptValue
-PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine) {
+PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine)
+{
if(context->argumentCount() != 2)
return context->throwError(QString("findWidget called with the wrong argument count. Expected 2."));
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 854ed15..d8dc273 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginEngine.h
+** \brief Engine that handles all plugin related features
+*/
+
#ifndef PLUGINENGINE_H
#define PLUGINENGINE_H
@@ -32,8 +47,8 @@ class PluginEngine : public QScriptEngine {
protected:
static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine);
- static bool loadFile(QString fileName, QScriptEngine *engine);
- static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
+// static bool loadFile(QString fileName, QScriptEngine *engine);
+// static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
static QScriptValue vdebug(QScriptContext *context, QScriptEngine *engine);
static QScriptValue findWidget(QScriptContext *context, QScriptEngine *engine);
diff --git a/src/vidalia/plugin/PluginWrapper.cpp b/src/vidalia/plugin/PluginWrapper.cpp
index 2736dbc..87a6ff1 100644
--- a/src/vidalia/plugin/PluginWrapper.cpp
+++ b/src/vidalia/plugin/PluginWrapper.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginWrapper.cpp
+** \brief Wrapper for the plugin scripts
+*/
+
#include "PluginWrapper.h"
#include "PluginEngine.h"
#include "DebugDialog.h"
diff --git a/src/vidalia/plugin/PluginWrapper.h b/src/vidalia/plugin/PluginWrapper.h
index 15f7853..1253bee 100644
--- a/src/vidalia/plugin/PluginWrapper.h
+++ b/src/vidalia/plugin/PluginWrapper.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginWrapper.h
+** \brief Wrapper for the plugin scripts
+*/
+
#ifndef PLUGINWRAPPER_H
#define PLUGINWRAPPER_H
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
index c2232e1..2fcd126 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file HelperProcessPrototype.cpp
+** \brief Prototype for the HelperProcess class
+*/
+
#include "HelperProcessPrototype.h"
HelperProcessPrototype::HelperProcessPrototype(QObject *parent)
@@ -11,12 +26,14 @@ HelperProcessPrototype::constructor(QScriptContext *context, QScriptEngine *engi
}
int
-HelperProcessPrototype::metaTypeId() {
+HelperProcessPrototype::metaTypeId()
+{
return qMetaTypeId<HelperProcess *>();
}
QString
-HelperProcessPrototype::name() {
+HelperProcessPrototype::name()
+{
return QString("HelperProcess");
}
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
index 56bccc0..742a428 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file TorControlPrototype.cpp
+** \brief Prototype for TorControl class
+*/
+
#include "TorControlPrototype.h"
#define GET_AND_CALL(type, func, res) \
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
index 8127c76..eb0cc6b 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.h
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.h
@@ -1,16 +1,16 @@
/*
** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If
-** you did not receive the LICENSE file with this file, you may obtain it
-** from the Vidalia source package distributed by the Vidalia Project at
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
** including this file, may be copied, modified, propagated, or distributed
** except according to the terms described in the LICENSE file.
*/
-/*
+/*
** \file TorControlPrototype.h
-** \brief Object for interacting with the Tor process and control interface
+** \brief Prototype for TorControl class
*/
#ifndef _TORCONTROLPROTO_H
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
index 52b8fef..8f71a37 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file VidaliaTabPrototype.cpp
+** \brief Prototype for VidaliaTab class
+*/
+
#include "VidaliaTabPrototype.h"
VidaliaTabPrototype::VidaliaTabPrototype(QObject *parent)
@@ -21,12 +36,14 @@ VidaliaTabPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
}
int
-VidaliaTabPrototype::metaTypeId() {
+VidaliaTabPrototype::metaTypeId()
+{
return qMetaTypeId<VidaliaTab *>();
}
QString
-VidaliaTabPrototype::name() {
+VidaliaTabPrototype::name()
+{
return QString("VidaliaTab");
}
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
index 59d640d..dcc355b 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file VidaliaTabPrototype.h
+** \brief Prototype for VidaliaTab class
+*/
+
#ifndef VIDALIATABPROT_H
#define VIDALIATABPROT_H
1
0
commit 92f39c6d275d07b9a49fc1a412c6482551190831
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Wed Jun 1 17:02:07 2011 -0300
Plugin framework: initial commit
It introduces the basic structure of the plugin management, not the actual
API. There's some refactoring to do, but the basic layout is working.
---
CMakeLists.txt | 2 +-
src/vidalia/CMakeLists.txt | 13 ++
src/vidalia/MainWindow.cpp | 24 +++-
src/vidalia/MainWindow.h | 7 +
src/vidalia/config/VidaliaSettings.cpp | 13 ++
src/vidalia/config/VidaliaSettings.h | 5 +
src/vidalia/plugin/PluginEngine.cpp | 64 ++++++++
src/vidalia/plugin/PluginEngine.h | 28 ++++
src/vidalia/plugin/PluginWrapper.cpp | 157 ++++++++++++++++++++
src/vidalia/plugin/PluginWrapper.h | 46 ++++++
.../plugin/prototypes/VidaliaTabPrototype.cpp | 10 ++
.../plugin/prototypes/VidaliaTabPrototype.h | 21 +++
12 files changed, 388 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dfd8f3b..0c07d0d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,10 +37,10 @@ include(FindQt4)
find_package(Qt4 REQUIRED)
set(QT_USE_QTNETWORK true)
set(QT_USE_QTXML true)
+set(QT_USE_QTSCRIPT true)
if (USE_MARBLE)
set(QT_USE_QTSVG true)
set(QT_USE_QTWEBKIT true)
- set(QT_USE_QTSCRIPT true)
set(QT_USE_QTDBUS true)
endif(USE_MARBLE)
include(${QT_USE_FILE})
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 5811320..4cbe458 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -20,6 +20,8 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/help/browser
${CMAKE_CURRENT_SOURCE_DIR}/log
${CMAKE_CURRENT_SOURCE_DIR}/network
+ ${CMAKE_CURRENT_SOURCE_DIR}/plugin
+ ${CMAKE_CURRENT_SOURCE_DIR}/plugin/prototypes
${MARBLE_INCLUDE_DIR}
)
@@ -80,6 +82,17 @@ qt4_wrap_cpp(vidalia_SRCS
bwgraph/BandwidthGraph.h
bwgraph/GraphFrame.h
)
+## Plugin framework sources
+set(vidalia_SRCS ${vidalia_SRCS}
+ plugin/PluginEngine.cpp
+ plugin/PluginWrapper.cpp
+ plugin/prototypes/VidaliaTabPrototype.cpp
+)
+qt4_wrap_cpp(vidalia_SRCS
+ plugin/PluginEngine.h
+ plugin/PluginWrapper.h
+ plugin/prototypes/VidaliaTabPrototype.h
+)
## Configuration dialog sources
set(vidalia_SRCS ${vidalia_SRCS}
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 70e8044..931df1c 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -37,6 +37,8 @@
#include "stringutil.h"
#include "procutil.h"
+#include "PluginWrapper.h"
+
#include <QtGui>
#define IMG_BWGRAPH ":/images/16x16/utilities-system-monitor.png"
@@ -100,6 +102,8 @@ MainWindow::MainWindow()
/* Create a new TorControl object, used to communicate with Tor */
_torControl = Vidalia::torControl();
+ _engine = new PluginEngine();
+
createGUI();
createConnections();
@@ -176,7 +180,11 @@ MainWindow::createMenuBar()
viewMenu->addSeparator();
viewMenu->addAction(_actionConfigure);
-// QMenu *pluginsMenu = menu->addMenu(tr("Plugins"));
+ QMenu *pluginsMenu = menu->addMenu(tr("Plugins"));
+ foreach(QAction *action, _engine->getAllActions()) {
+ pluginsMenu->addAction(action);
+ connect(action, SIGNAL(triggered()), this, SLOT(showPluginTab()));
+ }
QMenu *helpMenu = menu->addMenu(tr("Help"));
helpMenu->addAction(_actionVidaliaHelp);
@@ -1539,6 +1547,12 @@ MainWindow::addTab(VidaliaTab *tab)
* instanse passed */
if(_tabMap.contains(tab->getTitle())) {
ui.tabWidget->setCurrentIndex(_tabMap.indexOf(tab->getTitle()));
+
+ /** If we are trying to open the exact same tab twice
+ * don't do anything */
+ if(tab == ui.tabWidget->widget(_tabMap.indexOf(tab->getTitle())))
+ return;
+
/** Exception for tabs that need to be always created */
if (tab != _messageLog &&
tab != &_statusTab &&
@@ -1579,6 +1593,14 @@ MainWindow::delTab(int index)
}
void
+MainWindow::showPluginTab()
+{
+ QAction *act = qobject_cast<QAction *>(sender());
+ PluginWrapper *wrapper = qobject_cast<PluginWrapper *>(act->parent());
+ addTab(wrapper->buildGUI());
+}
+
+void
MainWindow::showStatusTab()
{
addTab(&_statusTab);
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 7d386d5..e5366b8 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -36,6 +36,8 @@
#include "TorControl.h"
+#include "PluginEngine.h"
+
#include <QMainWindow>
#include <QTimer>
#include <QSystemTrayIcon>
@@ -142,6 +144,9 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
+ /** Handles adding a new tab corresponding to a plugin */
+ void showPluginTab();
+
/** Called when the web browser or IM client have stopped */
void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
/** Called periodically to check if the browser is running. If it is not,
@@ -304,6 +309,8 @@ private:
NetViewer _netViewer; /**< Network map that draws circuits */
QStringList _tabMap; /**< Map to handle opened tabs */
BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
+
+ PluginEngine *_engine;
};
#endif
diff --git a/src/vidalia/config/VidaliaSettings.cpp b/src/vidalia/config/VidaliaSettings.cpp
index 0812b03..aa4d18b 100644
--- a/src/vidalia/config/VidaliaSettings.cpp
+++ b/src/vidalia/config/VidaliaSettings.cpp
@@ -39,6 +39,7 @@
#define SETTING_LAST_UPDATE_CHECK "LastUpdateCheck"
#define SETTING_USE_LOCAL_GEOIP_DATABASE "UseLocalGeoIpDatabase"
#define SETTING_LOCAL_GEOIP_DATABASE "LocalGeoIpDatabase"
+#define SETTING_PLUGIN_PATH "PluginPath"
#if defined(Q_OS_WIN32)
#define STARTUP_REG_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@@ -82,6 +83,7 @@ VidaliaSettings::VidaliaSettings()
setDefault(SETTING_LAST_UPDATE_CHECK, QDateTime());
setDefault(SETTING_USE_LOCAL_GEOIP_DATABASE, false);
setDefault(SETTING_LOCAL_GEOIP_DATABASE, "");
+ setDefault(SETTING_PLUGIN_PATH, vApp->dataDirectory());
}
/** Gets the currently preferred language code for Vidalia. */
@@ -321,3 +323,14 @@ VidaliaSettings::setLocalGeoIpDatabase(const QString &databaseFile)
setValue(SETTING_LOCAL_GEOIP_DATABASE, databaseFile);
}
+QString
+VidaliaSettings::pluginPath() const
+{
+ return QDir::convertSeparators(value(SETTING_PLUGIN_PATH).toString());
+}
+
+void
+VidaliaSettings::setPluginPath(const QString &path)
+{
+ setValue(SETTING_PLUGIN_PATH, path);
+}
diff --git a/src/vidalia/config/VidaliaSettings.h b/src/vidalia/config/VidaliaSettings.h
index 2667b12..029657f 100644
--- a/src/vidalia/config/VidaliaSettings.h
+++ b/src/vidalia/config/VidaliaSettings.h
@@ -125,6 +125,11 @@ public:
QString localGeoIpDatabase() const;
/** Sets the file to use as a local GeoIP database. */
void setLocalGeoIpDatabase(const QString &databaseFile);
+
+ /** Returns the path where the plugins live */
+ QString pluginPath() const;
+ /** Sets the path where the plugins live */
+ void setPluginPath(const QString &path);
};
#endif
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
new file mode 100644
index 0000000..fe85883
--- /dev/null
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -0,0 +1,64 @@
+#include "PluginEngine.h"
+#include "VidaliaSettings.h"
+#include "PluginWrapper.h"
+
+PluginEngine::PluginEngine(QObject *parent)
+ : QScriptEngine(parent)
+{
+ // load prototypes
+ VidaliaTabPrototype vtabproto;
+ QScriptValue vtabscript = newQObject(&vtabproto, QScriptEngine::ScriptOwnership);
+ setDefaultPrototype(qMetaTypeId<VidaliaTab *>(), vtabscript);
+
+ // load constructors
+ QScriptValue vtabctor = newFunction(VidaliaTabPrototype::constructor, vtabscript);
+ globalObject().setProperty("VidaliaTab", vtabctor);
+
+ loadAllPlugins();
+}
+
+PluginEngine::~PluginEngine() {}
+
+void
+PluginEngine::loadAllPlugins()
+{
+ qWarning() << "loadAllPlugins()";
+
+ VidaliaSettings settings;
+ QDir path = QDir(settings.pluginPath());
+
+ qWarning() << "PluginPath" << 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));
+
+ if(finfo.isDir()) {
+ tryLoadPlugin(finfo.filePath());
+ }
+ }
+}
+
+void
+PluginEngine::tryLoadPlugin(QDir path)
+{
+ qWarning() << "tryLoadPlugin()" << path.absolutePath();
+
+ QStringList files = path.entryList();
+
+ if(!files.contains("info.xml"))
+ return;
+
+ PluginWrapper *wrapper = new PluginWrapper(QString("%1%2info.xml").arg(path.absolutePath()).arg(QDir::separator()), this);
+ wrappers << wrapper;
+}
+
+QList<QAction *>
+PluginEngine::getAllActions()
+{
+ QList<QAction *> actions;
+ foreach(PluginWrapper *wrapper, wrappers)
+ actions << wrapper->menuAction();
+
+ return actions;
+}
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
new file mode 100644
index 0000000..09bff23
--- /dev/null
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -0,0 +1,28 @@
+#ifndef PLUGINENGINE_H
+#define PLUGINENGINE_H
+
+#include <QtGui>
+#include <QtScript>
+
+#include "VidaliaTabPrototype.h"
+
+class PluginWrapper;
+
+class PluginEngine : public QScriptEngine {
+ Q_OBJECT
+
+ public:
+ PluginEngine(QObject *parent = 0);
+ ~PluginEngine();
+
+ QList<QAction *> getAllActions();
+
+ protected:
+ void loadAllPlugins();
+ void tryLoadPlugin(QDir path);
+
+ QList<PluginWrapper *> wrappers;
+};
+
+#endif
+
diff --git a/src/vidalia/plugin/PluginWrapper.cpp b/src/vidalia/plugin/PluginWrapper.cpp
new file mode 100644
index 0000000..b06b863
--- /dev/null
+++ b/src/vidalia/plugin/PluginWrapper.cpp
@@ -0,0 +1,157 @@
+#include "PluginWrapper.h"
+#include "PluginEngine.h"
+
+#include <QtXml>
+
+PluginWrapper::PluginWrapper(const QString &info_path, PluginEngine *engine, QObject *parent)
+ : QObject(parent), _engine(engine)
+{
+ _action = 0;
+ _gui = false;
+ _persistent = false;
+ processInfo(info_path);
+
+ foreach(QString path, _files) {
+ qWarning() << path;
+ QFile file(path);
+ if(file.open(QIODevice::ReadOnly)) {
+ _engine->evaluate(file.readAll());
+ qWarning() << "evaluated";
+ } else
+ qWarning() << "Error opening file";
+ }
+}
+
+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";
+ return;
+ }
+
+ if(!info.setContent(&file)) {
+ qWarning() << "Problem setting contents";
+ file.close();
+ return;
+ }
+
+ QDomElement root = info.documentElement();
+
+ if(root.tagName() != "VidaliaPlugin") {
+ return;
+ }
+
+ QDomNode n = root.firstChild();
+ while(!n.isNull()) {
+ QDomElement e = n.toElement();
+ if(!e.isNull()) {
+ if(e.tagName() == "name")
+ _name = e.text();
+ else if(e.tagName() == "author")
+ _author = e.text();
+ else if(e.tagName() == "date")
+ _date = e.text();
+ else if(e.tagName() == "type") {
+ _persistent = (e.attribute("persistent", "false") == "true");
+ _gui = (e.attribute("gui", "false") == "true");
+ } else if(e.tagName() == "files") {
+ QDomNode froot = e.firstChild();
+ while(!froot.isNull()) {
+ QDomElement fe = froot.toElement();
+ if(fe.tagName() == "file")
+ _files << QString("%1%2%3").arg(QFileInfo(path).path()).arg(QDir::separator()).arg(fe.text());
+ froot = froot.nextSibling();
+ }
+ } else if(e.tagName() == "namespace") {
+ _nspace = e.text();
+ }
+ }
+ n = n.nextSibling();
+ }
+
+ file.close();
+}
+
+void
+PluginWrapper::start()
+{
+ _engine->evaluate(QString("%1.start()").arg(nspace()));
+}
+
+void
+PluginWrapper::stop()
+{
+ _engine->evaluate(QString("%1.stop()").arg(nspace()));
+}
+
+VidaliaTab *
+PluginWrapper::buildGUI()
+{
+ if(!hasGUI())
+ return NULL;
+ VidaliaTab *tab = qscriptvalue_cast<VidaliaTab *>(_engine->evaluate(QString("%1.buildGUI()").arg(nspace())));
+ if(_engine->hasUncaughtException()) {
+ qWarning() << "Exception:";
+ qWarning() << _engine->uncaughtExceptionLineNumber();
+ }
+ qWarning() << "Casted tab:" << tab << nspace();
+ return tab;
+}
+
+bool
+PluginWrapper::hasGUI()
+{
+ return _gui;
+}
+
+bool
+PluginWrapper::isPersistent()
+{
+ return _persistent;
+}
+
+QString
+PluginWrapper::name() const
+{
+ return _name;
+}
+
+QString
+PluginWrapper::date() const
+{
+ return _date;
+}
+
+QString
+PluginWrapper::author() const
+{
+ return _author;
+}
+
+QString
+PluginWrapper::nspace() const
+{
+ return _nspace;
+}
+
+QStringList
+PluginWrapper::files() const
+{
+ return _files;
+}
+
+QAction *
+PluginWrapper::menuAction()
+{
+ if(hasGUI()) {
+ _action = new QAction(_name, this);
+ }
+ return _action;
+}
diff --git a/src/vidalia/plugin/PluginWrapper.h b/src/vidalia/plugin/PluginWrapper.h
new file mode 100644
index 0000000..1c7ad8f
--- /dev/null
+++ b/src/vidalia/plugin/PluginWrapper.h
@@ -0,0 +1,46 @@
+#ifndef PLUGINWRAPPER_H
+#define PLUGINWRAPPER_H
+
+#include <QtCore>
+
+#include "VidaliaTab.h"
+
+class PluginEngine;
+
+class PluginWrapper : public QObject {
+ Q_OBJECT
+
+ public:
+ PluginWrapper(const QString &info_path, PluginEngine *engine, QObject *parent = 0);
+ ~PluginWrapper();
+
+ bool hasGUI();
+ bool isPersistent();
+
+ QString name() const;
+ QString date() const;
+ QString author() const;
+ QString nspace() const;
+ QStringList files() const;
+
+ QAction *menuAction();
+
+ public slots:
+ void start();
+ void stop();
+ VidaliaTab *buildGUI();
+
+ protected:
+ void processInfo(const QString &path);
+
+ PluginEngine *_engine;
+ QString _name, _date, _author;
+ bool _persistent, _gui;
+ QStringList _files;
+ QString _nspace;
+
+ QAction *_action;
+};
+
+#endif
+
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
new file mode 100644
index 0000000..58170ef
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
@@ -0,0 +1,10 @@
+#include "VidaliaTabPrototype.h"
+
+VidaliaTabPrototype::VidaliaTabPrototype(QObject *parent)
+ : QObject(parent)
+{}
+
+QScriptValue VidaliaTabPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
+{
+ return engine->newQObject(new VidaliaTab(QString("titulooo"), QString("nombreee")), QScriptEngine::ScriptOwnership);
+}
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
new file mode 100644
index 0000000..dbd89cd
--- /dev/null
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
@@ -0,0 +1,21 @@
+#ifndef VIDALIATABPROT_H
+#define VIDALIATABPROT_H
+
+#include <QtGui>
+#include <QtScript>
+
+#include "VidaliaTab.h"
+
+class VidaliaTabPrototype : public QObject, public QScriptable
+{
+ Q_OBJECT
+
+ public:
+ VidaliaTabPrototype(QObject *parent = 0);
+ static QScriptValue constructor(QScriptContext *context, QScriptEngine *engine);
+};
+
+Q_DECLARE_METATYPE(VidaliaTab *);
+
+#endif
+
1
0