25 #include <QIntValidator>
27 #include <QHostAddress>
29 #include <QMessageBox>
31 #define IMG_COPY ":/images/22x22/edit-copy.png"
41 connect(
ui.btnAddBridge, SIGNAL(clicked()),
this, SLOT(
addBridge()));
42 connect(
ui.btnRemoveBridge, SIGNAL(clicked()),
this, SLOT(
removeBridge()));
43 connect(
ui.btnCopyBridge, SIGNAL(clicked()),
45 connect(
ui.listBridges, SIGNAL(customContextMenuRequested(QPoint)),
47 connect(
ui.listBridges, SIGNAL(itemSelectionChanged()),
49 connect(
ui.lineBridge, SIGNAL(returnPressed()),
this, SLOT(
addBridge()));
50 connect(
ui.lblHelpFindBridges, SIGNAL(linkActivated(QString)),
52 connect(
ui.cmboProxyType, SIGNAL(currentIndexChanged(
int)),
56 ui.lineProxyPort->setValidator(
new QIntValidator(1, 65535,
this));
58 vApp->createShortcut(QKeySequence(QKeySequence::Copy),
65 ui.grpProxySettings->setTitle(
"");
66 ui.grpFirewallSettings->setTitle(
"");
67 ui.grpBridgeSettings->setTitle(
"");
75 ui.retranslateUi(
this);
116 QString input =
ui.lineBridge->text().trimmed();
120 if (!
ui.listBridges->findItems(input, Qt::MatchFixedString).isEmpty())
123 ui.listBridges->addItem(input);
124 ui.lineBridge->clear();
131 qDeleteAll(
ui.listBridges->selectedItems());
140 foreach (QListWidgetItem *item,
ui.listBridges->selectedItems()) {
141 #if defined(Q_WS_WIN)
142 contents += item->text() +
"\r\n";
144 contents += item->text() +
"\n";
147 if (!contents.isEmpty())
148 vApp->clipboard()->setText(contents.trimmed());
158 QListWidgetItem *item =
ui.listBridges->itemAt(pos);
162 QAction *copyAction =
163 new QAction(QIcon(
IMG_COPY), tr(
"Copy (Ctrl+C)"), &menu);
164 connect(copyAction, SIGNAL(triggered()),
167 menu.addAction(copyAction);
168 menu.exec(
ui.listBridges->mapToGlobal(pos));
175 bool enabled = !
ui.listBridges->selectedItems().isEmpty();
176 ui.btnCopyBridge->setEnabled(enabled);
177 ui.btnRemoveBridge->setEnabled(enabled);
188 QStringList bridgeList;
189 QList<quint16> reachablePorts;
192 if (
ui.chkUseProxy->isChecked()) {
193 if (
ui.lineProxyAddress->text().isEmpty()
194 ||
ui.lineProxyPort->text().isEmpty()) {
195 errmsg = tr(
"You must specify both an IP address or hostname and a "
196 "port number to configure Tor to use a proxy to access "
200 if (
ui.cmboProxyType->currentIndex() < 0) {
201 errmsg = tr(
"You must select the proxy type.");
205 if (
ui.chkFascistFirewall->isChecked()
206 &&
ui.lineReachablePorts->text().isEmpty()) {
207 errmsg = tr(
"You must specify one or more ports to which your "
208 "firewall allows you to connect.");
212 if (
ui.chkUseProxy->isChecked()) {
213 if (!
ui.lineProxyAddress->text().isEmpty()) {
214 addr =
ui.lineProxyAddress->text();
215 if (!
ui.lineProxyPort->text().isEmpty())
216 addr +=
":" +
ui.lineProxyPort->text();
219 user =
ui.lineProxyUsername->text();
220 pass =
ui.lineProxyPassword->text();
225 data =
ui.cmboProxyType->itemData(
ui.cmboProxyType->currentIndex());
226 Q_ASSERT(data.isValid());
240 foreach (QString portString,
241 ui.lineReachablePorts->text().split(
",", QString::SkipEmptyParts)) {
242 quint32 port = portString.toUInt(&ok);
243 if (!ok || port < 1 || port > 65535) {
244 errmsg = tr(
"'%1' is not a valid port number.").arg(portString);
247 reachablePorts << (quint16)port;
251 if (
ui.chkUseBridges->isChecked()) {
252 if (
ui.listBridges->count() < 1) {
253 errmsg = tr(
"You must specify one or more bridges.");
260 for (
int i = 0;
i <
ui.listBridges->count();
i++)
261 bridgeList <<
ui.listBridges->item(
i)->text();
272 QStringList reachablePortStrings;
279 if (proxy.size() >= 1)
280 ui.lineProxyAddress->setText(proxy.at(0));
281 if (proxy.size() >= 2)
282 ui.lineProxyPort->setText(proxy.at(1));
288 ui.cmboProxyType->clear();
289 if (!
vApp->torControl()->isRunning()
290 ||
vApp->torControl()->getTorVersion() >= 0x020201) {
298 ui.chkUseProxy->setChecked(
false);
300 ui.cmboProxyType->addItem(tr(
"HTTP / HTTPS"),
303 ui.cmboProxyType->setCurrentIndex(
ui.cmboProxyType->findData(proxyType));
308 foreach (quint16 port, reachablePorts) {
309 reachablePortStrings << QString::number(port);
311 ui.lineReachablePorts->setText(reachablePortStrings.join(
","));
315 ui.listBridges->clear();
324 QVariant data =
ui.cmboProxyType->itemData(selection);
328 ui.lineProxyUsername->setEnabled(
false);
329 ui.lineProxyPassword->setEnabled(
false);
331 ui.lineProxyUsername->setEnabled(
true);
332 ui.lineProxyPassword->setEnabled(
true);