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

[vidalia-svn] r4141: Small patch from Chris Harrison to populate the proxy type c (vidalia/trunk/src/vidalia/config)



Author: edmanm
Date: 2009-10-04 13:39:14 -0400 (Sun, 04 Oct 2009)
New Revision: 4141

Modified:
   vidalia/trunk/src/vidalia/config/NetworkPage.cpp
Log:

Small patch from Chris Harrison to populate the proxy type combo box based
on the proxy options supported by the currently running Tor process.


Modified: vidalia/trunk/src/vidalia/config/NetworkPage.cpp
===================================================================
--- vidalia/trunk/src/vidalia/config/NetworkPage.cpp	2009-10-03 21:49:21 UTC (rev 4140)
+++ vidalia/trunk/src/vidalia/config/NetworkPage.cpp	2009-10-04 17:39:14 UTC (rev 4141)
@@ -58,12 +58,6 @@
   ui.lineProxyAddress->setValidator(new DomainValidator(this));
   ui.lineProxyPort->setValidator(new QIntValidator(1, 65535, this));
 
-  ui.cmboProxyType->insertItem(NetworkSettings::Socks4Proxy, tr("SOCKS 4"));
-  ui.cmboProxyType->insertItem(NetworkSettings::Socks5Proxy, tr("SOCKS 5"));
-  ui.cmboProxyType->insertItem(NetworkSettings::HttpProxy, tr("HTTP"));
-  ui.cmboProxyType->insertItem(NetworkSettings::HttpHttpsProxy,
-                               tr("HTTP / HTTPS"));
-
   vApp->createShortcut(QKeySequence(QKeySequence::Copy),
                        ui.listBridges, this,
                        SLOT(copySelectedBridgesToClipboard()));
@@ -294,9 +288,13 @@
 
     user = ui.lineProxyUsername->text();
     pass = ui.lineProxyPassword->text();
-  
-    int type = ui.cmboProxyType->currentIndex();
+ 
+    QVariant data;
+    int type;
 
+    data = ui.cmboProxyType->itemData(ui.cmboProxyType->currentIndex());
+    Q_ASSERT(data.isValid());
+    type = data.toInt();
     Q_ASSERT(type >= NetworkSettings::ProxyTypeMin &&
              type <= NetworkSettings::ProxyTypeMax);
     proxy = static_cast<NetworkSettings::ProxyType>(type);
@@ -335,10 +333,11 @@
 {
   NetworkSettings settings(Vidalia::torControl());
   QStringList reachablePortStrings;
+  NetworkSettings::ProxyType proxyType;
 
   /* Load proxy settings */
-  ui.chkUseProxy->setChecked(settings.getProxyType() != NetworkSettings::NoProxy);
-  ui.cmboProxyType->setCurrentIndex(settings.getProxyType());
+  proxyType = settings.getProxyType();
+  ui.chkUseProxy->setChecked(proxyType != NetworkSettings::NoProxy);
   QStringList proxy = settings.getProxyAddress().split(":");
   if (proxy.size() >= 1)
     ui.lineProxyAddress->setText(proxy.at(0));
@@ -347,6 +346,26 @@
   ui.lineProxyUsername->setText(settings.getProxyUsername());
   ui.lineProxyPassword->setText(settings.getProxyPassword());
 
+  /* SOCKS options are only available on Tor >= 0.2.2.1-alpha, so don't show
+   * them if Tor is running and its version is less than that. */
+  ui.cmboProxyType->clear();
+  if (!vApp->torControl()->isRunning()
+        || vApp->torControl()->getTorVersion() >= 0x020201) {
+    ui.cmboProxyType->addItem(tr("SOCKS 4"), NetworkSettings::Socks4Proxy);
+    ui.cmboProxyType->addItem(tr("SOCKS 5"), NetworkSettings::Socks5Proxy);
+  } else if (proxyType == NetworkSettings::Socks4Proxy
+              || proxyType == NetworkSettings::Socks5Proxy) {
+    /* Disable proxy if the settings include a SOCKS proxy and our version of
+     * Tor is not compatible. */
+    proxyType = NetworkSettings::NoProxy;
+    ui.chkUseProxy->setChecked(false);
+  }
+  ui.cmboProxyType->addItem(tr("HTTP"), NetworkSettings::HttpProxy);
+  ui.cmboProxyType->addItem(tr("HTTP / HTTPS"),
+                            NetworkSettings::HttpHttpsProxy);
+
+  ui.cmboProxyType->setCurrentIndex(ui.cmboProxyType->findData(proxyType));
+
   /* Load firewall settings */
   ui.chkFascistFirewall->setChecked(settings.getFascistFirewall());
   QList<quint16> reachablePorts = settings.getReachablePorts();
@@ -448,7 +467,10 @@
 void
 NetworkPage::proxyTypeChanged(int selection)
 {
-  if (selection == NetworkSettings::Socks4Proxy) {
+  QVariant data = ui.cmboProxyType->itemData(selection);
+
+  if (data.isValid()
+      && data.toInt() == NetworkSettings::Socks4Proxy) {
     ui.lineProxyUsername->setEnabled(false);
     ui.lineProxyPassword->setEnabled(false);
   } else {