[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [vidalia/alpha] Improve engine and clean some code



commit d6416b36e8378de1e59ad7532f9d44e8a9539364
Author: Tomas Touceda <chiiph@xxxxxxxxxxxxxx>
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 *);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits