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

[vidalia-svn] r2640: Merge the remaining UI bits of the UPnP branch into trunk. (in vidalia: . trunk/src/vidalia trunk/src/vidalia/config)



Author: edmanm
Date: 2008-06-01 19:42:59 -0400 (Sun, 01 Jun 2008)
New Revision: 2640

Modified:
   vidalia/
   vidalia/trunk/src/vidalia/config/serverpage.cpp
   vidalia/trunk/src/vidalia/config/serverpage.h
   vidalia/trunk/src/vidalia/config/serverpage.ui
   vidalia/trunk/src/vidalia/mainwindow.cpp
   vidalia/trunk/src/vidalia/mainwindow.h
Log:
 r414@thebe:  edmanm | 2008-06-01 19:43:20 -0400
 Merge the remaining UI bits of the UPnP branch into trunk.



Property changes on: vidalia
___________________________________________________________________
 svk:merge ticket from /local/vidalia [r414] on 45a62a8a-8088-484c-baad-c7b3e776dd32

Modified: vidalia/trunk/src/vidalia/config/serverpage.cpp
===================================================================
--- vidalia/trunk/src/vidalia/config/serverpage.cpp	2008-06-01 23:42:57 UTC (rev 2639)
+++ vidalia/trunk/src/vidalia/config/serverpage.cpp	2008-06-01 23:42:59 UTC (rev 2640)
@@ -18,6 +18,7 @@
 #include <vidalia.h>
 #include <vmessagebox.h>
 #include <html.h>
+#include <config.h>
 
 #include "configdialog.h"
 #include "serverpage.h"
@@ -26,6 +27,10 @@
 #include "domainvalidator.h"
 #include "nicknamevalidator.h"
 
+#if defined(USE_MINIUPNPC)
+#include "upnptestdialog.h"
+#endif
+
 /* These are completely made up values (in bytes/sec). */
 #define CABLE256_AVG_RATE       (32*1024)
 #define CABLE256_MAX_RATE       (64*1024)
@@ -98,6 +103,13 @@
     new QIntValidator(MIN_BANDWIDTH_RATE, MAX_BANDWIDTH_RATE, this));
   ui.lineMaxRateLimit->setValidator(
     new QIntValidator(MIN_BANDWIDTH_RATE, MAX_BANDWIDTH_RATE, this));
+
+#if defined(USE_MINIUPNPC)
+  connect(ui.btnTestUpnp, SIGNAL(clicked()), this, SLOT(testUpnp()));
+#else
+  ui.chkEnableUpnp->setVisible(false);
+  ui.btnTestUpnp->setVisible(false);
+#endif
 }
 
 /** Destructor */
@@ -266,7 +278,11 @@
   _settings->setContactInfo(ui.lineServerContact->text());
   saveBandwidthLimits();
   saveExitPolicies();
-  
+
+#if defined(USE_MINIUPNPC)
+  _settings->setUpnpEnabled(ui.chkEnableUpnp->isChecked());
+#endif
+
   return true;
 }
 
@@ -290,6 +306,10 @@
   loadBandwidthLimits();
   loadExitPolicies();
   loadBridgeIdentity();
+
+#if defined(USE_MINIUPNPC)
+  ui.chkEnableUpnp->setChecked(_settings->isUpnpEnabled());
+#endif
 }
 
 /** Shows exit policy related help information */
@@ -480,3 +500,15 @@
   }
 }
 
+/** Tests automatic port forwarding using UPnP. */
+void
+ServerPage::testUpnp()
+{
+#if defined(USE_MINIUPNPC)
+  UPNPTestDialog dlg(ui.lineServerPort->text().toUInt(),
+                     ui.lineDirPort->text().toUInt(), this);
+
+  dlg.exec();
+#endif
+}
+

Modified: vidalia/trunk/src/vidalia/config/serverpage.h
===================================================================
--- vidalia/trunk/src/vidalia/config/serverpage.h	2008-06-01 23:42:57 UTC (rev 2639)
+++ vidalia/trunk/src/vidalia/config/serverpage.h	2008-06-01 23:42:59 UTC (rev 2640)
@@ -61,8 +61,8 @@
   void bandwidthHelp();
   /** Called when the user clicks the exit policy help button */
   void exitPolicyHelp();
-	/** Called when the user selects a new value from the rate combo box */
-	void rateChanged(int rate);
+  /** Called when the user selects a new value from the rate combo box */
+  void rateChanged(int rate);
   /** Called when the user edits the max or average bandwidth limits. */
   void customRateChanged();
   /** Called when Vidalia has authenticated to Tor. If the user's Tor is not
@@ -74,6 +74,8 @@
   void onDisconnected();
   /** Copies the user's bridge relay identity to the clipboard. */
   void copyBridgeIdentity();
+  /** Tests automatic port forwarding with UPnP. */
+  void testUpnp();
 
 private:
   /** Index values of rate values in the bandwidth limits dropdown box. */

Modified: vidalia/trunk/src/vidalia/config/serverpage.ui
===================================================================
--- vidalia/trunk/src/vidalia/config/serverpage.ui	2008-06-01 23:42:57 UTC (rev 2639)
+++ vidalia/trunk/src/vidalia/config/serverpage.ui	2008-06-01 23:42:59 UTC (rev 2640)
@@ -127,6 +127,49 @@
             </property>
            </spacer>
           </item>
+          <item row="4" column="0" colspan="6" >
+           <widget class="QCheckBox" name="chkEnableUpnp" >
+            <property name="contextMenuPolicy" >
+             <enum>Qt::NoContextMenu</enum>
+            </property>
+            <property name="toolTip" >
+             <string></string>
+            </property>
+            <property name="text" >
+             <string>Attempt to automatically configure port forwarding</string>
+            </property>
+           </widget>
+          </item>
+          <item row="4" column="6" >
+           <layout class="QHBoxLayout" >
+            <property name="margin" >
+             <number>0</number>
+            </property>
+            <item>
+             <widget class="QPushButton" name="btnTestUpnp" >
+              <property name="contextMenuPolicy" >
+               <enum>Qt::NoContextMenu</enum>
+              </property>
+              <property name="text" >
+               <string>Test</string>
+              </property>
+             </widget>
+            </item>
+            <item>
+             <spacer>
+              <property name="orientation" >
+               <enum>Qt::Horizontal</enum>
+              </property>
+              <property name="sizeHint" >
+               <size>
+                <width>40</width>
+                <height>20</height>
+               </size>
+              </property>
+             </spacer>
+            </item>
+           </layout>
+          </item>
           <item row="1" column="1" colspan="7" >
            <widget class="QLineEdit" name="lineServerContact" >
             <property name="cursor" >

Modified: vidalia/trunk/src/vidalia/mainwindow.cpp
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.cpp	2008-06-01 23:42:57 UTC (rev 2639)
+++ vidalia/trunk/src/vidalia/mainwindow.cpp	2008-06-01 23:42:59 UTC (rev 2640)
@@ -28,11 +28,9 @@
 #include <clientstatusevent.h>
 #include <dangerousversionevent.h>
 #include <vmessagebox.h>
-#include "config.h"
 
 #include "mainwindow.h"
 
-
 #define IMG_BWGRAPH        ":/images/16x16/utilities-system-monitor.png"
 #define IMG_CONTROL_PANEL  ":/images/16x16/preferences-desktop.png"
 #define IMG_MESSAGELOG     ":/images/16x16/format-justify-fill.png"
@@ -142,7 +140,13 @@
   /* Catch signals when the application is running or shutting down */
   connect(vApp, SIGNAL(running()), this, SLOT(running()));
   connect(vApp, SIGNAL(shutdown()), this, SLOT(shutdown()));
- 
+
+#if defined(USE_MINIUPNPC)
+  /* Catch UPnP-related signals */
+  connect(UPNPControl::instance(), SIGNAL(error(UPNPControl::UPNPError)),
+         this, SLOT(upnpError(UPNPControl::UPNPError)));
+#endif
+
   if (TrayIcon::isTrayIconSupported()) {
     /* Make the tray icon visible */
     _trayIcon.show();
@@ -227,6 +231,10 @@
     _torControl->stop();
   }
 
+  /* Disable port forwarding */
+  ServerSettings settings(_torControl);
+  settings.cleanupPortForwarding();
+
   if (_proxyProcess->state() != QProcess::NotRunning) {
     /* Close the proxy server (Polipo ignores the WM_CLOSE event sent by
      * terminate() so we have to kill() it) */
@@ -908,7 +916,10 @@
          + p(errmsg),
       VMessageBox::Ok);
   }
-  
+
+  /* Configure UPnP port forwarding if needed */
+  serverSettings.configurePortForwarding();
+
   /* Check if Tor has a circuit established */
   if (_torControl->circuitEstablished())
     circuitEstablished();
@@ -1167,4 +1178,25 @@
   return "Unknown";
 }
 
+#if defined(USE_MINIUPNPC)
+/** Called when a UPnP error occurs. */
+void
+MainWindow::upnpError(UPNPControl::UPNPError error)
+{
+  Q_UNUSED(error);
 
+#if 0
+  /* XXX: Is there a better way to do this? Currently, this could get called
+   * if there is an error when testing UPnP support, and again when attempting
+   * to reset the UPnP state when the test dialog is closed. The user would
+   * not be amused with all the warning dialogs. */
+
+  VMessageBox::warning(this,
+    tr("Port Forwarding Failed"),
+    p(tr("Vidalia was unable to configure automatic port forwarding."))
+      + p(UPNPControl::Instance()->errorString()),
+    VMessageBox::Ok);
+#endif
+}
+#endif
+

Modified: vidalia/trunk/src/vidalia/mainwindow.h
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.h	2008-06-01 23:42:57 UTC (rev 2639)
+++ vidalia/trunk/src/vidalia/mainwindow.h	2008-06-01 23:42:59 UTC (rev 2640)
@@ -30,7 +30,11 @@
 #include "network/netviewer.h"
 #include "ui_mainwindow.h"
 #include "helperprocess.h"
+#include "config.h"
 
+#if defined(USE_MINIUPNPC)
+#include "config/upnpcontrol.h"
+#endif
 
 class MainWindow : public VidaliaWindow
 {
@@ -103,7 +107,12 @@
   void onBrowserFailed(QString errmsg);
   /** Called when the proxy server fails to start */
   void onProxyFailed(QString errmsg);
-  
+
+#if defined(USE_MINIUPNPC)
+  /** Called when a UPnP error occurs. */
+  void upnpError(UPNPControl::UPNPError error);
+#endif
+
 private:
   enum TorStatus {
     Unset,      /**< Tor's status has not yet been set. */