2020-12-31 05:48:25 -03:00
|
|
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
2014-12-13 01:09:33 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 12:20:43 -03:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-05-27 19:55:01 -04:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-05-27 19:55:01 -04:00
|
|
|
#endif
|
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/optionsdialog.h>
|
2017-08-15 12:31:26 -03:00
|
|
|
#include <qt/forms/ui_optionsdialog.h>
|
2012-06-08 09:21:55 -04:00
|
|
|
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/bitcoinunits.h>
|
2019-01-14 08:40:00 -03:00
|
|
|
#include <qt/guiconstants.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <qt/guiutil.h>
|
|
|
|
#include <qt/optionsmodel.h>
|
2011-05-12 08:44:52 -04:00
|
|
|
|
2018-04-07 04:42:02 -03:00
|
|
|
#include <interfaces/node.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <validation.h> // for DEFAULT_SCRIPTCHECK_THREADS and MAX_SCRIPTCHECK_THREADS
|
|
|
|
#include <netbase.h>
|
|
|
|
#include <txdb.h> // for -dbcache defaults
|
2014-09-05 07:18:35 -04:00
|
|
|
|
2014-10-23 14:08:10 -03:00
|
|
|
#include <QDataWidgetMapper>
|
2012-06-08 09:21:55 -04:00
|
|
|
#include <QDir>
|
|
|
|
#include <QIntValidator>
|
2012-06-25 16:36:16 -04:00
|
|
|
#include <QLocale>
|
2012-05-08 17:03:41 -04:00
|
|
|
#include <QMessageBox>
|
2020-02-22 20:24:36 -03:00
|
|
|
#include <QSettings>
|
2018-09-15 12:02:14 -03:00
|
|
|
#include <QSystemTrayIcon>
|
2013-12-03 05:10:10 -03:00
|
|
|
#include <QTimer>
|
2011-06-01 08:40:06 -04:00
|
|
|
|
2014-11-08 15:48:35 -03:00
|
|
|
OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
|
2020-09-07 13:09:33 -03:00
|
|
|
QDialog(parent, GUIUtil::dialog_flags),
|
2012-06-08 09:21:55 -04:00
|
|
|
ui(new Ui::OptionsDialog),
|
2018-07-30 06:37:09 -04:00
|
|
|
model(nullptr),
|
|
|
|
mapper(nullptr)
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2012-06-08 09:21:55 -04:00
|
|
|
ui->setupUi(this);
|
2013-12-03 05:10:10 -03:00
|
|
|
|
|
|
|
/* Main elements init */
|
2014-02-16 18:00:12 -03:00
|
|
|
ui->databaseCache->setMinimum(nMinDbCache);
|
|
|
|
ui->databaseCache->setMaximum(nMaxDbCache);
|
2015-07-01 12:38:15 -03:00
|
|
|
ui->threadsScriptVerif->setMinimum(-GetNumCores());
|
2014-02-18 08:48:16 -03:00
|
|
|
ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);
|
2018-05-15 06:46:19 -04:00
|
|
|
ui->pruneWarning->setVisible(false);
|
|
|
|
ui->pruneWarning->setStyleSheet("QLabel { color: red; }");
|
|
|
|
|
|
|
|
ui->pruneSize->setEnabled(false);
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->prune, &QPushButton::toggled, ui->pruneSize, &QWidget::setEnabled);
|
2012-05-07 15:49:22 -04:00
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Network elements init */
|
|
|
|
#ifndef USE_UPNP
|
|
|
|
ui->mapPortUpnp->setEnabled(false);
|
2020-02-22 21:25:21 -03:00
|
|
|
#endif
|
|
|
|
#ifndef USE_NATPMP
|
|
|
|
ui->mapPortNatpmp->setEnabled(false);
|
2011-10-07 08:21:45 -03:00
|
|
|
#endif
|
2020-02-22 20:24:36 -03:00
|
|
|
connect(this, &QDialog::accepted, [this](){
|
|
|
|
QSettings settings;
|
2020-02-22 21:12:19 -03:00
|
|
|
model->node().mapPort(settings.value("fUseUPnP").toBool(), settings.value("fUseNatpmp").toBool());
|
2020-02-22 20:24:36 -03:00
|
|
|
});
|
2011-07-25 15:35:45 -04:00
|
|
|
|
2012-07-09 05:14:38 -04:00
|
|
|
ui->proxyIp->setEnabled(false);
|
|
|
|
ui->proxyPort->setEnabled(false);
|
|
|
|
ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));
|
|
|
|
|
2014-07-25 12:20:40 -04:00
|
|
|
ui->proxyIpTor->setEnabled(false);
|
|
|
|
ui->proxyPortTor->setEnabled(false);
|
|
|
|
ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));
|
|
|
|
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->connectSocks, &QPushButton::toggled, ui->proxyIp, &QWidget::setEnabled);
|
|
|
|
connect(ui->connectSocks, &QPushButton::toggled, ui->proxyPort, &QWidget::setEnabled);
|
|
|
|
connect(ui->connectSocks, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState);
|
2011-05-12 08:44:52 -04:00
|
|
|
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyIpTor, &QWidget::setEnabled);
|
|
|
|
connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyPortTor, &QWidget::setEnabled);
|
|
|
|
connect(ui->connectSocksTor, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState);
|
2011-05-12 08:44:52 -04:00
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Window elements init */
|
2012-09-21 14:06:53 -03:00
|
|
|
#ifdef Q_OS_MAC
|
2013-05-03 09:18:28 -04:00
|
|
|
/* remove Window tab on Mac */
|
|
|
|
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
|
2019-11-22 20:12:00 -03:00
|
|
|
/* hide launch at startup option on macOS */
|
2019-01-19 04:47:01 -03:00
|
|
|
ui->bitcoinAtStartup->setVisible(false);
|
|
|
|
ui->verticalLayout_Main->removeWidget(ui->bitcoinAtStartup);
|
|
|
|
ui->verticalLayout_Main->removeItem(ui->horizontalSpacer_0_Main);
|
2012-05-10 09:33:01 -04:00
|
|
|
#endif
|
2011-07-25 15:35:45 -04:00
|
|
|
|
2019-12-09 06:57:39 -03:00
|
|
|
/* remove Wallet tab and 3rd party-URL textbox in case of -disablewallet */
|
2014-11-08 15:48:35 -03:00
|
|
|
if (!enableWallet) {
|
|
|
|
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWallet));
|
2019-12-09 06:57:39 -03:00
|
|
|
ui->thirdPartyTxUrlsLabel->setVisible(false);
|
|
|
|
ui->thirdPartyTxUrls->setVisible(false);
|
2014-11-08 15:48:35 -03:00
|
|
|
}
|
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Display elements init */
|
|
|
|
QDir translations(":translations");
|
2015-12-09 07:53:12 -03:00
|
|
|
|
2019-06-26 10:28:13 -04:00
|
|
|
ui->bitcoinAtStartup->setToolTip(ui->bitcoinAtStartup->toolTip().arg(PACKAGE_NAME));
|
|
|
|
ui->bitcoinAtStartup->setText(ui->bitcoinAtStartup->text().arg(PACKAGE_NAME));
|
2015-12-09 07:53:12 -03:00
|
|
|
|
2019-06-26 10:28:13 -04:00
|
|
|
ui->openBitcoinConfButton->setToolTip(ui->openBitcoinConfButton->toolTip().arg(PACKAGE_NAME));
|
2017-08-30 15:14:07 -03:00
|
|
|
|
2019-06-26 10:28:13 -04:00
|
|
|
ui->lang->setToolTip(ui->lang->toolTip().arg(PACKAGE_NAME));
|
2012-06-08 09:21:55 -04:00
|
|
|
ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));
|
2017-06-01 21:25:02 -04:00
|
|
|
for (const QString &langStr : translations.entryList())
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2012-06-25 16:36:16 -04:00
|
|
|
QLocale locale(langStr);
|
|
|
|
|
|
|
|
/** check if the locale name consists of 2 parts (language_country) */
|
|
|
|
if(langStr.contains("_"))
|
|
|
|
{
|
2012-07-13 01:43:41 -04:00
|
|
|
/** display language strings as "native language - native country (locale name)", e.g. "Deutsch - Deutschland (de)" */
|
|
|
|
ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") + locale.nativeCountryName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
2012-06-25 16:36:16 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-13 01:43:41 -04:00
|
|
|
/** display language strings as "native language (locale name)", e.g. "Deutsch (de)" */
|
|
|
|
ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));
|
2012-06-25 16:36:16 -04:00
|
|
|
}
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
2012-06-08 09:21:55 -04:00
|
|
|
ui->unit->setModel(new BitcoinUnits(this));
|
2011-05-12 08:44:52 -04:00
|
|
|
|
2011-06-01 03:33:48 -04:00
|
|
|
/* Widget-to-option mapper */
|
2014-10-23 14:08:10 -03:00
|
|
|
mapper = new QDataWidgetMapper(this);
|
2011-05-31 16:24:53 -04:00
|
|
|
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
|
|
|
|
mapper->setOrientation(Qt::Vertical);
|
2012-06-08 09:21:55 -04:00
|
|
|
|
2018-07-30 17:47:48 -04:00
|
|
|
GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);
|
|
|
|
connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &OptionsDialog::reject);
|
|
|
|
mapper->setItemDelegate(delegate);
|
|
|
|
|
2014-07-25 12:20:40 -04:00
|
|
|
/* setup/change UI elements when proxy IPs are invalid/valid */
|
2015-11-16 06:43:36 -03:00
|
|
|
ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent));
|
|
|
|
ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent));
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->proxyIp, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);
|
|
|
|
connect(ui->proxyIpTor, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);
|
|
|
|
connect(ui->proxyPort, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);
|
|
|
|
connect(ui->proxyPortTor, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);
|
2018-09-15 12:02:14 -03:00
|
|
|
|
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
2020-10-24 18:34:41 -03:00
|
|
|
ui->showTrayIcon->setChecked(false);
|
|
|
|
ui->showTrayIcon->setEnabled(false);
|
2018-09-15 12:02:14 -03:00
|
|
|
ui->minimizeToTray->setChecked(false);
|
|
|
|
ui->minimizeToTray->setEnabled(false);
|
|
|
|
}
|
2019-04-07 15:33:35 -04:00
|
|
|
|
2021-02-21 15:58:19 -03:00
|
|
|
QFont embedded_font{GUIUtil::fixedPitchFont(true)};
|
|
|
|
ui->embeddedFont_radioButton->setText(ui->embeddedFont_radioButton->text().arg(QFontInfo(embedded_font).family()));
|
|
|
|
embedded_font.setWeight(QFont::Bold);
|
|
|
|
ui->embeddedFont_label_1->setFont(embedded_font);
|
|
|
|
ui->embeddedFont_label_9->setFont(embedded_font);
|
|
|
|
|
|
|
|
QFont system_font{GUIUtil::fixedPitchFont(false)};
|
|
|
|
ui->systemFont_radioButton->setText(ui->systemFont_radioButton->text().arg(QFontInfo(system_font).family()));
|
|
|
|
system_font.setWeight(QFont::Bold);
|
|
|
|
ui->systemFont_label_1->setFont(system_font);
|
|
|
|
ui->systemFont_label_9->setFont(system_font);
|
|
|
|
// Checking the embeddedFont_radioButton automatically unchecks the systemFont_radioButton.
|
|
|
|
ui->systemFont_radioButton->setChecked(true);
|
|
|
|
|
2019-04-07 15:33:35 -04:00
|
|
|
GUIUtil::handleCloseWindowShortcut(this);
|
2012-06-08 09:21:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
OptionsDialog::~OptionsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
2011-05-31 16:24:53 -04:00
|
|
|
}
|
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
void OptionsDialog::setModel(OptionsModel *_model)
|
2011-05-31 16:24:53 -04:00
|
|
|
{
|
2016-09-09 08:43:29 -03:00
|
|
|
this->model = _model;
|
2011-05-31 16:24:53 -04:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
if(_model)
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2013-12-03 05:10:10 -03:00
|
|
|
/* check if client restart is needed and show persistent message */
|
2016-09-09 08:43:29 -03:00
|
|
|
if (_model->isRestartRequired())
|
2013-12-03 05:10:10 -03:00
|
|
|
showRestartWarning(true);
|
|
|
|
|
2019-04-11 19:39:59 -04:00
|
|
|
// Prune values are in GB to be consistent with intro.cpp
|
|
|
|
static constexpr uint64_t nMinDiskSpace = (MIN_DISK_SPACE_FOR_BLOCK_FILES / GB_BYTES) + (MIN_DISK_SPACE_FOR_BLOCK_FILES % GB_BYTES) ? 1 : 0;
|
2019-04-11 19:44:48 -04:00
|
|
|
ui->pruneSize->setRange(nMinDiskSpace, std::numeric_limits<int>::max());
|
2019-04-11 19:39:59 -04:00
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
QString strLabel = _model->getOverriddenByCommandLine();
|
2013-12-03 05:10:10 -03:00
|
|
|
if (strLabel.isEmpty())
|
|
|
|
strLabel = tr("none");
|
|
|
|
ui->overriddenByCommandLineLabel->setText(strLabel);
|
|
|
|
|
2016-09-09 08:43:29 -03:00
|
|
|
mapper->setModel(_model);
|
2012-06-08 09:21:55 -04:00
|
|
|
setMapper();
|
|
|
|
mapper->toFirst();
|
2014-07-25 12:20:40 -04:00
|
|
|
|
|
|
|
updateDefaultProxyNets();
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
2011-05-12 08:44:52 -04:00
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */
|
2012-08-02 03:02:05 -04:00
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
/* Main */
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->prune, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
|
|
|
connect(ui->prune, &QCheckBox::clicked, this, &OptionsDialog::togglePruneWarning);
|
|
|
|
connect(ui->pruneSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
|
|
|
|
connect(ui->databaseCache, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
|
|
|
|
connect(ui->threadsScriptVerif, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &OptionsDialog::showRestartWarning);
|
2014-04-07 14:26:30 -03:00
|
|
|
/* Wallet */
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->spendZeroConfChange, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
2013-12-03 05:10:10 -03:00
|
|
|
/* Network */
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->allowIncoming, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
|
|
|
connect(ui->connectSocks, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
|
|
|
connect(ui->connectSocksTor, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
|
2013-12-03 05:10:10 -03:00
|
|
|
/* Display */
|
2018-06-24 11:18:22 -04:00
|
|
|
connect(ui->lang, static_cast<void (QValueComboBox::*)()>(&QValueComboBox::valueChanged), [this]{ showRestartWarning(); });
|
|
|
|
connect(ui->thirdPartyTxUrls, &QLineEdit::textChanged, [this]{ showRestartWarning(); });
|
2011-05-12 08:44:52 -04:00
|
|
|
}
|
|
|
|
|
2018-05-16 16:05:09 -04:00
|
|
|
void OptionsDialog::setCurrentTab(OptionsDialog::Tab tab)
|
|
|
|
{
|
|
|
|
QWidget *tab_widget = nullptr;
|
|
|
|
if (tab == OptionsDialog::Tab::TAB_NETWORK) tab_widget = ui->tabNetwork;
|
|
|
|
if (tab == OptionsDialog::Tab::TAB_MAIN) tab_widget = ui->tabMain;
|
|
|
|
if (tab_widget && ui->tabWidget->currentWidget() != tab_widget) {
|
|
|
|
ui->tabWidget->setCurrentWidget(tab_widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
void OptionsDialog::setMapper()
|
2011-05-12 08:44:52 -04:00
|
|
|
{
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Main */
|
|
|
|
mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
|
2013-12-03 05:10:10 -03:00
|
|
|
mapper->addMapping(ui->threadsScriptVerif, OptionsModel::ThreadsScriptVerif);
|
|
|
|
mapper->addMapping(ui->databaseCache, OptionsModel::DatabaseCache);
|
2018-05-15 06:46:19 -04:00
|
|
|
mapper->addMapping(ui->prune, OptionsModel::Prune);
|
|
|
|
mapper->addMapping(ui->pruneSize, OptionsModel::PruneSize);
|
2011-06-01 03:33:48 -04:00
|
|
|
|
2014-02-15 06:38:06 -03:00
|
|
|
/* Wallet */
|
|
|
|
mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange);
|
2014-03-17 10:04:56 -03:00
|
|
|
mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures);
|
2014-02-15 06:38:06 -03:00
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Network */
|
|
|
|
mapper->addMapping(ui->mapPortUpnp, OptionsModel::MapPortUPnP);
|
2020-02-22 21:25:21 -03:00
|
|
|
mapper->addMapping(ui->mapPortNatpmp, OptionsModel::MapPortNatpmp);
|
2014-05-29 07:02:22 -04:00
|
|
|
mapper->addMapping(ui->allowIncoming, OptionsModel::Listen);
|
2012-07-09 05:14:38 -04:00
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
mapper->addMapping(ui->connectSocks, OptionsModel::ProxyUse);
|
|
|
|
mapper->addMapping(ui->proxyIp, OptionsModel::ProxyIP);
|
|
|
|
mapper->addMapping(ui->proxyPort, OptionsModel::ProxyPort);
|
2011-06-01 03:33:48 -04:00
|
|
|
|
2014-07-25 12:20:40 -04:00
|
|
|
mapper->addMapping(ui->connectSocksTor, OptionsModel::ProxyUseTor);
|
|
|
|
mapper->addMapping(ui->proxyIpTor, OptionsModel::ProxyIPTor);
|
|
|
|
mapper->addMapping(ui->proxyPortTor, OptionsModel::ProxyPortTor);
|
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Window */
|
2012-10-07 13:50:03 -03:00
|
|
|
#ifndef Q_OS_MAC
|
2018-09-15 12:02:14 -03:00
|
|
|
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
2020-10-24 18:34:41 -03:00
|
|
|
mapper->addMapping(ui->showTrayIcon, OptionsModel::ShowTrayIcon);
|
2018-09-15 12:02:14 -03:00
|
|
|
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
|
|
|
|
}
|
2012-06-08 09:21:55 -04:00
|
|
|
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
|
|
|
|
#endif
|
2011-06-01 03:33:48 -04:00
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
/* Display */
|
|
|
|
mapper->addMapping(ui->lang, OptionsModel::Language);
|
|
|
|
mapper->addMapping(ui->unit, OptionsModel::DisplayUnit);
|
2014-04-24 17:21:45 -03:00
|
|
|
mapper->addMapping(ui->thirdPartyTxUrls, OptionsModel::ThirdPartyTxUrls);
|
2021-02-21 15:58:19 -03:00
|
|
|
mapper->addMapping(ui->embeddedFont_radioButton, OptionsModel::UseEmbeddedMonospacedFont);
|
2011-06-01 03:33:48 -04:00
|
|
|
}
|
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
void OptionsDialog::setOkButtonState(bool fState)
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2012-06-08 09:21:55 -04:00
|
|
|
ui->okButton->setEnabled(fState);
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
|
|
|
|
2012-08-18 09:54:39 -04:00
|
|
|
void OptionsDialog::on_resetButton_clicked()
|
|
|
|
{
|
|
|
|
if(model)
|
|
|
|
{
|
|
|
|
// confirmation dialog
|
|
|
|
QMessageBox::StandardButton btnRetVal = QMessageBox::question(this, tr("Confirm options reset"),
|
2015-04-28 11:48:28 -03:00
|
|
|
tr("Client restart required to activate changes.") + "<br><br>" + tr("Client will be shut down. Do you want to proceed?"),
|
2012-08-18 09:54:39 -04:00
|
|
|
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
|
|
|
|
|
|
|
|
if(btnRetVal == QMessageBox::Cancel)
|
|
|
|
return;
|
|
|
|
|
2013-12-20 14:47:49 -03:00
|
|
|
/* reset all options and close GUI */
|
2012-08-18 09:54:39 -04:00
|
|
|
model->Reset();
|
2013-12-03 05:10:10 -03:00
|
|
|
QApplication::quit();
|
2012-08-18 09:54:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 14:13:34 -03:00
|
|
|
void OptionsDialog::on_openBitcoinConfButton_clicked()
|
|
|
|
{
|
|
|
|
/* explain the purpose of the config file */
|
|
|
|
QMessageBox::information(this, tr("Configuration options"),
|
|
|
|
tr("The configuration file is used to specify advanced user options which override GUI settings. "
|
|
|
|
"Additionally, any command-line options will override this configuration file."));
|
|
|
|
|
|
|
|
/* show an error if there was some problem opening the file */
|
|
|
|
if (!GUIUtil::openBitcoinConf())
|
|
|
|
QMessageBox::critical(this, tr("Error"), tr("The configuration file could not be opened."));
|
|
|
|
}
|
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
void OptionsDialog::on_okButton_clicked()
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2012-06-08 09:21:55 -04:00
|
|
|
mapper->submit();
|
|
|
|
accept();
|
2014-07-25 12:20:40 -04:00
|
|
|
updateDefaultProxyNets();
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
|
|
|
|
2012-06-08 09:21:55 -04:00
|
|
|
void OptionsDialog::on_cancelButton_clicked()
|
2011-06-01 08:40:06 -04:00
|
|
|
{
|
2012-06-08 09:21:55 -04:00
|
|
|
reject();
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
|
|
|
|
2020-10-24 18:34:41 -03:00
|
|
|
void OptionsDialog::on_showTrayIcon_stateChanged(int state)
|
2016-05-11 23:28:02 -03:00
|
|
|
{
|
2020-10-24 18:34:41 -03:00
|
|
|
if (state == Qt::Checked) {
|
|
|
|
ui->minimizeToTray->setEnabled(true);
|
|
|
|
} else {
|
2016-05-11 23:28:02 -03:00
|
|
|
ui->minimizeToTray->setChecked(false);
|
|
|
|
ui->minimizeToTray->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-15 06:46:19 -04:00
|
|
|
void OptionsDialog::togglePruneWarning(bool enabled)
|
|
|
|
{
|
|
|
|
ui->pruneWarning->setVisible(!ui->pruneWarning->isVisible());
|
|
|
|
}
|
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
void OptionsDialog::showRestartWarning(bool fPersistent)
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2013-12-03 05:10:10 -03:00
|
|
|
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
2012-05-07 15:49:22 -04:00
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
if(fPersistent)
|
|
|
|
{
|
|
|
|
ui->statusLabel->setText(tr("Client restart required to activate changes."));
|
|
|
|
}
|
|
|
|
else
|
2012-05-08 17:03:41 -04:00
|
|
|
{
|
2013-12-03 05:10:10 -03:00
|
|
|
ui->statusLabel->setText(tr("This change would require a client restart."));
|
|
|
|
// clear non-persistent status label after 10 seconds
|
|
|
|
// Todo: should perhaps be a class attribute, if we extend the use of statusLabel
|
2018-06-24 11:18:22 -04:00
|
|
|
QTimer::singleShot(10000, this, &OptionsDialog::clearStatusLabel);
|
2012-05-08 17:03:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 05:10:10 -03:00
|
|
|
void OptionsDialog::clearStatusLabel()
|
2012-05-07 15:49:22 -04:00
|
|
|
{
|
2013-12-03 05:10:10 -03:00
|
|
|
ui->statusLabel->clear();
|
2017-02-13 19:49:10 -03:00
|
|
|
if (model && model->isRestartRequired()) {
|
|
|
|
showRestartWarning(true);
|
|
|
|
}
|
2012-05-07 15:49:22 -04:00
|
|
|
}
|
|
|
|
|
2015-11-18 10:02:14 -03:00
|
|
|
void OptionsDialog::updateProxyValidationState()
|
2012-07-09 05:14:38 -04:00
|
|
|
{
|
2015-11-18 10:02:14 -03:00
|
|
|
QValidatedLineEdit *pUiProxyIp = ui->proxyIp;
|
2015-11-16 06:43:36 -03:00
|
|
|
QValidatedLineEdit *otherProxyWidget = (pUiProxyIp == ui->proxyIpTor) ? ui->proxyIp : ui->proxyIpTor;
|
2015-11-18 10:02:14 -03:00
|
|
|
if (pUiProxyIp->isValid() && (!ui->proxyPort->isEnabled() || ui->proxyPort->text().toInt() > 0) && (!ui->proxyPortTor->isEnabled() || ui->proxyPortTor->text().toInt() > 0))
|
2012-07-09 05:14:38 -04:00
|
|
|
{
|
2015-11-16 06:43:36 -03:00
|
|
|
setOkButtonState(otherProxyWidget->isValid()); //only enable ok button if both proxys are valid
|
2017-02-13 19:49:10 -03:00
|
|
|
clearStatusLabel();
|
2012-07-09 05:14:38 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-11-16 06:43:36 -03:00
|
|
|
setOkButtonState(false);
|
|
|
|
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
|
|
|
ui->statusLabel->setText(tr("The supplied proxy address is invalid."));
|
2012-07-09 05:14:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 12:20:40 -04:00
|
|
|
void OptionsDialog::updateDefaultProxyNets()
|
|
|
|
{
|
|
|
|
proxyType proxy;
|
|
|
|
std::string strProxy;
|
|
|
|
QString strDefaultProxyGUI;
|
|
|
|
|
2017-04-17 17:43:47 -03:00
|
|
|
model->node().getProxy(NET_IPV4, proxy);
|
2014-07-25 12:20:40 -04:00
|
|
|
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);
|
|
|
|
|
2017-04-17 17:43:47 -03:00
|
|
|
model->node().getProxy(NET_IPV6, proxy);
|
2014-07-25 12:20:40 -04:00
|
|
|
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);
|
|
|
|
|
2018-07-02 05:37:59 -04:00
|
|
|
model->node().getProxy(NET_ONION, proxy);
|
2014-07-25 12:20:40 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-11-16 06:43:36 -03:00
|
|
|
ProxyAddressValidator::ProxyAddressValidator(QObject *parent) :
|
|
|
|
QValidator(parent)
|
2011-06-01 08:40:06 -04:00
|
|
|
{
|
2015-11-16 06:43:36 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
QValidator::State ProxyAddressValidator::validate(QString &input, int &pos) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(pos);
|
|
|
|
// Validate the proxy
|
2019-12-11 13:39:29 -03:00
|
|
|
CService serv(LookupNumeric(input.toStdString(), DEFAULT_GUI_PROXY_PORT));
|
2016-05-31 13:51:11 -04:00
|
|
|
proxyType addrProxy = proxyType(serv, true);
|
2015-11-16 06:43:36 -03:00
|
|
|
if (addrProxy.IsValid())
|
|
|
|
return QValidator::Acceptable;
|
|
|
|
|
|
|
|
return QValidator::Invalid;
|
2011-07-25 15:35:45 -04:00
|
|
|
}
|