5 #if defined(HAVE_CONFIG_H)
23 #include <validation.h>
27 #include <QLatin1Char>
29 #include <QStringList>
59 default:
throw std::logic_error(
strprintf(
"GUI option %i has no corresponding node setting.", option));
87 assert(!prune_enabled || prune_size_gb >= 1);
111 return std::max(1, prune_size.toInt());
120 static std::string
ProxyString(
bool is_set, QString
ip, QString port);
128 if (std::holds_alternative<FontChoiceAbstract>(f)) {
179 if (!settings.contains(
"fHideTrayIcon")) {
180 settings.setValue(
"fHideTrayIcon",
false);
185 if (!settings.contains(
"fMinimizeToTray"))
186 settings.setValue(
"fMinimizeToTray",
false);
189 if (!settings.contains(
"fMinimizeOnClose"))
190 settings.setValue(
"fMinimizeOnClose",
false);
194 if (!settings.contains(
"DisplayBitcoinUnit")) {
195 settings.setValue(
"DisplayBitcoinUnit", QVariant::fromValue(
BitcoinUnit::BTC));
197 QVariant unit = settings.value(
"DisplayBitcoinUnit");
205 if (!settings.contains(
"strThirdPartyTxUrls"))
206 settings.setValue(
"strThirdPartyTxUrls",
"");
209 if (!settings.contains(
"fCoinControlFeatures"))
210 settings.setValue(
"fCoinControlFeatures",
false);
213 if (!settings.contains(
"enable_psbt_controls")) {
214 settings.setValue(
"enable_psbt_controls",
false);
226 }
catch (
const std::exception& e) {
229 error.
original =
strprintf(
"Could not read setting \"%s\", %s.", setting, e.what());
230 error.
translated = tr(
"Could not read setting \"%1\", %2.").arg(QString::fromStdString(setting), e.what()).toStdString();
238 if (!settings.contains(
"strDataDir"))
243 if (!settings.contains(
"SubFeeFromAmount")) {
244 settings.setValue(
"SubFeeFromAmount",
false);
250 if (settings.contains(
"FontForMoney")) {
252 }
else if (settings.contains(
"UseEmbeddedMonospacedFont")) {
253 if (settings.value(
"UseEmbeddedMonospacedFont").toBool()) {
261 m_mask_values = settings.value(
"mask_values",
false).toBool();
271 for (
const QString& key : src.allKeys()) {
272 dst.setValue(key, src.value(key));
297 dataDir = settings.value(
"strDataDir", dataDir).toString();
303 settings.setValue(
"strDataDir", dataDir);
306 settings.setValue(
"fReset",
true);
322 if (proxy.isEmpty()) {
327 if (ip_port.size() == 2) {
328 return {
true, ip_port.at(0), ip_port.at(1)};
341 return is_set ? QString(
ip +
":" + port).toStdString() :
"";
378 if(role == Qt::EditRole)
388 bool successful =
true;
389 if(role == Qt::EditRole)
394 Q_EMIT dataChanged(index, index);
435 }
else if (suffix.empty()) {
446 }
else if (suffix.empty()) {
472 return settings.value(
"enable_psbt_controls");
477 suffix.empty() ?
getOption(option,
"-prev") :
497 if (std::holds_alternative<FontChoiceAbstract>(fc)) {
499 f.setWeight(QFont::Bold);
501 f = std::get<QFont>(fc);
513 auto changed = [&] {
return value.isValid() && value !=
getOption(option, suffix); };
516 bool successful =
true;
534 update(value.toBool());
540 update(value.toBool());
552 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
582 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
612 update(value.toBool());
618 update(value.toString().toStdString());
639 update(value.toString().toStdString());
645 const auto& new_font = value.value<
FontChoice>();
663 if (suffix.empty() && !value.toBool())
setOption(option,
true,
"-prev");
681 update(
static_cast<int64_t
>(value.toLongLong()));
687 update(
static_cast<int64_t
>(value.toLongLong()));
694 update(value.toBool());
721 return settings.setValue(
"fRestartRequired", fRequired);
727 return settings.value(
"fRestartRequired",
false).toBool();
740 static const char strSettingsVersionKey[] =
"nSettingsVersion";
741 int settingsVersion = settings.contains(strSettingsVersionKey) ? settings.value(strSettingsVersionKey).toInt() : 0;
747 if (settingsVersion < 130000 && settings.contains(
"nDatabaseCache") && settings.value(
"nDatabaseCache").toLongLong() == 100)
755 if (settings.contains(
"addrProxy") && settings.value(
"addrProxy").toString().endsWith(
"%2")) {
761 if (settings.contains(
"addrSeparateProxyTor") && settings.value(
"addrSeparateProxyTor").toString().endsWith(
"%2")) {
766 auto migrate_setting = [&](
OptionID option,
const QString& qt_name) {
767 if (!settings.contains(qt_name))
return;
768 QVariant value = settings.value(qt_name);
782 settings.remove(qt_name);
793 migrate_setting(
Listen,
"fListen");
794 migrate_setting(
Server,
"server");
795 migrate_setting(
PruneSize,
"nPruneSize");
796 migrate_setting(
Prune,
"bPrune");
797 migrate_setting(
ProxyIP,
"addrProxy");
798 migrate_setting(
ProxyUse,
"fUseProxy");
799 migrate_setting(
ProxyIPTor,
"addrSeparateProxyTor");
800 migrate_setting(
ProxyUseTor,
"fUseSeparateProxyTor");
801 migrate_setting(
Language,
"language");
std::optional< int64_t > SettingToInt(const common::SettingsValue &value)
std::optional< std::string > SettingToString(const common::SettingsValue &value)
std::optional< bool > SettingToBool(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
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)
interfaces::Node & node() const
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 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...
virtual void mapPort(bool use_upnp, bool use_natpmp)=0
Map port.
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
static constexpr bool DEFAULT_UPNP
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()
QStringList SplitSkipEmptyParts(const QString &string, const SeparatorType &separator)
Splits the string into substrings wherever separator occurs, and returns the list of those strings.
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 char * SettingName(OptionsModel::OptionID option)
Map GUI option ID to node setting name.
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 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)