2013-11-04 16:20:43 +01:00
|
|
|
// Copyright (c) 2011-2013 The Bitcoin developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2013-05-28 01:55:01 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include "bitcoin-config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-05-31 22:24:53 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2013-01-23 21:51:02 +01:00
|
|
|
#include "bitcoinunits.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "guiutil.h"
|
|
|
|
|
2011-12-20 00:49:07 +01:00
|
|
|
#include "init.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "net.h"
|
2013-12-13 16:14:48 +01:00
|
|
|
#include "wallet.h"
|
2012-04-15 23:39:49 +02:00
|
|
|
#include "walletdb.h"
|
2011-05-31 22:24:53 +02:00
|
|
|
|
2013-01-23 21:51:02 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
2012-02-17 03:09:41 +01:00
|
|
|
OptionsModel::OptionsModel(QObject *parent) :
|
|
|
|
QAbstractListModel(parent)
|
2011-05-31 22:24:53 +02:00
|
|
|
{
|
2012-02-17 03:09:41 +01:00
|
|
|
Init();
|
2011-05-31 22:24:53 +02:00
|
|
|
}
|
|
|
|
|
2012-05-24 19:02:21 +02:00
|
|
|
bool static ApplyProxySettings()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
CService addrProxy(settings.value("addrProxy", "127.0.0.1:9050").toString().toStdString());
|
|
|
|
int nSocksVersion(settings.value("nSocksVersion", 5).toInt());
|
|
|
|
if (!settings.value("fUseProxy", false).toBool()) {
|
|
|
|
addrProxy = CService();
|
|
|
|
nSocksVersion = 0;
|
2012-06-08 15:21:55 +02:00
|
|
|
return false;
|
2012-05-24 19:02:21 +02:00
|
|
|
}
|
|
|
|
if (nSocksVersion && !addrProxy.IsValid())
|
|
|
|
return false;
|
|
|
|
if (!IsLimited(NET_IPV4))
|
|
|
|
SetProxy(NET_IPV4, addrProxy, nSocksVersion);
|
|
|
|
if (nSocksVersion > 4) {
|
|
|
|
#ifdef USE_IPV6
|
|
|
|
if (!IsLimited(NET_IPV6))
|
|
|
|
SetProxy(NET_IPV6, addrProxy, nSocksVersion);
|
|
|
|
#endif
|
|
|
|
SetNameProxy(addrProxy, nSocksVersion);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-17 03:09:41 +01:00
|
|
|
void OptionsModel::Init()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
2012-07-07 16:35:29 +02:00
|
|
|
// These are Qt-only settings:
|
2012-02-17 03:09:41 +01:00
|
|
|
nDisplayUnit = settings.value("nDisplayUnit", BitcoinUnits::BTC).toInt();
|
|
|
|
bDisplayAddresses = settings.value("bDisplayAddresses", false).toBool();
|
|
|
|
fMinimizeToTray = settings.value("fMinimizeToTray", false).toBool();
|
|
|
|
fMinimizeOnClose = settings.value("fMinimizeOnClose", false).toBool();
|
|
|
|
nTransactionFee = settings.value("nTransactionFee").toLongLong();
|
2012-05-08 23:03:41 +02:00
|
|
|
language = settings.value("language", "").toString();
|
2013-08-12 17:03:03 +02:00
|
|
|
fCoinControlFeatures = settings.value("fCoinControlFeatures", false).toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
|
2012-05-13 16:09:14 +02:00
|
|
|
// These are shared with core Bitcoin; we want
|
2012-02-17 03:09:41 +01:00
|
|
|
// command-line options to override the GUI settings:
|
|
|
|
if (settings.contains("fUseUPnP"))
|
|
|
|
SoftSetBoolArg("-upnp", settings.value("fUseUPnP").toBool());
|
|
|
|
if (settings.contains("addrProxy") && settings.value("fUseProxy").toBool())
|
|
|
|
SoftSetArg("-proxy", settings.value("addrProxy").toString().toStdString());
|
2012-06-08 15:21:55 +02:00
|
|
|
if (settings.contains("nSocksVersion") && settings.value("fUseProxy").toBool())
|
|
|
|
SoftSetArg("-socks", settings.value("nSocksVersion").toString().toStdString());
|
2012-05-08 23:03:41 +02:00
|
|
|
if (!language.isEmpty())
|
|
|
|
SoftSetArg("-lang", language.toStdString());
|
2012-02-17 03:09:41 +01:00
|
|
|
}
|
|
|
|
|
2012-08-18 15:54:39 +02:00
|
|
|
void OptionsModel::Reset()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
// Remove all entries in this QSettings object
|
|
|
|
settings.clear();
|
|
|
|
|
|
|
|
// default setting for OptionsModel::StartAtStartup - disabled
|
|
|
|
if (GUIUtil::GetStartOnSystemStartup())
|
|
|
|
GUIUtil::SetStartOnSystemStartup(false);
|
|
|
|
|
|
|
|
// Re-Init to get default values
|
|
|
|
Init();
|
|
|
|
|
|
|
|
// Ensure Upgrade() is not running again by setting the bImportFinished flag
|
|
|
|
settings.setValue("bImportFinished", true);
|
|
|
|
}
|
|
|
|
|
2012-02-17 03:09:41 +01:00
|
|
|
bool OptionsModel::Upgrade()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
if (settings.contains("bImportFinished"))
|
|
|
|
return false; // Already upgraded
|
|
|
|
|
|
|
|
settings.setValue("bImportFinished", true);
|
|
|
|
|
|
|
|
// Move settings from old wallet.dat (if any):
|
2012-06-03 01:19:07 +02:00
|
|
|
CWalletDB walletdb(strWalletFile);
|
2012-02-17 03:09:41 +01:00
|
|
|
|
|
|
|
QList<QString> intOptions;
|
|
|
|
intOptions << "nDisplayUnit" << "nTransactionFee";
|
|
|
|
foreach(QString key, intOptions)
|
|
|
|
{
|
|
|
|
int value = 0;
|
|
|
|
if (walletdb.ReadSetting(key.toStdString(), value))
|
|
|
|
{
|
|
|
|
settings.setValue(key, value);
|
|
|
|
walletdb.EraseSetting(key.toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QList<QString> boolOptions;
|
|
|
|
boolOptions << "bDisplayAddresses" << "fMinimizeToTray" << "fMinimizeOnClose" << "fUseProxy" << "fUseUPnP";
|
|
|
|
foreach(QString key, boolOptions)
|
|
|
|
{
|
|
|
|
bool value = false;
|
|
|
|
if (walletdb.ReadSetting(key.toStdString(), value))
|
|
|
|
{
|
|
|
|
settings.setValue(key, value);
|
|
|
|
walletdb.EraseSetting(key.toStdString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CAddress addrProxyAddress;
|
|
|
|
if (walletdb.ReadSetting("addrProxy", addrProxyAddress))
|
|
|
|
{
|
2012-05-24 19:02:21 +02:00
|
|
|
settings.setValue("addrProxy", addrProxyAddress.ToStringIPPort().c_str());
|
2012-02-17 03:09:41 +01:00
|
|
|
walletdb.EraseSetting("addrProxy");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::ios_base::failure &e)
|
|
|
|
{
|
|
|
|
// 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
|
2012-05-24 19:02:21 +02:00
|
|
|
CService addrProxy;
|
2012-02-17 03:09:41 +01:00
|
|
|
if (walletdb.ReadSetting("addrProxy", addrProxy))
|
|
|
|
{
|
2012-02-26 23:39:32 +01:00
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
|
2012-02-17 03:09:41 +01:00
|
|
|
walletdb.EraseSetting("addrProxy");
|
|
|
|
}
|
|
|
|
}
|
2012-05-24 19:02:21 +02:00
|
|
|
ApplyProxySettings();
|
2012-02-17 03:09:41 +01:00
|
|
|
Init();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-31 22:24:53 +02:00
|
|
|
int OptionsModel::rowCount(const QModelIndex & parent) const
|
|
|
|
{
|
|
|
|
return OptionIDRowCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2012-05-01 18:44:11 +02:00
|
|
|
return QVariant(GUIUtil::GetStartOnSystemStartup());
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeToTray:
|
|
|
|
return QVariant(fMinimizeToTray);
|
|
|
|
case MapPortUPnP:
|
2012-12-12 08:31:30 +01:00
|
|
|
#ifdef USE_UPNP
|
2012-02-17 03:09:41 +01:00
|
|
|
return settings.value("fUseUPnP", GetBoolArg("-upnp", true));
|
2012-12-12 08:31:30 +01:00
|
|
|
#else
|
|
|
|
return QVariant(false);
|
|
|
|
#endif
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeOnClose:
|
|
|
|
return QVariant(fMinimizeOnClose);
|
2012-10-02 13:30:44 +02:00
|
|
|
case ProxyUse: {
|
|
|
|
proxyType proxy;
|
|
|
|
return QVariant(GetProxy(NET_IPV4, proxy));
|
|
|
|
}
|
2012-05-24 19:02:21 +02:00
|
|
|
case ProxyIP: {
|
2012-09-23 12:55:05 +02:00
|
|
|
proxyType proxy;
|
|
|
|
if (GetProxy(NET_IPV4, proxy))
|
|
|
|
return QVariant(QString::fromStdString(proxy.first.ToStringIP()));
|
2012-05-24 19:02:21 +02:00
|
|
|
else
|
2012-06-04 23:13:01 +02:00
|
|
|
return QVariant(QString::fromStdString("127.0.0.1"));
|
2012-05-24 19:02:21 +02:00
|
|
|
}
|
|
|
|
case ProxyPort: {
|
2012-09-23 12:55:05 +02:00
|
|
|
proxyType proxy;
|
|
|
|
if (GetProxy(NET_IPV4, proxy))
|
|
|
|
return QVariant(proxy.first.GetPort());
|
2012-05-24 19:02:21 +02:00
|
|
|
else
|
2012-09-23 12:55:05 +02:00
|
|
|
return QVariant(9050);
|
2012-05-24 19:02:21 +02:00
|
|
|
}
|
2012-10-02 13:30:44 +02:00
|
|
|
case ProxySocksVersion: {
|
|
|
|
proxyType proxy;
|
|
|
|
if (GetProxy(NET_IPV4, proxy))
|
|
|
|
return QVariant(proxy.second);
|
|
|
|
else
|
|
|
|
return QVariant(5);
|
|
|
|
}
|
2011-05-31 22:24:53 +02:00
|
|
|
case Fee:
|
2013-04-13 07:13:08 +02:00
|
|
|
return QVariant((qint64) nTransactionFee);
|
2011-07-29 14:36:35 +02:00
|
|
|
case DisplayUnit:
|
|
|
|
return QVariant(nDisplayUnit);
|
2011-07-30 17:42:02 +02:00
|
|
|
case DisplayAddresses:
|
|
|
|
return QVariant(bDisplayAddresses);
|
2012-05-08 23:03:41 +02:00
|
|
|
case Language:
|
|
|
|
return settings.value("language", "");
|
2013-08-12 17:03:03 +02:00
|
|
|
case CoinControlFeatures:
|
|
|
|
return QVariant(fCoinControlFeatures);
|
2011-05-31 22:24:53 +02:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
2012-09-23 12:55:05 +02:00
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
case MapPortUPnP:
|
2013-03-07 04:31:26 +01:00
|
|
|
settings.setValue("fUseUPnP", value.toBool());
|
|
|
|
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;
|
2012-05-24 19:02:21 +02:00
|
|
|
case ProxyUse:
|
|
|
|
settings.setValue("fUseProxy", value.toBool());
|
2012-10-02 13:30:44 +02:00
|
|
|
successful = ApplyProxySettings();
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2012-09-23 12:55:05 +02:00
|
|
|
case ProxyIP: {
|
|
|
|
proxyType proxy;
|
|
|
|
proxy.first = CService("127.0.0.1", 9050);
|
|
|
|
GetProxy(NET_IPV4, proxy);
|
|
|
|
|
|
|
|
CNetAddr addr(value.toString().toStdString());
|
|
|
|
proxy.first.SetIP(addr);
|
|
|
|
settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str());
|
|
|
|
successful = ApplyProxySettings();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxyPort: {
|
|
|
|
proxyType proxy;
|
|
|
|
proxy.first = CService("127.0.0.1", 9050);
|
|
|
|
GetProxy(NET_IPV4, proxy);
|
|
|
|
|
|
|
|
proxy.first.SetPort(value.toInt());
|
|
|
|
settings.setValue("addrProxy", proxy.first.ToStringIPPort().c_str());
|
|
|
|
successful = ApplyProxySettings();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxySocksVersion: {
|
|
|
|
proxyType proxy;
|
|
|
|
proxy.second = 5;
|
|
|
|
GetProxy(NET_IPV4, proxy);
|
|
|
|
|
|
|
|
proxy.second = value.toInt();
|
|
|
|
settings.setValue("nSocksVersion", proxy.second);
|
|
|
|
successful = ApplyProxySettings();
|
|
|
|
}
|
|
|
|
break;
|
2012-07-09 13:40:22 +02:00
|
|
|
case Fee:
|
2011-07-26 13:08:34 +02:00
|
|
|
nTransactionFee = value.toLongLong();
|
2013-04-13 07:13:08 +02:00
|
|
|
settings.setValue("nTransactionFee", (qint64) nTransactionFee);
|
2013-08-12 17:03:03 +02:00
|
|
|
emit transactionFeeChanged(nTransactionFee);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
2012-07-09 13:40:22 +02:00
|
|
|
case DisplayUnit:
|
|
|
|
nDisplayUnit = value.toInt();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("nDisplayUnit", nDisplayUnit);
|
2012-07-09 13:40:22 +02:00
|
|
|
emit displayUnitChanged(nDisplayUnit);
|
2012-04-17 23:27:59 +02:00
|
|
|
break;
|
2012-07-09 13:40:22 +02:00
|
|
|
case DisplayAddresses:
|
2011-07-30 17:42:02 +02:00
|
|
|
bDisplayAddresses = value.toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("bDisplayAddresses", bDisplayAddresses);
|
2012-04-17 23:27:59 +02:00
|
|
|
break;
|
2012-07-09 13:40:22 +02:00
|
|
|
case Language:
|
2012-05-08 23:03:41 +02:00
|
|
|
settings.setValue("language", value);
|
|
|
|
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);
|
|
|
|
emit coinControlFeaturesChanged(fCoinControlFeatures);
|
2013-11-16 17:37:31 +01:00
|
|
|
break;
|
2011-06-01 14:40:06 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-05-31 22:24:53 +02:00
|
|
|
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
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
bool OptionsModel::getProxySettings(QString& proxyIP, quint16 &proxyPort) const
|
|
|
|
{
|
|
|
|
std::string proxy = GetArg("-proxy", "");
|
|
|
|
if (proxy.empty()) return false;
|
|
|
|
|
|
|
|
CService addrProxy(proxy);
|
|
|
|
proxyIP = QString(addrProxy.ToStringIP().c_str());
|
|
|
|
proxyPort = addrProxy.GetPort();
|
|
|
|
return true;
|
|
|
|
}
|