diff options
author | Luke Dashjr <luke-jr+git@utopios.org> | 2016-08-09 05:45:50 +0000 |
---|---|---|
committer | Luke Dashjr <luke-jr+git@utopios.org> | 2016-08-09 05:45:50 +0000 |
commit | df634908ba758232413c50e8f1f7a80d546d777b (patch) | |
tree | 92cccae378b192f5f70986d2167209cbfd24ae08 /src/qt/optionsdialog.cpp | |
parent | e98e3dde6a976a2c8f266ee963d6931fd4b37262 (diff) | |
parent | e4382fbef56a0e04b0ed834e8b3a3a16f81db149 (diff) | |
download | bitcoin-df634908ba758232413c50e8f1f7a80d546d777b.tar.xz |
Merge tag 'branch-0.13' into bugfix_gitdir
Diffstat (limited to 'src/qt/optionsdialog.cpp')
-rw-r--r-- | src/qt/optionsdialog.cpp | 143 |
1 files changed, 94 insertions, 49 deletions
diff --git a/src/qt/optionsdialog.cpp b/src/qt/optionsdialog.cpp index 069080219e..f2db398899 100644 --- a/src/qt/optionsdialog.cpp +++ b/src/qt/optionsdialog.cpp @@ -1,5 +1,5 @@ -// Copyright (c) 2011-2013 The Bitcoin developers -// Distributed under the MIT/X11 software license, see the accompanying +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) @@ -13,12 +13,12 @@ #include "guiutil.h" #include "optionsmodel.h" -#include "main.h" // for MAX_SCRIPTCHECK_THREADS +#include "main.h" // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS #include "netbase.h" #include "txdb.h" // for -dbcache defaults #ifdef ENABLE_WALLET -#include "wallet.h" // for CWallet::minTxFee +#include "wallet/wallet.h" // for CWallet::GetRequiredFee() #endif #include <boost/thread.hpp> @@ -34,16 +34,14 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : QDialog(parent), ui(new Ui::OptionsDialog), model(0), - mapper(0), - fProxyIpValid(true) + mapper(0) { ui->setupUi(this); - GUIUtil::restoreWindowGeometry("nOptionsDialogWindow", this->size(), this); /* Main elements init */ ui->databaseCache->setMinimum(nMinDbCache); ui->databaseCache->setMaximum(nMaxDbCache); - ui->threadsScriptVerif->setMinimum(-(int)boost::thread::hardware_concurrency()); + ui->threadsScriptVerif->setMinimum(-GetNumCores()); ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS); /* Network elements init */ @@ -55,10 +53,17 @@ 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->connectSocks, SIGNAL(toggled(bool)), this, SLOT(updateProxyValidationState())); - ui->proxyIp->installEventFilter(this); + connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyIpTor, SLOT(setEnabled(bool))); + connect(ui->connectSocksTor, SIGNAL(toggled(bool)), ui->proxyPortTor, SLOT(setEnabled(bool))); + connect(ui->connectSocksTor, SIGNAL(toggled(bool)), this, SLOT(updateProxyValidationState())); /* Window elements init */ #ifdef Q_OS_MAC @@ -73,8 +78,13 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : /* Display elements init */ QDir translations(":translations"); + + ui->bitcoinAtStartup->setToolTip(ui->bitcoinAtStartup->toolTip().arg(tr(PACKAGE_NAME))); + ui->bitcoinAtStartup->setText(ui->bitcoinAtStartup->text().arg(tr(PACKAGE_NAME))); + + ui->lang->setToolTip(ui->lang->toolTip().arg(tr(PACKAGE_NAME))); ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant("")); - foreach(const QString &langStr, translations.entryList()) + Q_FOREACH(const QString &langStr, translations.entryList()) { QLocale locale(langStr); @@ -111,13 +121,17 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) : mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mapper->setOrientation(Qt::Vertical); - /* setup/change UI elements when proxy IP is invalid/valid */ - connect(this, SIGNAL(proxyIpChecks(QValidatedLineEdit *, int)), this, SLOT(doProxyIpChecks(QValidatedLineEdit *, int))); + /* setup/change UI elements when proxy IPs are invalid/valid */ + ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent)); + ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent)); + connect(ui->proxyIp, SIGNAL(validationDidChange(QValidatedLineEdit *)), this, SLOT(updateProxyValidationState())); + connect(ui->proxyIpTor, SIGNAL(validationDidChange(QValidatedLineEdit *)), this, SLOT(updateProxyValidationState())); + connect(ui->proxyPort, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState())); + connect(ui->proxyPortTor, SIGNAL(textChanged(const QString&)), this, SLOT(updateProxyValidationState())); } OptionsDialog::~OptionsDialog() { - GUIUtil::saveWindowGeometry("nOptionsDialogWindow", this); delete ui; } @@ -139,6 +153,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) */ @@ -151,6 +167,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())); @@ -175,8 +192,13 @@ 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->hideTrayIcon, OptionsModel::HideTrayIcon); mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray); mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose); #endif @@ -187,18 +209,6 @@ void OptionsDialog::setMapper() mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls); } -void OptionsDialog::enableOkButton() -{ - /* prevent enabling of the OK button when data modified, if there is an invalid proxy address present */ - if(fProxyIpValid) - setOkButtonState(true); -} - -void OptionsDialog::disableOkButton() -{ - setOkButtonState(false); -} - void OptionsDialog::setOkButtonState(bool fState) { ui->okButton->setEnabled(fState); @@ -210,7 +220,7 @@ void OptionsDialog::on_resetButton_clicked() { // confirmation dialog QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"), - tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shutdown, do you want to proceed?"), + tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shut down. Do you want to proceed?"), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel); if(btnRetVal == QMessageBox::Cancel) @@ -226,6 +236,7 @@ void OptionsDialog::on_okButton_clicked() { mapper->submit(); accept(); + updateDefaultProxyNets(); } void OptionsDialog::on_cancelButton_clicked() @@ -233,6 +244,19 @@ void OptionsDialog::on_cancelButton_clicked() reject(); } +void OptionsDialog::on_hideTrayIcon_stateChanged(int fState) +{ + if(fState) + { + ui->minimizeToTray->setChecked(false); + ui->minimizeToTray->setEnabled(false); + } + else + { + ui->minimizeToTray->setEnabled(true); + } +} + void OptionsDialog::showRestartWarning(bool fPersistent) { ui->statusLabel->setStyleSheet("QLabel { color: red; }"); @@ -255,36 +279,57 @@ void OptionsDialog::clearStatusLabel() ui->statusLabel->clear(); } -void OptionsDialog::doProxyIpChecks(QValidatedLineEdit *pUiProxyIp, int nProxyPort) +void OptionsDialog::updateProxyValidationState() { - 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))) + QValidatedLineEdit *pUiProxyIp = ui->proxyIp; + QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor) ? ui->proxyIp : ui->proxyIpTor; + if (pUiProxyIp->isValid() && (!ui->proxyPort->isEnabled() || ui->proxyPort->text().toInt() > 0) && (!ui->proxyPortTor->isEnabled() || ui->proxyPortTor->text().toInt() > 0)) { - disableOkButton(); - pUiProxyIp->setValid(false); - ui->statusLabel->setStyleSheet("QLabel { color: red; }"); - ui->statusLabel->setText(tr("The supplied proxy address is invalid.")); + setOkButtonState(otherProxyWidget->isValid()); //only enable ok button if both proxys are valid + ui->statusLabel->clear(); } else { - enableOkButton(); - ui->statusLabel->clear(); + setOkButtonState(false); + ui->statusLabel->setStyleSheet("QLabel { color: red; }"); + ui->statusLabel->setText(tr("The supplied proxy address is invalid.")); } } -bool OptionsDialog::eventFilter(QObject *object, QEvent *event) +void OptionsDialog::updateDefaultProxyNets() { - if(event->type() == QEvent::FocusOut) - { - if(object == ui->proxyIp) - { - emit proxyIpChecks(ui->proxyIp, ui->proxyPort->text().toInt()); - } - } - return QDialog::eventFilter(object, event); + 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); +} + +ProxyAddressValidator::ProxyAddressValidator(QObject *parent) : +QValidator(parent) +{ +} + +QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) const +{ + Q_UNUSED(pos); + // Validate the proxy + proxyType addrProxy = proxyType(CService(input.toStdString(), 9050), true); + if (addrProxy.IsValid()) + return QValidator::Acceptable; + + return QValidator::Invalid; } |