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

[vidalia-svn] r2206: Apply patch from Steven J. Murdoch that adds a BrowserExecut (in trunk: . src/vidalia src/vidalia/config)



Author: edmanm
Date: 2007-12-09 14:50:55 -0500 (Sun, 09 Dec 2007)
New Revision: 2206

Added:
   trunk/src/vidalia/browserprocess.cpp
   trunk/src/vidalia/browserprocess.h
Modified:
   trunk/
   trunk/AUTHORS
   trunk/src/vidalia/CMakeLists.txt
   trunk/src/vidalia/config/vidaliasettings.cpp
   trunk/src/vidalia/config/vidaliasettings.h
   trunk/src/vidalia/mainwindow.cpp
   trunk/src/vidalia/mainwindow.h
Log:
 r2280@lysithea:  edmanm | 2007-12-09 14:22:59 -0500
 Apply patch from Steven J. Murdoch that adds a BrowserExecutable configuration
 option to launch a Web browser when Tor has built a circuit, and exit Vidalia
 when the browser is closed.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /local/vidalia/trunk [r2280] on 0108964c-5b0b-4c9e-969f-e2288315d100

Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/AUTHORS	2007-12-09 19:50:55 UTC (rev 2206)
@@ -31,6 +31,10 @@
   Andrew Lewman wrote the original Mac OS X bundle installer off which
   Vidalia's is based, and also added Torbutton to the bundle.
 
+  Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/> wrote the code
+  to launch a web browser when Tor has built a circuit and close Vidalia when
+  the browser has exited.
+
   Brandon Nase <http://www.students.dsu.edu/naseb/> designed and built 
   the Vidalia-Project website.
 

Modified: trunk/src/vidalia/CMakeLists.txt
===================================================================
--- trunk/src/vidalia/CMakeLists.txt	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/src/vidalia/CMakeLists.txt	2007-12-09 19:50:55 UTC (rev 2206)
@@ -176,6 +176,7 @@
   vclicklabel.cpp
   vidaliawindow.cpp
   vmessagebox.cpp
+  browserprocess.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
   vidalia.h
@@ -184,6 +185,7 @@
   vclicklabel.h
   vidaliawindow.h
   vmessagebox.h
+  browserprocess.h
 )
 
 ## Specify all the Qt Designer .ui files

Added: trunk/src/vidalia/browserprocess.cpp
===================================================================
--- trunk/src/vidalia/browserprocess.cpp	                        (rev 0)
+++ trunk/src/vidalia/browserprocess.cpp	2007-12-09 19:50:55 UTC (rev 2206)
@@ -0,0 +1,54 @@
+/****************************************************************
+ *  This file is distributed under the following license:
+ *
+ *  Copyright (C) 2007, Steven J. Murdoch 
+ *                      <http://www.cl.cam.ac.uk/users/sjm217/>
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ *  Boston, MA  02110-1301, USA.
+ ****************************************************************/
+
+/**
+ ** Test invoking Firefox from Qt
+ ** Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/>
+ ** $Id$
+ **/
+
+#include <QString>
+  
+#include "browserprocess.h"
+
+BrowserProcess::BrowserProcess(QObject *parent)
+: QProcess(parent)
+{
+  // Call error handling routine on errors
+  QObject::connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError(QProcess::ProcessError)));
+}
+
+void
+BrowserProcess::start(QString app, QStringList args) 
+{
+  // Start the specified application
+  QProcess::start(app, args, QIODevice::ReadOnly | QIODevice::Text);
+}
+
+void
+BrowserProcess::onError(QProcess::ProcessError error)
+{
+  // Pass up error messages on startup, but ignore the rest
+  if (error == QProcess::FailedToStart) {
+    emit startFailed(errorString());
+  }
+}


Property changes on: trunk/src/vidalia/browserprocess.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/src/vidalia/browserprocess.h
===================================================================
--- trunk/src/vidalia/browserprocess.h	                        (rev 0)
+++ trunk/src/vidalia/browserprocess.h	2007-12-09 19:50:55 UTC (rev 2206)
@@ -0,0 +1,53 @@
+/****************************************************************
+ *  This file is distributed under the following license:
+ *
+ *  Copyright (C) 2007, Steven J. Murdoch 
+ *                      <http://www.cl.cam.ac.uk/users/sjm217/>
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; either version 2
+ *  of the License, or (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
+ *  Boston, MA  02110-1301, USA.
+ ****************************************************************/
+
+/**
+ ** Test invoking Firefox from Qt
+ ** Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/>
+ ** $Id$
+ **/
+
+#ifndef _BROWSERPROCESS_H
+#define _BROWSERPROCESS_H
+
+#include <QProcess>
+
+class BrowserProcess : public QProcess
+{
+  Q_OBJECT
+
+public:
+  // Default constructor
+  BrowserProcess(QObject *parent = 0);
+  // Start the specified application
+  void start(QString app, QStringList args);
+
+private slots:
+  // Invoked when underlying QProcess fails
+  void onError(QProcess::ProcessError error);
+
+signals:
+  // Invoked when start() fails
+  void startFailed(QString errorMessage);
+};
+
+#endif


Property changes on: trunk/src/vidalia/browserprocess.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/src/vidalia/config/vidaliasettings.cpp
===================================================================
--- trunk/src/vidalia/config/vidaliasettings.cpp	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/src/vidalia/config/vidaliasettings.cpp	2007-12-09 19:50:55 UTC (rev 2206)
@@ -42,6 +42,7 @@
 #define SETTING_RUN_TOR_AT_START    "RunTorAtStart"
 #define SETTING_DATA_DIRECTORY      "DataDirectory"
 #define SETTING_SHOW_MAINWINDOW_AT_START  "ShowMainWindowAtStart"
+#define SETTING_BROWSER_EXECUTABLE  "BrowserExecutable"
 
 #if defined(Q_OS_WIN32)
 #define STARTUP_REG_KEY        "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@@ -72,6 +73,7 @@
   setDefault(SETTING_LANGUAGE, LanguageSupport::defaultLanguageCode());
   setDefault(SETTING_RUN_TOR_AT_START, true);
   setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true);
+  setDefault(SETTING_BROWSER_EXECUTABLE, "");
 }
 
 /** Gets the currently preferred language code for Vidalia. */
@@ -168,3 +170,19 @@
 #endif
 }
 
+/** Returns a fully-qualified path to the web browser, including the
+ * executable name. */
+QString
+VidaliaSettings::getBrowserExecutable() const
+{
+  return QDir::convertSeparators(value(SETTING_BROWSER_EXECUTABLE).toString());
+}
+
+/** Sets the location and name of the web browser executable to the given string.
+ * If set to the empty string, the browser will not be started. */
+void
+VidaliaSettings::setBrowserExecutable(const QString &browserExecutable)
+{
+  setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
+}
+

Modified: trunk/src/vidalia/config/vidaliasettings.h
===================================================================
--- trunk/src/vidalia/config/vidaliasettings.h	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/src/vidalia/config/vidaliasettings.h	2007-12-09 19:50:55 UTC (rev 2206)
@@ -71,6 +71,13 @@
   bool runVidaliaOnBoot();
   /** Set whether to run Vidalia on system boot. */
   void setRunVidaliaOnBoot(bool run);
+
+  /** Returns a fully-qualified path to the web browser, including the
+   * executable name. */
+  QString getBrowserExecutable() const;
+  /** Sets the location and name of the web browser executable to the given string.
+   * If set to the empty string, the browser will not be started. */
+  void setBrowserExecutable(const QString &browserExecutable);
 };
 
 #endif

Modified: trunk/src/vidalia/mainwindow.cpp
===================================================================
--- trunk/src/vidalia/mainwindow.cpp	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/src/vidalia/mainwindow.cpp	2007-12-09 19:50:55 UTC (rev 2206)
@@ -152,6 +152,13 @@
   _torControl->setEvent(TorEvents::ClientStatus,  this, true);
   _torControl->setEvent(TorEvents::GeneralStatus, this, true);
 
+  /* Create a new BrowserProcess object, used to start the web browser */
+  _browserProcess = new BrowserProcess(this);
+  connect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
+	         this, SLOT(onBrowserFinished(int, QProcess::ExitStatus)));
+  connect(_browserProcess, SIGNAL(startFailed(QString)),
+	         this, SLOT(onBrowserFailed(QString)));
+
   /* Catch signals when the application is running or shutting down */
   connect(vApp, SIGNAL(running()), this, SLOT(running()));
   connect(vApp, SIGNAL(shutdown()), this, SLOT(shutdown()));
@@ -427,6 +434,35 @@
 #endif
 }
 
+/** Starts the web browser, if appropriately configured */
+void MainWindow::startBrowser(TorStatus status)
+{
+  VidaliaSettings settings;
+  QString executable = settings.getBrowserExecutable();
+  
+  if (!executable.isEmpty())
+    _browserProcess->start(executable, QStringList());
+}
+
+/** Called when browser has exited */
+void MainWindow::onBrowserFinished(int exitCode, QProcess::ExitStatus exitStatus)
+{
+  shutdown();
+}
+
+/** Called when the web browser, 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 */
+  int response = VMessageBox::warning(this, tr("Error starting web browser"),
+				      tr("Vidalia was unable to start the configured web browser"),
+				      VMessageBox::Ok|VMessageBox::Default|VMessageBox::Escape);
+}
+
 /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
  * previously set TorStatus value.*/
 MainWindow::TorStatus
@@ -1006,6 +1042,7 @@
 MainWindow::circuitEstablished()
 {
   updateTorStatus(CircuitEstablished);
+  startBrowser(CircuitEstablished);
 }
 
 /** Checks the status of the current version of Tor to see if it's old,

Modified: trunk/src/vidalia/mainwindow.h
===================================================================
--- trunk/src/vidalia/mainwindow.h	2007-12-08 17:58:05 UTC (rev 2205)
+++ trunk/src/vidalia/mainwindow.h	2007-12-09 19:50:55 UTC (rev 2206)
@@ -49,6 +49,7 @@
 #include "help/browser/helpbrowser.h"
 #include "network/netviewer.h"
 #include "ui_mainwindow.h"
+#include "browserprocess.h"
 
 
 class MainWindow : public VidaliaWindow
@@ -116,6 +117,10 @@
   void showServerConfigDialog();
   /** Called when the "show on startup" checkbox is toggled. */
   void toggleShowOnStartup(bool checked);
+  /** Called when the web browser has stopped */
+  void onBrowserFinished(int exitCode, QProcess::ExitStatus exitStatus);
+  /** Called web the web browser failed to start */
+  void onBrowserFailed(QString errmsg);
   
 #if QT_VERSION >= 0x040200 && !defined(Q_WS_MAC)
   /** Displays the main window if <b>reason</b> is DoubleClick. */
@@ -147,6 +152,8 @@
   /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
    * previously set TorStatus value. */
   TorStatus updateTorStatus(TorStatus status);
+  /** Starts the web browser, if appropriately configured */
+  void startBrowser(TorStatus status);
   /** Converts a TorStatus enum value to a string for debug logging purposes. */
   QString toString(TorStatus status);
   /** Authenticates Vidalia to Tor's control port. */
@@ -184,6 +191,8 @@
   ConfigDialog* _configDialog;
   /** A TorControl object that handles communication with Tor */
   TorControl* _torControl;
+  /** A BrowserProcess object that manages the web browser */
+  BrowserProcess* _browserProcess;
   /** Remembers the control password between when we start Tor with a hash of
    * the password and when we need to provide the password itself. */
   QString _controlPassword;