2011-05-22 17:19:43 +02:00
|
|
|
#include "clientmodel.h"
|
2011-05-28 20:32:19 +02:00
|
|
|
#include "guiconstants.h"
|
2011-05-31 22:24:53 +02:00
|
|
|
#include "optionsmodel.h"
|
2011-06-03 21:03:20 +02:00
|
|
|
#include "addresstablemodel.h"
|
2011-06-05 16:03:29 +02:00
|
|
|
#include "transactiontablemodel.h"
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2012-04-15 22:10:54 +02:00
|
|
|
#include "main.h"
|
2012-05-05 16:07:14 +02:00
|
|
|
#include "ui_interface.h"
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2011-07-08 18:05:10 +02:00
|
|
|
#include <QDateTime>
|
2012-05-05 16:07:14 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
static const int64 nClientStartupTime = GetTime();
|
2011-05-22 17:19:43 +02:00
|
|
|
|
2011-07-29 14:36:35 +02:00
|
|
|
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
|
|
|
|
QObject(parent), optionsModel(optionsModel),
|
2012-05-05 16:07:14 +02:00
|
|
|
cachedNumBlocks(0), cachedNumBlocksOfPeers(0), pollTimer(0)
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2011-09-10 11:43:45 +02:00
|
|
|
numBlocksAtStartup = -1;
|
2012-05-05 16:07:14 +02:00
|
|
|
|
|
|
|
pollTimer = new QTimer();
|
|
|
|
pollTimer->setInterval(MODEL_UPDATE_DELAY);
|
|
|
|
pollTimer->start();
|
|
|
|
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
|
2011-05-22 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2011-06-18 13:13:48 +02:00
|
|
|
int ClientModel::getNumConnections() const
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
|
|
|
return vNodes.size();
|
|
|
|
}
|
|
|
|
|
2011-06-18 13:13:48 +02:00
|
|
|
int ClientModel::getNumBlocks() const
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
|
|
|
return nBestHeight;
|
|
|
|
}
|
|
|
|
|
2011-09-10 11:43:45 +02:00
|
|
|
int ClientModel::getNumBlocksAtStartup()
|
|
|
|
{
|
|
|
|
if (numBlocksAtStartup == -1) numBlocksAtStartup = getNumBlocks();
|
|
|
|
return numBlocksAtStartup;
|
|
|
|
}
|
|
|
|
|
2011-07-08 18:05:10 +02:00
|
|
|
QDateTime ClientModel::getLastBlockDate() const
|
|
|
|
{
|
|
|
|
return QDateTime::fromTime_t(pindexBest->GetBlockTime());
|
|
|
|
}
|
|
|
|
|
2012-05-05 16:07:14 +02:00
|
|
|
void ClientModel::updateTimer()
|
2011-05-22 17:19:43 +02:00
|
|
|
{
|
2012-05-05 16:07:14 +02:00
|
|
|
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change.
|
|
|
|
// Periodically check and update with a timer.
|
2011-07-17 14:06:43 +02:00
|
|
|
int newNumBlocks = getNumBlocks();
|
2012-05-05 16:07:14 +02:00
|
|
|
int newNumBlocksOfPeers = getNumBlocksOfPeers();
|
2011-07-17 14:06:43 +02:00
|
|
|
|
2012-05-05 16:07:14 +02:00
|
|
|
if(cachedNumBlocks != newNumBlocks || cachedNumBlocksOfPeers != newNumBlocksOfPeers)
|
|
|
|
emit numBlocksChanged(newNumBlocks, newNumBlocksOfPeers);
|
|
|
|
|
|
|
|
cachedNumBlocks = newNumBlocks;
|
|
|
|
cachedNumBlocksOfPeers = newNumBlocksOfPeers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientModel::updateNumConnections(int numConnections)
|
|
|
|
{
|
|
|
|
emit numConnectionsChanged(numConnections);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientModel::updateAlert(const QString &hash, int status)
|
|
|
|
{
|
|
|
|
// Show error message notification for new alert
|
|
|
|
if(status == CT_NEW)
|
2012-03-24 18:48:18 +01:00
|
|
|
{
|
2012-05-05 16:07:14 +02:00
|
|
|
uint256 hash_256;
|
|
|
|
hash_256.SetHex(hash.toStdString());
|
|
|
|
CAlert alert = CAlert::getAlertByHash(hash_256);
|
|
|
|
if(!alert.IsNull())
|
|
|
|
{
|
|
|
|
emit error(tr("Network Alert"), QString::fromStdString(alert.strStatusBar), false);
|
|
|
|
}
|
2012-03-24 18:48:18 +01:00
|
|
|
}
|
2011-07-17 14:06:43 +02:00
|
|
|
|
2012-05-05 16:07:14 +02:00
|
|
|
// Emit a numBlocksChanged when the status message changes,
|
|
|
|
// so that the view recomputes and updates the status bar.
|
|
|
|
emit numBlocksChanged(getNumBlocks(), getNumBlocksOfPeers());
|
2011-05-30 20:20:12 +02:00
|
|
|
}
|
|
|
|
|
2011-06-30 19:14:42 +02:00
|
|
|
bool ClientModel::isTestNet() const
|
|
|
|
{
|
|
|
|
return fTestNet;
|
|
|
|
}
|
|
|
|
|
2011-06-18 13:13:48 +02:00
|
|
|
bool ClientModel::inInitialBlockDownload() const
|
|
|
|
{
|
|
|
|
return IsInitialBlockDownload();
|
|
|
|
}
|
|
|
|
|
2011-09-11 10:49:30 +02:00
|
|
|
int ClientModel::getNumBlocksOfPeers() const
|
2011-06-18 21:25:38 +02:00
|
|
|
{
|
2011-09-11 10:49:30 +02:00
|
|
|
return GetNumBlocksOfPeers();
|
2011-06-18 21:25:38 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 20:00:21 +01:00
|
|
|
QString ClientModel::getStatusBarWarnings() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(GetWarnings("statusbar"));
|
|
|
|
}
|
|
|
|
|
2011-05-31 22:24:53 +02:00
|
|
|
OptionsModel *ClientModel::getOptionsModel()
|
|
|
|
{
|
2011-06-03 21:03:20 +02:00
|
|
|
return optionsModel;
|
|
|
|
}
|
|
|
|
|
2011-07-01 17:06:36 +02:00
|
|
|
QString ClientModel::formatFullVersion() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(FormatFullVersion());
|
|
|
|
}
|
2012-04-07 02:06:53 +02:00
|
|
|
|
|
|
|
QString ClientModel::formatBuildDate() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(CLIENT_DATE);
|
|
|
|
}
|
2012-04-09 21:07:25 +02:00
|
|
|
|
|
|
|
QString ClientModel::clientName() const
|
|
|
|
{
|
|
|
|
return QString::fromStdString(CLIENT_NAME);
|
|
|
|
}
|
2012-05-12 00:28:58 +02:00
|
|
|
|
|
|
|
QDateTime ClientModel::formatClientStartupTime() const
|
|
|
|
{
|
|
|
|
return QDateTime::fromTime_t(nClientStartupTime);
|
|
|
|
}
|