Vidalia 0.3.1
UPNPTestDialog.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If
4** you did not receive the LICENSE file with this file, you may obtain it
5** from the Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file UPNPTestDialog.cpp
13** \brief Dialog that displays the progress of a UPnP configuration test
14*/
15
16#include "UPNPTestDialog.h"
17
18
19/** Default constructor. <b>orPort</b> and <b>dirPort</b> specify the ports
20 * used to test UPnP port forwarding. The original UPnP state will be restored
21 * when the test dialog is closed. */
22UPNPTestDialog::UPNPTestDialog(quint16 orPort, quint16 dirPort, QWidget *parent)
23 : QDialog(parent), _orPort(orPort), _dirPort(dirPort)
24{
25 ui.setupUi(this);
27
28 ui.buttonBox->setStandardButtons(QDialogButtonBox::Close
29 | QDialogButtonBox::Help);
30
31 ui.progressBar->setValue(0);
32 ui.progressBar->setFormat("");
33 ui.progressBar->setMinimum(0);
34 ui.progressBar->setMaximum(_upnp->discoverTimeout()/500 + 4);
35
36 _discoverTimer.setInterval(500);
37 connect(&_discoverTimer, SIGNAL(timeout()), this, SLOT(discoverTimeout()));
38 connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
39 this, SLOT(clicked(QAbstractButton*)));
40
42}
43
44/** Shows or hides the dialog based on <b>visible</b>. The UPnP test will be
45 * started when the dialog is first shown. */
46void
48{
49 QWidget::setVisible(visible);
50
51 if (visible)
52 startTest();
53 else
55}
56
57/** Initiates a UPnP test. */
58void
60{
61 ui.buttonBox->setEnabled(false);
62 ui.progressBar->setValue(0);
63
66
68}
69
70/** Called when the UPnP test successfully enables port forwarding. Enables
71 * the Close button, allowing the user to exit the test dialog. */
72void
74{
75 ui.buttonBox->setEnabled(true);
76 ui.buttonBox->setStandardButtons(QDialogButtonBox::Close
77 | QDialogButtonBox::Help);
78
79 disconnect(UPNPControl::instance(), 0, this, 0);
80}
81
82/** Called when the UPnP test fails due to an error. Enables the Close and
83 * Retry buttons, allowing the user to either rerun the test or give up. */
84void
86{
87 ui.buttonBox->setEnabled(true);
88 ui.buttonBox->setStandardButtons(QDialogButtonBox::Retry
89 | QDialogButtonBox::Close
90 | QDialogButtonBox::Help);
91
92 disconnect(UPNPControl::instance(), 0, this, 0);
93}
94
95/** Updates the progress bar to indicate the device discovery portion of the
96 * test is still in progress. */
97void
99{
100 ui.progressBar->setValue(ui.progressBar->value()+1);
101}
102
103/** Updates the test UI based on the UPnP <b>state</b>. */
104void
106{
107 switch (state) {
109 _discoverTimer.start();
110 ui.progressBar->setValue(ui.progressBar->value()+1);
111 ui.lblCurrentState->setText(tr("Discovering UPnP-enabled devices"));
112 break;
113
115 ui.progressBar->setValue(ui.progressBar->value()+1);
116 ui.lblCurrentState->setText(tr("Updating directory port mapping"));
117 break;
118
120 ui.progressBar->setValue(ui.progressBar->value()+1);
121 ui.lblCurrentState->setText(tr("Updating relay port mapping"));
122 break;
123
125 ui.progressBar->setValue(ui.progressBar->maximum());
126 ui.lblCurrentState->setText(tr("Test completed successfully!"));
128 break;
129
131 ui.progressBar->setValue(ui.progressBar->maximum());
132 ui.lblCurrentState->setText(UPNPControl::instance()->errorString());
133 testFailed();
134 break;
135
136 default:
137 break;
138 }
139 if (state != UPNPControl::DiscoverState)
140 _discoverTimer.stop();
141}
142
143/** Called when a user clicks on a button in the dialog's button box. If Retry
144 * is clicked, another UPnP test will be conducted. If Close is clicked, then
145 * the dialog is closed and the original UPnP state restored. */
146void
147UPNPTestDialog::clicked(QAbstractButton *button)
148{
149 switch (ui.buttonBox->standardButton(button)) {
150 case QDialogButtonBox::Retry:
151 startTest();
152 break;
153
154 case QDialogButtonBox::Close:
155 done(0);
156 break;
157
158 case QDialogButtonBox::Help:
159 emit help();
160 done(0);
161 break;
162
163 default:
164 break;
165 }
166}
167
stop errmsg connect(const QHostAddress &address, quint16 port)
stop errmsg disconnect()
void setDesiredState(quint16 desiredDirPort, quint16 desiredOrPort)
Definition: UPNPControl.cpp:89
static UPNPControl * instance()
Definition: UPNPControl.cpp:31
void getDesiredState(quint16 *desiredDirPort, quint16 *desiredOrPort)
Definition: UPNPControl.cpp:78
int discoverTimeout() const
@ UpdatingDirPortState
Definition: UPNPControl.h:48
@ UpdatingORPortState
Definition: UPNPControl.h:47
@ ForwardingCompleteState
Definition: UPNPControl.h:49
quint16 _oldDirPort
void upnpStateChanged(UPNPControl::UPNPState state)
Ui::UPNPTestDialog ui
void setVisible(bool visible)
UPNPControl * _upnp
void clicked(QAbstractButton *button)
QTimer _discoverTimer
UPNPTestDialog(quint16 orPort, quint16 dirPort, QWidget *parent=0)
quint16 _oldOrPort