neobytes/gui/src/optionsmodel.cpp

135 lines
3.6 KiB
C++
Raw Normal View History

#include "optionsmodel.h"
#include "main.h"
2011-06-05 11:45:42 +02:00
#include "net.h"
#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)
{
bool successful = true; /* set to false on parse error */
if(role == Qt::EditRole)
{
2011-06-05 11:45:42 +02:00
CWalletDB walletdb;
switch(index.row())
{
case StartAtStartup:
successful = false; /*TODO*/
break;
case MinimizeToTray:
fMinimizeToTray = value.toBool();
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
break;
case MapPortUPnP:
fUseUPnP = value.toBool();
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("fUseUPnP", fUseUPnP);
#ifdef USE_UPNP
MapPort(fUseUPnP);
#endif
break;
case MinimizeOnClose:
fMinimizeOnClose = value.toBool();
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
break;
case ConnectSOCKS4:
fUseProxy = value.toBool();
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("fUseProxy", fUseProxy);
break;
case ProxyIP:
{
/* Use CAddress to parse IP */
CAddress addr(value.toString().toStdString() + ":1");
if (addr.ip != INADDR_NONE)
{
addrProxy.ip = addr.ip;
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("addrProxy", addrProxy);
} else {
successful = false;
}
}
break;
case ProxyPort:
{
int nPort = atoi(value.toString().toAscii().data());
if (nPort > 0 && nPort < USHRT_MAX)
{
addrProxy.port = htons(nPort);
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("addrProxy", addrProxy);
} else {
successful = false;
}
}
break;
case Fee: {
int64 retval;
if(ParseMoney(value.toString().toStdString(), retval))
{
nTransactionFee = retval;
2011-06-05 11:45:42 +02:00
walletdb.WriteSetting("nTransactionFee", nTransactionFee);
} else {
successful = false; /* parse error */
}
}
break;
default:
break;
}
}
emit dataChanged(index, index);
return successful;
}
2011-06-01 09:34:12 +02:00
qint64 OptionsModel::getTransactionFee()
{
return nTransactionFee;
}
bool getMinimizeToTray()
{
return fMinimizeToTray;
}
bool getMinimizeOnClose()
{
return fMinimizeOnClose;
}