]> Git Repo - VerusCoin.git/blame - src/qt/clientmodel.cpp
reduce spacing between "Add to address book as" and the text field
[VerusCoin.git] / src / qt / clientmodel.cpp
CommitLineData
18cab09a
WL
1#include "clientmodel.h"
2#include "main.h"
63760fa1 3#include "guiconstants.h"
92f20d53 4#include "optionsmodel.h"
2547f1f7 5#include "addresstablemodel.h"
467c31ea 6#include "transactiontablemodel.h"
18cab09a
WL
7
8#include <QTimer>
9
18cab09a 10ClientModel::ClientModel(QObject *parent) :
467c31ea
WL
11 QObject(parent), optionsModel(0), addressTableModel(0),
12 transactionTableModel(0)
18cab09a 13{
0f3981be
WL
14 // Until signal notifications is built into the bitcoin core,
15 // simply update everything after polling using a timer.
18cab09a
WL
16 QTimer *timer = new QTimer(this);
17 connect(timer, SIGNAL(timeout()), this, SLOT(update()));
18 timer->start(MODEL_UPDATE_DELAY);
92f20d53 19
2547f1f7
WL
20 optionsModel = new OptionsModel(this);
21 addressTableModel = new AddressTableModel(this);
467c31ea 22 transactionTableModel = new TransactionTableModel(this);
18cab09a
WL
23}
24
7df70c00 25qint64 ClientModel::getBalance() const
18cab09a
WL
26{
27 return GetBalance();
28}
29
7df70c00 30int ClientModel::getNumConnections() const
18cab09a
WL
31{
32 return vNodes.size();
33}
34
7df70c00 35int ClientModel::getNumBlocks() const
18cab09a
WL
36{
37 return nBestHeight;
38}
39
7df70c00 40int ClientModel::getNumTransactions() const
18cab09a 41{
dd8e82f7
WL
42 int numTransactions = 0;
43 CRITICAL_BLOCK(cs_mapWallet)
44 {
45 numTransactions = mapWallet.size();
46 }
47 return numTransactions;
18cab09a
WL
48}
49
50void ClientModel::update()
51{
0f3981be 52 // Plainly emit all signals for now. To be more efficient this should check
b9e80983
WL
53 // whether the values actually changed first, although it'd be even better if these
54 // were events coming in from the bitcoin core.
18cab09a 55 emit balanceChanged(getBalance());
18cab09a
WL
56 emit numConnectionsChanged(getNumConnections());
57 emit numBlocksChanged(getNumBlocks());
58 emit numTransactionsChanged(getNumTransactions());
6630c1cb 59
b9e80983 60 addressTableModel->update();
9d9a4e87
WL
61}
62
38deedc1 63ClientModel::StatusCode ClientModel::sendCoins(const QString &payTo, qint64 payAmount, const QString &addToAddressBookAs)
6630c1cb
WL
64{
65 uint160 hash160 = 0;
66 bool valid = false;
67
68 if(!AddressToHash160(payTo.toUtf8().constData(), hash160))
69 {
70 return InvalidAddress;
71 }
72
73 if(payAmount <= 0)
74 {
75 return InvalidAmount;
76 }
77
78 if(payAmount > getBalance())
79 {
80 return AmountExceedsBalance;
81 }
82
83 if((payAmount + nTransactionFee) > getBalance())
84 {
85 return AmountWithFeeExceedsBalance;
86 }
87
88 CRITICAL_BLOCK(cs_main)
89 {
90 // Send to bitcoin address
91 CWalletTx wtx;
92 CScript scriptPubKey;
93 scriptPubKey << OP_DUP << OP_HASH160 << hash160 << OP_EQUALVERIFY << OP_CHECKSIG;
94
95 std::string strError = SendMoney(scriptPubKey, payAmount, wtx, true);
96 if (strError == "")
8e86dca2 97 {
38deedc1 98 // OK
8e86dca2 99 }
6630c1cb 100 else if (strError == "ABORTED")
8e86dca2 101 {
6630c1cb 102 return Aborted;
8e86dca2 103 }
6630c1cb
WL
104 else
105 {
106 emit error(tr("Sending..."), QString::fromStdString(strError));
107 return MiscError;
108 }
109 }
38deedc1 110
c51f0512
WL
111 // Add addresses that we've sent to to the address book
112 std::string strAddress = payTo.toStdString();
113 CRITICAL_BLOCK(cs_mapAddressBook)
114 if (!mapAddressBook.count(strAddress))
38deedc1 115 SetAddressBookName(strAddress, addToAddressBookAs.toStdString());
6630c1cb
WL
116
117 return OK;
118}
119
7df70c00
WL
120bool ClientModel::inInitialBlockDownload() const
121{
122 return IsInitialBlockDownload();
123}
124
6cab6635
WL
125int ClientModel::getTotalBlocksEstimate() const
126{
127 return GetTotalBlocksEstimate();
128}
129
130
92f20d53
WL
131OptionsModel *ClientModel::getOptionsModel()
132{
2547f1f7
WL
133 return optionsModel;
134}
135
136AddressTableModel *ClientModel::getAddressTableModel()
137{
138 return addressTableModel;
92f20d53 139}
467c31ea
WL
140
141TransactionTableModel *ClientModel::getTransactionTableModel()
142{
143 return transactionTableModel;
144}
This page took 0.04009 seconds and 4 git commands to generate.