2018-07-27 00:36:45 +02:00
|
|
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-05-28 01:55:01 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-05-28 01:55:01 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/optionsmodel.h>
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/bitcoinunits.h>
|
|
|
|
#include <qt/guiutil.h>
|
2013-04-13 07:13:08 +02:00
|
|
|
|
2018-04-07 09:42:02 +02:00
|
|
|
#include <interfaces/node.h>
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
|
|
|
|
#include <net.h>
|
|
|
|
#include <netbase.h>
|
|
|
|
#include <txdb.h> // for -dbcache defaults
|
2017-08-15 17:31:26 +02:00
|
|
|
#include <qt/intro.h>
|
2014-09-05 13:18:35 +02:00
|
|
|
|
2013-12-20 18:47:49 +01:00
|
|
|
#include <QNetworkProxy>
|
2013-01-23 21:51:02 +01:00
|
|
|
#include <QSettings>
|
2013-12-03 09:10:10 +01:00
|
|
|
#include <QStringList>
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2017-12-01 12:08:31 +01:00
|
|
|
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1";
|
|
|
|
|
2018-03-08 20:58:57 +01:00
|
|
|
static const QString GetDefaultProxyAddress();
|
|
|
|
|
2018-04-07 09:42:02 +02:00
|
|
|
OptionsModel::OptionsModel(interfaces::Node& node, QObject *parent, bool resetSettings) :
|
2017-04-17 20:23:14 +02:00
|
|
|
QAbstractListModel(parent), m_node(node)
|
2011-05-31 22:24:53 +02:00
|
|
|
{
|
2015-11-13 16:27:42 +01:00
|
|
|
Init(resetSettings);
|
2011-05-31 22:24:53 +02:00
|
|
|
}
|
|
|
|
|
2014-03-14 07:22:59 +01:00
|
|
|
void OptionsModel::addOverriddenOption(const std::string &option)
|
|
|
|
{
|
2017-08-01 21:17:40 +02:00
|
|
|
strOverriddenByCommandLine += QString::fromStdString(option) + "=" + QString::fromStdString(gArgs.GetArg(option, "")) + " ";
|
2014-03-14 07:22:59 +01:00
|
|
|
}
|
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
// Writes all missing QSettings with their default values
|
2015-11-13 16:27:42 +01:00
|
|
|
void OptionsModel::Init(bool resetSettings)
|
2012-02-17 03:09:41 +01:00
|
|
|
{
|
2015-11-13 16:27:42 +01:00
|
|
|
if (resetSettings)
|
|
|
|
Reset();
|
|
|
|
|
2016-07-26 14:01:36 +02:00
|
|
|
checkAndMigrate();
|
|
|
|
|
2012-02-17 03:09:41 +01:00
|
|
|
QSettings settings;
|
|
|
|
|
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:
|
2013-12-03 09:10:10 +01:00
|
|
|
|
|
|
|
// Window
|
2016-05-12 04:28:02 +02:00
|
|
|
if (!settings.contains("fHideTrayIcon"))
|
|
|
|
settings.setValue("fHideTrayIcon", false);
|
|
|
|
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
|
|
|
|
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
|
2018-07-24 17:59:49 +02:00
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
if (!settings.contains("fMinimizeToTray"))
|
|
|
|
settings.setValue("fMinimizeToTray", false);
|
2016-05-12 04:28:02 +02:00
|
|
|
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
|
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("nDisplayUnit"))
|
|
|
|
settings.setValue("nDisplayUnit", BitcoinUnits::BTC);
|
|
|
|
nDisplayUnit = settings.value("nDisplayUnit").toInt();
|
|
|
|
|
2014-04-24 22:21:45 +02:00
|
|
|
if (!settings.contains("strThirdPartyTxUrls"))
|
|
|
|
settings.setValue("strThirdPartyTxUrls", "");
|
|
|
|
strThirdPartyTxUrls = settings.value("strThirdPartyTxUrls", "").toString();
|
|
|
|
|
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-17 03:09:41 +01:00
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
// If setting doesn't exist create it with defaults.
|
|
|
|
//
|
2017-08-01 21:17:40 +02:00
|
|
|
// If gArgs.SoftSetArg() or gArgs.SoftSetBoolArg() return false we were overridden
|
2013-12-03 09:10:10 +01:00
|
|
|
// by command-line and show this in the UI.
|
|
|
|
|
|
|
|
// Main
|
2018-05-15 12:46:19 +02:00
|
|
|
if (!settings.contains("bPrune"))
|
|
|
|
settings.setValue("bPrune", false);
|
|
|
|
if (!settings.contains("nPruneSize"))
|
|
|
|
settings.setValue("nPruneSize", 2);
|
|
|
|
// Convert prune size to MB:
|
|
|
|
const uint64_t nPruneSizeMB = settings.value("nPruneSize").toInt() * 1000;
|
|
|
|
if (!m_node.softSetArg("-prune", settings.value("bPrune").toBool() ? std::to_string(nPruneSizeMB) : "0")) {
|
|
|
|
addOverriddenOption("-prune");
|
|
|
|
}
|
|
|
|
|
2014-02-18 12:48:16 +01:00
|
|
|
if (!settings.contains("nDatabaseCache"))
|
|
|
|
settings.setValue("nDatabaseCache", (qint64)nDefaultDbCache);
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetArg("-dbcache", settings.value("nDatabaseCache").toString().toStdString()))
|
2014-02-18 12:48:16 +01:00
|
|
|
addOverriddenOption("-dbcache");
|
|
|
|
|
|
|
|
if (!settings.contains("nThreadsScriptVerif"))
|
|
|
|
settings.setValue("nThreadsScriptVerif", DEFAULT_SCRIPTCHECK_THREADS);
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetArg("-par", settings.value("nThreadsScriptVerif").toString().toStdString()))
|
2014-02-18 12:48:16 +01:00
|
|
|
addOverriddenOption("-par");
|
|
|
|
|
2016-08-08 20:17:23 +02:00
|
|
|
if (!settings.contains("strDataDir"))
|
|
|
|
settings.setValue("strDataDir", Intro::getDefaultDataDirectory());
|
|
|
|
|
2014-02-18 12:48:16 +01:00
|
|
|
// Wallet
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2014-02-15 10:38:06 +01:00
|
|
|
if (!settings.contains("bSpendZeroConfChange"))
|
|
|
|
settings.setValue("bSpendZeroConfChange", true);
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool()))
|
2014-03-14 07:22:59 +01:00
|
|
|
addOverriddenOption("-spendzeroconfchange");
|
2013-12-11 15:00:56 +01:00
|
|
|
#endif
|
2013-12-03 09:10:10 +01:00
|
|
|
|
|
|
|
// Network
|
|
|
|
if (!settings.contains("fUseUPnP"))
|
2014-05-05 21:06:14 +02:00
|
|
|
settings.setValue("fUseUPnP", DEFAULT_UPNP);
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
2014-03-14 07:22:59 +01:00
|
|
|
addOverriddenOption("-upnp");
|
2013-12-03 09:10:10 +01:00
|
|
|
|
2014-05-29 13:02:22 +02:00
|
|
|
if (!settings.contains("fListen"))
|
|
|
|
settings.setValue("fListen", DEFAULT_LISTEN);
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetBoolArg("-listen", settings.value("fListen").toBool()))
|
2014-05-29 13:02:22 +02:00
|
|
|
addOverriddenOption("-listen");
|
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
if (!settings.contains("fUseProxy"))
|
|
|
|
settings.setValue("fUseProxy", false);
|
2017-12-01 12:08:31 +01:00
|
|
|
if (!settings.contains("addrProxy"))
|
2018-03-08 20:58:57 +01:00
|
|
|
settings.setValue("addrProxy", GetDefaultProxyAddress());
|
2013-12-03 09:10:10 +01:00
|
|
|
// Only try to set -proxy, if user has enabled fUseProxy
|
2017-04-17 20:23:14 +02:00
|
|
|
if (settings.value("fUseProxy").toBool() && !m_node.softSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
|
2014-03-14 07:22:59 +01:00
|
|
|
addOverriddenOption("-proxy");
|
2017-08-01 21:17:40 +02:00
|
|
|
else if(!settings.value("fUseProxy").toBool() && !gArgs.GetArg("-proxy", "").empty())
|
2014-09-25 03:53:19 +02:00
|
|
|
addOverriddenOption("-proxy");
|
2013-12-03 09:10:10 +01:00
|
|
|
|
2014-07-25 18:20:40 +02:00
|
|
|
if (!settings.contains("fUseSeparateProxyTor"))
|
|
|
|
settings.setValue("fUseSeparateProxyTor", false);
|
2017-12-01 12:08:31 +01:00
|
|
|
if (!settings.contains("addrSeparateProxyTor"))
|
2018-03-08 20:58:57 +01:00
|
|
|
settings.setValue("addrSeparateProxyTor", GetDefaultProxyAddress());
|
2014-07-25 18:20:40 +02:00
|
|
|
// Only try to set -onion, if user has enabled fUseSeparateProxyTor
|
2017-04-17 20:23:14 +02:00
|
|
|
if (settings.value("fUseSeparateProxyTor").toBool() && !m_node.softSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
|
2014-07-25 18:20:40 +02:00
|
|
|
addOverriddenOption("-onion");
|
2017-08-01 21:17:40 +02:00
|
|
|
else if(!settings.value("fUseSeparateProxyTor").toBool() && !gArgs.GetArg("-onion", "").empty())
|
2014-07-25 18:20:40 +02:00
|
|
|
addOverriddenOption("-onion");
|
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
// Display
|
|
|
|
if (!settings.contains("language"))
|
|
|
|
settings.setValue("language", "");
|
2017-04-17 20:23:14 +02:00
|
|
|
if (!m_node.softSetArg("-lang", settings.value("language").toString().toStdString()))
|
2014-03-14 07:22:59 +01:00
|
|
|
addOverriddenOption("-lang");
|
2013-12-03 09:10:10 +01:00
|
|
|
|
|
|
|
language = settings.value("language").toString();
|
2012-02-17 03:09:41 +01:00
|
|
|
}
|
|
|
|
|
2017-09-15 11:50:45 +02: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)
|
|
|
|
{
|
|
|
|
qWarning() << "Backing up GUI settings to" << GUIUtil::boostPathToQString(filename);
|
|
|
|
QSettings dst(GUIUtil::boostPathToQString(filename), QSettings::IniFormat);
|
|
|
|
dst.clear();
|
|
|
|
CopySettings(dst, src);
|
|
|
|
}
|
|
|
|
|
2012-08-18 15:54:39 +02:00
|
|
|
void OptionsModel::Reset()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
2017-09-15 11:50:45 +02:00
|
|
|
// Backup old settings to chain-specific datadir for troubleshooting
|
|
|
|
BackupSettings(GetDataDir(true) / "guisettings.ini.bak", settings);
|
|
|
|
|
2016-08-08 20:17:23 +02:00
|
|
|
// Save the strDataDir setting
|
|
|
|
QString dataDir = Intro::getDefaultDataDirectory();
|
|
|
|
dataDir = settings.value("strDataDir", dataDir).toString();
|
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
// Remove all entries from our QSettings object
|
2012-08-18 15:54:39 +02:00
|
|
|
settings.clear();
|
|
|
|
|
2016-08-08 20:17:23 +02:00
|
|
|
// Set strDataDir
|
|
|
|
settings.setValue("strDataDir", dataDir);
|
|
|
|
|
2016-08-10 21:35:22 +02:00
|
|
|
// Set that this was reset
|
|
|
|
settings.setValue("fReset", true);
|
|
|
|
|
2012-08-18 15:54:39 +02:00
|
|
|
// default setting for OptionsModel::StartAtStartup - disabled
|
|
|
|
if (GUIUtil::GetStartOnSystemStartup())
|
|
|
|
GUIUtil::SetStartOnSystemStartup(false);
|
2012-02-17 03:09:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-31 22:24:53 +02:00
|
|
|
int OptionsModel::rowCount(const QModelIndex & parent) const
|
|
|
|
{
|
|
|
|
return OptionIDRowCount;
|
|
|
|
}
|
|
|
|
|
2017-12-01 12:08:31 +01:00
|
|
|
struct ProxySetting {
|
|
|
|
bool is_set;
|
|
|
|
QString ip;
|
|
|
|
QString port;
|
|
|
|
};
|
|
|
|
|
|
|
|
static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
|
|
|
|
{
|
|
|
|
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 (!settings.contains(name)) {
|
|
|
|
return default_val;
|
|
|
|
}
|
|
|
|
// contains IP at index 0 and port at index 1
|
|
|
|
QStringList ip_port = settings.value(name).toString().split(":", QString::SkipEmptyParts);
|
|
|
|
if (ip_port.size() == 2) {
|
|
|
|
return {true, ip_port.at(0), ip_port.at(1)};
|
|
|
|
} else { // Invalid: return default
|
|
|
|
return default_val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port)
|
|
|
|
{
|
|
|
|
settings.setValue(name, ip_port.ip + ":" + ip_port.port);
|
|
|
|
}
|
|
|
|
|
2018-03-08 20:58:57 +01:00
|
|
|
static const QString GetDefaultProxyAddress()
|
|
|
|
{
|
|
|
|
return QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST).arg(DEFAULT_GUI_PROXY_PORT);
|
|
|
|
}
|
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
// read QSettings values and return them
|
2011-05-31 22:24:53 +02:00
|
|
|
QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
|
|
|
{
|
|
|
|
if(role == Qt::EditRole)
|
|
|
|
{
|
2012-02-17 03:09:41 +01:00
|
|
|
QSettings settings;
|
2011-05-31 22:24:53 +02:00
|
|
|
switch(index.row())
|
|
|
|
{
|
|
|
|
case StartAtStartup:
|
2013-12-03 09:10:10 +01:00
|
|
|
return GUIUtil::GetStartOnSystemStartup();
|
2016-05-12 04:28:02 +02:00
|
|
|
case HideTrayIcon:
|
|
|
|
return fHideTrayIcon;
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeToTray:
|
2013-12-03 09:10:10 +01:00
|
|
|
return fMinimizeToTray;
|
2011-05-31 22:24:53 +02:00
|
|
|
case MapPortUPnP:
|
2012-12-12 08:31:30 +01:00
|
|
|
#ifdef USE_UPNP
|
2013-12-03 09:10:10 +01:00
|
|
|
return settings.value("fUseUPnP");
|
2012-12-12 08:31:30 +01:00
|
|
|
#else
|
2013-12-03 09:10:10 +01:00
|
|
|
return false;
|
2012-12-12 08:31:30 +01:00
|
|
|
#endif
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeOnClose:
|
2013-12-03 09:10:10 +01:00
|
|
|
return fMinimizeOnClose;
|
|
|
|
|
|
|
|
// default proxy
|
|
|
|
case ProxyUse:
|
|
|
|
return settings.value("fUseProxy", false);
|
2017-12-01 12:08:31 +01:00
|
|
|
case ProxyIP:
|
|
|
|
return GetProxySetting(settings, "addrProxy").ip;
|
|
|
|
case ProxyPort:
|
|
|
|
return GetProxySetting(settings, "addrProxy").port;
|
2013-12-03 09:10:10 +01:00
|
|
|
|
2014-07-25 18:20:40 +02:00
|
|
|
// separate Tor proxy
|
|
|
|
case ProxyUseTor:
|
|
|
|
return settings.value("fUseSeparateProxyTor", false);
|
2017-12-01 12:08:31 +01:00
|
|
|
case ProxyIPTor:
|
|
|
|
return GetProxySetting(settings, "addrSeparateProxyTor").ip;
|
|
|
|
case ProxyPortTor:
|
|
|
|
return GetProxySetting(settings, "addrSeparateProxyTor").port;
|
2014-07-25 18:20:40 +02:00
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2014-02-15 10:38:06 +01:00
|
|
|
case SpendZeroConfChange:
|
|
|
|
return settings.value("bSpendZeroConfChange");
|
2013-12-11 15:00:56 +01:00
|
|
|
#endif
|
2011-07-29 14:36:35 +02:00
|
|
|
case DisplayUnit:
|
2013-12-03 09:10:10 +01:00
|
|
|
return nDisplayUnit;
|
2014-04-24 22:21:45 +02:00
|
|
|
case ThirdPartyTxUrls:
|
|
|
|
return strThirdPartyTxUrls;
|
2012-05-08 23:03:41 +02:00
|
|
|
case Language:
|
2013-12-03 09:10:10 +01:00
|
|
|
return settings.value("language");
|
2013-08-12 17:03:03 +02:00
|
|
|
case CoinControlFeatures:
|
2013-12-03 09:10:10 +01:00
|
|
|
return fCoinControlFeatures;
|
2018-05-15 12:46:19 +02:00
|
|
|
case Prune:
|
|
|
|
return settings.value("bPrune");
|
|
|
|
case PruneSize:
|
|
|
|
return settings.value("nPruneSize");
|
2013-12-03 09:10:10 +01:00
|
|
|
case DatabaseCache:
|
|
|
|
return settings.value("nDatabaseCache");
|
|
|
|
case ThreadsScriptVerif:
|
|
|
|
return settings.value("nThreadsScriptVerif");
|
2014-05-29 13:02:22 +02:00
|
|
|
case Listen:
|
|
|
|
return settings.value("fListen");
|
2011-05-31 22:24:53 +02:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
2012-09-23 12:55:05 +02:00
|
|
|
|
2013-12-03 09:10:10 +01:00
|
|
|
// write QSettings values
|
2011-05-31 22:24:53 +02:00
|
|
|
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
|
|
|
{
|
2011-06-01 14:40:06 +02:00
|
|
|
bool successful = true; /* set to false on parse error */
|
|
|
|
if(role == Qt::EditRole)
|
|
|
|
{
|
2012-02-17 03:09:41 +01:00
|
|
|
QSettings settings;
|
2011-06-01 14:40:06 +02:00
|
|
|
switch(index.row())
|
|
|
|
{
|
|
|
|
case StartAtStartup:
|
2012-05-01 18:44:11 +02:00
|
|
|
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2016-05-12 04:28:02 +02:00
|
|
|
case HideTrayIcon:
|
|
|
|
fHideTrayIcon = value.toBool();
|
|
|
|
settings.setValue("fHideTrayIcon", fHideTrayIcon);
|
|
|
|
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
|
|
|
|
break;
|
2011-06-01 14:40:06 +02:00
|
|
|
case MinimizeToTray:
|
|
|
|
fMinimizeToTray = value.toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2013-12-03 09:10:10 +01:00
|
|
|
case MapPortUPnP: // core option - can be changed on-the-fly
|
2013-03-07 04:31:26 +01:00
|
|
|
settings.setValue("fUseUPnP", value.toBool());
|
2017-04-17 20:23:14 +02:00
|
|
|
m_node.mapPort(value.toBool());
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case MinimizeOnClose:
|
|
|
|
fMinimizeOnClose = value.toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2013-12-03 09:10:10 +01:00
|
|
|
|
|
|
|
// default proxy
|
2012-05-24 19:02:21 +02:00
|
|
|
case ProxyUse:
|
2013-12-03 09:10:10 +01:00
|
|
|
if (settings.value("fUseProxy") != value) {
|
|
|
|
settings.setValue("fUseProxy", value.toBool());
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2012-09-23 12:55:05 +02:00
|
|
|
case ProxyIP: {
|
2017-12-01 12:08:31 +01:00
|
|
|
auto ip_port = GetProxySetting(settings, "addrProxy");
|
|
|
|
if (!ip_port.is_set || ip_port.ip != value.toString()) {
|
|
|
|
ip_port.ip = value.toString();
|
|
|
|
SetProxySetting(settings, "addrProxy", ip_port);
|
2013-12-03 09:10:10 +01:00
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
2012-09-23 12:55:05 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxyPort: {
|
2017-12-01 12:08:31 +01:00
|
|
|
auto ip_port = GetProxySetting(settings, "addrProxy");
|
|
|
|
if (!ip_port.is_set || ip_port.port != value.toString()) {
|
|
|
|
ip_port.port = value.toString();
|
|
|
|
SetProxySetting(settings, "addrProxy", ip_port);
|
2013-12-03 09:10:10 +01:00
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
2012-09-23 12:55:05 +02:00
|
|
|
}
|
|
|
|
break;
|
2014-07-25 18:20:40 +02:00
|
|
|
|
|
|
|
// separate Tor proxy
|
|
|
|
case ProxyUseTor:
|
|
|
|
if (settings.value("fUseSeparateProxyTor") != value) {
|
|
|
|
settings.setValue("fUseSeparateProxyTor", value.toBool());
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxyIPTor: {
|
2017-12-01 12:08:31 +01:00
|
|
|
auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
|
|
|
|
if (!ip_port.is_set || ip_port.ip != value.toString()) {
|
|
|
|
ip_port.ip = value.toString();
|
|
|
|
SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
|
2014-07-25 18:20:40 +02:00
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxyPortTor: {
|
2017-12-01 12:08:31 +01:00
|
|
|
auto ip_port = GetProxySetting(settings, "addrSeparateProxyTor");
|
|
|
|
if (!ip_port.is_set || ip_port.port != value.toString()) {
|
|
|
|
ip_port.port = value.toString();
|
|
|
|
SetProxySetting(settings, "addrSeparateProxyTor", ip_port);
|
2014-07-25 18:20:40 +02:00
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-12-11 15:00:56 +01:00
|
|
|
#ifdef ENABLE_WALLET
|
2014-02-15 10:38:06 +01:00
|
|
|
case SpendZeroConfChange:
|
|
|
|
if (settings.value("bSpendZeroConfChange") != value) {
|
|
|
|
settings.setValue("bSpendZeroConfChange", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
2013-12-11 15:00:56 +01:00
|
|
|
#endif
|
2012-07-09 13:40:22 +02:00
|
|
|
case DisplayUnit:
|
2014-06-07 08:20:22 +02:00
|
|
|
setDisplayUnit(value);
|
2012-04-17 23:27:59 +02:00
|
|
|
break;
|
2014-04-24 22:21:45 +02:00
|
|
|
case ThirdPartyTxUrls:
|
|
|
|
if (strThirdPartyTxUrls != value.toString()) {
|
|
|
|
strThirdPartyTxUrls = value.toString();
|
|
|
|
settings.setValue("strThirdPartyTxUrls", strThirdPartyTxUrls);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
2012-07-09 13:40:22 +02:00
|
|
|
case Language:
|
2013-12-03 09:10:10 +01:00
|
|
|
if (settings.value("language") != value) {
|
|
|
|
settings.setValue("language", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
2012-05-08 23:03:41 +02:00
|
|
|
break;
|
2013-11-16 17:37:31 +01:00
|
|
|
case CoinControlFeatures:
|
2013-08-12 17:03:03 +02:00
|
|
|
fCoinControlFeatures = value.toBool();
|
|
|
|
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT coinControlFeaturesChanged(fCoinControlFeatures);
|
2013-11-16 17:37:31 +01:00
|
|
|
break;
|
2018-05-15 12:46:19 +02:00
|
|
|
case Prune:
|
|
|
|
if (settings.value("bPrune") != value) {
|
|
|
|
settings.setValue("bPrune", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PruneSize:
|
|
|
|
if (settings.value("nPruneSize") != value) {
|
|
|
|
settings.setValue("nPruneSize", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
2013-12-03 09:10:10 +01:00
|
|
|
case DatabaseCache:
|
|
|
|
if (settings.value("nDatabaseCache") != value) {
|
|
|
|
settings.setValue("nDatabaseCache", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ThreadsScriptVerif:
|
|
|
|
if (settings.value("nThreadsScriptVerif") != value) {
|
|
|
|
settings.setValue("nThreadsScriptVerif", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
2014-05-29 13:02:22 +02:00
|
|
|
case Listen:
|
|
|
|
if (settings.value("fListen") != value) {
|
|
|
|
settings.setValue("fListen", value);
|
|
|
|
setRestartRequired(true);
|
|
|
|
}
|
|
|
|
break;
|
2011-06-01 14:40:06 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-07 08:20:22 +02:00
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT dataChanged(index, index);
|
2011-06-01 14:40:06 +02:00
|
|
|
|
|
|
|
return successful;
|
2011-05-31 22:24:53 +02:00
|
|
|
}
|
2011-06-01 09:34:12 +02:00
|
|
|
|
2014-06-07 08:20:22 +02:00
|
|
|
/** Updates current unit in memory, settings and emits displayUnitChanged(newUnit) signal */
|
|
|
|
void OptionsModel::setDisplayUnit(const QVariant &value)
|
|
|
|
{
|
|
|
|
if (!value.isNull())
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
nDisplayUnit = value.toInt();
|
|
|
|
settings.setValue("nDisplayUnit", nDisplayUnit);
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT displayUnitChanged(nDisplayUnit);
|
2014-06-07 08:20:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 18:47:49 +01:00
|
|
|
bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
|
2013-07-22 08:50:39 +02:00
|
|
|
{
|
2013-12-20 18:47:49 +01:00
|
|
|
// Directly query current base proxy, because
|
|
|
|
// GUI settings can be overridden with -proxy.
|
|
|
|
proxyType curProxy;
|
2017-04-17 20:23:14 +02:00
|
|
|
if (m_node.getProxy(NET_IPV4, curProxy)) {
|
2014-06-11 13:20:59 +02:00
|
|
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
2015-03-16 16:30:49 +01:00
|
|
|
proxy.setHostName(QString::fromStdString(curProxy.proxy.ToStringIP()));
|
|
|
|
proxy.setPort(curProxy.proxy.GetPort());
|
2013-12-20 18:47:49 +01:00
|
|
|
|
2014-06-11 13:20:59 +02:00
|
|
|
return true;
|
2013-12-20 18:47:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
proxy.setType(QNetworkProxy::NoProxy);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2014-06-11 13:20:59 +02:00
|
|
|
return false;
|
2013-07-22 08:50:39 +02:00
|
|
|
}
|
2013-12-03 09:10:10 +01:00
|
|
|
|
|
|
|
void OptionsModel::setRestartRequired(bool fRequired)
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
return settings.setValue("fRestartRequired", fRequired);
|
|
|
|
}
|
|
|
|
|
2017-03-09 13:34:54 +01:00
|
|
|
bool OptionsModel::isRestartRequired() const
|
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);
|
|
|
|
}
|
2018-03-08 20:58:57 +01:00
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
2016-11-30 03:45:24 +01:00
|
|
|
}
|