df7de2ecd2
Move some globals and all stuff pulling in crypto to the server/serverutil.cpp file Remove dead code. Move several items that were used in only one place to the respective files using them. Move the class WaitUntilFinishedHelper into its own file. Made sure no header includes utils.h remove a handfull of files including utils.h for nothing.
439 lines
16 KiB
C++
439 lines
16 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2011-2015 The Bitcoin Core developers
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include "config/flowee-config.h"
|
|
#endif
|
|
|
|
#include "optionsmodel.h"
|
|
|
|
#include "bitcoinunits.h"
|
|
#include "guiutil.h"
|
|
|
|
#include "amount.h"
|
|
#include "init.h"
|
|
#include "util.h"
|
|
#include "main.h" // For DEFAULT_SCRIPTCHECK_THREADS
|
|
#include "net.h"
|
|
#include "policy/policy.h" // for DEFAULT_BLOCK_ACCEPT_SIZE
|
|
#include <BlocksDB.h> // for -dbcache defaults
|
|
#include <Application.h>
|
|
#include <SettingsDefaults.h>
|
|
|
|
#ifdef ENABLE_WALLET
|
|
#include "wallet/wallet.h"
|
|
#include "wallet/walletdb.h"
|
|
#endif
|
|
|
|
#include <QNetworkProxy>
|
|
#include <QSettings>
|
|
#include <QStringList>
|
|
|
|
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) :
|
|
QAbstractListModel(parent)
|
|
{
|
|
Init(resetSettings);
|
|
}
|
|
|
|
void OptionsModel::addOverriddenOption(const std::string &option)
|
|
{
|
|
strOverriddenByCommandLine += QString::fromStdString(option) + "=" + QString::fromStdString(mapArgs[option]) + " ";
|
|
}
|
|
|
|
// Writes all missing QSettings with their default values
|
|
void OptionsModel::Init(bool resetSettings)
|
|
{
|
|
if (resetSettings)
|
|
Reset();
|
|
|
|
QSettings settings;
|
|
|
|
// Ensure restart flag is unset on client startup
|
|
setRestartRequired(false);
|
|
|
|
// These are Qt-only settings:
|
|
|
|
// Window
|
|
if (!settings.contains("fMinimizeToTray"))
|
|
settings.setValue("fMinimizeToTray", false);
|
|
fMinimizeToTray = settings.value("fMinimizeToTray").toBool();
|
|
|
|
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();
|
|
|
|
if (!settings.contains("strThirdPartyTxUrls"))
|
|
settings.setValue("strThirdPartyTxUrls", "");
|
|
strThirdPartyTxUrls = settings.value("strThirdPartyTxUrls", "").toString();
|
|
|
|
if (!settings.contains("fCoinControlFeatures"))
|
|
settings.setValue("fCoinControlFeatures", false);
|
|
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
|
|
|
|
// 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.
|
|
//
|
|
// If SoftSetArg() or SoftSetBoolArg() return false we were overridden
|
|
// by command-line and show this in the UI.
|
|
|
|
// Main
|
|
if (!settings.contains("blockSizeAcceptLimitBytes"))
|
|
settings.setValue("blockSizeAcceptLimitBytes", Settings::DefaultBlockAcceptSize);
|
|
if (mapArgs.count("-blocksizeacceptlimit"))
|
|
addOverriddenOption("-blocksizeacceptlimit");
|
|
else if (mapArgs.count("-blocksizeacceptlimitbytes"))
|
|
addOverriddenOption("-blocksizeacceptlimitbytes");
|
|
else if (mapArgs.count("-excessiveblocksize"))
|
|
addOverriddenOption("-excessiveblocksize");
|
|
else {
|
|
QVariant limit = settings.value("blockSizeAcceptLimitBytes");
|
|
bool ok;
|
|
int value = settings.value("blockSizeAcceptLimitBytes").toInt(&ok);
|
|
if (ok && value < 32000000)
|
|
limit = QVariant(32000000);
|
|
SoftSetArg("-blocksizeacceptlimitbytes", limit.toString().toStdString());
|
|
}
|
|
|
|
// Wallet
|
|
#ifdef ENABLE_WALLET
|
|
if (!settings.contains("bSpendZeroConfChange"))
|
|
settings.setValue("bSpendZeroConfChange", true);
|
|
if (!SoftSetBoolArg("-spendzeroconfchange", settings.value("bSpendZeroConfChange").toBool()))
|
|
addOverriddenOption("-spendzeroconfchange");
|
|
#endif
|
|
|
|
// Network
|
|
if (!settings.contains("fUseUPnP"))
|
|
settings.setValue("fUseUPnP", DEFAULT_UPNP);
|
|
if (!SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool()))
|
|
addOverriddenOption("-upnp");
|
|
|
|
if (!settings.contains("fListen"))
|
|
settings.setValue("fListen", DEFAULT_LISTEN);
|
|
if (!SoftSetBoolArg("-listen", settings.value("fListen").toBool()))
|
|
addOverriddenOption("-listen");
|
|
|
|
if (!settings.contains("fUseProxy"))
|
|
settings.setValue("fUseProxy", false);
|
|
if (!settings.contains("addrProxy"))
|
|
settings.setValue("addrProxy", "127.0.0.1:9050");
|
|
// Only try to set -proxy, if user has enabled fUseProxy
|
|
if (settings.value("fUseProxy").toBool() && !SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString()))
|
|
addOverriddenOption("-proxy");
|
|
else if(!settings.value("fUseProxy").toBool() && !GetArg("-proxy", "").empty())
|
|
addOverriddenOption("-proxy");
|
|
|
|
if (!settings.contains("fUseSeparateProxyTor"))
|
|
settings.setValue("fUseSeparateProxyTor", false);
|
|
if (!settings.contains("addrSeparateProxyTor"))
|
|
settings.setValue("addrSeparateProxyTor", "127.0.0.1:9050");
|
|
// Only try to set -onion, if user has enabled fUseSeparateProxyTor
|
|
if (settings.value("fUseSeparateProxyTor").toBool() && !SoftSetArg("-onion", settings.value("addrSeparateProxyTor").toString().toStdString()))
|
|
addOverriddenOption("-onion");
|
|
else if(!settings.value("fUseSeparateProxyTor").toBool() && !GetArg("-onion", "").empty())
|
|
addOverriddenOption("-onion");
|
|
|
|
// Display
|
|
if (!settings.contains("language"))
|
|
settings.setValue("language", "");
|
|
if (!SoftSetArg("-lang", settings.value("language").toString().toStdString()))
|
|
addOverriddenOption("-lang");
|
|
|
|
language = settings.value("language").toString();
|
|
}
|
|
|
|
void OptionsModel::Reset()
|
|
{
|
|
QSettings settings;
|
|
|
|
// Remove all entries from our QSettings object
|
|
settings.clear();
|
|
|
|
// default setting for OptionsModel::StartAtStartup - disabled
|
|
if (GUIUtil::GetStartOnSystemStartup())
|
|
GUIUtil::SetStartOnSystemStartup(false);
|
|
}
|
|
|
|
int OptionsModel::rowCount(const QModelIndex & parent) const
|
|
{
|
|
return OptionIDRowCount;
|
|
}
|
|
|
|
// read QSettings values and return them
|
|
QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
|
{
|
|
if(role == Qt::EditRole)
|
|
{
|
|
QSettings settings;
|
|
switch(index.row())
|
|
{
|
|
case StartAtStartup:
|
|
return GUIUtil::GetStartOnSystemStartup();
|
|
case MinimizeToTray:
|
|
return fMinimizeToTray;
|
|
case MapPortUPnP:
|
|
#ifdef USE_UPNP
|
|
return settings.value("fUseUPnP");
|
|
#else
|
|
return false;
|
|
#endif
|
|
case MinimizeOnClose:
|
|
return fMinimizeOnClose;
|
|
|
|
// default proxy
|
|
case ProxyUse:
|
|
return settings.value("fUseProxy", false);
|
|
case ProxyIP: {
|
|
// contains IP at index 0 and port at index 1
|
|
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
|
return strlIpPort.at(0);
|
|
}
|
|
case ProxyPort: {
|
|
// contains IP at index 0 and port at index 1
|
|
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
|
return strlIpPort.at(1);
|
|
}
|
|
|
|
// separate Tor proxy
|
|
case ProxyUseTor:
|
|
return settings.value("fUseSeparateProxyTor", false);
|
|
case ProxyIPTor: {
|
|
// contains IP at index 0 and port at index 1
|
|
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
|
|
return strlIpPort.at(0);
|
|
}
|
|
case ProxyPortTor: {
|
|
// contains IP at index 0 and port at index 1
|
|
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
|
|
return strlIpPort.at(1);
|
|
}
|
|
|
|
#ifdef ENABLE_WALLET
|
|
case SpendZeroConfChange:
|
|
return settings.value("bSpendZeroConfChange");
|
|
#endif
|
|
case DisplayUnit:
|
|
return nDisplayUnit;
|
|
case ThirdPartyTxUrls:
|
|
return strThirdPartyTxUrls;
|
|
case Language:
|
|
return settings.value("language");
|
|
case CoinControlFeatures:
|
|
return fCoinControlFeatures;
|
|
case Listen:
|
|
return settings.value("fListen");
|
|
case BlockSizeAcceptLimit:
|
|
return settings.value("blockSizeAcceptLimitBytes").toInt() / 1e6;
|
|
default:
|
|
return QVariant();
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
QSettings settings;
|
|
switch(index.row())
|
|
{
|
|
case StartAtStartup:
|
|
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
|
break;
|
|
case MinimizeToTray:
|
|
fMinimizeToTray = value.toBool();
|
|
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
|
break;
|
|
case MapPortUPnP: // core option - can be changed on-the-fly
|
|
settings.setValue("fUseUPnP", value.toBool());
|
|
MapPort(value.toBool());
|
|
break;
|
|
case MinimizeOnClose:
|
|
fMinimizeOnClose = value.toBool();
|
|
settings.setValue("fMinimizeOnClose", fMinimizeOnClose);
|
|
break;
|
|
|
|
// default proxy
|
|
case ProxyUse:
|
|
if (settings.value("fUseProxy") != value) {
|
|
settings.setValue("fUseProxy", value.toBool());
|
|
setRestartRequired(true);
|
|
}
|
|
break;
|
|
case ProxyIP: {
|
|
// contains current IP at index 0 and current port at index 1
|
|
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
|
// if that key doesn't exist or has a changed IP
|
|
if (!settings.contains("addrProxy") || strlIpPort.at(0) != value.toString()) {
|
|
// construct new value from new IP and current port
|
|
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
|
|
settings.setValue("addrProxy", strNewValue);
|
|
setRestartRequired(true);
|
|
}
|
|
}
|
|
break;
|
|
case ProxyPort: {
|
|
// contains current IP at index 0 and current port at index 1
|
|
QStringList strlIpPort = settings.value("addrProxy").toString().split(":", QString::SkipEmptyParts);
|
|
// if that key doesn't exist or has a changed port
|
|
if (!settings.contains("addrProxy") || strlIpPort.at(1) != value.toString()) {
|
|
// construct new value from current IP and new port
|
|
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
|
|
settings.setValue("addrProxy", strNewValue);
|
|
setRestartRequired(true);
|
|
}
|
|
}
|
|
break;
|
|
|
|
// separate Tor proxy
|
|
case ProxyUseTor:
|
|
if (settings.value("fUseSeparateProxyTor") != value) {
|
|
settings.setValue("fUseSeparateProxyTor", value.toBool());
|
|
setRestartRequired(true);
|
|
}
|
|
break;
|
|
case ProxyIPTor: {
|
|
// contains current IP at index 0 and current port at index 1
|
|
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
|
|
// if that key doesn't exist or has a changed IP
|
|
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(0) != value.toString()) {
|
|
// construct new value from new IP and current port
|
|
QString strNewValue = value.toString() + ":" + strlIpPort.at(1);
|
|
settings.setValue("addrSeparateProxyTor", strNewValue);
|
|
setRestartRequired(true);
|
|
}
|
|
}
|
|
break;
|
|
case ProxyPortTor: {
|
|
// contains current IP at index 0 and current port at index 1
|
|
QStringList strlIpPort = settings.value("addrSeparateProxyTor").toString().split(":", QString::SkipEmptyParts);
|
|
// if that key doesn't exist or has a changed port
|
|
if (!settings.contains("addrSeparateProxyTor") || strlIpPort.at(1) != value.toString()) {
|
|
// construct new value from current IP and new port
|
|
QString strNewValue = strlIpPort.at(0) + ":" + value.toString();
|
|
settings.setValue("addrSeparateProxyTor", strNewValue);
|
|
setRestartRequired(true);
|
|
}
|
|
}
|
|
break;
|
|
|
|
#ifdef ENABLE_WALLET
|
|
case SpendZeroConfChange:
|
|
if (settings.value("bSpendZeroConfChange") != value) {
|
|
settings.setValue("bSpendZeroConfChange", value);
|
|
setRestartRequired(true);
|
|
}
|
|
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 CoinControlFeatures:
|
|
fCoinControlFeatures = value.toBool();
|
|
settings.setValue("fCoinControlFeatures", fCoinControlFeatures);
|
|
Q_EMIT coinControlFeaturesChanged(fCoinControlFeatures);
|
|
break;
|
|
case Listen:
|
|
if (settings.value("fListen") != value) {
|
|
settings.setValue("fListen", value);
|
|
setRestartRequired(true);
|
|
}
|
|
break;
|
|
case BlockSizeAcceptLimit: {
|
|
int32_t valueBytes = round(value.toDouble() * 1e6);
|
|
if (settings.value("blockSizeAcceptLimitBytes") != valueBytes) {
|
|
settings.setValue("blockSizeAcceptLimitBytes", valueBytes);
|
|
setRestartRequired(true);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
Q_EMIT dataChanged(index, index);
|
|
|
|
return successful;
|
|
}
|
|
|
|
/** 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);
|
|
Q_EMIT displayUnitChanged(nDisplayUnit);
|
|
}
|
|
}
|
|
|
|
bool OptionsModel::getProxySettings(QNetworkProxy& proxy) const
|
|
{
|
|
// Directly query current base proxy, because
|
|
// GUI settings can be overridden with -proxy.
|
|
proxyType curProxy;
|
|
if (GetProxy(CNetAddr::NET_IPV4, curProxy)) {
|
|
proxy.setType(QNetworkProxy::Socks5Proxy);
|
|
proxy.setHostName(QString::fromStdString(curProxy.proxy.ToStringIP()));
|
|
proxy.setPort(curProxy.proxy.GetPort());
|
|
|
|
return true;
|
|
}
|
|
else
|
|
proxy.setType(QNetworkProxy::NoProxy);
|
|
|
|
return false;
|
|
}
|
|
|
|
void OptionsModel::setRestartRequired(bool fRequired)
|
|
{
|
|
QSettings settings;
|
|
return settings.setValue("fRestartRequired", fRequired);
|
|
}
|
|
|
|
bool OptionsModel::isRestartRequired()
|
|
{
|
|
QSettings settings;
|
|
return settings.value("fRestartRequired", false).toBool();
|
|
}
|