Fix status bar not displaying Alerts.
[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     numBlocksAtStartup = -1;
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 int ClientModel::getNumBlocksAtStartup()
36 {
37     if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks();
38     return numBlocksAtStartup;
39 }
40
41 QDateTime ClientModel::getLastBlockDate() const
42 {
43     return QDateTime::fromTime_t(pindexBest->GetBlockTime());
44 }
45
46 void ClientModel::update()
47 {
48     int newNumConnections = getNumConnections();
49     int newNumBlocks = getNumBlocks();
50
51     if(cachedNumConnections != newNumConnections)
52         emit numConnectionsChanged(newNumConnections);
53     if(cachedNumBlocks != newNumBlocks)
54         emit numBlocksChanged(newNumBlocks);
55
56     cachedNumConnections = newNumConnections;
57     cachedNumBlocks = newNumBlocks;
58 }
59
60 bool ClientModel::isTestNet() const
61 {
62     return fTestNet;
63 }
64
65 bool ClientModel::inInitialBlockDownload() const
66 {
67     return IsInitialBlockDownload();
68 }
69
70 int ClientModel::getNumBlocksOfPeers() const
71 {
72     return GetNumBlocksOfPeers();
73 }
74
75 QString ClientModel::getStatusBarWarnings() const
76 {
77     return QString::fromStdString(GetWarnings("statusbar"));
78 }
79
80 OptionsModel *ClientModel::getOptionsModel()
81 {
82     return optionsModel;
83 }
84
85 QString ClientModel::formatFullVersion() const
86 {
87     return QString::fromStdString(FormatFullVersion());
88 }