8 #include <qt/forms/ui_optionsdialog.h>
25 #include <QApplication>
26 #include <QDataWidgetMapper>
28 #include <QFontDialog>
29 #include <QIntValidator>
31 #include <QMessageBox>
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);
102 ui->pruneWarning->setVisible(
false);
103 ui->pruneWarning->setStyleSheet(
"QLabel { color: red; }");
105 ui->pruneSize->setEnabled(
false);
106 connect(
ui->prune, &QPushButton::toggled,
ui->pruneSize, &QWidget::setEnabled);
110 ui->mapPortUpnp->setEnabled(
false);
113 ui->mapPortNatpmp->setEnabled(
false);
116 ui->proxyIp->setEnabled(
false);
117 ui->proxyPort->setEnabled(
false);
118 ui->proxyPort->setValidator(
new QIntValidator(1, 65535,
this));
120 ui->proxyIpTor->setEnabled(
false);
121 ui->proxyPortTor->setEnabled(
false);
122 ui->proxyPortTor->setValidator(
new QIntValidator(1, 65535,
this));
124 connect(
ui->connectSocks, &QPushButton::toggled,
ui->proxyIp, &QWidget::setEnabled);
125 connect(
ui->connectSocks, &QPushButton::toggled,
ui->proxyPort, &QWidget::setEnabled);
128 connect(
ui->connectSocksTor, &QPushButton::toggled,
ui->proxyIpTor, &QWidget::setEnabled);
129 connect(
ui->connectSocksTor, &QPushButton::toggled,
ui->proxyPortTor, &QWidget::setEnabled);
135 ui->tabWidget->removeTab(
ui->tabWidget->indexOf(
ui->tabWindow));
137 ui->bitcoinAtStartup->setVisible(
false);
138 ui->verticalLayout_Main->removeWidget(
ui->bitcoinAtStartup);
139 ui->verticalLayout_Main->removeItem(
ui->horizontalSpacer_0_Main);
144 ui->tabWidget->removeTab(
ui->tabWidget->indexOf(
ui->tabWallet));
145 ui->thirdPartyTxUrlsLabel->setVisible(
false);
146 ui->thirdPartyTxUrls->setVisible(
false);
149 #ifdef ENABLE_EXTERNAL_SIGNER
150 ui->externalSignerPath->setToolTip(
ui->externalSignerPath->toolTip().arg(
PACKAGE_NAME));
153 ui->externalSignerPath->setToolTip(tr(
"Compiled without external signing support (required for external signing)"));
154 ui->externalSignerPath->setEnabled(
false);
157 QDir translations(
":translations");
159 ui->bitcoinAtStartup->setToolTip(
ui->bitcoinAtStartup->toolTip().arg(
PACKAGE_NAME));
160 ui->bitcoinAtStartup->setText(
ui->bitcoinAtStartup->text().arg(
PACKAGE_NAME));
162 ui->openBitcoinConfButton->setToolTip(
ui->openBitcoinConfButton->toolTip().arg(
PACKAGE_NAME));
165 ui->lang->addItem(QString(
"(") + tr(
"default") + QString(
")"), QVariant(
""));
166 for (
const QString &langStr : translations.entryList())
168 QLocale locale(langStr);
171 if(langStr.contains(
"_"))
174 ui->lang->addItem(locale.nativeLanguageName() + QString(
" - ") + locale.nativeCountryName() + QString(
" (") + langStr + QString(
")"), QVariant(langStr));
179 ui->lang->addItem(locale.nativeLanguageName() + QString(
" (") + langStr + QString(
")"), QVariant(langStr));
185 mapper =
new QDataWidgetMapper(
this);
186 mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
187 mapper->setOrientation(Qt::Vertical);
191 mapper->setItemDelegate(delegate);
201 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
202 ui->showTrayIcon->setChecked(
false);
203 ui->showTrayIcon->setEnabled(
false);
204 ui->minimizeToTray->setChecked(
false);
205 ui->minimizeToTray->setEnabled(
false);
225 this->
model = _model;
235 ui->pruneSize->setRange(nMinDiskSpace, std::numeric_limits<int>::max());
238 if (strLabel.isEmpty())
239 strLabel = tr(
"none");
240 ui->overriddenByCommandLineLabel->setText(strLabel);
259 connect(
ui->externalSignerPath, &QLineEdit::textChanged, [
this]{ showRestartWarning(); });
270 connect(
ui->thirdPartyTxUrls, &QLineEdit::textChanged, [
this]{ showRestartWarning(); });
275 QWidget *tab_widget =
nullptr;
276 if (tab == OptionsDialog::Tab::TAB_NETWORK) tab_widget =
ui->tabNetwork;
277 if (tab == OptionsDialog::Tab::TAB_MAIN) tab_widget =
ui->tabMain;
278 if (tab_widget &&
ui->tabWidget->currentWidget() != tab_widget) {
279 ui->tabWidget->setCurrentWidget(tab_widget);
315 if (QSystemTrayIcon::isSystemTrayAvailable()) {
330 ui->okButton->setEnabled(fState);
339 QString reset_dialog_text = tr(
"Client restart required to activate changes.") +
"<br><br>";
343 reset_dialog_text.append(tr(
"Current settings will be backed up at \"%1\".").arg(
m_client_model->
dataDir()) +
"<br><br>");
346 reset_dialog_text.append(tr(
"Client will be shut down. Do you want to proceed?"));
348 QMessageBox::StandardButton btnRetVal = QMessageBox::question(
this, tr(
"Confirm options reset"),
349 reset_dialog_text, QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel);
351 if (btnRetVal == QMessageBox::Cancel)
363 QMessageBox config_msgbox(
this);
364 config_msgbox.setIcon(QMessageBox::Information);
366 config_msgbox.setWindowTitle(tr(
"Configuration options"));
369 config_msgbox.setText(tr(
"The configuration file is used to specify advanced user options which override GUI settings. "
370 "Additionally, any command-line options will override this configuration file."));
372 QPushButton* open_button = config_msgbox.addButton(tr(
"Continue"), QMessageBox::ActionRole);
373 config_msgbox.addButton(tr(
"Cancel"), QMessageBox::RejectRole);
374 open_button->setDefault(
true);
376 config_msgbox.exec();
378 if (config_msgbox.clickedButton() != open_button)
return;
382 QMessageBox::critical(
this, tr(
"Error"), tr(
"The configuration file could not be opened."));
401 if (state == Qt::Checked) {
402 ui->minimizeToTray->setEnabled(
true);
404 ui->minimizeToTray->setChecked(
false);
405 ui->minimizeToTray->setEnabled(
false);
411 ui->pruneWarning->setVisible(!
ui->pruneWarning->isVisible());
416 ui->statusLabel->setStyleSheet(
"QLabel { color: red; }");
420 ui->statusLabel->setText(tr(
"Client restart required to activate changes."));
424 ui->statusLabel->setText(tr(
"This change would require a client restart."));
433 ui->statusLabel->clear();
443 if (pUiProxyIp->
isValid() && (!
ui->proxyPort->isEnabled() ||
ui->proxyPort->text().toInt() > 0) && (!
ui->proxyPortTor->isEnabled() ||
ui->proxyPortTor->text().toInt() > 0))
451 ui->statusLabel->setStyleSheet(
"QLabel { color: red; }");
452 ui->statusLabel->setText(tr(
"The supplied proxy address is invalid."));
458 std::string proxyIpText{
ui->proxyIp->text().toStdString()};
460 const std::optional<CNetAddr> ui_proxy_netaddr{
LookupHost(proxyIpText,
false)};
461 const CService ui_proxy{ui_proxy_netaddr.value_or(
CNetAddr{}),
ui->proxyPort->text().toUShort()};
462 proxyIpText = ui_proxy.ToStringAddrPort();
469 ui->proxyReachIPv4->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
472 ui->proxyReachIPv6->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
475 ui->proxyReachTor->setChecked(has_proxy && proxy.
ToString() == proxyIpText);
487 std::string hostname;
488 if (!
SplitHostPort(input.toStdString(), port, hostname) || port != 0)
return QValidator::Invalid;
493 return QValidator::Acceptable;
495 return QValidator::Invalid;
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
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
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
static QFont getFontForChoice(const FontChoice &fc)
const QString & getOverriddenByCommandLine()
interfaces::Node & node() const
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.
void setupFontOptions(QComboBox *cb, QLabel *preview)
int setFontChoice(QComboBox *cb, const OptionsModel::FontChoice &fc)
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
static const int64_t nMinDbCache
min. -dbcache (MiB)
static const int64_t nMaxDbCache
max. -dbcache (MiB)
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES