tor-commits
Threads by month
- ----- 2026 -----
- 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
July 2011
- 16 participants
- 868 discussions
commit 2e4fbffbe0e0593712e964f5710a6c970195514b
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Mon May 23 14:07:49 2011 -0300
Fix typo: It's detach, not dettach
---
src/vidalia/MainWindow.cpp | 8 ++++----
src/vidalia/MainWindow.h | 4 ++--
src/vidalia/VAttachButton.cpp | 2 +-
src/vidalia/VAttachButton.h | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 22949b0..6e16ee4 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -1506,7 +1506,7 @@ MainWindow::attachTab()
}
void
-MainWindow::dettachTab()
+MainWindow::detachTab()
{
VAttachButton *but = qobject_cast<VAttachButton *>(sender());
VidaliaTab *tab = but->getTab();
@@ -1518,7 +1518,7 @@ MainWindow::dettachTab()
QString key = _tabMap.at(index);
_tabMap.removeAll(key);
- _dettachedTabMap << key;
+ _detachedTabMap << key;
}
void
@@ -1573,8 +1573,8 @@ MainWindow::addTab(VidaliaTab *tab)
connect(atb, SIGNAL(attachTab()),
this, SLOT(attachTab()));
- connect(atb, SIGNAL(dettachTab()),
- this, SLOT(dettachTab()));
+ connect(atb, SIGNAL(detachTab()),
+ this, SLOT(detachTab()));
/** The new tab is added to the last position */
_tabMap << tab->getTitle();
connect(tab, SIGNAL(helpRequested(QString)),
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 2bfd02f..722a217 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -152,7 +152,7 @@ private slots:
void delTab(int index = -1);
void attachTab();
- void dettachTab();
+ void detachTab();
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
@@ -290,7 +290,7 @@ private:
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 _dettachedTabMap;
+ QStringList _detachedTabMap;
BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
PluginEngine *_engine;
diff --git a/src/vidalia/VAttachButton.cpp b/src/vidalia/VAttachButton.cpp
index 80e512b..42a4b3e 100644
--- a/src/vidalia/VAttachButton.cpp
+++ b/src/vidalia/VAttachButton.cpp
@@ -30,7 +30,7 @@ void
VAttachButton::toggleAttach()
{
if(_attached) {
- emit dettachTab();
+ emit detachTab();
} else {
emit attachTab();
}
diff --git a/src/vidalia/VAttachButton.h b/src/vidalia/VAttachButton.h
index e1ad3de..bdced09 100644
--- a/src/vidalia/VAttachButton.h
+++ b/src/vidalia/VAttachButton.h
@@ -17,7 +17,7 @@ class VAttachButton : public QPushButton {
signals:
void attachTab();
- void dettachTab();
+ void detachTab();
public slots:
void toggleAttach();
1
0
commit 6dcf75a834e65715a1d3cd90664be377f3312c60
Author: Tomas Touceda <chiiph(a)gentoo.org>
Date: Mon May 23 14:05:14 2011 -0300
First phase of detach tabs
Commentted is the code that handles drag and drop for re-attaching the tabs
again. It will probably work on windows, but I need to figure out a way to
handle this in a generic way first, and then go for the ifdefs.
---
src/vidalia/CMakeLists.txt | 2 +
src/vidalia/MainWindow.cpp | 57 ++++++++++++++++++++++++++++++++++++++++-
src/vidalia/MainWindow.h | 8 ++++++
src/vidalia/VAttachButton.cpp | 39 ++++++++++++++++++++++++++++
src/vidalia/VAttachButton.h | 30 +++++++++++++++++++++
src/vidalia/VTabWidget.cpp | 9 +++++-
src/vidalia/VTabWidget.h | 3 ++
src/vidalia/VidaliaTab.cpp | 18 +++++++++++++
src/vidalia/VidaliaTab.h | 6 ++++
9 files changed, 169 insertions(+), 3 deletions(-)
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index f340b65..9fd58ca 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -176,6 +176,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
Vidalia.cpp
LanguageSupport.cpp
VTabWidget.cpp
+ VAttachButton.cpp
MainWindow.cpp
VidaliaWindow.cpp
VMessageBox.cpp
@@ -187,6 +188,7 @@ set(vidalia_SRCS ${vidalia_SRCS}
qt4_wrap_cpp(vidalia_SRCS
Vidalia.h
VTabWidget.h
+ VAttachButton.h
MainWindow.h
VidaliaWindow.h
VMessageBox.h
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index 56b24c7..22949b0 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -25,6 +25,7 @@
#include "ServerSettings.h"
#include "AboutDialog.h"
#include "HelpBrowser.h"
+#include "VAttachButton.h"
#ifdef USE_AUTOUPDATE
#include "UpdatesAvailableDialog.h"
#endif
@@ -112,6 +113,8 @@ MainWindow::MainWindow()
_status = Unset;
_isVidaliaRunningTor = false;
updateTorStatus(Stopped);
+
+ setAcceptDrops(true);
}
/** Destructor */
@@ -1497,6 +1500,44 @@ MainWindow::handleCloseTab(int index)
}
void
+MainWindow::attachTab()
+{
+ qWarning() << "ATTACHHHHHHHHHH";
+}
+
+void
+MainWindow::dettachTab()
+{
+ VAttachButton *but = qobject_cast<VAttachButton *>(sender());
+ VidaliaTab *tab = but->getTab();
+ int index = ui.tabWidget->indexOf(tab);
+
+ ui.tabWidget->removeTab(index);
+ tab->setParent(0);
+ tab->show();
+
+ QString key = _tabMap.at(index);
+ _tabMap.removeAll(key);
+ _dettachedTabMap << key;
+}
+
+void
+MainWindow::handleAttachedClose()
+{
+ VidaliaTab *tab = qobject_cast<VidaliaTab *>(sender());
+ int index = ui.tabWidget->indexOf(tab);
+ qWarning() << index;
+ if(index < 0) {
+ qWarning() << "DETACHEEEEDDDDDDDDDDDDD";
+ tab->setParent(ui.tabWidget);
+ addTab(tab);
+ delTab(ui.tabWidget->currentIndex());
+ } else {
+ qWarning() << "ATTACHEEEEEDDDD";
+ }
+}
+
+void
MainWindow::addTab(VidaliaTab *tab)
{
/** If the tab's already open, display it and delete the
@@ -1518,8 +1559,22 @@ MainWindow::addTab(VidaliaTab *tab)
return;
}
+ VAttachButton *atb = new VAttachButton();
+
ui.tabWidget->addTab(tab, tab->getTitle());
- ui.tabWidget->setCurrentIndex(ui.tabWidget->count() - 1);
+ int pos = ui.tabWidget->count() - 1;
+ ui.tabWidget->setCurrentIndex(pos);
+
+ atb->setTab(tab);
+ ui.tabWidget->setTabButton(pos, QTabBar::LeftSide, atb);
+
+ connect(tab, SIGNAL(closeTab()),
+ this, SLOT(handleAttachedClose()));
+
+ connect(atb, SIGNAL(attachTab()),
+ this, SLOT(attachTab()));
+ connect(atb, SIGNAL(dettachTab()),
+ this, SLOT(dettachTab()));
/** The new tab is added to the last position */
_tabMap << tab->getTitle();
connect(tab, SIGNAL(helpRequested(QString)),
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 3b7d544..2bfd02f 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -60,6 +60,10 @@ 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. */
@@ -147,6 +151,9 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
+ void attachTab();
+ void dettachTab();
+
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -283,6 +290,7 @@ private:
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 _dettachedTabMap;
BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
PluginEngine *_engine;
diff --git a/src/vidalia/VAttachButton.cpp b/src/vidalia/VAttachButton.cpp
new file mode 100644
index 0000000..80e512b
--- /dev/null
+++ b/src/vidalia/VAttachButton.cpp
@@ -0,0 +1,39 @@
+#include "VAttachButton.h"
+
+VAttachButton::VAttachButton(QWidget *parent) :
+ QPushButton(parent)
+{
+ _tab = 0;
+ _attached = true;
+ setText(QString("X"));
+}
+
+VAttachButton::~VAttachButton()
+{
+ disconnect(0,0,0,0);
+}
+
+void
+VAttachButton::setTab(VidaliaTab *tab)
+{
+ _tab = tab;
+ connect(this, SIGNAL(clicked()), this, SLOT(toggleAttach()));
+}
+
+VidaliaTab *
+VAttachButton::getTab()
+{
+ return _tab;
+}
+
+void
+VAttachButton::toggleAttach()
+{
+ if(_attached) {
+ emit dettachTab();
+ } else {
+ emit attachTab();
+ }
+ _attached = !_attached;
+}
+
diff --git a/src/vidalia/VAttachButton.h b/src/vidalia/VAttachButton.h
new file mode 100644
index 0000000..e1ad3de
--- /dev/null
+++ b/src/vidalia/VAttachButton.h
@@ -0,0 +1,30 @@
+#ifndef VATTACHBUTTON_H
+#define VATTACHBUTTON_H
+
+#include <QtGui>
+
+#include "VidaliaTab.h"
+
+class VAttachButton : public QPushButton {
+ Q_OBJECT
+
+ public:
+ VAttachButton(QWidget *parent = 0);
+ ~VAttachButton();
+
+ void setTab(VidaliaTab *tab);
+ VidaliaTab *getTab();
+
+ signals:
+ void attachTab();
+ void dettachTab();
+
+ public slots:
+ void toggleAttach();
+
+ private:
+ VidaliaTab *_tab;
+ bool _attached;
+};
+
+#endif
diff --git a/src/vidalia/VTabWidget.cpp b/src/vidalia/VTabWidget.cpp
index 421f069..a1bef76 100644
--- a/src/vidalia/VTabWidget.cpp
+++ b/src/vidalia/VTabWidget.cpp
@@ -1,5 +1,3 @@
-#include <QTabBar>
-
#include "VTabWidget.h"
#include "VidaliaTab.h"
@@ -50,3 +48,10 @@ VTabWidget::retranslateUi()
setTabText(i, qobject_cast<VidaliaTab *>(widget(i))->getTitle());
}
}
+
+void
+VTabWidget::setTabButton(int pos, QTabBar::ButtonPosition butpos, QWidget *w)
+{
+ tabBar()->setTabButton(pos, butpos, w);
+}
+
diff --git a/src/vidalia/VTabWidget.h b/src/vidalia/VTabWidget.h
index c3eb8ce..45028e8 100644
--- a/src/vidalia/VTabWidget.h
+++ b/src/vidalia/VTabWidget.h
@@ -17,6 +17,7 @@
#define _VTABWIDGET_H
#include <QTabWidget>
+#include <QTabBar>
class VTabWidget : public QTabWidget
{
@@ -31,6 +32,8 @@ public:
/** Makes the tab at position unclosable */
void pinTab(int position);
+ void setTabButton(int pos, QTabBar::ButtonPosition butpos, QWidget *w);
+
protected:
void changeEvent(QEvent *e);
void retranslateUi();
diff --git a/src/vidalia/VidaliaTab.cpp b/src/vidalia/VidaliaTab.cpp
index ec5f1bf..a35838e 100644
--- a/src/vidalia/VidaliaTab.cpp
+++ b/src/vidalia/VidaliaTab.cpp
@@ -64,3 +64,21 @@ VidaliaTab::setOnTop(bool top)
{
_onTop = top;
}
+
+void
+VidaliaTab::closeEvent(QCloseEvent *event)
+{
+ event->ignore();
+ emit closeTab();
+}
+
+//void
+//VidaliaTab::mouseMoveEvent(QMouseEvent *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();
+//}
diff --git a/src/vidalia/VidaliaTab.h b/src/vidalia/VidaliaTab.h
index ac6edb1..df26c8a 100644
--- a/src/vidalia/VidaliaTab.h
+++ b/src/vidalia/VidaliaTab.h
@@ -51,6 +51,8 @@ signals:
* <b>topic</b>. */
void helpRequested(const QString &topic);
+ void closeTab();
+
protected:
/** Reimplement the windows' changeEvent() method to check if the event
* is a QEvent::LanguageChange event. If so, call retranslateUi(), which
@@ -59,6 +61,10 @@ protected:
/** Called when the user wants to change the currently visible language. */
virtual void retranslateUi();
+ 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 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
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
commit 1ac1c1746a3fe63bb9ba32f2ed1c1e13b12cda02
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sat Jul 2 18:46:57 2011 -0300
Remove debugger for now
---
src/vidalia/plugin/PluginEngine.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index d8dc273..2251e6c 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -57,7 +57,7 @@ class PluginEngine : public QScriptEngine {
QList<PluginWrapper *> wrappers;
- QScriptEngineDebugger debugger;
+// QScriptEngineDebugger debugger;
};
#endif
1
0
commit d6416b36e8378de1e59ad7532f9d44e8a9539364
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sun Jun 26 19:17:08 2011 -0300
Improve engine and clean some code
Removes all TBB related code, since it's now in a plugin.
Adds minor improvements to the engine, and the possibility of having a real
debugger.
---
src/vidalia/MainWindow.cpp | 241 --------------------
src/vidalia/MainWindow.h | 29 ---
src/vidalia/plugin/PluginEngine.cpp | 26 ++
src/vidalia/plugin/PluginEngine.h | 4 +
.../plugin/prototypes/HelperProcessPrototype.cpp | 14 ++
.../plugin/prototypes/HelperProcessPrototype.h | 2 +
6 files changed, 46 insertions(+), 270 deletions(-)
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index bcc3538..56b24c7 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -401,24 +401,6 @@ MainWindow::createConnections()
connect(UPNPControl::instance(), SIGNAL(error(UPNPControl::UPNPError)),
this, SLOT(upnpError(UPNPControl::UPNPError)));
#endif
- /* Create a new HelperProcess object, used to start the web browser */
- _browserProcess = new HelperProcess(this);
- connect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(onSubprocessFinished(int, QProcess::ExitStatus)));
- connect(_browserProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onBrowserFailed(QString)));
-
- /* Create a new HelperProcess object, used to start the IM client */
- _imProcess = new HelperProcess(this);
- connect(_imProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(onSubprocessFinished(int, QProcess::ExitStatus)));
- connect(_imProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onIMFailed(QString)));
-
- /* Create a new HelperProcess object, used to start the proxy server */
- _proxyProcess = new HelperProcess(this);
- connect(_proxyProcess, SIGNAL(startFailed(QString)),
- this, SLOT(onProxyFailed(QString)));
connect(_engine, SIGNAL(pluginTab(VidaliaTab *)),
this, SLOT(addTab(VidaliaTab *)));
@@ -470,10 +452,6 @@ MainWindow::running()
start();
}
- /* Start the proxy server, if configured */
- if (settings.runProxyAtStart())
- startProxy();
-
#if defined(USE_AUTOUPDATE)
if (settings.isAutoUpdateEnabled()) {
QDateTime lastCheckedAt = settings.lastCheckedForUpdates();
@@ -519,33 +497,6 @@ MainWindow::aboutToQuit()
ServerSettings settings(_torControl);
settings.cleanupPortForwarding();
- if (_proxyProcess->state() != QProcess::NotRunning) {
- /* Close the proxy server (Polipo ignores the WM_CLOSE event sent by
- * terminate() so we have to kill() it) */
- _proxyProcess->kill();
- }
-
- /* Kill the browser and IM client if using the new launcher */
- VidaliaSettings vidalia_settings;
-
- if (! vidalia_settings.getBrowserDirectory().isEmpty()) {
- /* Disconnect the finished signals so that we won't try to exit Vidalia again */
- QObject::disconnect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)), 0, 0);
- QObject::disconnect(_imProcess, SIGNAL(finished(int, QProcess::ExitStatus)), 0, 0);
-
- /* Use QProcess terminate function */
- if (_browserProcess->state() == QProcess::Running)
- _browserProcess->terminate();
-
-#if defined(Q_OS_WIN)
- /* Kill any processes which might have been forked off */
- win32_end_process_by_filename(vidalia_settings.getBrowserExecutable());
-#endif
-
- if (_imProcess->state() == QProcess::Running)
- _imProcess->terminate();
- }
-
/* Disconnect all of the TorControl object's signals */
QObject::disconnect(_torControl, 0, 0, 0);
}
@@ -1061,7 +1012,6 @@ MainWindow::circuitEstablished()
// TODO: fix hardcoded total length
setStartupProgress(130,
tr("Connected to the Tor network!"));
- startSubprocesses();
#if defined(USE_AUTOUPDATE)
VidaliaSettings settings;
@@ -1346,7 +1296,6 @@ MainWindow::updateTorStatus(TorStatus status)
trayIconFile = IMG_TOR_STOPPING;
statusIconFile = IMG_TOR_STOPPING_48;
-// ui.btnStartStopTor->setStatusTip(tr("Stop Tor Now"));
} else if (status == Started) {
actionText = tr("Stop Tor");
_actionRestartTor->setEnabled(true);
@@ -1512,7 +1461,6 @@ MainWindow::newIdentity()
/* Disable the New Identity button for MIN_NEWIDENTITY_INTERVAL */
_actionNewIdentity->setEnabled(false);
-// ui.lblNewIdentity->setEnabled(false);
QTimer::singleShot(MIN_NEWIDENTITY_INTERVAL,
this, SLOT(enableNewIdentity()));
@@ -1817,192 +1765,3 @@ MainWindow::installUpdatesFailed(const QString &errmsg)
#endif
-/** Called when browser or IM client have exited */
-void
-MainWindow::onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus)
-{
- Q_UNUSED(exitCode)
- Q_UNUSED(exitStatus)
-
- /* Get path to browser and IM client */
- VidaliaSettings settings;
- QString browserExecutable = settings.getBrowserExecutable();
- QString browserDirectory = settings.getBrowserDirectory();
- QString imExecutable = settings.getIMExecutable();
-
- /* A subprocess is finished if it successfully exited or was never asked to start */
- bool browserDone = (browserExecutable.isEmpty()
- && browserDirectory.isEmpty())
- || _browserProcess->isDone();
- bool imDone = imExecutable.isEmpty() || _imProcess->isDone();
-
- /* Exit if both subprocesses are finished */
- if (browserDone && imDone) {
- if (browserDirectory.isEmpty()) {
- /* We are using the standard launcher, exit immediately */
- vApp->quit();
- } else {
- /* We are using the alternate launcher, wait until the browser has really died */
- QTimer *browserWatcher = new QTimer(this);
- connect(browserWatcher, SIGNAL(timeout()), this, SLOT(onCheckForBrowser()));
- browserWatcher->start(2000);
- }
- }
-}
-
-/** Called periodically to check if the browser is running. If it is not,
- * exit Vidalia cleanly */
-void
-MainWindow::onCheckForBrowser()
-{
-/* This only works on Windows for now */
-#if defined(Q_OS_WIN)
-
- VidaliaSettings settings;
- QString browserDirectoryFilename = settings.getBrowserExecutable();
-
- /* Get list of running processes */
- QHash<qint64, QString> procList = win32_process_list();
-
- /* On old versions of Windows win32_process_list() will return
- an empty list. In this case, just keep Vidalia open */
- if (procList.isEmpty()) {
- return;
- }
-
- /* Loop over all processes or until we find <browserDirectoryFilename> */
- QHashIterator<qint64, QString> i(procList);
- while (i.hasNext()) {
- i.next();
- if (i.value().toLower() == browserDirectoryFilename) {
- /* The browser is still running, so Vidalia should keep running too */
- return;
- }
- }
-
- /* The browser isn't running, exit Vidalia */
- vApp->quit();
-#endif
-}
-
-/** Called when the web browser failed to start, for example, because the path
- * specified to the web browser executable didn't lead to an executable. */
-void
-MainWindow::onBrowserFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting web browser"),
- tr("Vidalia was unable to start the configured web browser"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Called when the IM client failed to start, for example, because the path
- * specified to the IM client executable didn't lead to an executable. */
-void
-MainWindow::onIMFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting IM client"),
- tr("Vidalia was unable to start the configured IM client"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Starts the proxy server, if appropriately configured */
-void
-MainWindow::startProxy()
-{
- VidaliaSettings settings;
- QString executable = settings.getProxyExecutable();
- _proxyProcess->start(executable, settings.getProxyExecutableArguments());
-}
-
-/** Called when the proxy server fails to start, for example, because
- * the path specified didn't lead to an executable. */
-void
-MainWindow::onProxyFailed(QString errmsg)
-{
- Q_UNUSED(errmsg);
-
- /* Display an error message and see if the user wants some help */
- VMessageBox::warning(this, tr("Error starting proxy server"),
- tr("Vidalia was unable to start the configured proxy server"),
- VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
-}
-
-/** Start a web browser when given the directory containing the executable and profile */
-void
-MainWindow::launchBrowserFromDirectory()
-{
- VidaliaSettings settings;
-
- QString browserDirectory = settings.getBrowserDirectory();
- QString browserDirectoryFilename = settings.getBrowserExecutable();
-
- /* Set TZ=UTC (to stop leaking timezone information) and
- * MOZ_NO_REMOTE=1 (to allow multiple instances of Firefox */
- QStringList env = QProcess::systemEnvironment();
- env << "TZ=UTC";
- env << "MOZ_NO_REMOTE=1";
- _browserProcess->setEnvironment(env);
-
- /* The browser is in <browserDirectory>/App/Firefox/<browserDirectoryFilename> */
- QString browserExecutable =
- QDir::toNativeSeparators(browserDirectory + "/App/Firefox/" + browserDirectoryFilename);
- /* The profile is in <browserDirectory>/Data/profile */
- QString profileDir =
- QDir::toNativeSeparators(browserDirectory + "/Data/profile");
-
- /* Copy the profile directory if it's not already there */
- QDir browserDirObj = QDir(browserDirectory);
-
- /* Copy the profile directory if it's not already there */
- if (!browserDirObj.exists("Data/profile")) {
- browserDirObj.mkdir("Data/profile");
- copy_dir(browserDirectory + "/App/DefaultData/profile", browserDirectory + "/Data/profile");
- }
-
- /* Copy the plugins directory if it's not already there */
- if (!browserDirObj.exists("Data/plugins")) {
- browserDirObj.mkdir("Data/plugins");
- copy_dir(browserDirectory + "/App/DefaultData/plugins", browserDirectory + "/Data/plugins");
- }
-
- /* Build the command line arguments */
- QStringList commandLine;
- // Is this better or worse than MOZ_NO_REMOTE?
- commandLine << "-no-remote";
- commandLine << "-profile";
- commandLine << profileDir;
-
- /* Launch the browser */
- _browserProcess->start(browserExecutable, commandLine);
-}
-
-/** Starts the web browser and IM client, if appropriately configured */
-void
-MainWindow::startSubprocesses()
-{
- VidaliaSettings settings;
- QString subprocess;
-
- /* Launch the web browser */
- if (!(subprocess = settings.getBrowserDirectory()).isEmpty()) {
- /* The user has set BrowserDirectory; use this */
- launchBrowserFromDirectory();
- } else if (!(subprocess = settings.getBrowserExecutable()).isEmpty()) {
- /* BrowserDirectory is not set, but BrowserExecutable is; use this */
- _browserProcess->setEnvironment(QProcess::systemEnvironment() << "TZ=UTC");
- _browserProcess->start(subprocess, QStringList());
- }
-
- /* Launch the IM client */
- subprocess = settings.getIMExecutable();
-
- if (!subprocess.isEmpty())
- _imProcess->start(subprocess, QStringList());
-}
-
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index 21ab1a2..3b7d544 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -147,21 +147,6 @@ private slots:
/** Deletes the tab at index if it exists and it isn't the Status tab */
void delTab(int index = -1);
-// /** Handles adding a new tab corresponding to a plugin */
-// void showPluginTab();
-
- /** Called when the web browser or IM client have stopped */
- void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
- /** Called periodically to check if the browser is running. If it is not,
- * exit Vidalia cleanly */
- void onCheckForBrowser();
- /** Called web the web browser failed to start */
- void onBrowserFailed(QString errmsg);
- /** Called web the IM client failed to start */
- void onIMFailed(QString errmsg);
- /** Called when the proxy server fails to start */
- void onProxyFailed(QString errmsg);
-
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -264,20 +249,6 @@ private:
/** The Vidalia icon that sits in the tray. */
QSystemTrayIcon _trayIcon;
- /** Start a web browser when given the directory containing the executable and profile */
- void launchBrowserFromDirectory();
- /** Starts the web browser, if appropriately configured */
- void startSubprocesses();
- /** Starts the proxy server, if appropriately configured */
- void startProxy();
-
- /** A HelperProcess object that manages the web browser */
- HelperProcess* _browserProcess;
- /** A HelperProcess object that manages the IM client */
- HelperProcess* _imProcess;
- /** A HelperProcess object that manages the proxy server */
- HelperProcess* _proxyProcess;
-
#if defined(USE_AUTOUPDATE)
/** Timer used to remind us to check for software updates. */
QTimer _updateTimer;
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index 4d6d745..f51607e 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -15,10 +15,12 @@ PluginEngine::PluginEngine(QObject *parent)
ADD_PROTOTYPE(TorControlPrototype)
globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
+ globalObject().setProperty("vidaliaApp", newQObject(vApp));
globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
globalObject().setProperty("vdebug", newFunction(vdebug));
+ globalObject().setProperty("findWidget", newFunction(findWidget));
VidaliaSettings settings;
globalObject().setProperty("pluginPath", QScriptValue(settings.pluginPath()));
@@ -28,6 +30,9 @@ PluginEngine::PluginEngine(QObject *parent)
DebugDialog::outputDebug(QString(" %1").arg(ext));
loadAllPlugins();
+
+// debugger.attachTo(this);
+// debugger.standardWindow()->show();
}
PluginEngine::~PluginEngine()
@@ -183,3 +188,24 @@ PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
return engine->undefinedValue();
}
+
+QScriptValue
+PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine) {
+ if(context->argumentCount() != 2)
+ return context->throwError(QString("findWidget called with the wrong argument count. Expected 2."));
+
+ QWidget *widget = qscriptvalue_cast<QWidget *>(context->argument(0));
+ QString name = context->argument(1).toString();
+
+ QObjectList list = widget->children();
+ QScriptValue ret = engine->nullValue();
+
+ for(int i = 0; i < list.length(); i++) {
+ if(list[i]->objectName() == name) {
+ ret = QScriptValue(i);
+ break;
+ }
+ }
+
+ return ret;
+}
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 13890f6..854ed15 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -3,6 +3,7 @@
#include <QtGui>
#include <QtScript>
+#include <QScriptEngineDebugger>
#include "VidaliaTabPrototype.h"
#include "HelperProcessPrototype.h"
@@ -34,11 +35,14 @@ class PluginEngine : public QScriptEngine {
static bool loadFile(QString fileName, QScriptEngine *engine);
static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
static QScriptValue vdebug(QScriptContext *context, QScriptEngine *engine);
+ static QScriptValue findWidget(QScriptContext *context, QScriptEngine *engine);
void loadAllPlugins();
void tryLoadPlugin(QDir path);
QList<PluginWrapper *> wrappers;
+
+ QScriptEngineDebugger debugger;
};
#endif
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
index 81d4d94..c2232e1 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
@@ -47,3 +47,17 @@ HelperProcessPrototype::isDone() const
return obj->isDone();
}
+QStringList
+HelperProcessPrototype::systemEnvironment()
+{
+ return HelperProcess::systemEnvironment();
+}
+
+void
+HelperProcessPrototype::setEnvironment(const QStringList &env)
+{
+ HelperProcess *obj = qscriptvalue_cast<HelperProcess *>(thisObject());
+
+ if(obj)
+ obj->setEnvironment(env);
+}
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.h b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
index b64a27c..1751347 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.h
@@ -19,6 +19,8 @@ class HelperProcessPrototype : public QObject, public QScriptable
Q_INVOKABLE void start(const QString &app, const QString &args);
Q_INVOKABLE void start(const QString &app, const QStringList &args);
Q_INVOKABLE bool isDone() const;
+ Q_INVOKABLE QStringList systemEnvironment();
+ Q_INVOKABLE void setEnvironment(const QStringList &env);
};
Q_DECLARE_METATYPE(HelperProcess *);
1
0
[vidalia/alpha] Add headers and temporary disable the include function
by chiiph@torproject.org 02 Jul '11
by chiiph@torproject.org 02 Jul '11
02 Jul '11
commit bad8cdb7ad327116311daca0c102c747aa0de568
Author: Tomas Touceda <chiiph(a)torproject.org>
Date: Sat Jul 2 18:12:16 2011 -0300
Add headers and temporary disable the include function
The include function won't be on the 0.3.1 release, it doesn't work as of
today, so I'm disabling it.
---
src/vidalia/plugin/DebugDialog.cpp | 16 +++
src/vidalia/plugin/DebugDialog.h | 16 +++
src/vidalia/plugin/PluginEngine.cpp | 142 +++++++++----------
src/vidalia/plugin/PluginEngine.h | 19 +++-
src/vidalia/plugin/PluginWrapper.cpp | 15 ++
src/vidalia/plugin/PluginWrapper.h | 15 ++
.../plugin/prototypes/HelperProcessPrototype.cpp | 21 +++-
.../plugin/prototypes/TorControlPrototype.cpp | 15 ++
.../plugin/prototypes/TorControlPrototype.h | 10 +-
.../plugin/prototypes/VidaliaTabPrototype.cpp | 21 +++-
.../plugin/prototypes/VidaliaTabPrototype.h | 15 ++
11 files changed, 219 insertions(+), 86 deletions(-)
diff --git a/src/vidalia/plugin/DebugDialog.cpp b/src/vidalia/plugin/DebugDialog.cpp
index df2aa1e..683ed6a 100644
--- a/src/vidalia/plugin/DebugDialog.cpp
+++ b/src/vidalia/plugin/DebugDialog.cpp
@@ -1,3 +1,19 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file DebugDialog.cpp
+** \brief Simple dialog to see exceptions, syntaxis problems, and general
+** output for pluging
+*/
+
#include "DebugDialog.h"
QStringList DebugDialog::outputBuffer;
diff --git a/src/vidalia/plugin/DebugDialog.h b/src/vidalia/plugin/DebugDialog.h
index 76b3bb6..7f6ff0a 100644
--- a/src/vidalia/plugin/DebugDialog.h
+++ b/src/vidalia/plugin/DebugDialog.h
@@ -1,3 +1,19 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file DebugDialog.h
+** \brief Simple dialog to see exceptions, syntaxis problems, and general
+** output for pluging
+*/
+
#ifndef DEBUGDIALOG_H
#define DEBUGDIALOG_H
diff --git a/src/vidalia/plugin/PluginEngine.cpp b/src/vidalia/plugin/PluginEngine.cpp
index f51607e..41f9712 100644
--- a/src/vidalia/plugin/PluginEngine.cpp
+++ b/src/vidalia/plugin/PluginEngine.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginEngine.cpp
+** \brief Engine that handles all plugin related features
+*/
+
#include "PluginEngine.h"
#include "VidaliaSettings.h"
#include "PluginWrapper.h"
@@ -17,7 +32,7 @@ PluginEngine::PluginEngine(QObject *parent)
globalObject().setProperty("torControl", newQObject(Vidalia::torControl()));
globalObject().setProperty("vidaliaApp", newQObject(vApp));
- globalObject().setProperty("include", newFunction(includeScript));
+// globalObject().setProperty("include", newFunction(includeScript));
globalObject().setProperty("importExtension", newFunction(importExtension));
globalObject().setProperty("vdebug", newFunction(vdebug));
globalObject().setProperty("findWidget", newFunction(findWidget));
@@ -30,9 +45,6 @@ PluginEngine::PluginEngine(QObject *parent)
DebugDialog::outputDebug(QString(" %1").arg(ext));
loadAllPlugins();
-
-// debugger.attachTo(this);
-// debugger.standardWindow()->show();
}
PluginEngine::~PluginEngine()
@@ -104,75 +116,54 @@ PluginEngine::importExtension(QScriptContext *context, QScriptEngine *engine)
return engine->importExtension(context->argument(0).toString());
}
-QScriptValue
-PluginEngine::includeScript(QScriptContext *context, QScriptEngine *engine)
-{
- QString currentFileName = engine->globalObject().property("qs").property("script").property("absoluteFilePath").toString();
- QFileInfo currentFileInfo(currentFileName);
- QString path = currentFileInfo.path();
- QString importFile = context->argument(0).toString();
- QFileInfo importInfo(importFile);
- if (importInfo.isRelative()) {
- importFile = path + "/" + importInfo.filePath();
- }
- if (!loadFile(importFile, engine)) {
- return context->throwError(QString("Failed to resolve include: %1").arg(importFile));
- }
- return engine->toScriptValue(true);
-}
-
-bool
-PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
-{
- // avoid loading files more than once
- static QSet<QString> loadedFiles;
- QFileInfo fileInfo(fileName);
- QString absoluteFileName = fileInfo.absoluteFilePath();
- QString absolutePath = fileInfo.absolutePath();
- QString canonicalFileName = fileInfo.canonicalFilePath();
- if (loadedFiles.contains(canonicalFileName)) {
- return true;
- }
- loadedFiles.insert(canonicalFileName);
- QString path = fileInfo.path();
-
- // load the file
- QFile file(fileName);
- if (file.open(QFile::ReadOnly)) {
- QTextStream stream(&file);
- QString contents = stream.readAll();
- file.close();
-
- int endlineIndex = contents.indexOf('\n');
- QString line = contents.left(endlineIndex);
- int lineNumber = 1;
-
- // strip off #!/usr/bin/env qscript line
- if (line.startsWith("#!")) {
- contents.remove(0, endlineIndex+1);
- ++lineNumber;
- }
-
- // set qt.script.absoluteFilePath
- QScriptValue script = engine->globalObject().property("qs").property("script");
- QScriptValue oldFilePathValue = script.property("absoluteFilePath");
- QScriptValue oldPathValue = script.property("absolutePath");
- script.setProperty("absoluteFilePath", engine->toScriptValue(absoluteFileName));
- script.setProperty("absolutePath", engine->toScriptValue(absolutePath));
-
- QScriptValue r = engine->evaluate(contents, fileName, lineNumber);
- if (engine->hasUncaughtException()) {
- QStringList backtrace = engine->uncaughtExceptionBacktrace();
- qDebug() << QString(" %1\n%2\n\n").arg(r.toString()).arg(backtrace.join("\n"));
- return true;
- }
- script.setProperty("absoluteFilePath", oldFilePathValue); // if we come from includeScript(), or whereever
- script.setProperty("absolutePath", oldPathValue); // if we come from includeScript(), or whereever
- } else {
- return false;
- }
- return true;
-}
+//QScriptValue
+//PluginEngine::includeScript(QScriptContext *context, QScriptEngine *engine)
+//{
+// VidaliaSettings settings;
+// QString path = settings.pluginPath();
+// QString importFile = context->argument(0).toString();
+// QFileInfo importInfo(importFile);
+// if (importInfo.isRelative()) {
+// importFile = path + "/" + importInfo.filePath();
+// }
+
+// if (!loadFile(importFile, engine)) {
+// return context->throwError(QString("Failed to resolve include: %1").arg(importFile));
+// }
+// return engine->toScriptValue(true);
+//}
+
+//bool
+//PluginEngine::loadFile(QString fileName, QScriptEngine *engine)
+//{
+// static QSet<QString> loadedFiles;
+// QFileInfo fileInfo(fileName);
+// QString absoluteFileName = fileInfo.absoluteFilePath();
+// QString absolutePath = fileInfo.absolutePath();
+// QString canonicalFileName = fileInfo.canonicalFilePath();
+// if (loadedFiles.contains(canonicalFileName)) {
+// return true;
+// }
+// loadedFiles.insert(canonicalFileName);
+// QString path = fileInfo.path();
+
+// QFile file(fileName);
+// if (file.open(QFile::ReadOnly)) {
+// QTextStream stream(&file);
+// QString contents = stream.readAll();
+// file.close();
+
+// QScriptValue r = engine->evaluate(contents);
+// if (engine->hasUncaughtException()) {
+// QStringList backtrace = engine->uncaughtExceptionBacktrace();
+// qDebug() << QString(" %1\n%2\n\n").arg(r.toString()).arg(backtrace.join("\n"));
+// return true;
+// }
+// } else {
+// return false;
+// }
+// return true;
+//}
QScriptValue
PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
@@ -184,13 +175,14 @@ PluginEngine::vdebug(QScriptContext *context, QScriptEngine *engine)
result.append(context->argument(i).toString());
}
- qWarning() << result;
+ vInfo(result);
return engine->undefinedValue();
}
QScriptValue
-PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine) {
+PluginEngine::findWidget(QScriptContext *context, QScriptEngine *engine)
+{
if(context->argumentCount() != 2)
return context->throwError(QString("findWidget called with the wrong argument count. Expected 2."));
diff --git a/src/vidalia/plugin/PluginEngine.h b/src/vidalia/plugin/PluginEngine.h
index 854ed15..d8dc273 100644
--- a/src/vidalia/plugin/PluginEngine.h
+++ b/src/vidalia/plugin/PluginEngine.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginEngine.h
+** \brief Engine that handles all plugin related features
+*/
+
#ifndef PLUGINENGINE_H
#define PLUGINENGINE_H
@@ -32,8 +47,8 @@ class PluginEngine : public QScriptEngine {
protected:
static QScriptValue importExtension(QScriptContext *context, QScriptEngine *engine);
- static bool loadFile(QString fileName, QScriptEngine *engine);
- static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
+// static bool loadFile(QString fileName, QScriptEngine *engine);
+// static QScriptValue includeScript(QScriptContext *context, QScriptEngine *engine);
static QScriptValue vdebug(QScriptContext *context, QScriptEngine *engine);
static QScriptValue findWidget(QScriptContext *context, QScriptEngine *engine);
diff --git a/src/vidalia/plugin/PluginWrapper.cpp b/src/vidalia/plugin/PluginWrapper.cpp
index 2736dbc..87a6ff1 100644
--- a/src/vidalia/plugin/PluginWrapper.cpp
+++ b/src/vidalia/plugin/PluginWrapper.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginWrapper.cpp
+** \brief Wrapper for the plugin scripts
+*/
+
#include "PluginWrapper.h"
#include "PluginEngine.h"
#include "DebugDialog.h"
diff --git a/src/vidalia/plugin/PluginWrapper.h b/src/vidalia/plugin/PluginWrapper.h
index 15f7853..1253bee 100644
--- a/src/vidalia/plugin/PluginWrapper.h
+++ b/src/vidalia/plugin/PluginWrapper.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file PluginWrapper.h
+** \brief Wrapper for the plugin scripts
+*/
+
#ifndef PLUGINWRAPPER_H
#define PLUGINWRAPPER_H
diff --git a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
index c2232e1..2fcd126 100644
--- a/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/HelperProcessPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If
+** you did not receive the LICENSE file with this file, you may obtain it
+** from the Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file HelperProcessPrototype.cpp
+** \brief Prototype for the HelperProcess class
+*/
+
#include "HelperProcessPrototype.h"
HelperProcessPrototype::HelperProcessPrototype(QObject *parent)
@@ -11,12 +26,14 @@ HelperProcessPrototype::constructor(QScriptContext *context, QScriptEngine *engi
}
int
-HelperProcessPrototype::metaTypeId() {
+HelperProcessPrototype::metaTypeId()
+{
return qMetaTypeId<HelperProcess *>();
}
QString
-HelperProcessPrototype::name() {
+HelperProcessPrototype::name()
+{
return QString("HelperProcess");
}
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
index 56bccc0..742a428 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file TorControlPrototype.cpp
+** \brief Prototype for TorControl class
+*/
+
#include "TorControlPrototype.h"
#define GET_AND_CALL(type, func, res) \
diff --git a/src/vidalia/plugin/prototypes/TorControlPrototype.h b/src/vidalia/plugin/prototypes/TorControlPrototype.h
index 8127c76..eb0cc6b 100644
--- a/src/vidalia/plugin/prototypes/TorControlPrototype.h
+++ b/src/vidalia/plugin/prototypes/TorControlPrototype.h
@@ -1,16 +1,16 @@
/*
** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If
-** you did not receive the LICENSE file with this file, you may obtain it
-** from the Vidalia source package distributed by the Vidalia Project at
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
** including this file, may be copied, modified, propagated, or distributed
** except according to the terms described in the LICENSE file.
*/
-/*
+/*
** \file TorControlPrototype.h
-** \brief Object for interacting with the Tor process and control interface
+** \brief Prototype for TorControl class
*/
#ifndef _TORCONTROLPROTO_H
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
index 52b8fef..8f71a37 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.cpp
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file VidaliaTabPrototype.cpp
+** \brief Prototype for VidaliaTab class
+*/
+
#include "VidaliaTabPrototype.h"
VidaliaTabPrototype::VidaliaTabPrototype(QObject *parent)
@@ -21,12 +36,14 @@ VidaliaTabPrototype::constructor(QScriptContext *context, QScriptEngine *engine)
}
int
-VidaliaTabPrototype::metaTypeId() {
+VidaliaTabPrototype::metaTypeId()
+{
return qMetaTypeId<VidaliaTab *>();
}
QString
-VidaliaTabPrototype::name() {
+VidaliaTabPrototype::name()
+{
return QString("VidaliaTab");
}
diff --git a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
index 59d640d..dcc355b 100644
--- a/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
+++ b/src/vidalia/plugin/prototypes/VidaliaTabPrototype.h
@@ -1,3 +1,18 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
+** including this file, may be copied, modified, propagated, or distributed
+** except according to the terms described in the LICENSE file.
+*/
+
+/*
+** \file VidaliaTabPrototype.h
+** \brief Prototype for VidaliaTab class
+*/
+
#ifndef VIDALIATABPROT_H
#define VIDALIATABPROT_H
1
0
[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
[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
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