You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.8 KiB
141 lines
3.8 KiB
14 years ago
|
#include "optionsmodel.h"
|
||
|
#include "main.h"
|
||
14 years ago
|
#include "net.h"
|
||
14 years ago
|
|
||
|
#include <QDebug>
|
||
|
|
||
|
OptionsModel::OptionsModel(QObject *parent) :
|
||
|
QAbstractListModel(parent)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
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:
|
||
|
return QVariant();
|
||
|
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:
|
||
|
return QVariant(QString::fromStdString(FormatMoney(nTransactionFee)));
|
||
|
default:
|
||
|
return QVariant();
|
||
|
}
|
||
|
}
|
||
|
return QVariant();
|
||
|
}
|
||
|
|
||
|
bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, int role)
|
||
|
{
|
||
14 years ago
|
bool successful = true; /* set to false on parse error */
|
||
|
if(role == Qt::EditRole)
|
||
|
{
|
||
14 years ago
|
CWalletDB walletdb;
|
||
14 years ago
|
switch(index.row())
|
||
|
{
|
||
|
case StartAtStartup:
|
||
|
successful = false; /*TODO*/
|
||
|
break;
|
||
|
case MinimizeToTray:
|
||
|
fMinimizeToTray = value.toBool();
|
||
14 years ago
|
walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
|
||
14 years ago
|
break;
|
||
|
case MapPortUPnP:
|
||
|
fUseUPnP = value.toBool();
|
||
14 years ago
|
walletdb.WriteSetting("fUseUPnP", fUseUPnP);
|
||
|
#ifdef USE_UPNP
|
||
|
MapPort(fUseUPnP);
|
||
|
#endif
|
||
14 years ago
|
break;
|
||
|
case MinimizeOnClose:
|
||
|
fMinimizeOnClose = value.toBool();
|
||
14 years ago
|
walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
|
||
14 years ago
|
break;
|
||
|
case ConnectSOCKS4:
|
||
|
fUseProxy = value.toBool();
|
||
14 years ago
|
walletdb.WriteSetting("fUseProxy", fUseProxy);
|
||
14 years ago
|
break;
|
||
|
case ProxyIP:
|
||
|
{
|
||
|
/* Use CAddress to parse IP */
|
||
|
CAddress addr(value.toString().toStdString() + ":1");
|
||
|
if (addr.ip != INADDR_NONE)
|
||
|
{
|
||
|
addrProxy.ip = addr.ip;
|
||
14 years ago
|
walletdb.WriteSetting("addrProxy", addrProxy);
|
||
14 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
successful = false;
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
case ProxyPort:
|
||
|
{
|
||
|
int nPort = atoi(value.toString().toAscii().data());
|
||
|
if (nPort > 0 && nPort < USHRT_MAX)
|
||
|
{
|
||
|
addrProxy.port = htons(nPort);
|
||
14 years ago
|
walletdb.WriteSetting("addrProxy", addrProxy);
|
||
14 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
successful = false;
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
case Fee: {
|
||
|
int64 retval;
|
||
|
if(ParseMoney(value.toString().toStdString(), retval))
|
||
|
{
|
||
|
nTransactionFee = retval;
|
||
14 years ago
|
walletdb.WriteSetting("nTransactionFee", nTransactionFee);
|
||
14 years ago
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
successful = false; /* parse error */
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
emit dataChanged(index, index);
|
||
14 years ago
|
|
||
|
return successful;
|
||
14 years ago
|
}
|
||
14 years ago
|
|
||
|
qint64 OptionsModel::getTransactionFee()
|
||
|
{
|
||
|
return nTransactionFee;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
bool OptionsModel::getMinimizeToTray()
|
||
14 years ago
|
{
|
||
|
return fMinimizeToTray;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool OptionsModel::getMinimizeOnClose()
|
||
14 years ago
|
{
|
||
|
return fMinimizeOnClose;
|
||
|
}
|