Skip to content
Permalink
Browse files

Merge pull request #4587

ed166df [Qt] allow users to set -onion via GUI (Philip Kaufmann)
  • Loading branch information
laanwj committed Aug 7, 2015
2 parents 100c9d3 + ed166df commit 0c465f5e6035c6df2868cbd5b940f9b24c07293f
Showing with 297 additions and 7 deletions.
  1. +188 −1 src/qt/forms/optionsdialog.ui
  2. +46 −5 src/qt/optionsdialog.cpp
  3. +3 −1 src/qt/optionsdialog.h
  4. +57 −0 src/qt/optionsmodel.cpp
  5. +3 −0 src/qt/optionsmodel.h
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>560</width>
<height>400</height>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
@@ -297,6 +297,193 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2_Network">
<item>
<widget class="QLabel" name="proxyActiveNets">
<property name="text">
<string>Used for reaching peers via:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachIPv4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachIPv4Label">
<property name="text">
<string>IPv4</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachIPv6">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachIPv6Label">
<property name="text">
<string>IPv6</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="proxyReachTor">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Shows, if the supplied default SOCKS5 proxy is used to reach peers via this network type.</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyReachTorLabel">
<property name="text">
<string>Tor</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2_Network">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="connectSocksTor">
<property name="toolTip">
<string>Connect to the Bitcoin network through a separate SOCKS5 proxy for Tor hidden services.</string>
</property>
<property name="text">
<string>Use separate SOCKS5 proxy to reach peers via Tor hidden services:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3_Network">
<item>
<widget class="QLabel" name="proxyIpTorLabel">
<property name="text">
<string>Proxy &amp;IP:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="buddy">
<cstring>proxyIpTor</cstring>
</property>
</widget>
</item>
<item>
<widget class="QValidatedLineEdit" name="proxyIpTor">
<property name="minimumSize">
<size>
<width>140</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>IP address of the proxy (e.g. IPv4: 127.0.0.1 / IPv6: ::1)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="proxyPortTorLabel">
<property name="text">
<string>&amp;Port:</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="buddy">
<cstring>proxyPortTor</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="proxyPortTor">
<property name="minimumSize">
<size>
<width>55</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Port of the proxy (e.g. 9050)</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4_Network">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_Network">
<property name="orientation">
@@ -35,7 +35,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
ui(new Ui::OptionsDialog),
model(0),
mapper(0),
fProxyIpValid(true)
fProxyIpsValid(true)
{
ui->setupUi(this);

@@ -54,10 +54,18 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
ui->proxyPort->setEnabled(false);
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));

ui->proxyIpTor->setEnabled(false);
ui->proxyPortTor->setEnabled(false);
ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));

connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyIp, SLOT(setEnabled(bool)));
connect(ui->connectSocks, SIGNAL(toggled(bool)), ui->proxyPort, SLOT(setEnabled(bool)));

connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyIpTor, SLOT(setEnabled(bool)));
connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyPortTor, SLOT(setEnabled(bool)));

ui->proxyIp->installEventFilter(this);
ui->proxyIpTor->installEventFilter(this);

/* Window elements init */
#ifdef Q_OS_MAC
@@ -110,7 +118,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setOrientation(Qt::Vertical);

/* setup/change UI elements when proxy IP is invalid/valid */
/* setup/change UI elements when proxy IPs are invalid/valid */
connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int)));
}

@@ -137,6 +145,8 @@ void OptionsDialog::setModel(OptionsModel *model)
mapper->setModel(model);
setMapper();
mapper->toFirst();

updateDefaultProxyNets();
}

/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
@@ -149,6 +159,7 @@ void OptionsDialog::setModel(OptionsModel *model)
/* Network */
connect(ui->allowIncoming, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->connectSocks, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
connect(ui->connectSocksTor, SIGNAL(clicked(bool)), this, SLOT(showRestartWarning()));
/* Display */
connect(ui->lang, SIGNAL(valueChanged()), this, SLOT(showRestartWarning()));
connect(ui->thirdPartyTxUrls, SIGNAL(textChanged(const QString &)), this, SLOT(showRestartWarning()));
@@ -173,6 +184,10 @@ void OptionsDialog::setMapper()
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);

mapper->addMapping(ui->connectSocksTor, OptionsModel::ProxyUseTor);
mapper->addMapping(ui->proxyIpTor, OptionsModel::ProxyIPTor);
mapper->addMapping(ui->proxyPortTor, OptionsModel::ProxyPortTor);

/* Window */
#ifndef Q_OS_MAC
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
@@ -188,7 +203,7 @@ void OptionsDialog::setMapper()
void OptionsDialog::enableOkButton()
{
/* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */
if(fProxyIpValid)
if(fProxyIpsValid)
setOkButtonState(true);
}

@@ -224,6 +239,7 @@ void OptionsDialog::on_okButton_clicked()
{
mapper->submit();
accept();
updateDefaultProxyNets();
}

void OptionsDialog::on_cancelButton_clicked()
@@ -257,11 +273,10 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
{
Q_UNUSED(nProxyPort);

const std::string strAddrProxy = pUiProxyIp->text().toStdString();
CService addrProxy;

/* Check for a valid IPv4 / IPv6 address */
if (!(fProxyIpValid = LookupNumeric(strAddrProxy.c_str(), addrProxy)))
if (!(fProxyIpsValid = LookupNumeric(pUiProxyIp->text().toStdString().c_str(), addrProxy)))
{
disableOkButton();
pUiProxyIp->setValid(false);
@@ -275,6 +290,28 @@ void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPo
}
}

void OptionsDialog::updateDefaultProxyNets()
{
proxyType proxy;
std::string strProxy;
QString strDefaultProxyGUI;

GetProxy(NET_IPV4, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv4->setChecked(true) : ui->proxyReachIPv4->setChecked(false);

GetProxy(NET_IPV6, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachIPv6->setChecked(true) : ui->proxyReachIPv6->setChecked(false);

GetProxy(NET_TOR, proxy);
strProxy = proxy.proxy.ToStringIP() + ":" + proxy.proxy.ToStringPort();
strDefaultProxyGUI = ui->proxyIp->text() + ":" + ui->proxyPort->text();
(strProxy == strDefaultProxyGUI.toStdString()) ? ui->proxyReachTor->setChecked(true) : ui->proxyReachTor->setChecked(false);
}

bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{
if(event->type() == QEvent::FocusOut)
@@ -283,6 +320,10 @@ bool OptionsDialog::eventFilter(QObject *object, QEvent *event)
{
Q_EMIT proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt());
}
else if(object == ui->proxyIpTor)
{
Q_EMIT proxyIpChecks(ui->proxyIpTor, ui->proxyPortTor->text().toInt());
}
}
return QDialog::eventFilter(object, event);
}
@@ -47,6 +47,8 @@ private Q_SLOTS:
void showRestartWarning(bool fPersistent = false);
void clearStatusLabel();
void doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
/* query the networks, for which the default proxy is used */
void updateDefaultProxyNets();

Q_SIGNALS:
void proxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort);
@@ -55,7 +57,7 @@ private Q_SLOTS:
Ui::OptionsDialog *ui;
OptionsModel *model;
QDataWidgetMapper *mapper;
bool fProxyIpValid;
bool fProxyIpsValid;
};

#endif // BITCOIN_QT_OPTIONSDIALOG_H

0 comments on commit 0c465f5

Please sign in to comment.
You can’t perform that action at this time.