Changeset View
Changeset View
Standalone View
Standalone View
src/qt/optionsmodel.cpp
Show All 22 Lines | |||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
#include "wallet/walletdb.h" | #include "wallet/walletdb.h" | ||||
#endif | #endif | ||||
#include <QNetworkProxy> | #include <QNetworkProxy> | ||||
#include <QSettings> | #include <QSettings> | ||||
#include <QStringList> | #include <QStringList> | ||||
const char *DEFAULT_GUI_PROXY_HOST = "127.0.0.1"; | |||||
OptionsModel::OptionsModel(QObject *parent, bool resetSettings) | OptionsModel::OptionsModel(QObject *parent, bool resetSettings) | ||||
: QAbstractListModel(parent) { | : QAbstractListModel(parent) { | ||||
Init(resetSettings); | Init(resetSettings); | ||||
} | } | ||||
void OptionsModel::addOverriddenOption(const std::string &option) { | void OptionsModel::addOverriddenOption(const std::string &option) { | ||||
strOverriddenByCommandLine += | strOverriddenByCommandLine += | ||||
QString::fromStdString(option) + "=" + | QString::fromStdString(option) + "=" + | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | #endif | ||||
if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) { | if (!gArgs.SoftSetBoolArg("-listen", settings.value("fListen").toBool())) { | ||||
addOverriddenOption("-listen"); | addOverriddenOption("-listen"); | ||||
} | } | ||||
if (!settings.contains("fUseProxy")) { | if (!settings.contains("fUseProxy")) { | ||||
settings.setValue("fUseProxy", false); | settings.setValue("fUseProxy", false); | ||||
} | } | ||||
if (!settings.contains("addrProxy")) { | if (!settings.contains("addrProxy")) { | ||||
settings.setValue("addrProxy", "127.0.0.1:9050"); | settings.setValue("addrProxy", | ||||
QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, | |||||
DEFAULT_GUI_PROXY_PORT)); | |||||
} | } | ||||
// Only try to set -proxy, if user has enabled fUseProxy | // Only try to set -proxy, if user has enabled fUseProxy | ||||
if (settings.value("fUseProxy").toBool() && | if (settings.value("fUseProxy").toBool() && | ||||
!gArgs.SoftSetArg( | !gArgs.SoftSetArg( | ||||
"-proxy", settings.value("addrProxy").toString().toStdString())) { | "-proxy", settings.value("addrProxy").toString().toStdString())) { | ||||
addOverriddenOption("-proxy"); | addOverriddenOption("-proxy"); | ||||
} else if (!settings.value("fUseProxy").toBool() && | } else if (!settings.value("fUseProxy").toBool() && | ||||
!gArgs.GetArg("-proxy", "").empty()) { | !gArgs.GetArg("-proxy", "").empty()) { | ||||
addOverriddenOption("-proxy"); | addOverriddenOption("-proxy"); | ||||
} | } | ||||
if (!settings.contains("fUseSeparateProxyTor")) { | if (!settings.contains("fUseSeparateProxyTor")) { | ||||
settings.setValue("fUseSeparateProxyTor", false); | settings.setValue("fUseSeparateProxyTor", false); | ||||
} | } | ||||
if (!settings.contains("addrSeparateProxyTor")) { | if (!settings.contains("addrSeparateProxyTor")) { | ||||
settings.setValue("addrSeparateProxyTor", "127.0.0.1:9050"); | settings.setValue("addrSeparateProxyTor", | ||||
QString("%1:%2").arg(DEFAULT_GUI_PROXY_HOST, | |||||
DEFAULT_GUI_PROXY_PORT)); | |||||
} | } | ||||
// Only try to set -onion, if user has enabled fUseSeparateProxyTor | // Only try to set -onion, if user has enabled fUseSeparateProxyTor | ||||
if (settings.value("fUseSeparateProxyTor").toBool() && | if (settings.value("fUseSeparateProxyTor").toBool() && | ||||
!gArgs.SoftSetArg( | !gArgs.SoftSetArg( | ||||
"-onion", | "-onion", | ||||
settings.value("addrSeparateProxyTor").toString().toStdString())) { | settings.value("addrSeparateProxyTor").toString().toStdString())) { | ||||
addOverriddenOption("-onion"); | addOverriddenOption("-onion"); | ||||
} else if (!settings.value("fUseSeparateProxyTor").toBool() && | } else if (!settings.value("fUseSeparateProxyTor").toBool() && | ||||
Show All 34 Lines | if (GUIUtil::GetStartOnSystemStartup()) { | ||||
GUIUtil::SetStartOnSystemStartup(false); | GUIUtil::SetStartOnSystemStartup(false); | ||||
} | } | ||||
} | } | ||||
int OptionsModel::rowCount(const QModelIndex &parent) const { | int OptionsModel::rowCount(const QModelIndex &parent) const { | ||||
return OptionIDRowCount; | return OptionIDRowCount; | ||||
} | } | ||||
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); | |||||
} | |||||
// read QSettings values and return them | // read QSettings values and return them | ||||
QVariant OptionsModel::data(const QModelIndex &index, int role) const { | QVariant OptionsModel::data(const QModelIndex &index, int role) const { | ||||
if (role == Qt::EditRole) { | if (role == Qt::EditRole) { | ||||
QSettings settings; | QSettings settings; | ||||
switch (index.row()) { | switch (index.row()) { | ||||
case StartAtStartup: | case StartAtStartup: | ||||
return GUIUtil::GetStartOnSystemStartup(); | return GUIUtil::GetStartOnSystemStartup(); | ||||
case HideTrayIcon: | case HideTrayIcon: | ||||
return fHideTrayIcon; | return fHideTrayIcon; | ||||
case MinimizeToTray: | case MinimizeToTray: | ||||
return fMinimizeToTray; | return fMinimizeToTray; | ||||
case MapPortUPnP: | case MapPortUPnP: | ||||
#ifdef USE_UPNP | #ifdef USE_UPNP | ||||
return settings.value("fUseUPnP"); | return settings.value("fUseUPnP"); | ||||
#else | #else | ||||
return false; | return false; | ||||
#endif | #endif | ||||
case MinimizeOnClose: | case MinimizeOnClose: | ||||
return fMinimizeOnClose; | return fMinimizeOnClose; | ||||
// default proxy | // default proxy | ||||
case ProxyUse: | case ProxyUse: | ||||
return settings.value("fUseProxy", false); | return settings.value("fUseProxy", false); | ||||
case ProxyIP: { | case ProxyIP: | ||||
// contains IP at index 0 and port at index 1 | return GetProxySetting(settings, "addrProxy").ip; | ||||
QStringList strlIpPort = | case ProxyPort: | ||||
settings.value("addrProxy") | return GetProxySetting(settings, "addrProxy").port; | ||||
.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 | // separate Tor proxy | ||||
case ProxyUseTor: | case ProxyUseTor: | ||||
return settings.value("fUseSeparateProxyTor", false); | return settings.value("fUseSeparateProxyTor", false); | ||||
case ProxyIPTor: { | case ProxyIPTor: | ||||
// contains IP at index 0 and port at index 1 | return GetProxySetting(settings, "addrSeparateProxyTor").ip; | ||||
QStringList strlIpPort = | case ProxyPortTor: | ||||
settings.value("addrSeparateProxyTor") | return GetProxySetting(settings, "addrSeparateProxyTor").port; | ||||
.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 | #ifdef ENABLE_WALLET | ||||
case SpendZeroConfChange: | case SpendZeroConfChange: | ||||
return settings.value("bSpendZeroConfChange"); | return settings.value("bSpendZeroConfChange"); | ||||
#endif | #endif | ||||
case DisplayUnit: | case DisplayUnit: | ||||
return nDisplayUnit; | return nDisplayUnit; | ||||
case ThirdPartyTxUrls: | case ThirdPartyTxUrls: | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (role == Qt::EditRole) { | ||||
// default proxy | // default proxy | ||||
case ProxyUse: | case ProxyUse: | ||||
if (settings.value("fUseProxy") != value) { | if (settings.value("fUseProxy") != value) { | ||||
settings.setValue("fUseProxy", value.toBool()); | settings.setValue("fUseProxy", value.toBool()); | ||||
setRestartRequired(true); | setRestartRequired(true); | ||||
} | } | ||||
break; | break; | ||||
case ProxyIP: { | case ProxyIP: { | ||||
// contains current IP at index 0 and current port at index 1 | auto ip_port = GetProxySetting(settings, "addrProxy"); | ||||
QStringList strlIpPort = | if (!ip_port.is_set || ip_port.ip != value.toString()) { | ||||
settings.value("addrProxy") | ip_port.ip = value.toString(); | ||||
.toString() | SetProxySetting(settings, "addrProxy", ip_port); | ||||
.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); | setRestartRequired(true); | ||||
} | } | ||||
} break; | } break; | ||||
case ProxyPort: { | case ProxyPort: { | ||||
// contains current IP at index 0 and current port at index 1 | auto ip_port = GetProxySetting(settings, "addrProxy"); | ||||
QStringList strlIpPort = | if (!ip_port.is_set || ip_port.port != value.toString()) { | ||||
settings.value("addrProxy") | ip_port.port = value.toString(); | ||||
.toString() | SetProxySetting(settings, "addrProxy", ip_port); | ||||
.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); | setRestartRequired(true); | ||||
} | } | ||||
} break; | } break; | ||||
// separate Tor proxy | // separate Tor proxy | ||||
case ProxyUseTor: | case ProxyUseTor: | ||||
if (settings.value("fUseSeparateProxyTor") != value) { | if (settings.value("fUseSeparateProxyTor") != value) { | ||||
settings.setValue("fUseSeparateProxyTor", value.toBool()); | settings.setValue("fUseSeparateProxyTor", value.toBool()); | ||||
setRestartRequired(true); | setRestartRequired(true); | ||||
} | } | ||||
break; | break; | ||||
case ProxyIPTor: { | case ProxyIPTor: { | ||||
// contains current IP at index 0 and current port at index 1 | auto ip_port = | ||||
QStringList strlIpPort = | GetProxySetting(settings, "addrSeparateProxyTor"); | ||||
settings.value("addrSeparateProxyTor") | if (!ip_port.is_set || ip_port.ip != value.toString()) { | ||||
.toString() | ip_port.ip = value.toString(); | ||||
.split(":", QString::SkipEmptyParts); | SetProxySetting(settings, "addrSeparateProxyTor", ip_port); | ||||
// 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); | setRestartRequired(true); | ||||
} | } | ||||
} break; | } break; | ||||
case ProxyPortTor: { | case ProxyPortTor: { | ||||
// contains current IP at index 0 and current port at index 1 | auto ip_port = | ||||
QStringList strlIpPort = | GetProxySetting(settings, "addrSeparateProxyTor"); | ||||
settings.value("addrSeparateProxyTor") | if (!ip_port.is_set || ip_port.port != value.toString()) { | ||||
.toString() | ip_port.port = value.toString(); | ||||
.split(":", QString::SkipEmptyParts); | SetProxySetting(settings, "addrSeparateProxyTor", ip_port); | ||||
// 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); | setRestartRequired(true); | ||||
} | } | ||||
} break; | } break; | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
case SpendZeroConfChange: | case SpendZeroConfChange: | ||||
if (settings.value("bSpendZeroConfChange") != value) { | if (settings.value("bSpendZeroConfChange") != value) { | ||||
settings.setValue("bSpendZeroConfChange", value); | settings.setValue("bSpendZeroConfChange", value); | ||||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |