|
|
|
@ -1,21 +1,94 @@
@@ -1,21 +1,94 @@
|
|
|
|
|
#include "optionsmodel.h" |
|
|
|
|
#include "bitcoinunits.h" |
|
|
|
|
#include <QSettings> |
|
|
|
|
|
|
|
|
|
#include "headers.h" |
|
|
|
|
#include "init.h" |
|
|
|
|
|
|
|
|
|
OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) : |
|
|
|
|
QAbstractListModel(parent), |
|
|
|
|
wallet(wallet), |
|
|
|
|
nDisplayUnit(BitcoinUnits::BTC), |
|
|
|
|
bDisplayAddresses(false) |
|
|
|
|
OptionsModel::OptionsModel(QObject *parent) : |
|
|
|
|
QAbstractListModel(parent) |
|
|
|
|
{ |
|
|
|
|
// Read our specific settings from the wallet db
|
|
|
|
|
CWalletDB walletdb(wallet->strWalletFile); |
|
|
|
|
walletdb.ReadSetting("nDisplayUnit", nDisplayUnit); |
|
|
|
|
walletdb.ReadSetting("bDisplayAddresses", bDisplayAddresses); |
|
|
|
|
Init(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
// 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()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); |
|
|
|
|
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)) |
|
|
|
|
{ |
|
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); |
|
|
|
|
walletdb.EraseSetting("addrProxy"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Init(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int OptionsModel::rowCount(const QModelIndex & parent) const |
|
|
|
|
{ |
|
|
|
|
return OptionIDRowCount; |
|
|
|
@ -25,6 +98,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
@@ -25,6 +98,7 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
|
|
|
|
{ |
|
|
|
|
if(role == Qt::EditRole) |
|
|
|
|
{ |
|
|
|
|
QSettings settings; |
|
|
|
|
switch(index.row()) |
|
|
|
|
{ |
|
|
|
|
case StartAtStartup: |
|
|
|
@ -32,11 +106,11 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
@@ -32,11 +106,11 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
|
|
|
|
case MinimizeToTray: |
|
|
|
|
return QVariant(fMinimizeToTray); |
|
|
|
|
case MapPortUPnP: |
|
|
|
|
return QVariant(fUseUPnP); |
|
|
|
|
return settings.value("fUseUPnP", GetBoolArg("-upnp", true)); |
|
|
|
|
case MinimizeOnClose: |
|
|
|
|
return QVariant(fMinimizeOnClose); |
|
|
|
|
case ConnectSOCKS4: |
|
|
|
|
return QVariant(fUseProxy); |
|
|
|
|
return settings.value("fUseProxy", false); |
|
|
|
|
case ProxyIP: |
|
|
|
|
return QVariant(QString::fromStdString(addrProxy.ToStringIP())); |
|
|
|
|
case ProxyPort: |
|
|
|
@ -59,7 +133,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
@@ -59,7 +133,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|
|
|
|
bool successful = true; /* set to false on parse error */ |
|
|
|
|
if(role == Qt::EditRole) |
|
|
|
|
{ |
|
|
|
|
CWalletDB walletdb(wallet->strWalletFile); |
|
|
|
|
QSettings settings; |
|
|
|
|
switch(index.row()) |
|
|
|
|
{ |
|
|
|
|
case StartAtStartup: |
|
|
|
@ -67,22 +141,22 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
@@ -67,22 +141,22 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|
|
|
|
break; |
|
|
|
|
case MinimizeToTray: |
|
|
|
|
fMinimizeToTray = value.toBool(); |
|
|
|
|
walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray); |
|
|
|
|
settings.setValue("fMinimizeToTray", fMinimizeToTray); |
|
|
|
|
break; |
|
|
|
|
case MapPortUPnP: |
|
|
|
|
fUseUPnP = value.toBool(); |
|
|
|
|
walletdb.WriteSetting("fUseUPnP", fUseUPnP); |
|
|
|
|
#ifdef USE_UPNP |
|
|
|
|
MapPort(fUseUPnP); |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
bool bUseUPnP = value.toBool(); |
|
|
|
|
settings.setValue("fUseUPnP", bUseUPnP); |
|
|
|
|
MapPort(bUseUPnP); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case MinimizeOnClose: |
|
|
|
|
fMinimizeOnClose = value.toBool(); |
|
|
|
|
walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose); |
|
|
|
|
settings.setValue("fMinimizeOnClose", fMinimizeOnClose); |
|
|
|
|
break; |
|
|
|
|
case ConnectSOCKS4: |
|
|
|
|
fUseProxy = value.toBool(); |
|
|
|
|
walletdb.WriteSetting("fUseProxy", fUseProxy); |
|
|
|
|
settings.setValue("fUseProxy", fUseProxy); |
|
|
|
|
break; |
|
|
|
|
case ProxyIP: |
|
|
|
|
{ |
|
|
|
@ -91,7 +165,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
@@ -91,7 +165,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|
|
|
|
if (addr.IsValid()) |
|
|
|
|
{ |
|
|
|
|
addrProxy.SetIP(addr); |
|
|
|
|
walletdb.WriteSetting("addrProxy", addrProxy); |
|
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -105,7 +179,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
@@ -105,7 +179,7 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|
|
|
|
if (nPort > 0 && nPort < std::numeric_limits<unsigned short>::max()) |
|
|
|
|
{ |
|
|
|
|
addrProxy.SetPort(nPort); |
|
|
|
|
walletdb.WriteSetting("addrProxy", addrProxy); |
|
|
|
|
settings.setValue("addrProxy", addrProxy.ToStringIPPort().c_str()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -115,18 +189,18 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
@@ -115,18 +189,18 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
|
|
|
|
break; |
|
|
|
|
case Fee: { |
|
|
|
|
nTransactionFee = value.toLongLong(); |
|
|
|
|
walletdb.WriteSetting("nTransactionFee", nTransactionFee); |
|
|
|
|
settings.setValue("nTransactionFee", nTransactionFee); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case DisplayUnit: { |
|
|
|
|
int unit = value.toInt(); |
|
|
|
|
nDisplayUnit = unit; |
|
|
|
|
walletdb.WriteSetting("nDisplayUnit", nDisplayUnit); |
|
|
|
|
settings.setValue("nDisplayUnit", nDisplayUnit); |
|
|
|
|
emit displayUnitChanged(unit); |
|
|
|
|
} |
|
|
|
|
case DisplayAddresses: { |
|
|
|
|
bDisplayAddresses = value.toBool(); |
|
|
|
|
walletdb.WriteSetting("bDisplayAddresses", bDisplayAddresses); |
|
|
|
|
settings.setValue("bDisplayAddresses", bDisplayAddresses); |
|
|
|
|
} |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|