2011-05-31 22:24:53 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "bitcoinunits.h"
|
2012-02-17 03:09:41 +01:00
|
|
|
#include <QSettings>
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2011-12-20 00:49:07 +01:00
|
|
|
#include "init.h"
|
2012-04-15 23:39:49 +02:00
|
|
|
#include "walletdb.h"
|
2012-05-01 18:44:11 +02:00
|
|
|
#include "guiutil.h"
|
2011-05-31 22:24:53 +02:00
|
|
|
|
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-02-17 03:09:41 +01:00
|
|
|
void OptionsModel::Init()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
// These are QT-only settings:
|
|
|
|
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();
|
2012-02-17 03:09:41 +01:00
|
|
|
|
|
|
|
// These are shared with core bitcoin; we want
|
|
|
|
// 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-04-17 23:03:24 +02:00
|
|
|
if (settings.contains("detachDB"))
|
|
|
|
SoftSetBoolArg("-detachdb", settings.value("detachDB").toBool());
|
2012-05-08 23:03:41 +02:00
|
|
|
if (!language.isEmpty())
|
|
|
|
SoftSetArg("-lang", language.toStdString());
|
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):
|
|
|
|
CWalletDB walletdb("wallet.dat");
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
addrProxy = addrProxyAddress;
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::ios_base::failure &e)
|
|
|
|
{
|
|
|
|
// 0.6.0rc1 saved this as a CService, which causes failure when parsing as a CAddress
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-02-17 03:09:41 +01:00
|
|
|
return settings.value("fUseUPnP", GetBoolArg("-upnp", true));
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeOnClose:
|
|
|
|
return QVariant(fMinimizeOnClose);
|
|
|
|
case ConnectSOCKS4:
|
2012-02-17 03:09:41 +01:00
|
|
|
return settings.value("fUseProxy", false);
|
2011-05-31 22:24:53 +02:00
|
|
|
case ProxyIP:
|
|
|
|
return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
|
|
|
|
case ProxyPort:
|
2012-01-17 09:34:24 +01:00
|
|
|
return QVariant(addrProxy.GetPort());
|
2011-05-31 22:24:53 +02:00
|
|
|
case Fee:
|
2011-07-26 13:08:34 +02:00
|
|
|
return QVariant(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-04-17 23:03:24 +02:00
|
|
|
case DetachDatabases:
|
|
|
|
return QVariant(fDetachDB);
|
2012-05-08 23:03:41 +02:00
|
|
|
case Language:
|
|
|
|
return settings.value("language", "");
|
2011-05-31 22:24:53 +02:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2012-02-17 03:09:41 +01:00
|
|
|
{
|
|
|
|
bool bUseUPnP = value.toBool();
|
|
|
|
settings.setValue("fUseUPnP", bUseUPnP);
|
|
|
|
MapPort(bUseUPnP);
|
|
|
|
}
|
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;
|
|
|
|
case ConnectSOCKS4:
|
|
|
|
fUseProxy = value.toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("fUseProxy", fUseProxy);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case ProxyIP:
|
|
|
|
{
|
2011-06-18 11:53:25 +02:00
|
|
|
// Use CAddress to parse and check IP
|
2012-01-17 09:27:03 +01:00
|
|
|
CNetAddr addr(value.toString().toStdString());
|
2012-01-03 23:33:31 +01:00
|
|
|
if (addr.IsValid())
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
2012-01-03 23:33:31 +01:00
|
|
|
addrProxy.SetIP(addr);
|
2012-02-26 23:39:32 +01:00
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-01 14:40:06 +02:00
|
|
|
successful = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ProxyPort:
|
|
|
|
{
|
|
|
|
int nPort = atoi(value.toString().toAscii().data());
|
2011-12-19 23:08:25 +01:00
|
|
|
if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max())
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
2012-01-03 23:33:31 +01:00
|
|
|
addrProxy.SetPort(nPort);
|
2012-02-26 23:39:32 +01:00
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str());
|
2011-06-07 18:59:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-01 14:40:06 +02:00
|
|
|
successful = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Fee: {
|
2011-07-26 13:08:34 +02:00
|
|
|
nTransactionFee = value.toLongLong();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("nTransactionFee", nTransactionFee);
|
2011-06-01 14:40:06 +02:00
|
|
|
}
|
|
|
|
break;
|
2011-07-29 14:36:35 +02:00
|
|
|
case DisplayUnit: {
|
|
|
|
int unit = value.toInt();
|
|
|
|
nDisplayUnit = unit;
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("nDisplayUnit", nDisplayUnit);
|
2011-07-29 14:36:35 +02:00
|
|
|
emit displayUnitChanged(unit);
|
|
|
|
}
|
2012-04-17 23:27:59 +02:00
|
|
|
break;
|
2011-07-30 17:42:02 +02:00
|
|
|
case DisplayAddresses: {
|
|
|
|
bDisplayAddresses = value.toBool();
|
2012-02-17 03:09:41 +01:00
|
|
|
settings.setValue("bDisplayAddresses", bDisplayAddresses);
|
2011-07-30 17:42:02 +02:00
|
|
|
}
|
2012-04-17 23:27:59 +02:00
|
|
|
break;
|
2012-04-17 23:03:24 +02:00
|
|
|
case DetachDatabases: {
|
|
|
|
fDetachDB = value.toBool();
|
|
|
|
settings.setValue("detachDB", fDetachDB);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-08 23:03:41 +02:00
|
|
|
case Language: {
|
|
|
|
settings.setValue("language", value);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
qint64 OptionsModel::getTransactionFee()
|
|
|
|
{
|
|
|
|
return nTransactionFee;
|
|
|
|
}
|
2011-06-01 14:40:06 +02:00
|
|
|
|
2011-06-05 14:19:57 +02:00
|
|
|
bool OptionsModel::getMinimizeToTray()
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
|
|
|
return fMinimizeToTray;
|
|
|
|
}
|
|
|
|
|
2011-06-05 14:19:57 +02:00
|
|
|
bool OptionsModel::getMinimizeOnClose()
|
2011-06-01 14:40:06 +02:00
|
|
|
{
|
|
|
|
return fMinimizeOnClose;
|
|
|
|
}
|
2011-07-29 14:36:35 +02:00
|
|
|
|
|
|
|
int OptionsModel::getDisplayUnit()
|
|
|
|
{
|
|
|
|
return nDisplayUnit;
|
|
|
|
}
|
2011-07-30 17:42:02 +02:00
|
|
|
|
|
|
|
bool OptionsModel::getDisplayAddresses()
|
|
|
|
{
|
|
|
|
return bDisplayAddresses;
|
|
|
|
}
|