Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bitcoin-build-config.h> // IWYU pragma: keep7#include <qt/optionsdialog.h>8#include <qt/forms/ui_optionsdialog.h>10#include <qt/bitcoinunits.h>11#include <qt/clientmodel.h>12#include <qt/guiconstants.h>13#include <qt/guiutil.h>14#include <qt/optionsmodel.h>16#include <common/system.h>17#include <interfaces/node.h>18#include <netbase.h>19#include <node/caches.h>20#include <node/chainstatemanager_args.h>21#include <util/strencodings.h>23#include <chrono>25#include <QApplication>26#include <QDataWidgetMapper>27#include <QDir>28#include <QFontDialog>29#include <QIntValidator>30#include <QLocale>31#include <QMessageBox>32#include <QSystemTrayIcon>33#include <QTimer>35int setFontChoice(QComboBox* cb, const OptionsModel::FontChoice& fc)36{37int i;38for (i = cb->count(); --i >= 0; ) {39QVariant item_data = cb->itemData(i);40if (!item_data.canConvert<OptionsModel::FontChoice>()) continue;41if (item_data.value<OptionsModel::FontChoice>() == fc) {42break;43}44}45if (i == -1) {46// New item needed47QFont chosen_font = OptionsModel::getFontForChoice(fc);48QSignalBlocker block_currentindexchanged_signal(cb); // avoid triggering QFontDialog49cb->insertItem(0, QFontInfo(chosen_font).family(), QVariant::fromValue(fc));50i = 0;51}53cb->setCurrentIndex(i);54return i;55}57void setupFontOptions(QComboBox* cb, QLabel* preview)58{59QFont embedded_font{GUIUtil::fixedPitchFont(true)};60QFont system_font{GUIUtil::fixedPitchFont(false)};61cb->addItem(QObject::tr("Embedded \"%1\"").arg(QFontInfo(embedded_font).family()), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::EmbeddedFont}));62cb->addItem(QObject::tr("Default system font \"%1\"").arg(QFontInfo(system_font).family()), QVariant::fromValue(OptionsModel::FontChoice{OptionsModel::FontChoiceAbstract::BestSystemFont}));63cb->addItem(QObject::tr("Custom…"));65const auto& on_font_choice_changed = [cb, preview](int index) {66static int previous_index = -1;67QVariant item_data = cb->itemData(index);68QFont f;69if (item_data.canConvert<OptionsModel::FontChoice>()) {70f = OptionsModel::getFontForChoice(item_data.value<OptionsModel::FontChoice>());71} else {72bool ok;73f = QFontDialog::getFont(&ok, GUIUtil::fixedPitchFont(false), cb->parentWidget());74if (!ok) {75cb->setCurrentIndex(previous_index);76return;77}78index = setFontChoice(cb, OptionsModel::FontChoice{f});79}80if (preview) {81preview->setFont(f);82}83previous_index = index;84};85QObject::connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), on_font_choice_changed);86on_font_choice_changed(cb->currentIndex());87}89OptionsDialog::OptionsDialog(QWidget* parent, bool enableWallet)90: QDialog(parent, GUIUtil::dialog_flags | Qt::WindowMaximizeButtonHint),91ui(new Ui::OptionsDialog)92{93ui->setupUi(this);95ui->verticalLayout->setStretchFactor(ui->tabWidget, 1);97/* Main elements init */98ui->databaseCache->setRange(MIN_DBCACHE_BYTES / 1_MiB, std::numeric_limits<int>::max());99ui->threadsScriptVerif->setMinimum(-GetNumCores());100ui->threadsScriptVerif->setMaximum(MAX_SCRIPTCHECK_THREADS);101ui->pruneWarning->setVisible(false);102ui->pruneWarning->setStyleSheet("QLabel { color: red; }");104ui->pruneSize->setEnabled(false);105connect(ui->prune, &QPushButton::toggled, ui->pruneSize, &QWidget::setEnabled);107/* Network elements init */108ui->proxyIp->setEnabled(false);109ui->proxyPort->setEnabled(false);110ui->proxyPort->setValidator(new QIntValidator(1, 65535, this));112ui->proxyIpTor->setEnabled(false);113ui->proxyPortTor->setEnabled(false);114ui->proxyPortTor->setValidator(new QIntValidator(1, 65535, this));116connect(ui->connectSocks, &QPushButton::toggled, ui->proxyIp, &QWidget::setEnabled);117connect(ui->connectSocks, &QPushButton::toggled, ui->proxyPort, &QWidget::setEnabled);118connect(ui->connectSocks, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState);120connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyIpTor, &QWidget::setEnabled);121connect(ui->connectSocksTor, &QPushButton::toggled, ui->proxyPortTor, &QWidget::setEnabled);122connect(ui->connectSocksTor, &QPushButton::toggled, this, &OptionsDialog::updateProxyValidationState);124/* Window elements init */125#ifdef Q_OS_MACOS126/* remove Window tab on Mac */127ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));128/* hide launch at startup option on macOS */129ui->bitcoinAtStartup->setVisible(false);130ui->verticalLayout_Main->removeWidget(ui->bitcoinAtStartup);131ui->verticalLayout_Main->removeItem(ui->horizontalSpacer_0_Main);132#endif134/* remove Wallet tab and 3rd party-URL textbox in case of -disablewallet */135if (!enableWallet) {136ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWallet));137ui->thirdPartyTxUrlsLabel->setVisible(false);138ui->thirdPartyTxUrls->setVisible(false);139}141#ifdef ENABLE_EXTERNAL_SIGNER142ui->externalSignerPath->setToolTip(ui->externalSignerPath->toolTip().arg(CLIENT_NAME));143#else144//: "External signing" means using devices such as hardware wallets.145ui->externalSignerPath->setToolTip(tr("Compiled without external signing support (required for external signing)"));146ui->externalSignerPath->setEnabled(false);147#endif148/* Display elements init */149QDir translations(":translations");151ui->bitcoinAtStartup->setToolTip(ui->bitcoinAtStartup->toolTip().arg(CLIENT_NAME));152ui->bitcoinAtStartup->setText(ui->bitcoinAtStartup->text().arg(CLIENT_NAME));154ui->openBitcoinConfButton->setToolTip(ui->openBitcoinConfButton->toolTip().arg(CLIENT_NAME));156ui->lang->setToolTip(ui->lang->toolTip().arg(CLIENT_NAME));157ui->lang->addItem(QString("(") + tr("default") + QString(")"), QVariant(""));158for (const QString &langStr : translations.entryList())159{160QLocale locale(langStr);162/** check if the locale name consists of 2 parts (language_country) */163if(langStr.contains("_"))164{165/** display language strings as "native language - native country/territory (locale name)", e.g. "Deutsch - Deutschland (de)" */166ui->lang->addItem(locale.nativeLanguageName() + QString(" - ") +167locale.nativeTerritoryName() +168QString(" (") + langStr + QString(")"), QVariant(langStr));170}171else172{173/** display language strings as "native language (locale name)", e.g. "Deutsch (de)" */174ui->lang->addItem(locale.nativeLanguageName() + QString(" (") + langStr + QString(")"), QVariant(langStr));175}176}177ui->unit->setModel(new BitcoinUnits(this));179/* Widget-to-option mapper */180mapper = new QDataWidgetMapper(this);181mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);182mapper->setOrientation(Qt::Vertical);184GUIUtil::ItemDelegate* delegate = new GUIUtil::ItemDelegate(mapper);185connect(delegate, &GUIUtil::ItemDelegate::keyEscapePressed, this, &OptionsDialog::reject);186mapper->setItemDelegate(delegate);188/* setup/change UI elements when proxy IPs are invalid/valid */189ui->proxyIp->setCheckValidator(new ProxyAddressValidator(parent));190ui->proxyIpTor->setCheckValidator(new ProxyAddressValidator(parent));191connect(ui->proxyIp, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);192connect(ui->proxyIpTor, &QValidatedLineEdit::validationDidChange, this, &OptionsDialog::updateProxyValidationState);193connect(ui->proxyPort, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);194connect(ui->proxyPortTor, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);196if (!QSystemTrayIcon::isSystemTrayAvailable()) {197ui->showTrayIcon->setChecked(false);198ui->showTrayIcon->setEnabled(false);199ui->minimizeToTray->setChecked(false);200ui->minimizeToTray->setEnabled(false);201}203setupFontOptions(ui->moneyFont, ui->moneyFont_preview);205GUIUtil::handleCloseWindowShortcut(this);206}208OptionsDialog::~OptionsDialog()209{210delete ui;211}213void OptionsDialog::setClientModel(ClientModel* client_model)214{215m_client_model = client_model;216}218void OptionsDialog::setModel(OptionsModel *_model)219{220this->model = _model;222if(_model)223{224/* check if client restart is needed and show persistent message */225if (_model->isRestartRequired())226showRestartWarning(true);228// Prune values are in GB to be consistent with intro.cpp229static constexpr uint64_t nMinDiskSpace = (MIN_DISK_SPACE_FOR_BLOCK_FILES / GB_BYTES) + (MIN_DISK_SPACE_FOR_BLOCK_FILES % GB_BYTES) ? 1 : 0;230ui->pruneSize->setRange(nMinDiskSpace, std::numeric_limits<int>::max());232QString strLabel = _model->getOverriddenByCommandLine();233if (strLabel.isEmpty())234strLabel = tr("none");235ui->overriddenByCommandLineLabel->setText(strLabel);237mapper->setModel(_model);238setMapper();239mapper->toFirst();241const auto& font_for_money = _model->data(_model->index(OptionsModel::FontForMoney, 0), Qt::EditRole).value<OptionsModel::FontChoice>();242setFontChoice(ui->moneyFont, font_for_money);244updateDefaultProxyNets();245}247/* warn when one of the following settings changes by user action (placed here so init via mapper doesn't trigger them) */249/* Main */250connect(ui->prune, &QCheckBox::clicked, this, &OptionsDialog::showRestartWarning);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.