2011-05-31 22:24:53 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-07-29 14:36:35 +02:00
|
|
|
#include "bitcoinunits.h"
|
2011-06-26 19:23:24 +02:00
|
|
|
|
|
|
|
#include "headers.h"
|
2011-12-20 00:49:07 +01:00
|
|
|
#include "init.h"
|
2011-05-31 22:24:53 +02:00
|
|
|
|
2011-06-26 19:23:24 +02:00
|
|
|
OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
|
|
|
|
QAbstractListModel(parent),
|
2011-07-29 14:36:35 +02:00
|
|
|
wallet(wallet),
|
2011-07-30 17:42:02 +02:00
|
|
|
nDisplayUnit(BitcoinUnits::BTC),
|
|
|
|
bDisplayAddresses(false)
|
2011-05-31 22:24:53 +02:00
|
|
|
{
|
2011-07-29 14:36:35 +02:00
|
|
|
// Read our specific settings from the wallet db
|
|
|
|
CWalletDB walletdb(wallet->strWalletFile);
|
|
|
|
walletdb.ReadSetting("nDisplayUnit", nDisplayUnit);
|
2011-07-30 17:42:02 +02:00
|
|
|
walletdb.ReadSetting("bDisplayAddresses", bDisplayAddresses);
|
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)
|
|
|
|
{
|
|
|
|
switch(index.row())
|
|
|
|
{
|
|
|
|
case StartAtStartup:
|
2011-12-20 00:49:07 +01:00
|
|
|
return QVariant(GetStartOnSystemStartup());
|
2011-05-31 22:24:53 +02:00
|
|
|
case MinimizeToTray:
|
|
|
|
return QVariant(fMinimizeToTray);
|
|
|
|
case MapPortUPnP:
|
|
|
|
return QVariant(fUseUPnP);
|
|
|
|
case MinimizeOnClose:
|
|
|
|
return QVariant(fMinimizeOnClose);
|
|
|
|
case ConnectSOCKS4:
|
|
|
|
return QVariant(fUseProxy);
|
|
|
|
case ProxyIP:
|
|
|
|
return QVariant(QString::fromStdString(addrProxy.ToStringIP()));
|
|
|
|
case ProxyPort:
|
|
|
|
return QVariant(QString::fromStdString(addrProxy.ToStringPort()));
|
|
|
|
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);
|
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)
|
|
|
|
{
|
2011-06-26 19:23:24 +02:00
|
|
|
CWalletDB walletdb(wallet->strWalletFile);
|
2011-06-01 14:40:06 +02:00
|
|
|
switch(index.row())
|
|
|
|
{
|
|
|
|
case StartAtStartup:
|
2011-12-20 00:49:07 +01:00
|
|
|
successful = SetStartOnSystemStartup(value.toBool());
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case MinimizeToTray:
|
|
|
|
fMinimizeToTray = value.toBool();
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case MapPortUPnP:
|
|
|
|
fUseUPnP = value.toBool();
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("fUseUPnP", fUseUPnP);
|
|
|
|
#ifdef USE_UPNP
|
|
|
|
MapPort(fUseUPnP);
|
|
|
|
#endif
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case MinimizeOnClose:
|
|
|
|
fMinimizeOnClose = value.toBool();
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
|
2011-06-01 14:40:06 +02:00
|
|
|
break;
|
|
|
|
case ConnectSOCKS4:
|
|
|
|
fUseProxy = value.toBool();
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("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);
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("addrProxy", addrProxy);
|
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);
|
2011-06-05 11:45:42 +02:00
|
|
|
walletdb.WriteSetting("addrProxy", addrProxy);
|
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();
|
|
|
|
walletdb.WriteSetting("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;
|
|
|
|
walletdb.WriteSetting("nDisplayUnit", nDisplayUnit);
|
|
|
|
emit displayUnitChanged(unit);
|
|
|
|
}
|
2011-07-30 17:42:02 +02:00
|
|
|
case DisplayAddresses: {
|
|
|
|
bDisplayAddresses = value.toBool();
|
|
|
|
walletdb.WriteSetting("bDisplayAddresses", bDisplayAddresses);
|
|
|
|
}
|
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;
|
|
|
|
}
|