5#include <bitcoin-build-config.h>
8#include <qt/forms/ui_optionsdialog.h>
25#include <QApplication>
26#include <QDataWidgetMapper>
29#include <QIntValidator>
32#include <QSystemTrayIcon>
38 for (i = cb->count(); --i >= 0; ) {
39 QVariant item_data = cb->itemData(i);
48 QSignalBlocker block_currentindexchanged_signal(cb);
49 cb->insertItem(0, QFontInfo(chosen_font).family(), QVariant::fromValue(fc));
53 cb->setCurrentIndex(i);
63 cb->addItem(QObject::tr(
"Custom…"));
65 const auto& on_font_choice_changed = [cb, preview](
int index) {
66 static int previous_index = -1;
67 QVariant item_data = cb->itemData(index);
75 cb->setCurrentIndex(previous_index);
83 previous_index = index;
85 QObject::connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), on_font_choice_changed);
86 on_font_choice_changed(cb->currentIndex());
95 ui->verticalLayout->setStretchFactor(
ui->tabWidget, 1);
98 ui->databaseCache->setRange(
MIN_DB_CACHE >> 20, std::numeric_limits<int>::max());
101 ui->pruneWarning->setVisible(
false);
102 ui->pruneWarning->setStyleSheet(
"QLabel { color: red; }");
104 ui->pruneSize->setEnabled(
false);
105 connect(
ui->prune, &QPushButton::toggled,
ui->pruneSize, &QWidget::setEnabled);
108 ui->proxyIp->setEnabled(
false);
109 ui->proxyPort->setEnabled(
false);
110 ui->proxyPort->setValidator(
new QIntValidator(1, 65535,
this));
112 ui->proxyIpTor->setEnabled(
false);
113 ui->proxyPortTor->setEnabled(
false);
114 ui->proxyPortTor->setValidator(
new QIntValidator(1, 65535,
this));
116 connect(
ui->connectSocks, &QPushButton::toggled,
ui->proxyIp, &QWidget::setEnabled);
117 connect(
ui->connectSocks, &QPushButton::toggled,
ui->proxyPort, &QWidget::setEnabled);
120 connect(
ui->connectSocksTor, &QPushButton::toggled,
ui->proxyIpTor, &QWidget::setEnabled);
121 connect(
ui->connectSocksTor, &QPushButton::toggled,
ui->proxyPortTor, &QWidget::setEnabled);
127 ui->tabWidget->removeTab(
ui->tabWidget->indexOf(
ui->tabWindow));
129 ui->bitcoinAtStartup->setVisible(
false);
130 ui->verticalLayout_Main->removeWidget(
ui->bitcoinAtStartup);
131 ui->verticalLayout_Main->removeItem(
ui->horizontalSpacer_0_Main);
136 ui->tabWidget->removeTab(
ui->tabWidget->indexOf(
ui->tabWallet));
137 ui->thirdPartyTxUrlsLabel->setVisible(
false);
138 ui->thirdPartyTxUrls->setVisible(
false);
141#ifdef ENABLE_EXTERNAL_SIGNER
142 ui->externalSignerPath->setToolTip(
ui->externalSignerPath->toolTip().arg(CLIENT_NAME));
145 ui->externalSignerPath->setToolTip(tr(
"Compiled without external signing support (required for external signing)"));
146 ui->externalSignerPath->setEnabled(
false);
149 QDir translations(
":translations");
151 ui->bitcoinAtStartup->setToolTip(
ui->bitcoinAtStartup->toolTip().arg(CLIENT_NAME));
152 ui->bitcoinAtStartup->setText(
ui->bitcoinAtStartup->text().arg(CLIENT_NAME));
154 ui->openBitcoinConfButton->setToolTip(
ui->openBitcoinConfButton->toolTip().arg(CLIENT_NAME));
156 ui->lang->setToolTip(
ui->lang->toolTip().arg(CLIENT_NAME));
157 ui->lang->addItem(QString(
"(") + tr(
"default") + QString(
")"), QVariant(
""));
158 for (
const QString &langStr : translations.entryList())
160 QLocale locale(langStr);
163 if(langStr.contains(
"_"))
166 ui->lang->addItem(locale.nativeLanguageName() + QString(
" - ") +
167#
if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 0))
168 locale.nativeTerritoryName() +
170 locale.nativeCountryName() +
172 QString(
" (") + langStr + QString(
")"), QVariant(langStr));
178 ui->lang->addItem(locale.nativeLanguageName() + QString(
" (") + langStr + QString(
")"), QVariant(langStr));
184 mapper =
new QDataWidgetMapper(
this);
185 mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
186 mapper->setOrientation(Qt::Vertical);
190 mapper->setItemDelegate(delegate);
200 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
201 ui->showTrayIcon->setChecked(
false);
202 ui->showTrayIcon->setEnabled(
false);
203 ui->minimizeToTray->setChecked(
false);
204 ui->minimizeToTray->setEnabled(
false);
224 this->
model = _model;
234 ui->pruneSize->setRange(nMinDiskSpace, std::numeric_limits<int>::max());
237 if (strLabel.isEmpty())
238 strLabel = tr(
"none");
239 ui->overriddenByCommandLineLabel->setText(strLabel);
258 connect(
ui->externalSignerPath, &QLineEdit::textChanged, [
this]{ showRestartWarning(); });
269 connect(
ui->thirdPartyTxUrls, &QLineEdit::textChanged, [
this]{ showRestartWarning(); });
274 QWidget *tab_widget =
nullptr;
275 if (tab == OptionsDialog::Tab::TAB_NETWORK) tab_widget =
ui->tabNetwork;
276 if (tab == OptionsDialog::Tab::TAB_MAIN) tab_widget =
ui->tabMain;
277 if (tab_widget &&
ui->tabWidget->currentWidget() != tab_widget) {
278 ui->tabWidget->setCurrentWidget(tab_widget);
313 if (QSystemTrayIcon::isSystemTrayAvailable()) {
328 ui->okButton->setEnabled(fState);
337 QString reset_dialog_text = tr(
"Client restart required to activate changes.") +
"<br><br>";
341 reset_dialog_text.append(tr(
"Current settings will be backed up at \"%1\".").arg(
m_client_model->
dataDir()) +
"<br><br>");
344 reset_dialog_text.append(tr(
"Client will be shut down. Do you want to proceed?"));
346 QMessageBox::StandardButton btnRetVal = QMessageBox::question(
this, tr(
"Confirm options reset"),
347 reset_dialog_text, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
349 if (btnRetVal == QMessageBox::Cancel)
361 QMessageBox config_msgbox(
this);
362 config_msgbox.setIcon(QMessageBox::Information);
364 config_msgbox.setWindowTitle(tr(
"Configuration options"));
367 config_msgbox.setText(tr(
"The configuration file is used to specify advanced user options which override GUI settings. "
368 "Additionally, any command-line options will override this configuration file."));
370 QPushButton* open_button = config_msgbox.addButton(tr(
"Continue"), QMessageBox::ActionRole);
371 config_msgbox.addButton(tr(
"Cancel"), QMessageBox::RejectRole);
372 open_button->setDefault(
true);
374 config_msgbox.exec();
376 if (config_msgbox.clickedButton() != open_button)
return;
380 QMessageBox::critical(
this, tr(
"Error"), tr(
"The configuration file could not be opened."));
399 if (state == Qt::Checked) {
400 ui->minimizeToTray->setEnabled(
true);
402 ui->minimizeToTray->setChecked(
false);
403 ui->minimizeToTray->setEnabled(
false);
409 ui->pruneWarning->setVisible(!
ui->pruneWarning->isVisible());
414 ui->statusLabel->setStyleSheet(
"QLabel { color: red; }");
418 ui->statusLabel->setText(tr(
"Client restart required to activate changes."));
422 ui->statusLabel->setText(tr(
"This change would require a client restart."));
431 ui->statusLabel->clear();
441 if (pUiProxyIp->
isValid() && (!
ui->proxyPort->isEnabled() ||
ui->proxyPort->text().toInt() > 0) && (!
ui->proxyPortTor->isEnabled() ||
ui->proxyPortTor->text().toInt() > 0))
449 ui->statusLabel->setStyleSheet(
"QLabel { color: red; }");
450 ui->statusLabel->setText(tr(
"The supplied proxy address is invalid."));
456 std::string proxyIpText{
ui->proxyIp->text().toStdString()};
458 const std::optional<CNetAddr> ui_proxy_netaddr{
LookupHost(proxyIpText,
false)};
459 const CService ui_proxy{ui_proxy_netaddr.value_or(
CNetAddr{}),
ui->proxyPort->text().toUShort()};
460 proxyIpText = ui_proxy.ToStringAddrPort();
467 ui->proxyReachIPv4->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
470 ui->proxyReachIPv6->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
473 ui->proxyReachTor->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
485 std::string hostname;
486 if (!
SplitHostPort(input.toStdString(), port, hostname) || port != 0)
return QValidator::Invalid;
491 return QValidator::Acceptable;
493 return QValidator::Invalid;
Bitcoin unit definitions.
A combination of a network address (CNetAddr) and a (TCP) port.
Model for Bitcoin network client.
void setModel(OptionsModel *model)
void setCurrentTab(OptionsDialog::Tab tab)
void on_showTrayIcon_stateChanged(int state)
void on_okButton_clicked()
void on_openBitcoinConfButton_clicked()
void updateDefaultProxyNets()
void updateProxyValidationState()
void togglePruneWarning(bool enabled)
void showRestartWarning(bool fPersistent=false)
ClientModel * m_client_model
void on_resetButton_clicked()
OptionsDialog(QWidget *parent, bool enableWallet)
QDataWidgetMapper * mapper
void setClientModel(ClientModel *client_model)
void on_cancelButton_clicked()
void setOkButtonState(bool fState)
Interface from Qt to configuration data structure for Bitcoin client.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
std::variant< FontChoiceAbstract, QFont > FontChoice
bool isRestartRequired() const
interfaces::Node & node() const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
const QString & getOverriddenByCommandLine()
static QFont getFontForChoice(const FontChoice &fc)
Proxy address widget validator, checks for a valid proxy address.
ProxyAddressValidator(QObject *parent)
State validate(QString &input, int &pos) const override
std::string ToString() const
Line edit that can be marked as "invalid" to show input validation feedback.
void validationDidChange(QValidatedLineEdit *validatedLineEdit)
virtual bool getProxy(Network net, Proxy &proxy_info)=0
Get proxy.
int GetNumCores()
Return the number of cores available on the current system.
static constexpr uint64_t GB_BYTES
Utility functions used by the Bitcoin Qt UI.
QFont fixedPitchFont(bool use_embedded_font)
void handleCloseWindowShortcut(QWidget *w)
constexpr auto dialog_flags
@ NET_ONION
TOR (v2 or v3)
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
bool IsUnixSocketPath(const std::string &name)
Check if a string is a valid UNIX domain socket path.
CService LookupNumeric(const std::string &name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
Resolve a service string with a numeric IP to its first corresponding service.
static constexpr size_t MIN_DB_CACHE
min. -dbcache (bytes)
void setupFontOptions(QComboBox *cb, QLabel *preview)
int setFontChoice(QComboBox *cb, const OptionsModel::FontChoice &fc)
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES