2011-05-22 11:19:43 -04:00
|
|
|
#include "clientmodel.h"
|
2011-05-28 14:32:19 -04:00
|
|
|
#include "guiconstants.h"
|
2011-05-31 16:24:53 -04:00
|
|
|
#include "optionsmodel.h"
|
2011-06-03 15:03:20 -04:00
|
|
|
#include "addresstablemodel.h"
|
2011-06-05 10:03:29 -04:00
|
|
|
#include "transactiontablemodel.h"
|
2011-05-22 11:19:43 -04:00
|
|
|
|
2011-06-26 13:23:24 -04:00
|
|
|
#include "headers.h"
|
|
|
|
|
2011-05-22 11:19:43 -04:00
|
|
|
#include <QTimer>
|
2011-07-08 12:05:10 -04:00
|
|
|
#include <QDateTime>
|
2011-05-22 11:19:43 -04:00
|
|
|
|
2011-07-29 08:36:35 -04:00
|
|
|
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
|
|
|
|
QObject(parent), optionsModel(optionsModel),
|
2011-07-17 08:06:43 -04:00
|
|
|
cachedNumConnections(0), cachedNumBlocks(0)
|
2011-05-22 11:19:43 -04:00
|
|
|
{
|
2011-06-18 05:53:25 -04:00
|
|
|
// Until signal notifications is built into the bitcoin core,
|
|
|
|
// simply update everything after polling using a timer.
|
2011-05-22 11:19:43 -04:00
|
|
|
QTimer *timer = new QTimer(this);
|
|
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
|
|
|
|
timer->start(MODEL_UPDATE_DELAY);
|
2011-09-10 06:43:45 -03:00
|
|
|
|
|
|
|
numBlocksAtStartup = -1;
|
2011-05-22 11:19:43 -04:00
|
|
|
}
|
|
|
|
|
2011-06-18 07:13:48 -04:00
|
|
|
int ClientModel::getNumConnections() const
|
2011-05-22 11:19:43 -04:00
|
|
|
{
|
|
|
|
return vNodes.size();
|
|
|
|
}
|
|
|
|
|
2011-06-18 07:13:48 -04:00
|
|
|
int ClientModel::getNumBlocks() const
|
2011-05-22 11:19:43 -04:00
|
|
|
{
|
|
|
|
return nBestHeight;
|
|
|
|
}
|
|
|
|
|
2011-09-10 06:43:45 -03:00
|
|
|
int ClientModel::getNumBlocksAtStartup()
|
|
|
|
{
|
|
|
|
if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks();
|
|
|
|
return numBlocksAtStartup;
|
|
|
|
}
|
|
|
|
|
2011-07-08 12:05:10 -04:00
|
|
|
QDateTime ClientModel::getLastBlockDate() const
|
|
|
|
{
|
|
|
|
return QDateTime::fromTime_t(pindexBest->GetBlockTime());
|
|
|
|
}
|
|
|
|
|
2011-05-22 11:19:43 -04:00
|
|
|
void ClientModel::update()
|
|
|
|
{
|
2011-07-17 08:06:43 -04:00
|
|
|
int newNumConnections = getNumConnections();
|
|
|
|
int newNumBlocks = getNumBlocks();
|
|
|
|
|
|
|
|
if(cachedNumConnections != newNumConnections)
|
|
|
|
emit numConnectionsChanged(newNumConnections);
|
|
|
|
if(cachedNumBlocks != newNumBlocks)
|
|
|
|
emit numBlocksChanged(newNumBlocks);
|
|
|
|
|
|
|
|
cachedNumConnections = newNumConnections;
|
|
|
|
cachedNumBlocks = newNumBlocks;
|
2011-05-30 14:20:12 -04:00
|
|
|
}
|
|
|
|
|
2011-06-30 13:14:42 -04:00
|
|
|
bool ClientModel::isTestNet() const
|
|
|
|
{
|
|
|
|
return fTestNet;
|
|
|
|
}
|
|
|
|
|
2011-06-18 07:13:48 -04:00
|
|
|
bool ClientModel::inInitialBlockDownload() const
|
|
|
|
{
|
|
|
|
return IsInitialBlockDownload();
|
|
|
|
}
|
|
|
|
|
2011-09-11 05:49:30 -03:00
|
|
|
int ClientModel::getNumBlocksOfPeers() const
|
2011-06-18 15:25:38 -04:00
|
|
|
{
|
2011-09-11 05:49:30 -03:00
|
|
|
return GetNumBlocksOfPeers();
|
2011-06-18 15:25:38 -04:00
|
|
|
}
|
|
|
|
|
2011-05-31 16:24:53 -04:00
|
|
|
OptionsModel *ClientModel::getOptionsModel()
|
|
|
|
{
|
2011-06-03 15:03:20 -04:00
|
|
|
return optionsModel;
|
|
|
|
}
|
|
|
|
|
2011-07-01 11:06:36 -04:00
|
|
|
QString ClientModel::formatFullVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(FormatFullVersion());
|
|
|
|
}
|