[tor-commits] [vidalia/alpha] Actually save ControlPort and SocksPort when modified

chiiph at torproject.org chiiph at torproject.org
Sat Mar 17 17:01:06 UTC 2012


commit d09c2ed80f2fab69536db19940211c8c835eb033
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Fri Mar 16 14:31:36 2012 -0300

    Actually save ControlPort and SocksPort when modified
    
    Reload settings after editing torrc through its dialog.
    Also, remove a lot of whitespace.
---
 src/torcontrol/RouterDescriptor.cpp      |    6 +-
 src/torcontrol/RouterDescriptor.h        |    8 ++--
 src/vidalia/config/AdvancedPage.cpp      |   39 ++++++++++--------
 src/vidalia/config/ConfigDialog.cpp      |   30 +++++++------
 src/vidalia/config/ConfigDialog.h        |    8 ++--
 src/vidalia/config/ConfigPage.h          |   11 +++--
 src/vidalia/config/NetworkSettings.cpp   |   16 ++++----
 src/vidalia/config/ServerPage.cpp        |   60 ++++++++++++++--------------
 src/vidalia/config/ServerSettings.cpp    |   40 +++++++++---------
 src/vidalia/config/TorSettings.cpp       |   64 +++++++++++++++++++-----------
 src/vidalia/config/TorSettings.h         |   26 +++++++-----
 src/vidalia/config/VSettings.cpp         |    8 ++--
 src/vidalia/config/VSettings.h           |    8 ++--
 src/vidalia/config/torrc/Torrc.cpp       |   26 +++++++-----
 src/vidalia/config/torrc/TorrcParser.cpp |   21 +++++-----
 15 files changed, 204 insertions(+), 167 deletions(-)

diff --git a/src/torcontrol/RouterDescriptor.cpp b/src/torcontrol/RouterDescriptor.cpp
index 21643f2..26051c1 100644
--- a/src/torcontrol/RouterDescriptor.cpp
+++ b/src/torcontrol/RouterDescriptor.cpp
@@ -1,10 +1,10 @@
 /*
 **  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 
+**  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 
+**  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.
 */
 
diff --git a/src/torcontrol/RouterDescriptor.h b/src/torcontrol/RouterDescriptor.h
index d0c3400..32dfc36 100644
--- a/src/torcontrol/RouterDescriptor.h
+++ b/src/torcontrol/RouterDescriptor.h
@@ -1,14 +1,14 @@
 /*
 **  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 
+**  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 
+**  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 RouterDescriptor.h
 ** \brief Parses a blob of router descriptor text from Tor
 */
diff --git a/src/vidalia/config/AdvancedPage.cpp b/src/vidalia/config/AdvancedPage.cpp
index 44216c7..7f9d884 100644
--- a/src/vidalia/config/AdvancedPage.cpp
+++ b/src/vidalia/config/AdvancedPage.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -138,7 +138,7 @@ AdvancedPage::save(QString &errmsg)
     if (controlAddress.isNull()) {
       errmsg = tr("'%1' is not a valid IP address.")
                 .arg(ui.lineControlAddress->text());
-      return false; 
+      return false;
     }
     _settings->setControlMethod(ControlMethod::Port);
   } else {
@@ -149,9 +149,9 @@ AdvancedPage::save(QString &errmsg)
     }
     _settings->setControlMethod(ControlMethod::Socket);
   }
-  
+
   /* Validate the selected authentication options */
-  TorSettings::AuthenticationMethod authMethod = 
+  TorSettings::AuthenticationMethod authMethod =
     indexToAuthMethod(ui.cmbAuthMethod->currentIndex());
   if (authMethod == TorSettings::PasswordAuth
         && ui.linePassword->text().isEmpty()
@@ -178,13 +178,13 @@ AdvancedPage::save(QString &errmsg)
 
   /* Only remember the torrc and datadir values if Vidalia started Tor, or
    * if the user changed the displayed values. */
-  if (Vidalia::torControl()->isVidaliaRunningTor() or 
+  if (Vidalia::torControl()->isVidaliaRunningTor() or
       !Vidalia::torControl()->isConnected()) {
     QString torrc = ui.lineTorConfig->text();
     if (torrc != _settings->getTorrc()) {
       _settings->setTorrc(torrc);
       if(Vidalia::torControl()->isConnected()) {
-        QMessageBox::StandardButtons res = QMessageBox::question(this, tr("Warning"), 
+        QMessageBox::StandardButtons res = QMessageBox::question(this, tr("Warning"),
             tr("You changed torrc path, would you like to restart Tor?"),
             QMessageBox::Yes | QMessageBox::No);
         if(res == QMessageBox::Yes)
@@ -225,6 +225,10 @@ AdvancedPage::load()
 {
   ui.lineControlAddress->setText(_settings->getControlAddress().toString());
   ui.lineControlPort->setText(QString::number(_settings->getControlPort()));
+
+  // We don't want to loose the socksport
+  _settings->setSocksPort(_settings->getSocksPort());
+
   ui.lineTorConfig->setText(_settings->getTorrc());
   ui.lineTorDataDirectory->setText(_settings->getDataDirectory());
   ui.chkAuto->setChecked(_settings->autoControlPort());
@@ -292,7 +296,7 @@ void
 AdvancedPage::browseTorConfig()
 {
   /* Prompt the user to select a file or create a new one */
-  QString filename = QFileDialog::getOpenFileName(this, 
+  QString filename = QFileDialog::getOpenFileName(this,
                        tr("Select Tor Configuration File"),
                        QFileInfo(ui.lineTorConfig->text()).filePath(),
                        tr("Tor Configuration File (torrc);;All Files (*)"));
@@ -311,7 +315,7 @@ AdvancedPage::browseTorConfig()
                      tr("%1 does not exist. Would you like to create it?")
                                                             .arg(filename),
                      VMessageBox::Yes, VMessageBox::No);
-    
+
     if (response == VMessageBox::No) {
       /* Don't create it. Just bail. */
       return;
@@ -339,7 +343,7 @@ AdvancedPage::browseTorDataDirectory()
                       tr("Select a Directory to Use for Tor Data"),
                       ui.lineTorDataDirectory->text());
 
-  if (!dataDir.isEmpty()) 
+  if (!dataDir.isEmpty())
     ui.lineTorDataDirectory->setText(dataDir);
 }
 
@@ -355,7 +359,7 @@ AdvancedPage::browseSocketPath()
                       tr("Select a file to use for Tor socket path"),
                       start);
 
-  if (!socketPath.isEmpty()) 
+  if (!socketPath.isEmpty())
     ui.lineSocketPath->setText(socketPath);
 }
 
@@ -371,12 +375,12 @@ AdvancedPage::setupService(bool useService)
   if (!useService && isInstalled) {
     /* Uninstall if we don't want to use it anymore */
     Vidalia::torControl()->stop();
-    
+
     if (!service.remove()) {
       VMessageBox::critical(this,
                             tr("Unable to remove Tor Service"),
                             tr("Vidalia was unable to remove the Tor service.\n\n"
-                               "You may need to remove it manually."), 
+                               "You may need to remove it manually."),
                             VMessageBox::Ok, VMessageBox::Cancel);
     }
   } else if (useService && !isInstalled) {
@@ -395,14 +399,15 @@ AdvancedPage::setupService(bool useService)
 #endif
 
 /** Called when the user presses the Edit current torrc button */
-void 
+void
 AdvancedPage::displayTorrcDialog()
 {
   TorrcDialog rcdialog(this);
   rcdialog.exec();
+  emit reloadAll();
 }
 
-void 
+void
 AdvancedPage::toggleControl(bool)
 {
   if(ui.rdoControlPort->isChecked()) {
@@ -439,7 +444,7 @@ AdvancedPage::toggleAuto(bool)
 void
 AdvancedPage::displayWarning(bool checked)
 {
-  ui.lblWarn->setVisible(!checked and 
-                         indexToAuthMethod(ui.cmbAuthMethod->currentIndex()) == 
+  ui.lblWarn->setVisible(!checked and
+                         indexToAuthMethod(ui.cmbAuthMethod->currentIndex()) ==
                          TorSettings::PasswordAuth);
 }
diff --git a/src/vidalia/config/ConfigDialog.cpp b/src/vidalia/config/ConfigDialog.cpp
index a92e959..1724814 100644
--- a/src/vidalia/config/ConfigDialog.cpp
+++ b/src/vidalia/config/ConfigDialog.cpp
@@ -3,12 +3,12 @@
 **  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 
+**  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 ConfigDialog.cpp
 ** \brief Contains a series of Vidalia and Tor configuration pages
 */
@@ -43,12 +43,12 @@ ConfigDialog::ConfigDialog(QWidget* parent)
 {
   /* Invoke the Qt Designer generated QObject setup routine */
   ui.setupUi(this);
- 
+
   /* Override the QDialogButtonBox button text so we can use our own
    * translations. */
   QPushButton *button = ui.buttonBox->button(QDialogButtonBox::Ok);
   if (button) {
-    Vidalia::createShortcut(QKeySequence(Qt::Key_Return), 
+    Vidalia::createShortcut(QKeySequence(Qt::Key_Return),
                             this, button, SLOT(click()));
   }
   button = ui.buttonBox->button(QDialogButtonBox::Cancel);
@@ -56,7 +56,7 @@ ConfigDialog::ConfigDialog(QWidget* parent)
     Vidalia::createShortcut("Esc", this, button, SLOT(click()));
     Vidalia::createShortcut("Ctrl+W", this, button, SLOT(click()));
   }
-  
+
   /* Connect the button box signals to the appropriate slots */
   connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(saveChanges()));
   connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
@@ -96,14 +96,16 @@ ConfigDialog::ConfigDialog(QWidget* parent)
   foreach (ConfigPage *page, ui.stackPages->pages()) {
     connect(page, SIGNAL(helpRequested(QString)),
             this, SLOT(help(QString)));
+    connect(page, SIGNAL(reloadAll()),
+            this, SLOT(loadSettings()));
   }
 
   /* Create the toolbar */
   ui.toolBar->addActions(grp->actions());
   ui.toolBar->addSeparator();
-  connect(grp, SIGNAL(triggered(QAction *)), 
+  connect(grp, SIGNAL(triggered(QAction *)),
           ui.stackPages, SLOT(showPage(QAction *)));
-  
+
   /* Create and bind the Help button */
   QAction *helpAct = new QAction(QIcon(IMAGE_HELP), tr("Help"), ui.toolBar);
   helpAct->setData("Help");
@@ -121,7 +123,7 @@ ConfigDialog::ConfigDialog(QWidget* parent)
 
 /** Creates a new action associated with a config page. */
 QAction*
-ConfigDialog::createPageAction(const QIcon &img, const QString &text, 
+ConfigDialog::createPageAction(const QIcon &img, const QString &text,
                                const QString &data, QActionGroup *group)
 {
   QAction *action = new QAction(img, text, group);
@@ -181,16 +183,16 @@ void
 ConfigDialog::saveChanges()
 {
   QString errmsg;
-  
+
   /* Call each config page's save() method to save its data */
   foreach (ConfigPage *page, ui.stackPages->pages()) {
     if (!page->save(errmsg)) {
       /* Display the offending page */
       ui.stackPages->setCurrentPage(page);
-      
+
       /* Show the user what went wrong */
-      VMessageBox::warning(this, 
-        tr("Error Saving Settings"), 
+      VMessageBox::warning(this,
+        tr("Error Saving Settings"),
         p(tr("Vidalia was unable to save your %1 settings.")
              .arg(tr(qPrintable(page->title()), "ConfigDialog"))) + p(errmsg),
         VMessageBox::Ok);
@@ -259,7 +261,7 @@ void
 ConfigDialog::help()
 {
   Page currentPage = static_cast<Page>(ui.stackPages->currentIndex());
-  
+
   switch (currentPage) {
     case Network:
       help("config.network"); break;
diff --git a/src/vidalia/config/ConfigDialog.h b/src/vidalia/config/ConfigDialog.h
index fe63954..441a85d 100644
--- a/src/vidalia/config/ConfigDialog.h
+++ b/src/vidalia/config/ConfigDialog.h
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -76,10 +76,10 @@ private slots:
   /** Stub method that relays the checkForUpdates() signal from the General
    * settings page to the owner of the config dialog (MainWindow). */
   void onCheckForUpdates();
-
-private:
   /** Loads the current configuration settings */
   void loadSettings();
+
+private:
   /** Creates a new action for a config page. */
   QAction* createPageAction(const QIcon &img, const QString &text,
                             const QString &data, QActionGroup *group);
diff --git a/src/vidalia/config/ConfigPage.h b/src/vidalia/config/ConfigPage.h
index 2a237c1..d939302 100644
--- a/src/vidalia/config/ConfigPage.h
+++ b/src/vidalia/config/ConfigPage.h
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -25,7 +25,7 @@ class ConfigPage : public QWidget
 
 public:
   /** Default Constructor */
-  ConfigPage(QWidget *parent = 0, const QString title = QString()) 
+  ConfigPage(QWidget *parent = 0, const QString title = QString())
    : QWidget(parent), _title(title) {}
 
   /** Returns the title of this configuration page. */
@@ -54,7 +54,7 @@ public:
   /** Subclassed pages can overload this method to revert any cancelled
    * settings. */
   virtual void revert() {}
-  
+
   virtual void retranslateUi() {}
 
 signals:
@@ -62,6 +62,9 @@ signals:
    * <b>topic</b>. */
   void helpRequested(const QString &topic);
 
+  /** Emitted when all the settings need to be reloaded */
+  void reloadAll();
+
 private:
   QString _title; /**< Title of this configuration page. */
 };
diff --git a/src/vidalia/config/NetworkSettings.cpp b/src/vidalia/config/NetworkSettings.cpp
index 4f56432..bb4e7ba 100644
--- a/src/vidalia/config/NetworkSettings.cpp
+++ b/src/vidalia/config/NetworkSettings.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -86,7 +86,7 @@ NetworkSettings::apply(QString *errmsg)
 
   if (!user.isEmpty() || !pass.isEmpty())
     auth = QString("%1:%2").arg(user).arg(pass);
- 
+
   switch (getProxyType()) {
     case NoProxy:
       break;
@@ -110,7 +110,7 @@ NetworkSettings::apply(QString *errmsg)
       torrc->setValue(SETTING_SOCKS5_USERNAME, user);
       torrc->setValue(SETTING_SOCKS5_PASSWORD, pass);
     }
-    
+
     torrc->setValue(SETTING_HTTPS_PROXY, https);
     torrc->setValue(SETTING_HTTPS_PROXY_AUTH, auth);
   } else {
@@ -216,7 +216,7 @@ NetworkSettings::setReachablePorts(const QList<quint16> &reachablePorts)
 }
 
 /** Returns the proxy type Tor is using, or NoProxy if it makes direct
- * connections. */ 
+ * connections. */
 NetworkSettings::ProxyType
 NetworkSettings::getProxyType()
 {
@@ -252,7 +252,7 @@ NetworkSettings::getProxyUsername()
   return value(SETTING_PROXY_USERNAME).toString();
 }
 
-/** Sets the proxy server username to <b>user</b>. */ 
+/** Sets the proxy server username to <b>user</b>. */
 void
 NetworkSettings::setProxyUsername(const QString &user)
 {
@@ -266,7 +266,7 @@ NetworkSettings::getProxyPassword()
   return value(SETTING_PROXY_PASSWORD).toString();
 }
 
-/** Sets the proxy server password to <b>pass</b>. */ 
+/** Sets the proxy server password to <b>pass</b>. */
 void
 NetworkSettings::setProxyPassword(const QString &pass)
 {
@@ -350,7 +350,7 @@ NetworkSettings::ProxyType
 NetworkSettings::proxyTypeFromString(const QString &type)
 {
   QString str = type.toLower();
-  
+
   if (str == "socks4")
     return Socks4Proxy;
   if (str == "socks5")
diff --git a/src/vidalia/config/ServerPage.cpp b/src/vidalia/config/ServerPage.cpp
index eb23c0b..52d311a 100644
--- a/src/vidalia/config/ServerPage.cpp
+++ b/src/vidalia/config/ServerPage.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -48,8 +48,8 @@
 #define HIGHBW_MAX_RATE         (10240*1024)
 /** Minimum allowed bandwidth rate (20KB) */
 #define MIN_BANDWIDTH_RATE      20
-/** Maximum bandwidth rate. This is limited to 2147483646 bytes, 
- * or 2097151 kilobytes. (2147483646/1024) */ 
+/** Maximum bandwidth rate. This is limited to 2147483646 bytes,
+ * or 2097151 kilobytes. (2147483646/1024) */
 #define MAX_BANDWIDTH_RATE      2097151
 
 /** Ports represented by the "Websites" checkbox. (80) */
@@ -62,7 +62,7 @@
  * (703,1863,5050,5190,5222,8300,8888) */
 #define PORTS_IM     (QStringList() << "706" << "1863" << "5050" << "5190" \
                                     << "5222" << "5223" << "8300" << "8888")
-/** Ports represented by the "Internet Relay Chat" checkbox. 
+/** Ports represented by the "Internet Relay Chat" checkbox.
  * (6660-6669,6697,7000-7001) */
 #define PORTS_IRC    (QStringList() << "6660-6669" << "6697" << "7000-7001")
 
@@ -73,7 +73,7 @@ ServerPage::ServerPage(QWidget *parent)
 {
   /* Invoke the Qt Designer generated object setup routine */
   ui.setupUi(this);
-  
+
   /* Create ServerSettings object */
   _settings = new ServerSettings(Vidalia::torControl());
 
@@ -83,9 +83,9 @@ ServerPage::ServerPage(QWidget *parent)
   connect(ui.btnUpnpHelp, SIGNAL(clicked()), this, SLOT(upnpHelp()));
   connect(ui.cmboRate, SIGNAL(currentIndexChanged(int)),
                  this, SLOT(rateChanged(int)));
-  connect(ui.lineAvgRateLimit, SIGNAL(editingFinished()), 
+  connect(ui.lineAvgRateLimit, SIGNAL(editingFinished()),
                          this, SLOT(customRateChanged()));
-  connect(ui.lineMaxRateLimit, SIGNAL(editingFinished()), 
+  connect(ui.lineMaxRateLimit, SIGNAL(editingFinished()),
                          this, SLOT(customRateChanged()));
   connect(ui.rdoClientMode, SIGNAL(toggled(bool)),
                       this, SLOT(serverModeChanged(bool)));
@@ -204,7 +204,7 @@ ServerPage::loadBridgeIdentity()
     tc->getInfo("address", address);
     tc->getInfo("fingerprint", fingerprint);
     tc->getConf("ORPort", orPort);
-  
+
     if (!address.isEmpty() && !orPort.isEmpty() && orPort != "0")
       bridge = address + ":" + orPort + " ";
     if (!fingerprint.isEmpty())
@@ -229,11 +229,11 @@ ServerPage::serverModeChanged(bool enabled)
   bool bridgeEnabled = ui.rdoBridgeMode->isChecked();
   bool relayEnabled = ui.rdoServerMode->isChecked() ||
                       ui.rdoNonExitMode->isChecked();
-  
+
   /* Show the tab menu only if the user is running a normal relay or a bridge
    * relay. */
   ui.tabsMenu->setVisible(relayEnabled || bridgeEnabled);
-  
+
   /* Display the widgets that show the user their bridge identity if bridge
    * relay mode is selected. */
   ui.lblYourBridgeRelayIs->setVisible(bridgeEnabled);
@@ -260,7 +260,7 @@ ServerPage::serverModeChanged(bool enabled)
 
   ui.chkMirrorDirectory->setEnabled(!bridgeEnabled);
 
-  /* Disable the Exit Policies tab when bridge or non-exit relay mode is 
+  /* Disable the Exit Policies tab when bridge or non-exit relay mode is
    * selected */
   ui.tabsMenu->setTabEnabled(2, !bridgeEnabled and !ui.rdoNonExitMode->isChecked());
 
@@ -301,8 +301,8 @@ ServerPage::save(QString &errmsg)
 {
   /* Force the bandwidth rate limits to validate */
   customRateChanged();
-  
-  if (ui.rdoServerMode->isChecked() || 
+
+  if (ui.rdoServerMode->isChecked() ||
       ui.rdoNonExitMode->isChecked() ||
       ui.rdoBridgeMode->isChecked()) {
     /* A server must have an ORPort and a nickname */
@@ -319,7 +319,7 @@ ServerPage::save(QString &errmsg)
       ui.lineMaxRateLimit->setText(QString::number(5242880/1024) /* 5MB */);
     }
   }
-  
+
   /* "Server" is enabled whether we're a bridge or normal relay. "Bridge" is
    * only enabled if we're a bridge (obviously). */
   _settings->setServerEnabled(ui.rdoServerMode->isChecked()
@@ -346,7 +346,7 @@ ServerPage::save(QString &errmsg)
   if(ui.chkAccounting->checkState() != Qt::Checked)
     _settings->disableAccounting();
   else {
-    _settings->setAccountingMax(ui.spnAmount->value(), 
+    _settings->setAccountingMax(ui.spnAmount->value(),
                                 ui.cmbUnit->currentText());
     _settings->setAccountingStart(ui.cmbTime->currentText(),
                                   ui.spnDay->value(),
@@ -431,23 +431,23 @@ ServerPage::loadBandwidthLimits()
   quint32 avgRate = _settings->getBandwidthAvgRate();
   quint32 maxRate = _settings->getBandwidthBurstRate();
 
-  if (avgRate == CABLE256_AVG_RATE && 
+  if (avgRate == CABLE256_AVG_RATE &&
       maxRate == CABLE256_MAX_RATE) {
     /* Cable/DSL 256 Kbps */
-    ui.cmboRate->setCurrentIndex(CableDsl256); 
-  } else if (avgRate == CABLE512_AVG_RATE && 
+    ui.cmboRate->setCurrentIndex(CableDsl256);
+  } else if (avgRate == CABLE512_AVG_RATE &&
              maxRate == CABLE512_MAX_RATE) {
     /* Cable/DSL 512 Kbps */
     ui.cmboRate->setCurrentIndex(CableDsl512);
-  } else if (avgRate == CABLE768_AVG_RATE && 
+  } else if (avgRate == CABLE768_AVG_RATE &&
              maxRate == CABLE768_MAX_RATE) {
     /* Cable/DSL 768 Kbps */
     ui.cmboRate->setCurrentIndex(CableDsl768);
-  } else if (avgRate == T1_AVG_RATE && 
+  } else if (avgRate == T1_AVG_RATE &&
              maxRate == T1_MAX_RATE) {
     /* T1/Cable/DSL 1.5 Mbps */
     ui.cmboRate->setCurrentIndex(T1CableDsl1500);
-  } else if (avgRate == HIGHBW_AVG_RATE && 
+  } else if (avgRate == HIGHBW_AVG_RATE &&
              maxRate == HIGHBW_MAX_RATE) {
     /* > 1.5 Mbps */
     ui.cmboRate->setCurrentIndex(GreaterThan1500);
@@ -501,7 +501,7 @@ void
 ServerPage::loadExitPolicies()
 {
   ExitPolicy exitPolicy = _settings->getExitPolicy();
-  
+
   if (exitPolicy.contains(Policy(Policy::RejectAll))) {
     /* If the policy ends with reject *:*, check if the policy explicitly
      * accepts these ports */
@@ -533,7 +533,7 @@ ServerPage::saveExitPolicies()
   } else {
     exitPolicy = new ExitPolicy();
     bool rejectUnchecked = ui.chkMisc->isChecked();
-    
+
     /* If misc is checked, then reject unchecked items and leave the default exit
     * policy alone. Else, accept only checked items and end with reject *:*,
     * replacing the default exit policy. */
@@ -573,12 +573,12 @@ ServerPage::saveExitPolicies()
 void
 ServerPage::rateChanged(int index)
 {
-  /* If the "Custom" option is selected, show the custom bandwidth 
+  /* If the "Custom" option is selected, show the custom bandwidth
    * limits form. */
   ui.frmCustomRate->setVisible(index == CustomBwLimits);
 }
 
-/** Called when the user edits the long-term average or maximum bandwidth limit. 
+/** Called when the user edits the long-term average or maximum bandwidth limit.
  * This ensures that the average bandwidth rate is greater than MIN_RATE
  * (20KB/s) and that the max rate is greater than the average rate. */
 void
@@ -587,7 +587,7 @@ ServerPage::customRateChanged()
   /* Make sure the average rate isn't too low or too high */
   quint32 avgRate = (quint32)ui.lineAvgRateLimit->text().toUInt();
   if (avgRate < MIN_BANDWIDTH_RATE) {
-    ui.lineAvgRateLimit->setText(QString::number(MIN_BANDWIDTH_RATE));    
+    ui.lineAvgRateLimit->setText(QString::number(MIN_BANDWIDTH_RATE));
   }
   if (avgRate > MAX_BANDWIDTH_RATE) {
     ui.lineAvgRateLimit->setText(QString::number(MAX_BANDWIDTH_RATE));
@@ -610,7 +610,7 @@ ServerPage::testUpnp()
 #if defined(USE_MINIUPNPC)
   UPNPTestDialog dlg(ui.lineServerPort->text().toUInt(),
                      ui.lineDirPort->text().toUInt(), this);
-  
+
   connect(&dlg, SIGNAL(help()), this, SLOT(upnpHelp()));
 
   dlg.exec();
@@ -653,11 +653,11 @@ ServerPage::displayBridgeUsage()
     bool ok;
 
     keyvals = string_parse_keyvals(info, &ok);
-    if (!ok || !keyvals.contains("TimeStarted") 
+    if (!ok || !keyvals.contains("TimeStarted")
             || !keyvals.contains("CountrySummary"))
       goto err;
 
-    timeStarted = QDateTime::fromString(keyvals.value("TimeStarted"), 
+    timeStarted = QDateTime::fromString(keyvals.value("TimeStarted"),
                                         "yyyy-MM-dd HH:mm:ss");
     if (!timeStarted.isValid())
       goto err;
diff --git a/src/vidalia/config/ServerSettings.cpp b/src/vidalia/config/ServerSettings.cpp
index 2593dda..25c7a80 100644
--- a/src/vidalia/config/ServerSettings.cpp
+++ b/src/vidalia/config/ServerSettings.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -75,13 +75,13 @@ ServerSettings::ServerSettings(TorControl *torControl)
   setDefault(SETTING_RELAY_BANDWIDTH_BURST, 10485760);
   setDefault(SETTING_EXITPOLICY,
     ExitPolicy(ExitPolicy::Middleman).toString());
-  setDefault(SETTING_ENABLE_UPNP, false); 
+  setDefault(SETTING_ENABLE_UPNP, false);
   setDefault(SETTING_BRIDGE_RELAY, false);
   setDefault(SETTING_PUBLISH_SERVER_DESCRIPTOR, "1");
 }
 
 /** Applies the current server configuration settings to Tor. If <b>errmsg</b>
- * is specified and an error occurs while applying the settings, it will be 
+ * is specified and an error occurs while applying the settings, it will be
  * set to a string describing the error. */
 bool
 ServerSettings::apply(QString *errmsg)
@@ -100,26 +100,26 @@ ServerSettings::apply(QString *errmsg)
     torrc->setValue(SETTING_ORPORT,
                 volatileValue(SETTING_ORPORT).toString());
     /* Server DirPort */
-    torrc->setValue(SETTING_DIRPORT, 
+    torrc->setValue(SETTING_DIRPORT,
                 volatileValue(SETTING_DIRPORT).toString());
     /* Server Exit Policy */
     torrc->clear(QStringList() << SETTING_EXITPOLICY);
-    if(volatileValue(SETTING_BRIDGE_RELAY).toBool() || 
+    if(volatileValue(SETTING_BRIDGE_RELAY).toBool() ||
        volatileValue(SETTING_NONEXIT_RELAY).toBool()) {
       torrc->setValue(SETTING_EXITPOLICY, "reject *:*");
     } else {
       torrc->setValue(SETTING_EXITPOLICY, volatileValue(SETTING_EXITPOLICY).toString());
     }
     /* Server bandwidth settings */
-    torrc->setValue((torVersion >= 0x020001 ? SETTING_RELAY_BANDWIDTH_RATE 
+    torrc->setValue((torVersion >= 0x020001 ? SETTING_RELAY_BANDWIDTH_RATE
                  : SETTING_BANDWIDTH_RATE),
                 QString::number(volatileValue(SETTING_BANDWIDTH_RATE).toUInt()) + " bytes");
     torrc->setValue((torVersion >= 0x020001 ? SETTING_RELAY_BANDWIDTH_BURST
                  : SETTING_BANDWIDTH_BURST),
                 QString::number(volatileValue(SETTING_BANDWIDTH_BURST).toUInt()) + " bytes");
-    
+
     /* Server Contact Information */
-    QString contact = 
+    QString contact =
       volatileValue(SETTING_CONTACT).toString().trimmed();
     QString defaultContact = defaultValue(SETTING_CONTACT).toString();
     if ((contact == defaultContact) ||
@@ -128,7 +128,7 @@ ServerSettings::apply(QString *errmsg)
       contact = "";
     }
     torrc->setValue(SETTING_CONTACT, scrub_email_addr(contact));
-  
+
     /* Set if we're a bridge relay */
     if (volatileValue(SETTING_BRIDGE_RELAY).toBool()) {
       torrc->setValue(SETTING_BRIDGE_RELAY, "1");
@@ -144,8 +144,8 @@ ServerSettings::apply(QString *errmsg)
   } else {
     QStringList resetKeys;
     quint32 torVersion = torControl()->getTorVersion();
-    resetKeys << SETTING_ORPORT 
-              << SETTING_NICKNAME 
+    resetKeys << SETTING_ORPORT
+              << SETTING_NICKNAME
               << SETTING_DIRPORT
               << SETTING_CONTACT
               << SETTING_EXITPOLICY
@@ -216,8 +216,8 @@ ServerSettings::torValue(const QString &key) const
   return AbstractTorSettings::torValue(key);
 }
 
-/** Enables or disables running Tor as a server. 
- * \param enable Whether to enable or disable the Tor server. 
+/** Enables or disables running Tor as a server.
+ * \param enable Whether to enable or disable the Tor server.
  */
 void
 ServerSettings::setServerEnabled(bool enable)
@@ -338,7 +338,7 @@ ServerSettings::getNickname()
     nickname = defaultValue(SETTING_NICKNAME).toString();
   }
   /* Ensure the nickname contains only valid characters and is not too long. */
-  return ensure_valid_chars(nickname, 
+  return ensure_valid_chars(nickname,
                             VALID_NICKNAME_CHARS).left(MAX_NICKNAME_LEN);
 }
 
@@ -528,7 +528,7 @@ ServerSettings::accountingMaxAmount()
       return 0;
     return parts.at(0).trimmed().toInt();
   }
-  
+
   return 0;
 }
 
@@ -541,7 +541,7 @@ ServerSettings::accountingMaxUnit()
       return QString();
     return parts.at(1).trimmed();
   }
-  
+
   return QString();
 }
 
@@ -554,7 +554,7 @@ ServerSettings::accountingStartDwm()
       return QString();
     return parts.at(0).trimmed();
   }
-  
+
   return QString();
 }
 
@@ -567,7 +567,7 @@ ServerSettings::accountingStartDay()
       return 1;
     return parts.at(1).trimmed().toInt();
   }
-  
+
   return 1;
 }
 
@@ -582,6 +582,6 @@ ServerSettings::accountingStartTime()
       return parts.at(2).trimmed();
     return parts.at(1).trimmed();
   }
-  
+
   return QString();
 }
diff --git a/src/vidalia/config/TorSettings.cpp b/src/vidalia/config/TorSettings.cpp
index 85164d0..0a7b2d1 100644
--- a/src/vidalia/config/TorSettings.cpp
+++ b/src/vidalia/config/TorSettings.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -32,6 +32,7 @@
 #define SETTING_DEFAULTS_TORRC      "DefaultsTorrc"
 #define SETTING_CONTROL_ADDR        "ControlListenAddress"
 #define SETTING_CONTROL_PORT        "ControlPort"
+#define SETTING_SOCKS_PORT          "SocksPort"
 #define SETTING_SOCKET_PATH         "ControlSocket"
 #define SETTING_CONTROL_METHOD      "ControlMethod"
 #define SETTING_AUTH_TOKEN          "AuthToken"
@@ -86,6 +87,7 @@ TorSettings::TorSettings(TorControl *torControl)
   setDefault(SETTING_DEFAULTS_TORRC,Vidalia::dataDirectory() + "/defaults_torrc");
   setDefault(SETTING_CONTROL_ADDR,  "127.0.0.1");
   setDefault(SETTING_CONTROL_PORT,  9051);
+  setDefault(SETTING_SOCKS_PORT,  9050);
   setDefault(SETTING_AUTH_METHOD,   toString(DEFAULT_AUTH_METHOD));
   setDefault(SETTING_CONTROL_METHOD, DEFAULT_CONTROL_METHOD);
   setDefault(SETTING_SOCKET_PATH, DEFAULT_SOCKET_PATH);
@@ -102,9 +104,6 @@ bool
 TorSettings::apply(QString *errmsg)
 {
   Torrc *torrc = Vidalia::torrc();
-  
-  torrc->setValue(SETTING_CONTROL_PORT, 
-                  QString::number(volatileValue(SETTING_CONTROL_PORT).toInt()));
 
   torrc->clear(QStringList()
                << TOR_ARG_SOCKSPORT
@@ -114,24 +113,25 @@ TorSettings::apply(QString *errmsg)
 
   if(volatileValue(SETTING_AUTOCONTROL).toBool()) {
     torrc->setValue(SETTING_CONTROL_PORT, "auto");
-    torrc->setValue(TOR_ARG_SOCKSPORT, "auto");
+    torrc->setValue(SETTING_SOCKS_PORT, "auto");
     torrc->setValue(TOR_ARG_CONTROLFILE, QString("%1/port.conf").arg(getDataDirectory()));
   } else {
-    QString socks = "9050", control = "9051";
+    QString socks = volatileValue(SETTING_SOCKS_PORT).toString();
+    QString control = volatileValue(SETTING_CONTROL_PORT).toString();
     {
-      with_torrc_value(TOR_ARG_SOCKSPORT)
+      with_torrc_value(SETTING_SOCKS_PORT)
         socks = ret.at(0);
     }
     {
-      with_torrc_value(TOR_ARG_SOCKSPORT)
+      with_torrc_value(SETTING_CONTROL_PORT)
         control = ret.at(0);
     }
-    torrc->setValue(TOR_ARG_SOCKSPORT, socks);
+    torrc->setValue(SETTING_SOCKS_PORT, socks);
     torrc->setValue(SETTING_CONTROL_PORT, control);
   }
 
   QString hashedPassword;
-  AuthenticationMethod authMethod = 
+  AuthenticationMethod authMethod =
     toAuthenticationMethod(localValue(SETTING_AUTH_METHOD).toString());
   switch (authMethod) {
     case CookieAuth:
@@ -139,7 +139,7 @@ TorSettings::apply(QString *errmsg)
       torrc->setValue(TOR_ARG_HASHED_PASSWORD, "");
       break;
     case PasswordAuth:
-      hashedPassword = useRandomPassword() 
+      hashedPassword = useRandomPassword()
                           ? hashPassword(randomPassword())
                           : hashPassword(getControlPassword());
       if (hashedPassword.isEmpty()) {
@@ -161,7 +161,7 @@ TorSettings::apply(QString *errmsg)
 
 /** Gets the location of Tor's data directory. */
 QString
-TorSettings::getDataDirectory()
+TorSettings::getDataDirectory() const
 {
   with_torrc_value(SETTING_DATA_DIRECTORY) {
     return ret.at(0);
@@ -206,7 +206,7 @@ TorSettings::getTorrc() const
 }
 
 /** Sets the torrc that will be used when starting Tor.
- * \param torrc The torrc to use. 
+ * \param torrc The torrc to use.
  */
 void
 TorSettings::setTorrc(const QString &torrc)
@@ -226,7 +226,7 @@ TorSettings::getDefaultsTorrc() const
 }
 
 /** Sets the defaults torrc that will be used when starting Tor.
- * \param torrc The defaults torrc to use. 
+ * \param torrc The defaults torrc to use.
  */
 void
 TorSettings::setDefaultsTorrc(const QString &torrc)
@@ -241,7 +241,7 @@ TorSettings::getControlAddress() const
   QString addr = defaultValue(SETTING_CONTROL_ADDR).toString();
   with_torrc_value(SETTING_CONTROL_ADDR) {
     addr = ret.at(0);
-  } 
+  }
   return QHostAddress(addr);
 }
 
@@ -263,6 +263,17 @@ TorSettings::getControlPort() const
   return port;
 }
 
+/** Get the socks port used to connect to Tor */
+quint16
+TorSettings::getSocksPort() const
+{
+  quint16 port = defaultValue(SETTING_SOCKS_PORT).toInt();
+  with_torrc_value(SETTING_SOCKS_PORT) {
+    port = (quint16)ret.at(0).toUInt();
+  }
+  return port;
+}
+
 /** Set the control port used to connect to Tor */
 void
 TorSettings::setControlPort(quint16 port)
@@ -270,8 +281,15 @@ TorSettings::setControlPort(quint16 port)
   setVolatileValue(SETTING_CONTROL_PORT, port);
 }
 
+/** Set the socks port used to connect to Tor */
+void
+TorSettings::setSocksPort(quint16 port)
+{
+  setVolatileValue(SETTING_SOCKS_PORT, port);
+}
+
 /** Get the path for ControlSocket */
-QString 
+QString
 TorSettings::getSocketPath() const
 {
   with_torrc_value(SETTING_SOCKET_PATH) {
@@ -281,7 +299,7 @@ TorSettings::getSocketPath() const
 }
 
 /** Set the path for ControlSocket */
-void 
+void
 TorSettings::setSocketPath(const QString &path)
 {
   setVolatileValue(SETTING_SOCKET_PATH, path);
@@ -295,7 +313,7 @@ TorSettings::getControlMethod() const
 }
 
 /** Set the control method */
-void 
+void
 TorSettings::setControlMethod(ControlMethod::Method method)
 {
   setValue(SETTING_CONTROL_METHOD, ControlMethod::toString(method));
@@ -439,7 +457,7 @@ TorSettings::toString(AuthenticationMethod method) const
  * description of the authentication method given in <b>authMethod</b>. */
 TorSettings::AuthenticationMethod
 TorSettings::toAuthenticationMethod(const QString &authMethod) const
-{ 
+{
   QString str = authMethod.toLower();
   if (str == toString(NullAuth))
     return NullAuth;
@@ -463,7 +481,7 @@ QString
 TorSettings::hashPassword(const QString &password)
 {
   QByteArray salt;
-  
+
   /* Generate an 8 octet salt value. Bail if we fail to generate enough
    * random bytes (unlikely). */
   while (salt.size() < 8) {
@@ -510,13 +528,13 @@ TorSettings::bootstrapFrom() const
   return QDir::convertSeparators(value(SETTING_BOOTSTRAP_FROM).toString());
 }
 
-bool 
+bool
 TorSettings::autoControlPort() const
 {
   return getControlPort() == 0;
 }
 
-void 
+void
 TorSettings::setAutoControlPort(const bool autoControl)
 {
   setVolatileValue(SETTING_AUTOCONTROL, autoControl);
diff --git a/src/vidalia/config/TorSettings.h b/src/vidalia/config/TorSettings.h
index 2fdf1e5..1352518 100644
--- a/src/vidalia/config/TorSettings.h
+++ b/src/vidalia/config/TorSettings.h
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -35,22 +35,22 @@ public:
     PasswordAuth,  /**< Use a hashed password for authentication. */
     UnknownAuth    /**< Unknown authentication method. */
   };
-  
+
   /** Default constructor. */
   TorSettings(TorControl *torControl = 0);
-  /** Applies any changes to Tor's control port or authentication settings. */ 
+  /** Applies any changes to Tor's control port or authentication settings. */
   bool apply(QString *errmsg = 0);
 
   /** Gets the name and path of Tor's executable. */
   QString getExecutable() const;
   /** Sets the name and path of Tor's executable. */
   void setExecutable(const QString &torExecutable);
- 
+
   /** Gets the location of Tor's data directory. */
-  QString getDataDirectory();
+  QString getDataDirectory() const;
   /** Sets the location to use for Tor's data directory. */
   void setDataDirectory(const QString &dataDir);
-  
+
   /** Gets the torrc to use when starting Tor. */
   QString getTorrc() const;
   /** Sets the torrc to use when starting Tor. */
@@ -60,16 +60,20 @@ public:
   QString getDefaultsTorrc() const;
   /** Sets the defaults torrc to use when starting Tor. */
   void setDefaultsTorrc(const QString &torrc);
-  
+
   /** Get Tor's control interface address. */
   QHostAddress getControlAddress() const;
   /** Set Tor's control interface address. */
   void setControlAddress(const QHostAddress &addr);
-  
+
   /** Get the control port. */
   quint16 getControlPort() const;
+  /** Get the socks port. */
+  quint16 getSocksPort() const;
   /** Set the control port. */
   void setControlPort(quint16 port);
+  /** Set the socks port. */
+  void setSocksPort(quint16 port);
 
   /** Get the path for ControlSocket */
   QString getSocketPath() const;
@@ -89,7 +93,7 @@ public:
 
   /** Set the path for ControlSocket */
   void setSocketPath(const QString &path);
-  
+
   /** Returns the plaintext (i.e., not hashed) control password used when
    * authenticating to Tor. */
   QString getControlPassword() const;
@@ -126,7 +130,7 @@ public:
   /** Generates a random control password consisting of PASSWORD_LEN
    * characters. */
   static QString randomPassword();
-  /** Returns the hash of <b>password</b> as given by the command 
+  /** Returns the hash of <b>password</b> as given by the command
    * "tor --hash-password foo". */
   static QString hashPassword(const QString &password);
 
diff --git a/src/vidalia/config/VSettings.cpp b/src/vidalia/config/VSettings.cpp
index 020485b..c1e2dfc 100644
--- a/src/vidalia/config/VSettings.cpp
+++ b/src/vidalia/config/VSettings.cpp
@@ -3,14 +3,14 @@
 **  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 
+**  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 VSettings.cpp
-** \brief Stores and retrieves settings from Vidalia's configuration file. 
+** \brief Stores and retrieves settings from Vidalia's configuration file.
 */
 
 #include "VSettings.h"
@@ -114,7 +114,7 @@ VSettings::allSettings() const
 
 QVariant
 VSettings::volatileValue(const QString &key,
-                         const QVariant &defaultVal)
+                         const QVariant &defaultVal) const
 {
   if(_volatileSettings.count(key) == 0)
     return defaultVal;
diff --git a/src/vidalia/config/VSettings.h b/src/vidalia/config/VSettings.h
index 539f9a8..9aaf1dc 100644
--- a/src/vidalia/config/VSettings.h
+++ b/src/vidalia/config/VSettings.h
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -31,7 +31,7 @@ public:
   VSettings(const QString group = QString());
   /** Default destructor */
   ~VSettings();
-  
+
   /** Returns the location of Vidalia's configuration settings file. */
   static QString settingsFile();
   /** Returns true if Vidalia's configuration settings file already exists. */
@@ -60,7 +60,7 @@ protected:
   QMap<QString, QVariant> allSettings() const;
 
   virtual QVariant volatileValue(const QString &key,
-                                 const QVariant &defaultVal = QVariant());
+                                 const QVariant &defaultVal = QVariant()) const;
   virtual void setVolatileValue(const QString &key, const QVariant &val);
 
 private:
diff --git a/src/vidalia/config/torrc/Torrc.cpp b/src/vidalia/config/torrc/Torrc.cpp
index 7d2ad6c..d1589b9 100644
--- a/src/vidalia/config/torrc/Torrc.cpp
+++ b/src/vidalia/config/torrc/Torrc.cpp
@@ -3,12 +3,12 @@
 **  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 
+**  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 Torrc.cpp
 ** \brief Handles the interaction with the torrc file
 */
@@ -27,6 +27,9 @@ Torrc::Torrc(const QString &torrcPath, const QString &defaultsPath) :
 void
 Torrc::load(const QString &torrcPath, const QString &defaultsPath)
 {
+  _torrcMap.clear();
+  _defaultsMap.clear();
+
   _lines = _parser.parse(torrcPath, _torrcMap);
 
   if(not defaultsPath.isEmpty())
@@ -46,7 +49,7 @@ Torrc::apply(TorControl *tc, QString *errmsg)
     *errmsg = "Couldn't open torrc file";
     return false;
   }
-  
+
   QString torrc_contents = "";
   QString current_line;
 
@@ -59,11 +62,14 @@ Torrc::apply(TorControl *tc, QString *errmsg)
 
   if(torrc_info.isWritable())
     torrc.write(torrc_contents.trimmed().toLatin1());
+  else
+    vWarn("Torrc is not writable!");
+
   torrc.close();
 
   clearAll();
   load(_torrcPath);
-  
+
   changed = false;
 
   bool ret = true;
@@ -160,17 +166,17 @@ Torrc::setValue(const QString &key, const QString &value, const QString &comment
 
   changed = true;
 
-  TorOpt opt(_parser.getTorOpt(key));
   TorrcLine *line = new TorrcLine(QString("%1 %2")
                                   .arg(key)
                                   .arg(value).trimmed(),
                                   comment.trimmed());
-
   if(key.isEmpty()) {
     _lines << line;
     return;
   }
 
+  TorOpt opt(_parser.getTorOpt(key));
+
   if(opt.isMultivalued()) {
     bool found = false;
     QPair<QString,TorOpt> val;
@@ -180,7 +186,7 @@ Torrc::setValue(const QString &key, const QString &value, const QString &comment
         break;
       }
     }
-    
+
     opt.setLine(line);
 
     if(!found)
@@ -241,7 +247,5 @@ Torrc::setRawContents(const QString &contents, QString *errmsg, TorControl *tc)
 
   load(_torrcPath);
 
-  if(tc && tc->isConnected())
-    return tc->signal(TorSignal::Reload, errmsg);
-  return true;
+  return apply(tc, errmsg);
 }
diff --git a/src/vidalia/config/torrc/TorrcParser.cpp b/src/vidalia/config/torrc/TorrcParser.cpp
index ed21e8e..2c5c679 100644
--- a/src/vidalia/config/torrc/TorrcParser.cpp
+++ b/src/vidalia/config/torrc/TorrcParser.cpp
@@ -3,8 +3,8 @@
 **  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 
+**  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.
 */
 
@@ -237,7 +237,7 @@ TorrcParser::TorrcParser()
   _torOpts << TorOpt("MinUptimeHidServDirectoryV2", TorOpt::TimeInterval, "25 hours");
   _torOpts << TorOpt("VoteOnHidServDirectoriesV2", TorOpt::Boolean, "1");
   _torOpts << TorOpt("_UsingTestNetworkDefaults", TorOpt::Boolean, "0");
- 
+
   _regexp = createRegExp();
 }
 
@@ -278,7 +278,7 @@ TorrcParser::parse(const QString &path,
     vWarn("Can't read torrc file, aborting parsing.");
     return lines;
   }
-  
+
   if(not torrc.open(QIODevice::ReadOnly)) {
     vWarn("Can't open torrc file, aborting parsing.");
     return lines;
@@ -288,7 +288,7 @@ TorrcParser::parse(const QString &path,
   torrc.close();
 
   lines = toTorrcLines(raw_contents);
-  
+
   QString key, value;
   int sp_pos = -1;
 
@@ -317,12 +317,13 @@ TorrcParser::parse(const QString &path,
 
     TorOpt opt(getTorOpt(key));
     opt.setLine(line);
+
     if(map.contains(key) and opt.isMultivalued())
       map.insertMulti(key, QPair<QString, TorOpt>(value, opt));
     else
       map.insert(key, QPair<QString, TorOpt>(value, opt));
   }
-  
+
   return lines;
 }
 
@@ -339,7 +340,7 @@ TorrcParser::stripContents(QString contents)
       stripped_contents += "\n";
       continue;
     }
-    
+
     current_line = line.mid(0, comment_pos).trimmed();
     if(current_line.size() == 0)
       continue;
@@ -363,7 +364,7 @@ TorrcParser::toTorrcLines(QString contents)
       lines << new TorrcLine(line.trimmed());
       continue;
     }
-    
+
     current_line = line.mid(0, comment_pos).trimmed().replace("\t", " ");
     if(current_line.size() == 0) {
       // The line is just a comment
@@ -375,9 +376,9 @@ TorrcParser::toTorrcLines(QString contents)
 
   return lines;
 }
-  
+
 QList<TorrcLine *>
-TorrcParser::findValueLines(TorrcLine *line, 
+TorrcParser::findValueLines(TorrcLine *line,
                             const QList<TorrcLine *> &lines) const
 {
   QList<TorrcLine *> collected;





More information about the tor-commits mailing list