aboutsummaryrefslogtreecommitdiff
path: root/src/qt/optionsmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/optionsmodel.cpp')
-rw-r--r--src/qt/optionsmodel.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
new file mode 100644
index 0000000000..896170975e
--- /dev/null
+++ b/src/qt/optionsmodel.cpp
@@ -0,0 +1,133 @@
+#include "optionsmodel.h"
+
+#include "headers.h"
+
+#include <QDebug>
+
+OptionsModel::OptionsModel(CWallet *wallet, QObject *parent) :
+ QAbstractListModel(parent),
+ wallet(wallet)
+{
+}
+
+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(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)
+ {
+ CWalletDB walletdb(wallet->strWalletFile);
+ switch(index.row())
+ {
+ case StartAtStartup:
+ successful = false; /*TODO*/
+ break;
+ case MinimizeToTray:
+ fMinimizeToTray = value.toBool();
+ walletdb.WriteSetting("fMinimizeToTray", fMinimizeToTray);
+ break;
+ case MapPortUPnP:
+ fUseUPnP = value.toBool();
+ walletdb.WriteSetting("fUseUPnP", fUseUPnP);
+#ifdef USE_UPNP
+ MapPort(fUseUPnP);
+#endif
+ break;
+ case MinimizeOnClose:
+ fMinimizeOnClose = value.toBool();
+ walletdb.WriteSetting("fMinimizeOnClose", fMinimizeOnClose);
+ break;
+ case ConnectSOCKS4:
+ fUseProxy = value.toBool();
+ walletdb.WriteSetting("fUseProxy", fUseProxy);
+ break;
+ case ProxyIP:
+ {
+ // Use CAddress to parse and check IP
+ CAddress addr(value.toString().toStdString() + ":1");
+ if (addr.ip != INADDR_NONE)
+ {
+ addrProxy.ip = addr.ip;
+ 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);
+ walletdb.WriteSetting("addrProxy", addrProxy);
+ }
+ else
+ {
+ successful = false;
+ }
+ }
+ break;
+ case Fee: {
+ nTransactionFee = value.toLongLong();
+ walletdb.WriteSetting("nTransactionFee", nTransactionFee);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ emit dataChanged(index, index);
+
+ return successful;
+}
+
+qint64 OptionsModel::getTransactionFee()
+{
+ return nTransactionFee;
+}
+
+bool OptionsModel::getMinimizeToTray()
+{
+ return fMinimizeToTray;
+}
+
+bool OptionsModel::getMinimizeOnClose()
+{
+ return fMinimizeOnClose;
+}