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

[vidalia-svn] r1962: Save and load the settings on the 'Network' config page usin (in trunk: . src/gui/config)



Author: edmanm
Date: 2007-09-30 19:22:21 -0400 (Sun, 30 Sep 2007)
New Revision: 1962

Modified:
   trunk/
   trunk/src/gui/config/networkpage.cpp
   trunk/src/gui/config/networkpage.h
Log:
 r1990@lysithea:  edmanm | 2007-09-30 19:18:38 -0400
 Save and load the settings on the 'Network' config page using NetworkSettings.
 These settings are not yet applied to Tor.



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

Modified: trunk/src/gui/config/networkpage.cpp
===================================================================
--- trunk/src/gui/config/networkpage.cpp	2007-09-30 23:22:13 UTC (rev 1961)
+++ trunk/src/gui/config/networkpage.cpp	2007-09-30 23:22:21 UTC (rev 1962)
@@ -25,9 +25,12 @@
  * \brief Network and firewall configuration options
  */
 
+#include <QIntValidator>
 #include <vidalia.h>
+#include <config/networksettings.h>
 
 #include "networkpage.h"
+#include "domainvalidator.h"
 
 
 /** Constructor */
@@ -36,9 +39,12 @@
 {
   /* Invoke the Qt Designer generated object setup routine */
   ui.setupUi(this);
-  
-  /* Keep a pointer to the TorControl object used to talk to Tor */
-  _torControl = Vidalia::torControl();
+ 
+  connect(ui.btnAddBridge, SIGNAL(clicked()), this, SLOT(addBridge()));
+  connect(ui.btnRemoveBridge, SIGNAL(clicked()), this, SLOT(removeBridge()));
+
+  ui.lineHttpProxyAddress->setValidator(new DomainValidator(this));
+  ui.lineHttpProxyPort->setValidator(new QIntValidator(1, 65535, this));
 }
 
 /** Destructor */
@@ -46,11 +52,80 @@
 {
 }
 
+/** Adds a bridge to the bridge list box. */
+void
+NetworkPage::addBridge()
+{
+  QString bridge = ui.lineBridge->text().trimmed();
+  if (bridge.isEmpty())
+    return;
+  if (!ui.listBridges->findItems(bridge, Qt::MatchFixedString).isEmpty())
+    return; /* duplicate bridge */
+
+  /* XXX: We should do some verification that the gibberish the user typed in
+   * is actually valid. */
+  ui.listBridges->addItem(bridge);
+}
+
+/** Removes one or more selected bridges from the bridge list box. */
+void
+NetworkPage::removeBridge()
+{
+  qDeleteAll(ui.listBridges->selectedItems());
+}
+
 /** Saves changes made to settings on the Firewall settings page. */
 bool
 NetworkPage::save(QString &errmsg)
 {
-  Q_UNUSED(errmsg);
+  NetworkSettings settings;
+  QStringList bridgeList;
+  QList<quint16> reachablePorts;
+  bool ok;
+  
+  /* Save the HTTP/HTTPS proxy settings */
+  settings.setUseHttpProxy(ui.chkUseProxy->isChecked());
+  settings.setUseHttpsProxy(ui.chkProxyUseHttps->isChecked());
+  if (!ui.lineHttpProxyAddress->text().isEmpty()) {
+    QString proxy = ui.lineHttpProxyAddress->text();
+    if (!ui.lineHttpProxyPort->text().isEmpty())
+      proxy += ":" + ui.lineHttpProxyPort->text();
+
+    settings.setHttpProxy(proxy);
+    settings.setHttpsProxy(proxy);
+  } else {
+    settings.setHttpProxy("");
+    settings.setHttpsProxy("");
+  }
+
+  if (!ui.lineHttpProxyUsername->text().isEmpty() ||
+      !ui.lineHttpProxyPassword->text().isEmpty()) {
+    QString auth = ui.lineHttpProxyUsername->text() + ":" +
+                   ui.lineHttpProxyPassword->text();
+    settings.setHttpProxyAuthenticator(auth);
+    settings.setHttpsProxyAuthenticator(auth);
+  } else {
+    settings.setHttpProxyAuthenticator("");
+    settings.setHttpsProxyAuthenticator("");
+  }
+  
+  /* Save the reachable port settings */
+  settings.setFascistFirewall(ui.chkFascistFirewall->isChecked());
+  foreach (QString portString, ui.lineReachablePorts->text().split(",")) {
+    quint32 port = portString.toUInt(&ok);
+    if (!ok || port < 1 || port > 65535) {
+      errmsg = tr("'%1' is not a valid port number.").arg(portString);
+      return false;
+    }
+    reachablePorts << (quint16)port;
+  }
+  settings.setReachablePorts(reachablePorts);
+
+  /* Save the bridge settings */
+  settings.setUseBridges(ui.chkUseBridges->isChecked());
+  for (int i = 0; i < ui.listBridges->count(); i++)
+    bridgeList << ui.listBridges->item(i)->text();
+  settings.setBridgeList(bridgeList);
   return true;
 }
 
@@ -58,8 +133,33 @@
 void
 NetworkPage::load()
 {
-  ui.grpFirewallSettings->setVisible(false);
-  ui.grpProxySettings->setVisible(false);
-  ui.grpBridgeSettings->setVisible(false);
+  NetworkSettings settings;
+  QStringList reachablePortStrings;
+
+  /* Load HTTP/HTTPS proxy settings */
+  ui.chkUseProxy->setChecked(settings.getUseHttpProxy());
+  ui.chkProxyUseHttps->setChecked(settings.getUseHttpsProxy());
+  QStringList proxy = settings.getHttpProxy().split(":");
+  QStringList proxyAuth = settings.getHttpProxyAuthenticator().split(":");
+  if (proxy.size() >= 1)
+    ui.lineHttpProxyAddress->setText(proxy.at(0));
+  if (proxy.size() >= 2)
+    ui.lineHttpProxyPort->setText(proxy.at(1));
+  if (proxyAuth.size() >= 1)  
+    ui.lineHttpProxyUsername->setText(proxyAuth.at(0));
+  if (proxyAuth.size() >= 2)
+    ui.lineHttpProxyPassword->setText(proxyAuth.at(1));
+
+  /* Load firewall settings */
+  ui.chkFascistFirewall->setChecked(settings.getFascistFirewall());
+  QList<quint16> reachablePorts = settings.getReachablePorts();
+  foreach (quint16 port, reachablePorts) {
+    reachablePortStrings << QString::number(port);
+  }
+  ui.lineReachablePorts->setText(reachablePortStrings.join(","));
+
+  /* Load bridge settings */
+  ui.chkUseBridges->setChecked(settings.getUseBridges());
+  ui.listBridges->addItems(settings.getBridgeList());
 }
 

Modified: trunk/src/gui/config/networkpage.h
===================================================================
--- trunk/src/gui/config/networkpage.h	2007-09-30 23:22:13 UTC (rev 1961)
+++ trunk/src/gui/config/networkpage.h	2007-09-30 23:22:21 UTC (rev 1962)
@@ -48,10 +48,13 @@
   /** Loads the settings for this page */
   void load();
 
+private slots:
+  /** Adds a bridge to the bridge list box. */
+  void addBridge();
+  /** Removes one or more selected bridges from the bridge list box. */
+  void removeBridge();
+
 private:
-  /** A TorControl object used to talk to Tor */
-  TorControl* _torControl;
-
   /** Qt Designer generated object */
   Ui::NetworkPage ui;
 };