[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2674: Patch from sjmurdoch to optionally start an IM application w (in vidalia: . trunk/src/vidalia trunk/src/vidalia/config)
Author: edmanm
Date: 2008-06-06 19:28:48 -0400 (Fri, 06 Jun 2008)
New Revision: 2674
Modified:
vidalia/
vidalia/trunk/src/vidalia/config/vidaliasettings.cpp
vidalia/trunk/src/vidalia/config/vidaliasettings.h
vidalia/trunk/src/vidalia/helperprocess.cpp
vidalia/trunk/src/vidalia/helperprocess.h
vidalia/trunk/src/vidalia/mainwindow.cpp
vidalia/trunk/src/vidalia/mainwindow.h
Log:
r476@thebe: edmanm | 2008-06-06 19:24:12 -0400
Patch from sjmurdoch to optionally start an IM application when Vidalia
starts.
Property changes on: vidalia
___________________________________________________________________
svk:merge ticket from /local/vidalia [r476] on 45a62a8a-8088-484c-baad-c7b3e776dd32
Modified: vidalia/trunk/src/vidalia/config/vidaliasettings.cpp
===================================================================
--- vidalia/trunk/src/vidalia/config/vidaliasettings.cpp 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/config/vidaliasettings.cpp 2008-06-06 23:28:48 UTC (rev 2674)
@@ -32,6 +32,7 @@
#define SETTING_DATA_DIRECTORY "DataDirectory"
#define SETTING_SHOW_MAINWINDOW_AT_START "ShowMainWindowAtStart"
#define SETTING_BROWSER_EXECUTABLE "BrowserExecutable"
+#define SETTING_IM_EXECUTABLE "IMExecutable"
#define SETTING_RUN_PROXY_AT_START "RunProxyAtStart"
#define SETTING_PROXY_EXECUTABLE "ProxyExecutable"
#define SETTING_PROXY_EXECUTABLE_ARGUMENTS "ProxyExecutableArguments"
@@ -66,6 +67,7 @@
setDefault(SETTING_RUN_TOR_AT_START, true);
setDefault(SETTING_SHOW_MAINWINDOW_AT_START, true);
setDefault(SETTING_BROWSER_EXECUTABLE, "");
+ setDefault(SETTING_IM_EXECUTABLE, "");
setDefault(SETTING_RUN_PROXY_AT_START, false);
setDefault(SETTING_PROXY_EXECUTABLE, "");
setDefault(SETTING_PROXY_EXECUTABLE_ARGUMENTS, QStringList());
@@ -181,6 +183,22 @@
setValue(SETTING_BROWSER_EXECUTABLE, browserExecutable);
}
+/** Returns a fully-qualified path to the IM client, including the
+ * executable name. */
+QString
+VidaliaSettings::getIMExecutable() const
+{
+ return QDir::convertSeparators(value(SETTING_IM_EXECUTABLE).toString());
+}
+
+/** Sets the location and name of the IM client executable to the given string.
+ * If set to the empty string, the client will not be started. */
+void
+VidaliaSettings::setIMExecutable(const QString &IMExecutable)
+{
+ setValue(SETTING_IM_EXECUTABLE, IMExecutable);
+}
+
/** Returns true if Vidalia should start a proxy application when it
* starts. */
bool
Modified: vidalia/trunk/src/vidalia/config/vidaliasettings.h
===================================================================
--- vidalia/trunk/src/vidalia/config/vidaliasettings.h 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/config/vidaliasettings.h 2008-06-06 23:28:48 UTC (rev 2674)
@@ -68,6 +68,13 @@
* string. If set to the empty string, the browser will not be started. */
void setBrowserExecutable(const QString &browserExecutable);
+ /** Returns a fully-qualified path to the IM client, including the
+ * executable name. */
+ QString getIMExecutable() const;
+ /** Sets the location and name of the IM client executable to the given
+ * string. If set to the empty string, the client will not be started. */
+ void setIMExecutable(const QString &IMExecutable);
+
/** Returns true if Vidalia should start a proxy application when it
* starts. */
bool runProxyAtStart();
Modified: vidalia/trunk/src/vidalia/helperprocess.cpp
===================================================================
--- vidalia/trunk/src/vidalia/helperprocess.cpp 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/helperprocess.cpp 2008-06-06 23:28:48 UTC (rev 2674)
@@ -50,6 +50,12 @@
// Call error handling routine on errors
QObject::connect(this, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(onError(QProcess::ProcessError)));
+ // Call started handler on successful startup
+ QObject::connect(this, SIGNAL(started()),
+ this, SLOT(onStart()));
+
+ // Mark as not having started
+ _okStart = false;
}
/** Start the specified application. */
@@ -70,4 +76,16 @@
}
}
+/** Invoked when underlying QProcess starts. */
+void
+HelperProcess::onStart()
+{
+ _okStart = true;
+}
+/** Returns true iff process is not running. */
+bool
+HelperProcess::isDone() const
+{
+ return state() == NotRunning;
+}
Modified: vidalia/trunk/src/vidalia/helperprocess.h
===================================================================
--- vidalia/trunk/src/vidalia/helperprocess.h 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/helperprocess.h 2008-06-06 23:28:48 UTC (rev 2674)
@@ -53,10 +53,18 @@
HelperProcess(QObject *parent = 0);
/** Start the specified application. */
void start(const QString &app, const QStringList &args);
+ /** Returns true iff process is not running. */
+ bool isDone() const;
+private:
+ /** True iff the underlying QProcess has sucessfully started */
+ bool _okStart;
+
private slots:
/** Invoked when underlying QProcess fails. */
void onError(QProcess::ProcessError error);
+ /** Invoked when underlying QProcess starts. */
+ void onStart();
signals:
/** Invoked when start() fails. */
Modified: vidalia/trunk/src/vidalia/mainwindow.cpp
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.cpp 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/mainwindow.cpp 2008-06-06 23:28:48 UTC (rev 2674)
@@ -128,10 +128,17 @@
/* Create a new HelperProcess object, used to start the web browser */
_browserProcess = new HelperProcess(this);
connect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
- this, SLOT(onBrowserFinished(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 web browser */
+ _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)),
@@ -409,26 +416,43 @@
#endif
}
-/** Starts the web browser, if appropriately configured */
-void MainWindow::startBrowser()
+/** Starts the web browser and IM client, if appropriately configured */
+void MainWindow::startSubprocesses()
{
VidaliaSettings settings;
QString executable = settings.getBrowserExecutable();
if (!executable.isEmpty())
_browserProcess->start(executable, QStringList());
+
+ executable = settings.getIMExecutable();
+
+ if (!executable.isEmpty())
+ _imProcess->start(executable, QStringList());
+
}
-/** Called when browser has exited */
-void MainWindow::onBrowserFinished(int exitCode, QProcess::ExitStatus exitStatus)
+/** Called when browser or IM client have exited */
+void MainWindow::onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitCode)
Q_UNUSED(exitStatus)
- shutdown();
+ /* Get path to browser and IM client */
+ VidaliaSettings settings;
+ QString browserExecutable = settings.getBrowserExecutable();
+ QString imExecutable = settings.getIMExecutable();
+
+ /* A subprocess is finished if it successfully exited or was never asked to start */
+ bool browserDone = browserExecutable.isEmpty() || _browserProcess->isDone();
+ bool imDone = imExecutable.isEmpty() || _imProcess->isDone();
+
+ /* Exit if both subprocesses are finished */
+ if (browserDone && imDone)
+ shutdown();
}
-/** Called when the web browser, for example, because the path
+/** 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)
@@ -441,6 +465,19 @@
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()
{
@@ -1032,7 +1069,7 @@
MainWindow::circuitEstablished()
{
updateTorStatus(CircuitEstablished);
- startBrowser();
+ startSubprocesses();
}
/** Checks the status of the current version of Tor to see if it's old,
Modified: vidalia/trunk/src/vidalia/mainwindow.h
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.h 2008-06-06 21:57:53 UTC (rev 2673)
+++ vidalia/trunk/src/vidalia/mainwindow.h 2008-06-06 23:28:48 UTC (rev 2674)
@@ -101,10 +101,12 @@
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 when the web browser or IM client have stopped */
+ void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
/** 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);
@@ -137,7 +139,7 @@
* previously set TorStatus value. */
TorStatus updateTorStatus(TorStatus status);
/** Starts the web browser, if appropriately configured */
- void startBrowser();
+ void startSubprocesses();
/** Starts the proxy server, if appropriately configured */
void startProxy();
/** Converts a TorStatus enum value to a string for debug logging purposes. */
@@ -179,6 +181,8 @@
TorControl* _torControl;
/** 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;
/** Remembers the control password between when we start Tor with a hash of