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.
251} else {252m_font_money = FontChoiceAbstract::BestSystemFont;253}254}255Q_EMIT fontForMoneyChanged(getFontForMoney());257m_mask_values = settings.value("mask_values", false).toBool();259return true;260}262/** Helper function to copy contents from one QSettings to another.263* By using allKeys this also covers nested settings in a hierarchy.264*/265static void CopySettings(QSettings& dst, const QSettings& src)266{267for (const QString& key : src.allKeys()) {268dst.setValue(key, src.value(key));269}270}272/** Back up a QSettings to an ini-formatted file. */273static void BackupSettings(const fs::path& filename, const QSettings& src)274{275qInfo() << "Backing up GUI settings to" << GUIUtil::PathToQString(filename);276QSettings dst(GUIUtil::PathToQString(filename), QSettings::IniFormat);277dst.clear();278CopySettings(dst, src);279}281void OptionsModel::Reset()282{283// Backup and reset settings.json284node().resetSettings();286QSettings settings;288// Backup old settings to chain-specific datadir for troubleshooting289BackupSettings(gArgs.GetDataDirNet() / "guisettings.ini.bak", settings);291// Save the strDataDir setting292QString dataDir = GUIUtil::getDefaultDataDirectory();293dataDir = settings.value("strDataDir", dataDir).toString();295// Remove all entries from our QSettings object296settings.clear();298// Set strDataDir299settings.setValue("strDataDir", dataDir);301// Set that this was reset302settings.setValue("fReset", true);304// default setting for OptionsModel::StartAtStartup - disabled305if (GUIUtil::GetStartOnSystemStartup())306GUIUtil::SetStartOnSystemStartup(false);307}309int OptionsModel::rowCount(const QModelIndex & parent) const310{311return OptionIDRowCount;312}314static ProxySetting ParseProxyString(const QString& proxy)315{316static const ProxySetting default_val = {false, DEFAULT_GUI_PROXY_HOST, QString("%1").arg(DEFAULT_GUI_PROXY_PORT)};317// Handle the case that the setting is not set at all318if (proxy.isEmpty()) {319return default_val;320}321uint16_t port{0};322std::string hostname;323if (SplitHostPort(proxy.toStdString(), port, hostname) && port != 0) {324// Valid and port within the valid range325// Check if the hostname contains a colon, indicating an IPv6 address326if (hostname.find(':') != std::string::npos) {327hostname = "[" + hostname + "]"; // Wrap IPv6 address in brackets328}329return {true, QString::fromStdString(hostname), QString::number(port)};330} else { // Invalid: return default331return default_val;332}333}335static ProxySetting ParseProxyString(const std::string& proxy)336{337return ParseProxyString(QString::fromStdString(proxy));338}340static std::string ProxyString(bool is_set, QString ip, QString port)341{342return is_set ? QString(ip + ":" + port).toStdString() : "";343}345static QString GetDefaultProxyAddress()346{347return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);348}350void OptionsModel::SetPruneTargetGB(int prune_target_gb)351{352const common::SettingsValue cur_value = node().getPersistentSetting("prune");353const common::SettingsValue new_value = PruneSetting(prune_target_gb > 0, prune_target_gb);355// Force setting to take effect. It is still safe to change the value at356// this point because this function is only called after the intro screen is357// shown, before the node starts.358node().forceSetting("prune", new_value);360// Update settings.json if value configured in intro screen is different361// from saved value. Avoid writing settings.json if bitcoin.conf value362// doesn't need to be overridden.363if (PruneEnabled(cur_value) != PruneEnabled(new_value) ||364PruneSizeGB(cur_value) != PruneSizeGB(new_value)) {365// Call UpdateRwSetting() instead of setOption() to avoid setting366// RestartRequired flag367UpdateRwSetting(node(), Prune, "", new_value);368}370// Keep previous pruning size, if pruning was disabled.371if (PruneEnabled(cur_value)) {372UpdateRwSetting(node(), Prune, "-prev", PruneEnabled(new_value) ? common::SettingsValue{} : cur_value);373}374}376// read QSettings values and return them377QVariant OptionsModel::data(const QModelIndex & index, int role) const378{379if(role == Qt::EditRole)380{381return getOption(OptionID(index.row()));382}383return QVariant();384}386// write QSettings values387bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)388{389bool successful = true; /* set to false on parse error */390if(role == Qt::EditRole)391{392successful = setOption(OptionID(index.row()), value);393}395Q_EMIT dataChanged(index, index);397return successful;398}400// NOLINTNEXTLINE(misc-no-recursion)401QVariant OptionsModel::getOption(OptionID option, const std::string& suffix) const402{403auto setting = [&]{ return node().getPersistentSetting(SettingName(option) + suffix); };405QSettings settings;406switch (option) {407case StartAtStartup:408return GUIUtil::GetStartOnSystemStartup();409case ShowTrayIcon:410return m_show_tray_icon;411case MinimizeToTray:412return fMinimizeToTray;413case MapPortNatpmp:414return SettingToBool(setting(), DEFAULT_NATPMP);415case MinimizeOnClose:416return fMinimizeOnClose;418// default proxy419case ProxyUse:420case ProxyUseTor:421return ParseProxyString(SettingToString(setting(), "")).is_set;422case ProxyIP:423case ProxyIPTor: {424ProxySetting proxy = ParseProxyString(SettingToString(setting(), ""));425if (proxy.is_set) {426return proxy.ip;427} else if (suffix.empty()) {428return getOption(option, "-prev");429} else {430return ParseProxyString(GetDefaultProxyAddress().toStdString()).ip;431}432}433case ProxyPort:434case ProxyPortTor: {435ProxySetting proxy = ParseProxyString(SettingToString(setting(), ""));436if (proxy.is_set) {437return proxy.port;438} else if (suffix.empty()) {439return getOption(option, "-prev");440} else {441return ParseProxyString(GetDefaultProxyAddress().toStdString()).port;442}443}445#ifdef ENABLE_WALLET446case SpendZeroConfChange:447return SettingToBool(setting(), wallet::DEFAULT_SPEND_ZEROCONF_CHANGE);448case ExternalSignerPath:449return QString::fromStdString(SettingToString(setting(), ""));450case SubFeeFromAmount:451return m_sub_fee_from_amount;452#endif453case DisplayUnit:454return QVariant::fromValue(m_display_bitcoin_unit);455case ThirdPartyTxUrls:456return strThirdPartyTxUrls;457case Language:458return QString::fromStdString(SettingToString(setting(), ""));459case FontForMoney:460return QVariant::fromValue(m_font_money);461case CoinControlFeatures:462return fCoinControlFeatures;463case EnablePSBTControls:464return settings.value("enable_psbt_controls");465case Prune:466return PruneEnabled(setting());467case PruneSize:468return PruneEnabled(setting()) ? PruneSizeGB(setting()) :469suffix.empty() ? getOption(option, "-prev") :470DEFAULT_PRUNE_TARGET_GB;471case DatabaseCache:472return qlonglong(SettingTo<int64_t>(setting(), node::GetDefaultDBCache() / 1_MiB));473case ThreadsScriptVerif:474return qlonglong(SettingTo<int64_t>(setting(), DEFAULT_SCRIPTCHECK_THREADS));475case Listen:476return SettingToBool(setting(), DEFAULT_LISTEN);477case Server:478return SettingToBool(setting(), false);479case MaskValues:480return m_mask_values;481default:482return QVariant();483}484}486QFont OptionsModel::getFontForChoice(const FontChoice& fc)487{488QFont f;489if (std::holds_alternative<FontChoiceAbstract>(fc)) {490f = GUIUtil::fixedPitchFont(fc != UseBestSystemFont);491f.setWeight(QFont::Bold);492} else {493f = std::get<QFont>(fc);494}495return f;496}498QFont OptionsModel::getFontForMoney() const499{500return getFontForChoice(m_font_money);
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.