Vidalia 0.2.15
UPNPTestDialog.h
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If 
00004 **  you did not receive the LICENSE file with this file, you may obtain it
00005 **  from the Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file UPNPTestDialog.h
00013 ** \brief Dialog that displays the progress of a UPnP configuration test
00014 */
00015 
00016 #ifndef _UPNPTESTDIALOG_H
00017 #define _UPNPTESTDIALOG_H
00018 
00019 #include "ui_UPNPTestDialog.h"
00020 #include "UPNPControl.h"
00021 
00022 #include <QDialog>
00023 #include <QAbstractButton>
00024 #include <QTimer>
00025 
00026 
00027 class UPNPTestDialog : public QDialog
00028 {
00029   Q_OBJECT
00030 
00031 public:
00032   /** Default constructor. <b>orPort</b> and <b>dirPort</b> specify the ports
00033    * used to test UPnP port forwarding. The original UPnP state will be
00034    * restored when the test dialog is closed. */
00035   UPNPTestDialog(quint16 orPort, quint16 dirPort, QWidget *parent = 0);
00036 
00037 signals:
00038   /** Emitted when the user clicks the 'Help' button requesting the help topic
00039    * on port forwarding. */
00040   void help();
00041 
00042 protected slots:
00043   /** Shows or hides the dialog based on <b>visible</b>. The UPnP test will be
00044    * started when the dialog is first shown. */
00045   void setVisible(bool visible);
00046 
00047   /** Called when a user clicks on a button in the dialog's button box. If
00048    * Retry is clicked, another UPnP test will be conducted. If Close is clicked,
00049    * then the dialog is closed and the original UPnP state restored. */
00050   void clicked(QAbstractButton *button);
00051   
00052   /** Updates the test UI based on the UPnP <b>state</b>. */
00053   void upnpStateChanged(UPNPControl::UPNPState state);
00054 
00055   /** Updates the progress bar to indicate the device discovery portion of the
00056    * test is still in progress. */
00057   void discoverTimeout();
00058 
00059 protected:
00060   /** Initiates a UPnP test. */
00061   void startTest();
00062 
00063   /** Called when the UPnP test successfully enables port forwarding. Enables
00064    * the Close button, allowing the user to exit the test dialog. */
00065   void testSuccessful();
00066 
00067   /** Called when the UPnP test fails due to an error. Enables the Close and
00068    * Retry buttons, allowing the user to either rerun the test or give up. */
00069   void testFailed();
00070 
00071 private:
00072   /** Pointer to the UPNPControl singleton instance. */
00073   UPNPControl *_upnp; 
00074   
00075   /** Timer used to update the progress bar while during the device discovery
00076    * portion of the test. */
00077   QTimer _discoverTimer;
00078   
00079   quint16 _oldOrPort;  /**< Original (pre-test) forwarded ORPort. */
00080   quint16 _oldDirPort; /**< Original (pre-test) forwarded DirPort. */
00081   quint16 _orPort;     /**< ORPort used during the test. */
00082   quint16 _dirPort;    /**< DirPort used during the test. */
00083   
00084   Ui::UPNPTestDialog ui;
00085 };
00086 
00087 #endif
00088