tor-commits
Threads by month
- ----- 2026 -----
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- 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
- 1 participants
- 215000 discussions
commit 249d587881b4b34080b837ef60a40141ed3a3fdd
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Tue May 24 20:13:37 2011 -0300
Remove unnecessary output
---
src/vidalia/MainWindow.cpp | 6 ------
src/vidalia/VidaliaTab.cpp | 1 -
2 files changed, 0 insertions(+), 7 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 73f610c..3e9ce40 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -1513,10 +1513,8 @@ MainWindow::handleCloseTab(int index)
void
MainWindow::attachTab()
{
- qWarning() << "ATTACHHHHHHHHHH";
QAction *act = qobject_cast<QAction *>(sender());
VidaliaTab *tab = qobject_cast<VidaliaTab *>(act->parent());
- qWarning() << tab;
_detachedTabMap.removeAll(tab->getTitle());
tab->setParent(ui.tabWidget);
addTab(tab);
@@ -1553,9 +1551,7 @@ MainWindow::handleAttachedClose()
{
VidaliaTab *tab = qobject_cast<VidaliaTab *>(sender());
int index = ui.tabWidget->indexOf(tab);
- qWarning() << index;
if(index < 0) {
- qWarning() << "DETACHEEEEDDDDDDDDDDDDD";
QAction *act = 0;
foreach(QAction *tmpAct, _reattachMenu.actions()) {
if(tmpAct->parent() == tab) {
@@ -1578,8 +1574,6 @@ MainWindow::handleAttachedClose()
}
delTab(ui.tabWidget->currentIndex());
- } else {
- qWarning() << "ATTACHEEEEEDDDD";
}
}
diff --git a/src/vidalia/VidaliaTab.cpp b/src/vidalia/VidaliaTab.cpp
index a35838e..62377e7 100644
--- a/src/vidalia/VidaliaTab.cpp
+++ b/src/vidalia/VidaliaTab.cpp
@@ -77,7 +77,6 @@ VidaliaTab::closeEvent(QCloseEvent *event)
//{
// QDrag *dr = new QDrag(this);
// QMimeData *data = new QMimeData();
-// qWarning() << "THIS" << this;
// data->setData(tr("vidalia/pointer"), QByteArray().setNum((int)this));
// dr->setMimeData(data);
// dr->start();
1
0
02 Jul '11
commit a1d95d1c1734b208ab69452de158eb0234b623db
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Thu Jun 2 14:18:47 2011 -0300
Remove the commented drag and drop code
---
src/vidalia/VidaliaTab.cpp | 9 ---------
src/vidalia/VidaliaTab.h | 2 --
2 files changed, 0 insertions(+), 11 deletions(-)
diff --git a/src/vidalia/VidaliaTab.cpp b/src/vidalia/VidaliaTab.cpp
index 62377e7..ee2da03 100644
--- a/src/vidalia/VidaliaTab.cpp
+++ b/src/vidalia/VidaliaTab.cpp
@@ -72,12 +72,3 @@ VidaliaTab::closeEvent(QCloseEvent *event)
emit closeTab();
}
-//void
-//VidaliaTab::mouseMoveEvent(QMouseEvent *event)
-//{
-// QDrag *dr = new QDrag(this);
-// QMimeData *data = new QMimeData();
-// data->setData(tr("vidalia/pointer"), QByteArray().setNum((int)this));
-// dr->setMimeData(data);
-// dr->start();
-//}
diff --git a/src/vidalia/VidaliaTab.h b/src/vidalia/VidaliaTab.h
index df26c8a..8a053dc 100644
--- a/src/vidalia/VidaliaTab.h
+++ b/src/vidalia/VidaliaTab.h
@@ -63,8 +63,6 @@ protected:
virtual void closeEvent(QCloseEvent *event);
-// virtual void mouseMoveEvent(QMouseEvent *event);
-
bool _onTop; /**< True if the current tab is the one being displayed */
private:
1
0
commit 3db72ba0776c8ec42a4601f9b3e6f4e7302a3525
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Fri May 27 20:53:58 2011 -0300
Add comments and clean up a bit
---
src/vidalia/MainWindow.cpp | 3 ---
src/vidalia/MainWindow.h | 17 +++++++++--------
src/vidalia/VAttachButton.cpp | 15 +++++++++++++++
src/vidalia/VAttachButton.h | 20 ++++++++++++++++++++
4 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 3e9ce40..4c4359e 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -115,8 +115,6 @@ MainWindow::MainWindow()
_status = Unset;
_isVidaliaRunningTor = false;
updateTorStatus(Stopped);
-
- setAcceptDrops(true);
}
/** Destructor */
@@ -197,7 +195,6 @@ MainWindow::createMenuBar()
pluginsMenu->addAction(_actionDebugDialog);
menu->addMenu(&_reattachMenu);
- _dummy->setText(tr("No detached tabs"));
_reattachMenu.addAction(_dummy);
_dummy->setEnabled(false);
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index b7874fd..d30c059 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -60,10 +60,6 @@ protected:
/** Called when the user changes the UI translation. */
virtual void retranslateUi();
-// void dropEvent(QDropEvent *de);
-// void dragMoveEvent(QDragMoveEvent *de);
-// void dragEnterEvent(QDragEnterEvent *event);
-
private slots:
/** Respond to a double-click on the tray icon by opening the Control Panel
* window. */
@@ -151,9 +147,14 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
+ /** Attaches a tab to the tabwidget */
void attachTab();
+ /** Detaches a tab from the tabwidget */
void detachTab();
+ /** Called when trying to close a tab that has been detached */
+ void handleAttachedClose();
+
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -284,19 +285,19 @@ private:
QAction *_actionExit;
QAction *_actionDebugDialog;
- QMenu _reattachMenu;
- QAction *_dummy;
+ QMenu _reattachMenu; /**< Menu used to handle tab re-attaching */
+ QAction *_dummy; /**< Dummy action to display when there are no more tabs */
Ui::MainWindow ui; /**< Qt Designer generated object. */
StatusTab _statusTab; /**< Status tab that displays the load progress and a short log */
MessageLog *_messageLog; /**< Message log that displays a more detailed log from Tor */
NetViewer _netViewer; /**< Network map that draws circuits */
- QStringList _tabMap; /**< Map to handle opened tabs */
- QStringList _detachedTabMap;
BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
PluginEngine *_engine;
+ QStringList _tabMap; /**< Map to handle opened tabs */
+ QStringList _detachedTabMap; /**< Map to handle detached tabs */
};
#endif
diff --git a/src/vidalia/VAttachButton.cpp b/src/vidalia/VAttachButton.cpp
index 6d9991b..b5a5bab 100644
--- a/src/vidalia/VAttachButton.cpp
+++ b/src/vidalia/VAttachButton.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 VAttachButton.cpp
+** \brief Button that handles detaching of tabs
+*/
+
#include "VAttachButton.h"
#define IMG_DETACH ":/images/16x16/detach-arrow.png"
diff --git a/src/vidalia/VAttachButton.h b/src/vidalia/VAttachButton.h
index bdced09..038eef9 100644
--- a/src/vidalia/VAttachButton.h
+++ b/src/vidalia/VAttachButton.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 VAttachButton.cpp
+** \brief Button that handles detaching of tabs
+*/
+
#ifndef VATTACHBUTTON_H
#define VATTACHBUTTON_H
@@ -12,14 +27,19 @@ class VAttachButton : public QPushButton {
VAttachButton(QWidget *parent = 0);
~VAttachButton();
+ /** Sets the parent tab for this button */
void setTab(VidaliaTab *tab);
+ /** Returns the parent tab for this button */
VidaliaTab *getTab();
signals:
+ /** Emitted when the button is pressed and the tab is detached */
void attachTab();
+ /** Emitted when the button is pressed and the tab is attached */
void detachTab();
public slots:
+ /** Handles the onClicked signal */
void toggleAttach();
private:
1
0
02 Jul '11
commit 38044c9518ef6335b9499043c3dca965d000e9e6
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Wed Jun 1 23:44:10 2011 -0300
Improve communication between modules
Takes out the hacky casts and parent handling for a more Qt-ish way of
doing this.
---
src/vidalia/MainWindow.cpp | 12 +++---------
src/vidalia/MainWindow.h | 4 ++--
src/vidalia/plugin/PluginEngine.cpp | 23 ++++++++++++++---------
src/vidalia/plugin/PluginEngine.h | 10 ++++++++++
src/vidalia/plugin/PluginWrapper.cpp | 23 ++++++++++++++++++++++-
src/vidalia/plugin/PluginWrapper.h | 6 ++++++
6 files changed, 57 insertions(+), 21 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 931df1c..bd72346 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -183,7 +183,6 @@ MainWindow::createMenuBar()
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"));
@@ -414,6 +413,9 @@ MainWindow::createConnections()
_proxyProcess = new HelperProcess(this);
connect(_proxyProcess, SIGNAL(startFailed(QString)),
this, SLOT(onProxyFailed(QString)));
+
+ connect(_engine, SIGNAL(pluginTab(VidaliaTab *)),
+ this, SLOT(addTab(VidaliaTab *)));
}
/** Called when the application is closing, by selecting "Exit" from the tray
@@ -1593,14 +1595,6 @@ 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 e5366b8..8172f71 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -144,8 +144,8 @@ 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();
+// /** 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);
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index fe85883..c7b74ea 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -5,19 +5,17 @@
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);
+ ADD_CLASS("VidaliaTab", VidaliaTabPrototype, VidaliaTab *,
+ VidaliaTabPrototype::constructor)
loadAllPlugins();
}
-PluginEngine::~PluginEngine() {}
+PluginEngine::~PluginEngine()
+{
+ foreach(PluginWrapper *wrapper, wrappers)
+ wrapper->stop();
+}
void
PluginEngine::loadAllPlugins()
@@ -50,7 +48,14 @@ PluginEngine::tryLoadPlugin(QDir path)
return;
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())
+ wrapper->start();
+
wrappers << wrapper;
+
+ connect(wrapper, SIGNAL(pluginTab(VidaliaTab *)), this, SIGNAL(pluginTab(VidaliaTab *)));
}
QList<QAction *>
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 09bff23..7876803 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -8,6 +8,13 @@
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);
+
class PluginEngine : public QScriptEngine {
Q_OBJECT
@@ -17,6 +24,9 @@ class PluginEngine : public QScriptEngine {
QList<QAction *> getAllActions();
+ signals:
+ void pluginTab(VidaliaTab *);
+
protected:
void loadAllPlugins();
void tryLoadPlugin(QDir path);
diff --git a/src/vidalia/plugin/PluginWrapper.cpp b/src/vidalia/plugin/PluginWrapper.cpp
index b06b863..8e839fa 100644
--- a/src/vidalia/plugin/PluginWrapper.cpp
+++ b/src/vidalia/plugin/PluginWrapper.cpp
@@ -100,6 +100,8 @@ PluginWrapper::buildGUI()
if(_engine->hasUncaughtException()) {
qWarning() << "Exception:";
qWarning() << _engine->uncaughtExceptionLineNumber();
+
+ return NULL;
}
qWarning() << "Casted tab:" << tab << nspace();
return tab;
@@ -150,8 +152,27 @@ PluginWrapper::files() const
QAction *
PluginWrapper::menuAction()
{
+ _action = new QAction(_name, this);
+
if(hasGUI()) {
- _action = new QAction(_name, this);
+ connect(_action, SIGNAL(triggered()), this, SLOT(emitPluginTab()));
+ }
+
+ // if it hasn't been started yet
+ if(!isPersistent()) {
+ connect(_action, SIGNAL(triggered()), this, SLOT(start()));
}
+
return _action;
}
+
+void
+PluginWrapper::emitPluginTab()
+{
+ VidaliaTab *tab = buildGUI();
+ if(tab)
+ emit pluginTab(tab);
+ else
+ // TODO: make this more than a console print
+ qWarning() << "Error: buildGUI() failed for plugin" << name();
+}
diff --git a/src/vidalia/plugin/PluginWrapper.h b/src/vidalia/plugin/PluginWrapper.h
index 1c7ad8f..d99538c 100644
--- a/src/vidalia/plugin/PluginWrapper.h
+++ b/src/vidalia/plugin/PluginWrapper.h
@@ -25,11 +25,17 @@ class PluginWrapper : public QObject {
QAction *menuAction();
+ signals:
+ void pluginTab(VidaliaTab *);
+
public slots:
void start();
void stop();
VidaliaTab *buildGUI();
+ private slots:
+ void emitPluginTab();
+
protected:
void processInfo(const QString &path);
1
0
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