Full support for other units, add configuration option for default unit (used when...
[novacoin.git] / src / qt / clientmodel.cpp
1 #include "clientmodel.h"
2 #include "guiconstants.h"
3 #include "optionsmodel.h"
4 #include "addresstablemodel.h"
5 #include "transactiontablemodel.h"
6
7 #include "headers.h"
8
9 #include <QTimer>
10 #include <QDateTime>
11
12 ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
13     QObject(parent), optionsModel(optionsModel),
14     cachedNumConnections(0), cachedNumBlocks(0)
15 {
16     // Until signal notifications is built into the bitcoin core,
17     //  simply update everything after polling using a timer.
18     QTimer *timer = new QTimer(this);
19     connect(timer, SIGNAL(timeout()), this, SLOT(update()));
20     timer->start(MODEL_UPDATE_DELAY);
21 }
22
23 int ClientModel::getNumConnections() const
24 {
25     return vNodes.size();
26 }
27
28 int ClientModel::getNumBlocks() const
29 {
30     return nBestHeight;
31 }
32
33 QDateTime ClientModel::getLastBlockDate() const
34 {
35     return QDateTime::fromTime_t(pindexBest->GetBlockTime());
36 }
37
38 void ClientModel::update()
39 {
40     int newNumConnections = getNumConnections();
41     int newNumBlocks = getNumBlocks();
42
43     if(cachedNumConnections != newNumConnections)
44         emit numConnectionsChanged(newNumConnections);
45     if(cachedNumBlocks != newNumBlocks)
46         emit numBlocksChanged(newNumBlocks);
47
48     cachedNumConnections = newNumConnections;
49     cachedNumBlocks = newNumBlocks;
50 }
51
52 bool ClientModel::isTestNet() const
53 {
54     return fTestNet;
55 }
56
57 bool ClientModel::inInitialBlockDownload() const
58 {
59     return IsInitialBlockDownload();
60 }
61
62 int ClientModel::getTotalBlocksEstimate() const
63 {
64     return GetTotalBlocksEstimate();
65 }
66
67 OptionsModel *ClientModel::getOptionsModel()
68 {
69     return optionsModel;
70 }
71
72 QString ClientModel::formatFullVersion() const
73 {
74     return QString::fromStdString(FormatFullVersion());
75 }