make initial block download reporting somewhat better by tracking version responses
[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(CWallet *wallet, QObject *parent) :
13     QObject(parent), wallet(wallet), optionsModel(0),
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     optionsModel = new OptionsModel(wallet, this);
23 }
24
25 int ClientModel::getNumConnections() const
26 {
27     return vNodes.size();
28 }
29
30 int ClientModel::getNumBlocks() const
31 {
32     return nBestHeight;
33 }
34
35 QDateTime ClientModel::getLastBlockDate() const
36 {
37     return QDateTime::fromTime_t(pindexBest->GetBlockTime());
38 }
39
40 void ClientModel::update()
41 {
42     int newNumConnections = getNumConnections();
43     int newNumBlocks = getNumBlocks();
44
45     if(cachedNumConnections != newNumConnections)
46         emit numConnectionsChanged(newNumConnections);
47     if(cachedNumBlocks != newNumBlocks)
48         emit numBlocksChanged(newNumBlocks);
49
50     cachedNumConnections = newNumConnections;
51     cachedNumBlocks = newNumBlocks;
52 }
53
54 bool ClientModel::isTestNet() const
55 {
56     return fTestNet;
57 }
58
59 bool ClientModel::inInitialBlockDownload() const
60 {
61     return IsInitialBlockDownload();
62 }
63
64 int ClientModel::getTotalBlocksEstimate() const
65 {
66     return GetTotalBlocksEstimate();
67 }
68
69 OptionsModel *ClientModel::getOptionsModel()
70 {
71     return optionsModel;
72 }
73
74 QString ClientModel::formatFullVersion() const
75 {
76     return QString::fromStdString(FormatFullVersion());
77 }