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

[vidalia-svn] r1955: Make src/control/ not depend on src/config/. (in trunk: . src/control src/gui)



Author: edmanm
Date: 2007-09-29 16:59:05 -0400 (Sat, 29 Sep 2007)
New Revision: 1955

Modified:
   trunk/
   trunk/src/control/torcontrol.cpp
   trunk/src/control/torcontrol.h
   trunk/src/gui/mainwindow.cpp
Log:
 r1974@lysithea:  edmanm | 2007-09-29 16:26:30 -0400
 Make src/control/ not depend on src/config/.



Property changes on: trunk
___________________________________________________________________
 svk:merge ticket from /local/vidalia/trunk [r1974] on dc66be73-d13e-47ba-a267-8dc7cda68c65

Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp	2007-09-29 20:58:59 UTC (rev 1954)
+++ trunk/src/control/torcontrol.cpp	2007-09-29 20:59:05 UTC (rev 1955)
@@ -26,8 +26,6 @@
  */
 
 #include <QHostAddress>
-#include <config/torsettings.h>
-#include <util/net.h>
 #include <util/file.h>
 #include "torcontrol.h"
 
@@ -81,20 +79,11 @@
 /** Start the Tor process. Returns true if the process was successfully
  * started, otherwise returns false. */
 void
-TorControl::start()
+TorControl::start(const QString &tor, const QStringList &args)
 {
   if (isRunning()) {
     emit started();
   } else {
-    TorSettings settings;
-    
-    /* Make sure our torrc and the full path to it exists. If it doesn't,
-     * then touch it. */
-    QString torrc = settings.getTorrc();
-    if (!torrc.isEmpty()) {
-      touch_file(torrc, true);
-    }
-    
 #if defined(Q_OS_WIN32)
     if (TorService::isSupported() && _torService->isInstalled()) {
       _torService->start();
@@ -114,8 +103,7 @@
                        this, SLOT(onLogStdout(QString, QString)));
   
       /* Kick off the Tor process. */
-      _torProcess->start(expand_filename(settings.getExecutable()), 
-                         settings.getArguments());
+      _torProcess->start(expand_filename(tor), args);
 #if defined(Q_OS_WIN32)
     }
 #endif
@@ -199,13 +187,7 @@
   if (_torProcess) {
     return (_torProcess->pid() != 0);
   }
-  
-  TorSettings settings;
-  if (net_test_connect(settings.getControlAddress(),
-                       settings.getControlPort(), 250)) {
-    return true;
-  }
-  return false;
+  return _controlConn->isConnected();
 }
 
 /** Called when Tor has printed a log message to stdout. */
@@ -219,11 +201,9 @@
 /** Connect to Tor's control port. The control port to use is determined by
  * Vidalia's configuration file. */
 void
-TorControl::connect()
+TorControl::connect(const QHostAddress &address, quint16 port)
 {
-  TorSettings settings;
-  _controlConn->connect(settings.getControlAddress(),
-                        settings.getControlPort());
+  _controlConn->connect(address, port);
 }
 
 /** Emits a signal that the control socket successfully established a
@@ -271,7 +251,7 @@
 bool
 TorControl::isConnected()
 {
-  return (_controlConn->status() == ControlConnection::Connected);
+  return _controlConn->isConnected();
 }
 
 /** Send a message to Tor and reads the response. If Vidalia was unable to

Modified: trunk/src/control/torcontrol.h
===================================================================
--- trunk/src/control/torcontrol.h	2007-09-29 20:58:59 UTC (rev 1954)
+++ trunk/src/control/torcontrol.h	2007-09-29 20:59:05 UTC (rev 1955)
@@ -57,7 +57,7 @@
   ~TorControl();
 
   /** Start the Tor process */
-  void start();
+  void start(const QString &tor, const QStringList &args);
   /** Stop the Tor process */
   bool stop(QString *errmsg = 0);
   /** Detect if the Tor process is running */
@@ -66,7 +66,7 @@
   bool isVidaliaRunningTor();
   
   /** Connect to Tor's control socket */
-  void connect();
+  void connect(const QHostAddress &address, quint16 port);
   /** Disconnect from Tor's control socket */
   void disconnect();
   /** Check if we're connected to Tor's control socket */

Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp	2007-09-29 20:58:59 UTC (rev 1954)
+++ trunk/src/gui/mainwindow.cpp	2007-09-29 20:59:05 UTC (rev 1955)
@@ -35,6 +35,7 @@
 #include <util/file.h>
 #include <util/html.h>
 #include <util/string.h>
+#include <util/net.h>
 #include <QSysInfo>
 
 #include "common/vmessagebox.h"
@@ -505,14 +506,29 @@
 void 
 MainWindow::start()
 {
+  TorSettings settings;
+
   updateTorStatus(Starting);
+
+  /* Check if Tor is already running separately */
+  if (net_test_connect(settings.getControlAddress(),
+                       settings.getControlPort())) {
+    started();
+    return;
+  }
+
+  /* Make sure the torrc we want to use really exists. */
+  QString torrc = settings.getTorrc();
+  if (!torrc.isEmpty() && !QFileInfo(torrc).exists())
+    touch_file(torrc, true);
+
   /* This doesn't get set to false until Tor is actually up and running, so we
    * don't yell at users twice if their Tor doesn't even start, due to the fact
    * that QProcess::stopped() is emitted even if the process didn't even
    * start. */
   _isIntentionalExit = true;
   /* Kick off the Tor process */
-  _torControl->start();
+  _torControl->start(settings.getExecutable(), settings.getArguments());
 }
 
 /** Called when the Tor process fails to start, for example, because the path
@@ -551,6 +567,8 @@
 void 
 MainWindow::started()
 {
+  TorSettings settings;
+
   updateTorStatus(Started);
 
   /* Now that Tor is running, we want to know if it dies when we didn't want
@@ -561,7 +579,8 @@
   /* Remember whether we started Tor or not */
   _isVidaliaRunningTor = _torControl->isVidaliaRunningTor();
   /* Try to connect to Tor's control port */
-  _torControl->connect();
+  _torControl->connect(settings.getControlAddress(),
+                       settings.getControlPort());
 }
 
 /** Called when the connection to the control socket fails. The reason will be
@@ -578,7 +597,9 @@
 
   if (response == VMessageBox::Retry) {
     /* Let's give it another try. */
-    _torControl->connect();
+    TorSettings settings;
+    _torControl->connect(settings.getControlAddress(),
+                         settings.getControlPort());
   } else {
     /* Show the help browser (if requested) */
     if (response == VMessageBox::Help)
@@ -857,10 +878,11 @@
       showConfigDialog(ConfigDialog::Advanced);
   }
   
-  if (_torControl->isRunning() && _isVidaliaRunningTor) 
-    stop();
-  else if (_torControl->isConnected())
-    disconnect();
+  if (_torControl->isRunning())
+    if (_isVidaliaRunningTor) 
+      stop();
+    else
+      disconnect();
   if (retry)
     start();
 }