0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-05 10:17:30 -05:00
bitcoin-bitcoin-core/src/qt/optionsmodel.cpp

722 lines
25 KiB
C++
Raw Normal View History

// Copyright (c) 2011-2021 The Bitcoin Core developers
2014-12-13 12:09:33 +08:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <qt/optionsmodel.h>
#include <qt/bitcoinunits.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
#include <interfaces/node.h>
#include <mapport.h>
#include <net.h>
#include <netbase.h>
#include <txdb.h> // for -dbcache defaults
#include <util/string.h>
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
#include <wallet/wallet.h> // For DEFAULT_SPEND_ZEROCONF_CHANGE
2019-10-12 12:49:29 -04:00
#include <QDebug>
#include <QLatin1Char>
#include <QSettings>
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
#include <QStringList>
#include <QVariant>
#include <univalue.h>
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
static const QString GetDefaultProxyAddress();
/** Map GUI option ID to node setting name. */
static const char* SettingName(OptionsModel::OptionID option)
{
switch (option) {
case OptionsModel::DatabaseCache: return "dbcache";
case OptionsModel::ThreadsScriptVerif: return "par";
case OptionsModel::SpendZeroConfChange: return "spendzeroconfchange";
case OptionsModel::ExternalSignerPath: return "signer";
case OptionsModel::MapPortUPnP: return "upnp";
case OptionsModel::MapPortNatpmp: return "natpmp";
case OptionsModel::Listen: return "listen";
case OptionsModel::Server: return "server";
case OptionsModel::PruneSize: return "prune";
case OptionsModel::Prune: return "prune";
case OptionsModel::ProxyIP: return "proxy";
case OptionsModel::ProxyPort: return "proxy";
case OptionsModel::ProxyUse: return "proxy";
case OptionsModel::ProxyIPTor: return "onion";
case OptionsModel::ProxyPortTor: return "onion";
case OptionsModel::ProxyUseTor: return "onion";
default: throw std::logic_error(strprintf("GUI option %i has no corresponding node setting.", option));
}
}
/** Call node.updateRwSetting() with Bitcoin 22.x workaround. */
static void UpdateRwSetting(interfaces::Node& node, OptionsModel::OptionID option, const util::SettingsValue& value)
{
if (value.isNum() &&
(option == OptionsModel::DatabaseCache ||
option == OptionsModel::ThreadsScriptVerif ||
option == OptionsModel::Prune ||
option == OptionsModel::PruneSize)) {
// Write certain old settings as strings, even though they are numbers,
// because Bitcoin 22.x releases try to read these specific settings as
// strings in addOverriddenOption() calls at startup, triggering
// uncaught exceptions in UniValue::get_str(). These errors were fixed
// in later releases by https://github.com/bitcoin/bitcoin/pull/24498.
// If new numeric settings are added, they can be written as numbers
// instead of strings, because bitcoin 22.x will not try to read these.
node.updateRwSetting(SettingName(option), value.getValStr());
} else {
node.updateRwSetting(SettingName(option), value);
}
}
//! Convert enabled/size values to bitcoin -prune setting.
static util::SettingsValue PruneSetting(bool prune_enabled, int prune_size_gb)
{
assert(!prune_enabled || prune_size_gb >= 1); // PruneSizeGB and ParsePruneSizeGB never return less
return prune_enabled ? PruneGBtoMiB(prune_size_gb) : 0;
}
//! Get pruning enabled value to show in GUI from bitcoin -prune setting.
static bool PruneEnabled(const util::SettingsValue& prune_setting)
{
// -prune=1 setting is manual pruning mode, so disabled for purposes of the gui
return SettingToInt(prune_setting, 0) > 1;
}
//! Get pruning size value to show in GUI from bitcoin -prune setting. If
//! pruning is not enabled, just show default recommended pruning size (2GB).
static int PruneSizeGB(const util::SettingsValue& prune_setting)
{
int value = SettingToInt(prune_setting, 0);
return value > 1 ? PruneMiBtoGB(value) : DEFAULT_PRUNE_TARGET_GB;
}
//! Parse pruning size value provided by user in GUI or loaded from QSettings
//! (windows registry key or qt .conf file). Smallest value that the GUI can
//! display is 1 GB, so round up if anything less is parsed.
static int ParsePruneSizeGB(const QVariant& prune_size)
{
return std::max(1, prune_size.toInt());
}
struct ProxySetting {
bool is_set;
QString ip;
QString port;
};
static ProxySetting ParseProxyString(const std::string& proxy);
static std::string ProxyString(bool is_set, QString ip, QString port);
OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent) :
QAbstractListModel(parent), m_node{node}
{
}
void OptionsModel::addOverriddenOption(const std::string &option)
{
strOverriddenByCommandLine += QString::fromStdString(option) + "=" + QString::fromStdString(gArgs.GetArg(option, "")) + " ";
}
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// Writes all missing QSettings with their default values
bool OptionsModel::Init(bilingual_str& error)
2012-02-16 21:09:41 -05:00
{
// Initialize display settings from stored settings.
m_prune_size_gb = PruneSizeGB(node().getPersistentSetting("prune"));
ProxySetting proxy = ParseProxyString(SettingToString(node().getPersistentSetting("proxy"), GetDefaultProxyAddress().toStdString()));
m_proxy_ip = proxy.ip;
m_proxy_port = proxy.port;
ProxySetting onion = ParseProxyString(SettingToString(node().getPersistentSetting("onion"), GetDefaultProxyAddress().toStdString()));
m_onion_ip = onion.ip;
m_onion_port = onion.port;
2016-07-26 14:01:36 +02:00
checkAndMigrate();
2012-02-16 21:09:41 -05:00
QSettings settings;
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// Ensure restart flag is unset on client startup
setRestartRequired(false);
2012-07-07 16:35:29 +02:00
// These are Qt-only settings:
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// Window
if (!settings.contains("fHideTrayIcon")) {
settings.setValue("fHideTrayIcon", false);
}
m_show_tray_icon = !settings.value("fHideTrayIcon").toBool();
Q_EMIT showTrayIconChanged(m_show_tray_icon);
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
if (!settings.contains("fMinimizeToTray"))
settings.setValue("fMinimizeToTray", false);
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && m_show_tray_icon;
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
if (!settings.contains("fMinimizeOnClose"))
settings.setValue("fMinimizeOnClose", false);
fMinimizeOnClose = settings.value("fMinimizeOnClose").toBool();
// Display
if (!settings.contains("DisplayBitcoinUnit")) {
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(BitcoinUnit::BTC));
}
QVariant unit = settings.value("DisplayBitcoinUnit");
if (unit.canConvert<BitcoinUnit>()) {
m_display_bitcoin_unit = unit.value<BitcoinUnit>();
} else {
m_display_bitcoin_unit = BitcoinUnit::BTC;
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
}
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
if (!settings.contains("strThirdPartyTxUrls"))
settings.setValue("strThirdPartyTxUrls", "");
strThirdPartyTxUrls = settings.value("strThirdPartyTxUrls", "").toString();
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
if (!settings.contains("fCoinControlFeatures"))
settings.setValue("fCoinControlFeatures", false);
2013-08-12 17:03:03 +02:00
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
2012-02-16 21:09:41 -05:00
if (!settings.contains("enable_psbt_controls")) {
settings.setValue("enable_psbt_controls", false);
}
m_enable_psbt_controls = settings.value("enable_psbt_controls", false).toBool();
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// These are shared with the core or have a command-line parameter
// and we want command-line parameters to overwrite the GUI settings.
for (OptionID option : {DatabaseCache, ThreadsScriptVerif, SpendZeroConfChange, ExternalSignerPath, MapPortUPnP,
MapPortNatpmp, Listen, Server, Prune, ProxyUse, ProxyUseTor}) {
std::string setting = SettingName(option);
if (node().isSettingIgnored(setting)) addOverriddenOption("-" + setting);
try {
getOption(option);
} catch (const std::exception& e) {
// This handles exceptions thrown by univalue that can happen if
// settings in settings.json don't have the expected types.
error.original = strprintf("Could not read setting \"%s\", %s.", setting, e.what());
error.translated = tr("Could not read setting \"%1\", %2.").arg(QString::fromStdString(setting), e.what()).toStdString();
return false;
}
}
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// If setting doesn't exist create it with defaults.
//
// If gArgs.SoftSetArg() or gArgs.SoftSetBoolArg() return false we were overridden
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// by command-line and show this in the UI.
// Main
if (!settings.contains("strDataDir"))
settings.setValue("strDataDir", GUIUtil::getDefaultDataDirectory());
// Wallet
#ifdef ENABLE_WALLET
2021-07-29 21:57:57 +05:30
if (!settings.contains("SubFeeFromAmount")) {
settings.setValue("SubFeeFromAmount", false);
}
m_sub_fee_from_amount = settings.value("SubFeeFromAmount", false).toBool();
#endif
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// Display
if (!settings.contains("language"))
settings.setValue("language", "");
if (!gArgs.SoftSetArg("-lang", settings.value("language").toString().toStdString()))
addOverriddenOption("-lang");
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
language = settings.value("language").toString();
2021-02-21 20:58:19 +02:00
if (!settings.contains("UseEmbeddedMonospacedFont")) {
settings.setValue("UseEmbeddedMonospacedFont", "true");
}
m_use_embedded_monospaced_font = settings.value("UseEmbeddedMonospacedFont").toBool();
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
return true;
2012-02-16 21:09:41 -05:00
}
/** Helper function to copy contents from one QSettings to another.
* By using allKeys this also covers nested settings in a hierarchy.
*/
static void CopySettings(QSettings& dst, const QSettings& src)
{
for (const QString& key : src.allKeys()) {
dst.setValue(key, src.value(key));
}
}
/** Back up a QSettings to an ini-formatted file. */
static void BackupSettings(const fs::path& filename, const QSettings& src)
{
qInfo() << "Backing up GUI settings to" << GUIUtil::PathToQString(filename);
QSettings dst(GUIUtil::PathToQString(filename), QSettings::IniFormat);
dst.clear();
CopySettings(dst, src);
}
void OptionsModel::Reset()
{
QSettings settings;
// Backup old settings to chain-specific datadir for troubleshooting
BackupSettings(gArgs.GetDataDirNet() / "guisettings.ini.bak", settings);
// Save the strDataDir setting
QString dataDir = GUIUtil::getDefaultDataDirectory();
dataDir = settings.value("strDataDir", dataDir).toString();
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// Remove all entries from our QSettings object
settings.clear();
// Set strDataDir
settings.setValue("strDataDir", dataDir);
// Set that this was reset
settings.setValue("fReset", true);
// default setting for OptionsModel::StartAtStartup - disabled
if (GUIUtil::GetStartOnSystemStartup())
GUIUtil::SetStartOnSystemStartup(false);
2012-02-16 21:09:41 -05:00
}
int OptionsModel::rowCount(const QModelIndex & parent) const
{
return OptionIDRowCount;
}
static ProxySetting ParseProxyString(const QString& proxy)
{
static const ProxySetting default_val = {false, DEFAULT_GUI_PROXY_HOST, QString("%1").arg(DEFAULT_GUI_PROXY_PORT)};
// Handle the case that the setting is not set at all
if (proxy.isEmpty()) {
return default_val;
}
// contains IP at index 0 and port at index 1
QStringList ip_port = GUIUtil::SplitSkipEmptyParts(proxy, ":");
if (ip_port.size() == 2) {
return {true, ip_port.at(0), ip_port.at(1)};
} else { // Invalid: return default
return default_val;
}
}
static ProxySetting ParseProxyString(const std::string& proxy)
{
return ParseProxyString(QString::fromStdString(proxy));
}
static std::string ProxyString(bool is_set, QString ip, QString port)
{
return is_set ? QString(ip + ":" + port).toStdString() : "";
}
static const QString GetDefaultProxyAddress()
{
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
}
void OptionsModel::SetPruneTargetGB(int prune_target_gb)
{
const util::SettingsValue cur_value = node().getPersistentSetting("prune");
const util::SettingsValue new_value = PruneSetting(prune_target_gb > 0, prune_target_gb);
m_prune_size_gb = prune_target_gb;
// Force setting to take effect. It is still safe to change the value at
// this point because this function is only called after the intro screen is
// shown, before the node starts.
node().forceSetting("prune", new_value);
// Update settings.json if value configured in intro screen is different
// from saved value. Avoid writing settings.json if bitcoin.conf value
// doesn't need to be overridden.
if (PruneEnabled(cur_value) != PruneEnabled(new_value) ||
PruneSizeGB(cur_value) != PruneSizeGB(new_value)) {
// Call UpdateRwSetting() instead of setOption() to avoid setting
// RestartRequired flag
UpdateRwSetting(node(), Prune, new_value);
}
}
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
// read QSettings values and return them
QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
if(role == Qt::EditRole)
{
return getOption(OptionID(index.row()));
}
return QVariant();
}
// write QSettings values
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
{
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
successful = setOption(OptionID(index.row()), value);
}
Q_EMIT dataChanged(index, index);
return successful;
}
QVariant OptionsModel::getOption(OptionID option) const
{
auto setting = [&]{ return node().getPersistentSetting(SettingName(option)); };
QSettings settings;
switch (option) {
case StartAtStartup:
return GUIUtil::GetStartOnSystemStartup();
case ShowTrayIcon:
return m_show_tray_icon;
case MinimizeToTray:
return fMinimizeToTray;
case MapPortUPnP:
#ifdef USE_UPNP
return SettingToBool(setting(), DEFAULT_UPNP);
#else
return false;
2020-02-23 02:12:19 +02:00
#endif // USE_UPNP
case MapPortNatpmp:
2020-02-23 02:12:19 +02:00
#ifdef USE_NATPMP
return SettingToBool(setting(), DEFAULT_NATPMP);
2020-02-23 02:12:19 +02:00
#else
return false;
2020-02-23 02:12:19 +02:00
#endif // USE_NATPMP
case MinimizeOnClose:
return fMinimizeOnClose;
// default proxy
case ProxyUse:
return ParseProxyString(SettingToString(setting(), "")).is_set;
case ProxyIP:
return m_proxy_ip;
case ProxyPort:
return m_proxy_port;
// separate Tor proxy
case ProxyUseTor:
return ParseProxyString(SettingToString(setting(), "")).is_set;
case ProxyIPTor:
return m_onion_ip;
case ProxyPortTor:
return m_onion_port;
#ifdef ENABLE_WALLET
case SpendZeroConfChange:
return SettingToBool(setting(), wallet::DEFAULT_SPEND_ZEROCONF_CHANGE);
case ExternalSignerPath:
return QString::fromStdString(SettingToString(setting(), ""));
case SubFeeFromAmount:
return m_sub_fee_from_amount;
#endif
case DisplayUnit:
return QVariant::fromValue(m_display_bitcoin_unit);
case ThirdPartyTxUrls:
return strThirdPartyTxUrls;
case Language:
return settings.value("language");
case UseEmbeddedMonospacedFont:
return m_use_embedded_monospaced_font;
case CoinControlFeatures:
return fCoinControlFeatures;
case EnablePSBTControls:
return settings.value("enable_psbt_controls");
case Prune:
return PruneEnabled(setting());
case PruneSize:
return m_prune_size_gb;
case DatabaseCache:
return qlonglong(SettingToInt(setting(), nDefaultDbCache));
case ThreadsScriptVerif:
return qlonglong(SettingToInt(setting(), DEFAULT_SCRIPTCHECK_THREADS));
case Listen:
return SettingToBool(setting(), DEFAULT_LISTEN);
case Server:
return SettingToBool(setting(), false);
default:
return QVariant();
}
}
bool OptionsModel::setOption(OptionID option, const QVariant& value)
{
auto changed = [&] { return value.isValid() && value != getOption(option); };
auto update = [&](const util::SettingsValue& value) { return UpdateRwSetting(node(), option, value); };
bool successful = true; /* set to false on parse error */
QSettings settings;
switch (option) {
case StartAtStartup:
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
break;
case ShowTrayIcon:
m_show_tray_icon = value.toBool();
settings.setValue("fHideTrayIcon", !m_show_tray_icon);
Q_EMIT showTrayIconChanged(m_show_tray_icon);
break;
case MinimizeToTray:
fMinimizeToTray = value.toBool();
settings.setValue("fMinimizeToTray", fMinimizeToTray);
break;
case MapPortUPnP: // core option - can be changed on-the-fly
if (changed()) {
update(value.toBool());
node().mapPort(value.toBool(), getOption(MapPortNatpmp).toBool());
}
break;
case MapPortNatpmp: // core option - can be changed on-the-fly
if (changed()) {
update(value.toBool());
node().mapPort(getOption(MapPortUPnP).toBool(), value.toBool());
}
break;
case MinimizeOnClose:
fMinimizeOnClose = value.toBool();
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
break;
// default proxy
case ProxyUse:
if (changed()) {
update(ProxyString(value.toBool(), m_proxy_ip, m_proxy_port));
setRestartRequired(true);
}
break;
case ProxyIP:
if (changed()) {
m_proxy_ip = value.toString();
if (getOption(ProxyUse).toBool()) {
update(ProxyString(true, m_proxy_ip, m_proxy_port));
setRestartRequired(true);
}
}
break;
case ProxyPort:
if (changed()) {
m_proxy_port = value.toString();
if (getOption(ProxyUse).toBool()) {
update(ProxyString(true, m_proxy_ip, m_proxy_port));
setRestartRequired(true);
}
}
break;
// separate Tor proxy
case ProxyUseTor:
if (changed()) {
update(ProxyString(value.toBool(), m_onion_ip, m_onion_port));
setRestartRequired(true);
}
break;
case ProxyIPTor:
if (changed()) {
m_onion_ip = value.toString();
if (getOption(ProxyUseTor).toBool()) {
update(ProxyString(true, m_onion_ip, m_onion_port));
setRestartRequired(true);
}
}
break;
case ProxyPortTor:
if (changed()) {
m_onion_port = value.toString();
if (getOption(ProxyUseTor).toBool()) {
update(ProxyString(true, m_onion_ip, m_onion_port));
setRestartRequired(true);
}
}
break;
#ifdef ENABLE_WALLET
case SpendZeroConfChange:
if (changed()) {
update(value.toBool());
setRestartRequired(true);
}
break;
case ExternalSignerPath:
if (changed()) {
update(value.toString().toStdString());
setRestartRequired(true);
}
break;
case SubFeeFromAmount:
m_sub_fee_from_amount = value.toBool();
settings.setValue("SubFeeFromAmount", m_sub_fee_from_amount);
break;
#endif
case DisplayUnit:
setDisplayUnit(value);
break;
case ThirdPartyTxUrls:
if (strThirdPartyTxUrls != value.toString()) {
strThirdPartyTxUrls = value.toString();
settings.setValue("strThirdPartyTxUrls", strThirdPartyTxUrls);
setRestartRequired(true);
}
break;
case Language:
if (settings.value("language") != value) {
settings.setValue("language", value);
setRestartRequired(true);
}
break;
case UseEmbeddedMonospacedFont:
m_use_embedded_monospaced_font = value.toBool();
settings.setValue("UseEmbeddedMonospacedFont", m_use_embedded_monospaced_font);
Q_EMIT useEmbeddedMonospacedFontChanged(m_use_embedded_monospaced_font);
break;
case CoinControlFeatures:
fCoinControlFeatures = value.toBool();
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
Q_EMIT coinControlFeaturesChanged(fCoinControlFeatures);
break;
case EnablePSBTControls:
m_enable_psbt_controls = value.toBool();
settings.setValue("enable_psbt_controls", m_enable_psbt_controls);
break;
case Prune:
if (changed()) {
update(PruneSetting(value.toBool(), m_prune_size_gb));
setRestartRequired(true);
}
break;
case PruneSize:
if (changed()) {
m_prune_size_gb = ParsePruneSizeGB(value);
if (getOption(Prune).toBool()) {
update(PruneSetting(true, m_prune_size_gb));
setRestartRequired(true);
}
}
break;
case DatabaseCache:
if (changed()) {
update(static_cast<int64_t>(value.toLongLong()));
setRestartRequired(true);
}
break;
case ThreadsScriptVerif:
if (changed()) {
update(static_cast<int64_t>(value.toLongLong()));
setRestartRequired(true);
}
break;
case Listen:
case Server:
if (changed()) {
update(value.toBool());
setRestartRequired(true);
}
break;
default:
break;
}
return successful;
}
2011-06-01 09:34:12 +02:00
void OptionsModel::setDisplayUnit(const QVariant& new_unit)
{
if (new_unit.isNull() || new_unit.value<BitcoinUnit>() == m_display_bitcoin_unit) return;
m_display_bitcoin_unit = new_unit.value<BitcoinUnit>();
QSettings settings;
settings.setValue("DisplayBitcoinUnit", QVariant::fromValue(m_display_bitcoin_unit));
Q_EMIT displayUnitChanged(m_display_bitcoin_unit);
}
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
void OptionsModel::setRestartRequired(bool fRequired)
{
QSettings settings;
return settings.setValue("fRestartRequired", fRequired);
}
bool OptionsModel::isRestartRequired() const
[Qt] massive options/settings rework (no core changes) - add new options for database cache and script verification threads - add label which displays options that are overridden by command-line parameters - proxy settings are not applied on-the-fly anymore and require a client restart (ApplyProxySettings() was removed and was not working very well anyway) - re-work options reset and require a client shutdown (as it is much easier to do it this way without having to mess with what can be changed on-the-fly and what needs a restart anyway) - options reset now writes default values for every single option - when changing an option which requires a client restart display a 10 second warning message in statusLabel (via a QTimer) - when applying the changes via ok change that to a persistent message, which is displayed even after closing optionsdialog and re-open it, when no client restart was made - remove dialog boxes used when changing language or proxy settings - add setRestartRequired() and isRestartRequired() to OptionsModel and use the set function when updating options to signal OptionsDialog when a restart is needed - resize optionsdialog a little and add some min sizes for certain GUI elements - remove apply button from optionsdialog - save and restore optionsdialog window position - update nTransactionFee in QSettings with a set -paytxfee value when opening optionsdialog (I'm not sure about this yet, perhaps revert to not updating QSettings and just display current -paytxfee value in optionsdialog.)
2013-12-03 09:10:10 +01:00
{
QSettings settings;
return settings.value("fRestartRequired", false).toBool();
}
2016-07-26 14:01:36 +02:00
void OptionsModel::checkAndMigrate()
{
// Migration of default values
// Check if the QSettings container was already loaded with this client version
QSettings settings;
static const char strSettingsVersionKey[] = "nSettingsVersion";
int settingsVersion = settings.contains(strSettingsVersionKey) ? settings.value(strSettingsVersionKey).toInt() : 0;
if (settingsVersion < CLIENT_VERSION)
{
// -dbcache was bumped from 100 to 300 in 0.13
// see https://github.com/bitcoin/bitcoin/pull/8273
// force people to upgrade to the new value if they are using 100MB
if (settingsVersion < 130000 && settings.contains("nDatabaseCache") && settings.value("nDatabaseCache").toLongLong() == 100)
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
settings.setValue(strSettingsVersionKey, CLIENT_VERSION);
}
// Overwrite the 'addrProxy' setting in case it has been set to an illegal
// default value (see issue #12623; PR #12650).
if (settings.contains("addrProxy") && settings.value("addrProxy").toString().endsWith("%2")) {
settings.setValue("addrProxy", GetDefaultProxyAddress());
}
// Overwrite the 'addrSeparateProxyTor' setting in case it has been set to an illegal
// default value (see issue #12623; PR #12650).
if (settings.contains("addrSeparateProxyTor") && settings.value("addrSeparateProxyTor").toString().endsWith("%2")) {
settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
}
// Migrate and delete legacy GUI settings that have now moved to <datadir>/settings.json.
auto migrate_setting = [&](OptionID option, const QString& qt_name) {
if (!settings.contains(qt_name)) return;
QVariant value = settings.value(qt_name);
if (node().getPersistentSetting(SettingName(option)).isNull()) {
if (option == ProxyIP) {
ProxySetting parsed = ParseProxyString(value.toString());
setOption(ProxyIP, parsed.ip);
setOption(ProxyPort, parsed.port);
} else if (option == ProxyIPTor) {
ProxySetting parsed = ParseProxyString(value.toString());
setOption(ProxyIPTor, parsed.ip);
setOption(ProxyPortTor, parsed.port);
} else {
setOption(option, value);
}
}
settings.remove(qt_name);
};
migrate_setting(DatabaseCache, "nDatabaseCache");
migrate_setting(ThreadsScriptVerif, "nThreadsScriptVerif");
#ifdef ENABLE_WALLET
migrate_setting(SpendZeroConfChange, "bSpendZeroConfChange");
migrate_setting(ExternalSignerPath, "external_signer_path");
#endif
migrate_setting(MapPortUPnP, "fUseUPnP");
migrate_setting(MapPortNatpmp, "fUseNatpmp");
migrate_setting(Listen, "fListen");
migrate_setting(Server, "server");
migrate_setting(PruneSize, "nPruneSize");
migrate_setting(Prune, "bPrune");
migrate_setting(ProxyIP, "addrProxy");
migrate_setting(ProxyUse, "fUseProxy");
migrate_setting(ProxyIPTor, "addrSeparateProxyTor");
migrate_setting(ProxyUseTor, "fUseSeparateProxyTor");
// In case migrating QSettings caused any settings value to change, rerun
// parameter interaction code to update other settings. This is particularly
// important for the -listen setting, which should cause -listenonion, -upnp,
// and other settings to default to false if it was set to false.
// (https://github.com/bitcoin-core/gui/issues/567).
node().initParameterInteraction();
2016-11-29 18:45:24 -08:00
}