5#include <bitcoin-build-config.h>
21#include <validation.h>
56 default:
throw std::logic_error(
strprintf(
"GUI option %i has no corresponding node setting.", option));
84 assert(!prune_enabled || prune_size_gb >= 1);
108 return std::max(1, prune_size.toInt());
117static std::string
ProxyString(
bool is_set, QString
ip, QString port);
125 if (std::holds_alternative<FontChoiceAbstract>(f)) {
176 if (!settings.contains(
"fHideTrayIcon")) {
177 settings.setValue(
"fHideTrayIcon",
false);
182 if (!settings.contains(
"fMinimizeToTray"))
183 settings.setValue(
"fMinimizeToTray",
false);
186 if (!settings.contains(
"fMinimizeOnClose"))
187 settings.setValue(
"fMinimizeOnClose",
false);
191 if (!settings.contains(
"DisplayBitcoinUnit")) {
192 settings.setValue(
"DisplayBitcoinUnit", QVariant::fromValue(
BitcoinUnit::BTC));
194 QVariant unit = settings.value(
"DisplayBitcoinUnit");
202 if (!settings.contains(
"strThirdPartyTxUrls"))
203 settings.setValue(
"strThirdPartyTxUrls",
"");
206 if (!settings.contains(
"fCoinControlFeatures"))
207 settings.setValue(
"fCoinControlFeatures",
false);
210 if (!settings.contains(
"enable_psbt_controls")) {
211 settings.setValue(
"enable_psbt_controls",
false);
223 }
catch (
const std::exception& e) {
226 error.
original =
strprintf(
"Could not read setting \"%s\", %s.", setting, e.what());
227 error.
translated = tr(
"Could not read setting \"%1\", %2.").arg(QString::fromStdString(setting), e.what()).toStdString();
235 if (!settings.contains(
"strDataDir"))
240 if (!settings.contains(
"SubFeeFromAmount")) {
241 settings.setValue(
"SubFeeFromAmount",
false);
247 if (settings.contains(
"FontForMoney")) {
249 }
else if (settings.contains(
"UseEmbeddedMonospacedFont")) {
250 if (settings.value(
"UseEmbeddedMonospacedFont").toBool()) {
258 m_mask_values = settings.value(
"mask_values",
false).toBool();
268 for (
const QString& key : src.allKeys()) {
269 dst.setValue(key, src.value(key));
294 dataDir = settings.value(
"strDataDir", dataDir).toString();
300 settings.setValue(
"strDataDir", dataDir);
303 settings.setValue(
"fReset",
true);
319 if (proxy.isEmpty()) {
323 std::string hostname;
324 if (
SplitHostPort(proxy.toStdString(), port, hostname) && port != 0) {
327 if (hostname.find(
':') != std::string::npos) {
328 hostname =
"[" + hostname +
"]";
330 return {
true, QString::fromStdString(hostname), QString::number(port)};
343 return is_set ? QString(
ip +
":" + port).toStdString() :
"";
380 if(role == Qt::EditRole)
390 bool successful =
true;
391 if(role == Qt::EditRole)
396 Q_EMIT dataChanged(index, index);
428 }
else if (suffix.empty()) {
439 }
else if (suffix.empty()) {
465 return settings.value(
"enable_psbt_controls");
470 suffix.empty() ?
getOption(option,
"-prev") :
490 if (std::holds_alternative<FontChoiceAbstract>(fc)) {
492 f.setWeight(QFont::Bold);
494 f = std::get<QFont>(fc);
507 auto changed = [&] {
return value.isValid() && value !=
getOption(option, suffix); };
510 bool successful =
true;
528 update(value.toBool());
540 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
570 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
600 update(value.toBool());
606 update(value.toString().toStdString());
627 update(value.toString().toStdString());
633 const auto& new_font = value.value<
FontChoice>();
651 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
669 update(
static_cast<int64_t
>(value.toLongLong()));
675 update(
static_cast<int64_t
>(value.toLongLong()));
682 update(value.toBool());
709 return settings.setValue(
"fRestartRequired", fRequired);
715 return settings.value(
"fRestartRequired",
false).toBool();
728 static const char strSettingsVersionKey[] =
"nSettingsVersion";
729 int settingsVersion = settings.contains(strSettingsVersionKey) ? settings.value(strSettingsVersionKey).toInt() : 0;
735 if (settingsVersion < 130000 && settings.contains(
"nDatabaseCache") && settings.value(
"nDatabaseCache").toLongLong() == 100)
743 if (settings.contains(
"addrProxy") && settings.value(
"addrProxy").toString().endsWith(
"%2")) {
749 if (settings.contains(
"addrSeparateProxyTor") && settings.value(
"addrSeparateProxyTor").toString().endsWith(
"%2")) {
754 auto migrate_setting = [&](
OptionID option,
const QString& qt_name) {
755 if (!settings.contains(qt_name))
return;
756 QVariant value = settings.value(qt_name);
770 settings.remove(qt_name);
780 migrate_setting(
Listen,
"fListen");
781 migrate_setting(
Server,
"server");
782 migrate_setting(
PruneSize,
"nPruneSize");
783 migrate_setting(
Prune,
"bPrune");
784 migrate_setting(
ProxyIP,
"addrProxy");
785 migrate_setting(
ProxyUse,
"fUseProxy");
786 migrate_setting(
ProxyIPTor,
"addrSeparateProxyTor");
787 migrate_setting(
ProxyUseTor,
"fUseSeparateProxyTor");
788 migrate_setting(
Language,
"language");
std::optional< bool > SettingToBool(const common::SettingsValue &value)
std::optional< std::string > SettingToString(const common::SettingsValue &value)
std::optional< int64_t > SettingToInt(const common::SettingsValue &value)
static constexpr int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
BitcoinUnit m_display_bitcoin_unit
QString strOverriddenByCommandLine
std::variant< FontChoiceAbstract, QFont > FontChoice
bool isRestartRequired() const
QFont getFontForMoney() const
bool fCoinControlFeatures
interfaces::Node & node() const
void coinControlFeaturesChanged(bool)
QString strThirdPartyTxUrls
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool m_sub_fee_from_amount
bool setOption(OptionID option, const QVariant &value, const std::string &suffix="")
void displayUnitChanged(BitcoinUnit unit)
void SetPruneTargetGB(int prune_target_gb)
bool Init(bilingual_str &error)
void showTrayIconChanged(bool)
OptionsModel(interfaces::Node &node, QObject *parent=nullptr)
bool hasSigner()
Whether -signer was set or not.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
bool m_enable_psbt_controls
QVariant getOption(OptionID option, const std::string &suffix="") const
void setDisplayUnit(const QVariant &new_unit)
Updates current unit in memory, settings and emits displayUnitChanged(new_unit) signal.
static FontChoice FontChoiceFromString(const QString &)
static QFont getFontForChoice(const FontChoice &fc)
void fontForMoneyChanged(const QFont &)
static QString FontChoiceToString(const OptionsModel::FontChoice &)
void addOverriddenOption(const std::string &option)
static const FontChoice UseBestSystemFont
void setRestartRequired(bool fRequired)
const std::string & getValStr() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Top-level interface for a bitcoin node (bitcoind process).
virtual common::SettingsValue getPersistentSetting(const std::string &name)=0
Return setting value from <datadir>/settings.json or bitcoin.conf.
virtual void resetSettings()=0
Clear all settings in <datadir>/settings.json and store a backup of previous settings in <datadir>/se...
virtual void mapPort(bool use_pcp)=0
Map port.
virtual void initParameterInteraction()=0
Init parameter interaction.
virtual void forceSetting(const std::string &name, const common::SettingsValue &value)=0
Force a setting value to be applied, overriding any other configuration source, but not being persist...
static const int CLIENT_VERSION
bitcoind-res.rc includes this file, but it cannot cope with real c++ code.
static CService ip(uint32_t i)
static constexpr int DEFAULT_PRUNE_TARGET_GB
static constexpr bool DEFAULT_NATPMP
QFont fixedPitchFont(bool use_embedded_font)
QString getDefaultDataDirectory()
Determine default data directory for operating system.
bool SetStartOnSystemStartup(bool fAutoStart)
QString PathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
bool GetStartOnSystemStartup()
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
static const bool DEFAULT_LISTEN
-listen default
static void CopySettings(QSettings &dst, const QSettings &src)
Helper function to copy contents from one QSettings to another.
static int ParsePruneSizeGB(const QVariant &prune_size)
Parse pruning size value provided by user in GUI or loaded from QSettings (windows registry key or qt...
static const QLatin1String fontchoice_str_embedded
static ProxySetting ParseProxyString(const std::string &proxy)
static QString GetDefaultProxyAddress()
static int PruneSizeGB(const common::SettingsValue &prune_setting)
Get pruning size value to show in GUI from bitcoin -prune setting.
static const char * SettingName(OptionsModel::OptionID option)
Map GUI option ID to node setting name.
static const QString fontchoice_str_custom_prefix
static void UpdateRwSetting(interfaces::Node &node, OptionsModel::OptionID option, const std::string &suffix, const common::SettingsValue &value)
Call node.updateRwSetting() with Bitcoin 22.x workaround.
static bool PruneEnabled(const common::SettingsValue &prune_setting)
Get pruning enabled value to show in GUI from bitcoin -prune setting.
static std::string ProxyString(bool is_set, QString ip, QString port)
static void BackupSettings(const fs::path &filename, const QSettings &src)
Back up a QSettings to an ini-formatted file.
const char * DEFAULT_GUI_PROXY_HOST
static const QLatin1String fontchoice_str_best_system
static common::SettingsValue PruneSetting(bool prune_enabled, int prune_size_gb)
Convert enabled/size values to bitcoin -prune setting.
static int PruneMiBtoGB(int64_t mib)
Convert configured prune target MiB to displayed GB.
static int64_t PruneGBtoMiB(int gb)
Convert displayed prune target GB to configured MiB.
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT
static const int64_t nDefaultDbCache
-dbcache default (MiB)
bool SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)
Splits socket address string into host string and port value.