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

[vidalia-svn] r2633: Flesh out the rest of the UPnP test dialog. The dialog uses (in vidalia: . branches/upnp/src/vidalia/config)



Author: edmanm
Date: 2008-05-31 20:52:11 -0400 (Sat, 31 May 2008)
New Revision: 2633

Modified:
   vidalia/
   vidalia/branches/upnp/src/vidalia/config/serverpage.cpp
   vidalia/branches/upnp/src/vidalia/config/upnptestdialog.cpp
   vidalia/branches/upnp/src/vidalia/config/upnptestdialog.h
Log:
 r399@thebe:  edmanm | 2008-05-31 20:51:00 -0400
 Flesh out the rest of the UPnP test dialog. The dialog uses the ORPort and
 DirPort values currently set (but not necessarily saved) in the relay config
 page and attempts to forward those for the user. The previously set UPnP state
 will be restored when the test dialog is closed.



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

Modified: vidalia/branches/upnp/src/vidalia/config/serverpage.cpp
===================================================================
--- vidalia/branches/upnp/src/vidalia/config/serverpage.cpp	2008-06-01 00:52:09 UTC (rev 2632)
+++ vidalia/branches/upnp/src/vidalia/config/serverpage.cpp	2008-06-01 00:52:11 UTC (rev 2633)
@@ -505,7 +505,8 @@
 ServerPage::testUpnp()
 {
 #if defined(USE_MINIUPNPC)
-  UPNPTestDialog dlg(this);
+  UPNPTestDialog dlg(ui.lineServerPort->text().toUInt(),
+                     ui.lineDirPort->text().toUInt(), this);
 
   dlg.exec();
 #endif

Modified: vidalia/branches/upnp/src/vidalia/config/upnptestdialog.cpp
===================================================================
--- vidalia/branches/upnp/src/vidalia/config/upnptestdialog.cpp	2008-06-01 00:52:09 UTC (rev 2632)
+++ vidalia/branches/upnp/src/vidalia/config/upnptestdialog.cpp	2008-06-01 00:52:11 UTC (rev 2633)
@@ -17,10 +17,144 @@
 #include "upnptestdialog.h"
 
 
-/** Default constructor. */
-UPNPTestDialog::UPNPTestDialog(QWidget *parent)
-  : QDialog(parent)
+/** Default constructor. <b>orPort</b> and <b>dirPort</b> specify the ports
+ * used to test UPnP port forwarding. The original UPnP state will be restored
+ * when the test dialog is closed. */
+UPNPTestDialog::UPNPTestDialog(quint16 orPort, quint16 dirPort, QWidget *parent)
+  : QDialog(parent), _orPort(orPort), _dirPort(dirPort)
 {
   ui.setupUi(this);
+  _upnp = UPNPControl::Instance();
+
+  ui.buttonBox->setStandardButtons(QDialogButtonBox::Close);
+  
+  ui.progressBar->setValue(0);
+  ui.progressBar->setFormat("");
+  ui.progressBar->setMinimum(0);
+  ui.progressBar->setMaximum(_upnp->discoverTimeout()/500 + 4);
+
+  _discoverTimer.setInterval(500);
+  connect(&_discoverTimer, SIGNAL(timeout()), this, SLOT(discoverTimeout()));
+  connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
+          this, SLOT(clicked(QAbstractButton*)));
+
+  _upnp->getDesiredState(&_oldDirPort, &_oldOrPort);
 }
 
+/** Shows or hides the dialog based on <b>visible</b>. The UPnP test will be
+ * started when the dialog is first shown. */
+void
+UPNPTestDialog::setVisible(bool visible)
+{
+  QWidget::setVisible(visible);
+
+  if (visible)
+    startTest();
+  else
+    _upnp->setDesiredState(_oldDirPort, _oldOrPort);
+}
+
+/** Initiates a UPnP test. */
+void
+UPNPTestDialog::startTest()
+{
+  ui.buttonBox->setEnabled(false);
+  ui.progressBar->setValue(0);
+
+  connect(UPNPControl::Instance(), SIGNAL(stateChanged(UPNPControl::UPNPState)),
+          this, SLOT(upnpStateChanged(UPNPControl::UPNPState)));
+  
+  UPNPControl::Instance()->setDesiredState(_dirPort, _orPort);  
+}
+
+/** Called when the UPnP test successfully enables port forwarding. Enables
+ * the Close button, allowing the user to exit the test dialog. */
+void
+UPNPTestDialog::testSuccessful()
+{
+  ui.buttonBox->setEnabled(true);
+  ui.buttonBox->setStandardButtons(QDialogButtonBox::Close);
+
+  disconnect(UPNPControl::Instance(), 0, this, 0);
+}
+
+/** Called when the UPnP test fails due to an error. Enables the Close and
+ * Retry buttons, allowing the user to either rerun the test or give up. */
+void
+UPNPTestDialog::testFailed()
+{
+  ui.buttonBox->setEnabled(true);
+  ui.buttonBox->setStandardButtons(QDialogButtonBox::Retry
+                                     | QDialogButtonBox::Close);
+  
+  disconnect(UPNPControl::Instance(), 0, this, 0);
+}
+
+/** Updates the progress bar to indicate the device discovery portion of the
+ * test is still in progress. */
+void
+UPNPTestDialog::discoverTimeout()
+{
+  ui.progressBar->setValue(ui.progressBar->value()+1);
+}
+
+/** Updates the test UI based on the UPnP <b>state</b>. */
+void
+UPNPTestDialog::upnpStateChanged(UPNPControl::UPNPState state)
+{
+  switch (state) {
+    case UPNPControl::DiscoverState:
+      _discoverTimer.start();
+      ui.progressBar->setValue(ui.progressBar->value()+1);
+      ui.lblCurrentState->setText(tr("Discovering UPnP-enabled devices"));
+      break;
+
+    case UPNPControl::UpdatingDirPortState:
+      ui.progressBar->setValue(ui.progressBar->value()+1);
+      ui.lblCurrentState->setText(tr("Updating directory port mapping"));
+      break;
+
+    case UPNPControl::UpdatingORPortState:
+      ui.progressBar->setValue(ui.progressBar->value()+1);
+      ui.lblCurrentState->setText(tr("Updating relay port mapping"));
+      break;
+
+    case UPNPControl::ForwardingCompleteState:
+      ui.progressBar->setValue(ui.progressBar->maximum());
+      ui.lblCurrentState->setText(tr("Test completed successfully!"));
+      testSuccessful();
+      break;
+
+    case UPNPControl::ErrorState:
+      ui.progressBar->setValue(ui.progressBar->maximum());
+      ui.lblCurrentState->setText(UPNPControl::Instance()->errorString());
+      testFailed();
+      break;
+
+    default:
+      break;
+  }
+  if (state != UPNPControl::DiscoverState)
+    _discoverTimer.stop();
+}
+
+/** Called when a user clicks on a button in the dialog's button box. If Retry
+ * is clicked, another UPnP test will be conducted. If Close is clicked, then
+ * the dialog is closed and the original UPnP state restored. */
+void
+UPNPTestDialog::clicked(QAbstractButton *button)
+{
+  switch (ui.buttonBox->standardButton(button)) {
+    case QDialogButtonBox::Retry:
+      startTest();
+      break;
+
+    case QDialogButtonBox::Close:
+      done(0);
+      break;
+
+    default:
+      break;
+  }
+}
+

Modified: vidalia/branches/upnp/src/vidalia/config/upnptestdialog.h
===================================================================
--- vidalia/branches/upnp/src/vidalia/config/upnptestdialog.h	2008-06-01 00:52:09 UTC (rev 2632)
+++ vidalia/branches/upnp/src/vidalia/config/upnptestdialog.h	2008-06-01 00:52:11 UTC (rev 2633)
@@ -14,13 +14,15 @@
 ** \brief Dialog that displays the progress of a UPnP configuration test
 */
 
-
 #ifndef _UPNPTESTDIALOG_H
 #define _UPNPTESTDIALOG_H
 
 #include <QDialog>
+#include <QAbstractButton>
+#include <QTimer>
 
 #include "ui_upnptestdialog.h"
+#include "upnpcontrol.h"
 
 
 class UPNPTestDialog : public QDialog
@@ -28,9 +30,53 @@
   Q_OBJECT
 
 public:
-  /** Default constructor */
-  UPNPTestDialog(QWidget *parent = 0);
+  /** Default constructor. <b>orPort</b> and <b>dirPort</b> specify the ports
+   * used to test UPnP port forwarding. The original UPnP state will be
+   * restored when the test dialog is closed. */
+  UPNPTestDialog(quint16 orPort, quint16 dirPort, QWidget *parent = 0);
 
+protected slots:
+  /** Shows or hides the dialog based on <b>visible</b>. The UPnP test will be
+   * started when the dialog is first shown. */
+  void setVisible(bool visible);
+
+  /** Called when a user clicks on a button in the dialog's button box. If
+   * Retry is clicked, another UPnP test will be conducted. If Close is clicked,
+   * then the dialog is closed and the original UPnP state restored. */
+  void clicked(QAbstractButton *button);
+  
+  /** Updates the test UI based on the UPnP <b>state</b>. */
+  void upnpStateChanged(UPNPControl::UPNPState state);
+
+  /** Updates the progress bar to indicate the device discovery portion of the
+   * test is still in progress. */
+  void discoverTimeout();
+
+protected:
+  /** Initiates a UPnP test. */
+  void startTest();
+
+  /** Called when the UPnP test successfully enables port forwarding. Enables
+   * the Close button, allowing the user to exit the test dialog. */
+  void testSuccessful();
+
+  /** Called when the UPnP test fails due to an error. Enables the Close and
+   * Retry buttons, allowing the user to either rerun the test or give up. */
+  void testFailed();
+
+private:
+  /** Pointer to the UPNPControl singleton instance. */
+  UPNPControl *_upnp; 
+  
+  /** Timer used to update the progress bar while during the device discovery
+   * portion of the test. */
+  QTimer _discoverTimer;
+  
+  quint16 _oldOrPort;  /**< Original (pre-test) forwarded ORPort. */
+  quint16 _oldDirPort; /**< Original (pre-test) forwarded DirPort. */
+  quint16 _orPort;     /**< ORPort used during the test. */
+  quint16 _dirPort;    /**< DirPort used during the test. */
+  
   Ui::UPNPTestDialog ui;
 };