Display a "freshness" indicator instead of nr of blocks
[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 {
15     // Until signal notifications is built into the bitcoin core,
16     //  simply update everything after polling using a timer.
17     QTimer *timer = new QTimer(this);
18     connect(timer, SIGNAL(timeout()), this, SLOT(update()));
19     timer->start(MODEL_UPDATE_DELAY);
20
21     optionsModel = new OptionsModel(wallet, this);
22 }
23
24 int ClientModel::getNumConnections() const
25 {
26     return vNodes.size();
27 }
28
29 int ClientModel::getNumBlocks() const
30 {
31     return nBestHeight;
32 }
33
34 QDateTime ClientModel::getLastBlockDate() const
35 {
36     return QDateTime::fromTime_t(pindexBest->GetBlockTime());
37 }
38
39 void ClientModel::update()
40 {
41     // Plainly emit all signals for now. To be more efficient this should check
42     //   whether the values actually changed first, although it'd be even better if these
43     //   were events coming in from the bitcoin core.
44     emit numConnectionsChanged(getNumConnections());
45     emit numBlocksChanged(getNumBlocks());
46 }
47
48 bool ClientModel::isTestNet() const
49 {
50     return fTestNet;
51 }
52
53 bool ClientModel::inInitialBlockDownload() const
54 {
55     return IsInitialBlockDownload();
56 }
57
58 int ClientModel::getTotalBlocksEstimate() const
59 {
60     return GetTotalBlocksEstimate();
61 }
62
63 OptionsModel *ClientModel::getOptionsModel()
64 {
65     return optionsModel;
66 }
67
68 QString ClientModel::formatFullVersion() const
69 {
70     return QString::fromStdString(FormatFullVersion());
71 }