Build identification strings
[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 <QDateTime>
10
11 ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
12     QObject(parent), optionsModel(optionsModel),
13     cachedNumConnections(0), cachedNumBlocks(0)
14 {
15     numBlocksAtStartup = -1;
16 }
17
18 int ClientModel::getNumConnections() const
19 {
20     return vNodes.size();
21 }
22
23 int ClientModel::getNumBlocks() const
24 {
25     return nBestHeight;
26 }
27
28 int ClientModel::getNumBlocksAtStartup()
29 {
30     if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks();
31     return numBlocksAtStartup;
32 }
33
34 QDateTime ClientModel::getLastBlockDate() const
35 {
36     return QDateTime::fromTime_t(pindexBest->GetBlockTime());
37 }
38
39 void ClientModel::update()
40 {
41     int newNumConnections = getNumConnections();
42     int newNumBlocks = getNumBlocks();
43     QString newStatusBar = getStatusBarWarnings();
44
45     if(cachedNumConnections != newNumConnections)
46         emit numConnectionsChanged(newNumConnections);
47     if(cachedNumBlocks != newNumBlocks || cachedStatusBar != newStatusBar)
48     {
49         // Simply emit a numBlocksChanged for now in case the status message changes,
50         // so that the view updates the status bar.
51         // TODO: It should send a notification.
52         //    (However, this might generate looped notifications and needs to be thought through and tested carefully)
53         //    error(tr("Network Alert"), newStatusBar);
54         emit numBlocksChanged(newNumBlocks);
55     }
56
57     cachedNumConnections = newNumConnections;
58     cachedNumBlocks = newNumBlocks;
59     cachedStatusBar = newStatusBar;
60 }
61
62 bool ClientModel::isTestNet() const
63 {
64     return fTestNet;
65 }
66
67 bool ClientModel::inInitialBlockDownload() const
68 {
69     return IsInitialBlockDownload();
70 }
71
72 int ClientModel::getNumBlocksOfPeers() const
73 {
74     return GetNumBlocksOfPeers();
75 }
76
77 QString ClientModel::getStatusBarWarnings() const
78 {
79     return QString::fromStdString(GetWarnings("statusbar"));
80 }
81
82 OptionsModel *ClientModel::getOptionsModel()
83 {
84     return optionsModel;
85 }
86
87 QString ClientModel::formatFullVersion() const
88 {
89     return QString::fromStdString(FormatFullVersion());
90 }
91
92 QString ClientModel::formatBuildDate() const
93 {
94     return QString::fromStdString(CLIENT_DATE);
95 }