26 #include <QIntValidator>
28 #include <QHostAddress>
30 #include <QMessageBox>
32 #define IMG_COPY ":/images/22x22/edit-copy.png"
44 connect(
ui.btnCopyBridge, SIGNAL(clicked()),
46 connect(
ui.listBridges, SIGNAL(customContextMenuRequested(QPoint)),
48 connect(
ui.listBridges, SIGNAL(itemSelectionChanged()),
51 connect(
ui.lblHelpFindBridges, SIGNAL(linkActivated(QString)),
54 connect(
ui.cmboProxyType, SIGNAL(currentIndexChanged(
int)),
58 ui.lineProxyPort->setValidator(
new QIntValidator(1, 65535,
this));
60 vApp->createShortcut(QKeySequence(QKeySequence::Copy),
65 ui.btnFindBridges->setVisible(
false);
66 ui.lblHelpFindBridges->setText(
67 tr(
"<a href=\"bridges.finding\">How can I find bridges?</a>"));
78 ui.grpProxySettings->setTitle(
"");
79 ui.grpFirewallSettings->setTitle(
"");
80 ui.grpBridgeSettings->setTitle(
"");
88 ui.retranslateUi(
this);
129 QString input =
ui.lineBridge->text().trimmed();
133 if (!
ui.listBridges->findItems(input, Qt::MatchFixedString).isEmpty())
136 ui.listBridges->addItem(input);
137 ui.lineBridge->clear();
144 qDeleteAll(
ui.listBridges->selectedItems());
153 foreach (QListWidgetItem *item,
ui.listBridges->selectedItems()) {
154 #if defined(Q_WS_WIN)
155 contents += item->text() +
"\r\n";
157 contents += item->text() +
"\n";
160 if (!contents.isEmpty())
161 vApp->clipboard()->setText(contents.trimmed());
171 QListWidgetItem *item =
ui.listBridges->itemAt(pos);
175 QAction *copyAction =
176 new QAction(QIcon(
IMG_COPY), tr(
"Copy (Ctrl+C)"), &menu);
177 connect(copyAction, SIGNAL(triggered()),
180 menu.addAction(copyAction);
181 menu.exec(
ui.listBridges->mapToGlobal(pos));
188 bool enabled = !
ui.listBridges->selectedItems().isEmpty();
189 ui.btnCopyBridge->setEnabled(enabled);
190 ui.btnRemoveBridge->setEnabled(enabled);
201 QStringList bridgeList;
202 QList<quint16> reachablePorts;
205 if (
ui.chkUseProxy->isChecked()) {
206 if (
ui.lineProxyAddress->text().isEmpty()
207 ||
ui.lineProxyPort->text().isEmpty()) {
208 errmsg = tr(
"You must specify both an IP address or hostname and a "
209 "port number to configure Tor to use a proxy to access "
213 if (
ui.cmboProxyType->currentIndex() < 0) {
214 errmsg = tr(
"You must select the proxy type.");
218 if (
ui.chkFascistFirewall->isChecked()
219 &&
ui.lineReachablePorts->text().isEmpty()) {
220 errmsg = tr(
"You must specify one or more ports to which your "
221 "firewall allows you to connect.");
225 if (
ui.chkUseProxy->isChecked()) {
226 if (!
ui.lineProxyAddress->text().isEmpty()) {
227 addr =
ui.lineProxyAddress->text();
228 if (!
ui.lineProxyPort->text().isEmpty())
229 addr +=
":" +
ui.lineProxyPort->text();
232 user =
ui.lineProxyUsername->text();
233 pass =
ui.lineProxyPassword->text();
238 data =
ui.cmboProxyType->itemData(
ui.cmboProxyType->currentIndex());
239 Q_ASSERT(data.isValid());
253 foreach (QString portString,
254 ui.lineReachablePorts->text().split(
",", QString::SkipEmptyParts)) {
255 quint32 port = portString.toUInt(&ok);
256 if (!ok || port < 1 || port > 65535) {
257 errmsg = tr(
"'%1' is not a valid port number.").arg(portString);
260 reachablePorts << (quint16)port;
264 if (
ui.chkUseBridges->isChecked()) {
265 if (
ui.listBridges->count() < 1) {
266 errmsg = tr(
"You must specify one or more bridges.");
273 for (
int i = 0;
i <
ui.listBridges->count();
i++)
274 bridgeList <<
ui.listBridges->item(
i)->text();
285 QStringList reachablePortStrings;
292 if (proxy.size() >= 1)
293 ui.lineProxyAddress->setText(proxy.at(0));
294 if (proxy.size() >= 2)
295 ui.lineProxyPort->setText(proxy.at(1));
301 ui.cmboProxyType->clear();
302 if (!
vApp->torControl()->isRunning()
303 ||
vApp->torControl()->getTorVersion() >= 0x020201) {
311 ui.chkUseProxy->setChecked(
false);
313 ui.cmboProxyType->addItem(tr(
"HTTP / HTTPS"),
316 ui.cmboProxyType->setCurrentIndex(
ui.cmboProxyType->findData(proxyType));
321 foreach (quint16 port, reachablePorts) {
322 reachablePortStrings << QString::number(port);
324 ui.lineReachablePorts->setText(reachablePortStrings.join(
","));
328 ui.listBridges->clear();
341 dlg, SLOT(setStatus(QString)));
343 dlg, SLOT(setDownloadProgress(qint64, qint64)));
345 dlg, SLOT(bridgeRequestFailed(QString)));
351 switch (dlg->exec()) {
352 case QDialogButtonBox::Cancel:
356 case QDialogButtonBox::Help:
368 if (
ui.chkUseProxy->isChecked() &&
371 ui.lineProxyPort->text().toUInt(),
372 ui.lineProxyUsername->text(),
373 ui.lineProxyPassword->text());
385 bool foundNewBridges =
false;
388 foreach (QString bridge, bridges) {
389 QString address = normalized.split(
" ").at(0);
390 if (
ui.listBridges->findItems(address, Qt::MatchContains).isEmpty()) {
391 ui.listBridges->addItem(normalized);
392 foundNewBridges =
true;
396 if (! foundNewBridges) {
397 QMessageBox dlg(
this);
398 dlg.setIcon(QMessageBox::Information);
399 dlg.setText(tr(
"No new bridges are currently available. You can either "
400 "wait a while and try again, or try another method of "
401 "finding new bridges."));
402 dlg.setInformativeText(tr(
"Click Help to see other methods of finding "
404 dlg.setStandardButtons(QMessageBox::Ok | QMessageBox::Help);
406 if (dlg.exec() == QMessageBox::Help)
416 QVariant data =
ui.cmboProxyType->itemData(selection);
420 ui.lineProxyUsername->setEnabled(
false);
421 ui.lineProxyPassword->setEnabled(
false);
423 ui.lineProxyUsername->setEnabled(
true);
424 ui.lineProxyPassword->setEnabled(
true);