diff options
Diffstat (limited to 'src/qt/clientmodel.cpp')
| -rw-r--r-- | src/qt/clientmodel.cpp | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index b820d16ab..e8d99a8d4 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -1,4 +1,5 @@ #include "clientmodel.h" + #include "guiconstants.h" #include "optionsmodel.h" #include "addresstablemodel.h" @@ -6,6 +7,7 @@ #include "alert.h" #include "main.h" +#include "checkpoints.h" #include "ui_interface.h" #include <QDateTime> @@ -15,10 +17,10 @@ static const int64 nClientStartupTime = GetTime(); ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) : QObject(parent), optionsModel(optionsModel), - cachedNumBlocks(0), cachedNumBlocksOfPeers(0), pollTimer(0) + cachedNumBlocks(0), cachedNumBlocksOfPeers(0), + cachedReindexing(0), cachedImporting(0), + numBlocksAtStartup(-1), pollTimer(0) { - numBlocksAtStartup = -1; - pollTimer = new QTimer(this); pollTimer->setInterval(MODEL_UPDATE_DELAY); pollTimer->start(); @@ -50,7 +52,17 @@ int ClientModel::getNumBlocksAtStartup() QDateTime ClientModel::getLastBlockDate() const { - return QDateTime::fromTime_t(pindexBest->GetBlockTime()); + if (pindexBest) + return QDateTime::fromTime_t(pindexBest->GetBlockTime()); + else if(!isTestNet()) + return QDateTime::fromTime_t(1231006505); // Genesis block's time + else + return QDateTime::fromTime_t(1296688602); // Genesis block's time (testnet) +} + +double ClientModel::getVerificationProgress() const +{ + return Checkpoints::GuessVerificationProgress(pindexBest); } void ClientModel::updateTimer() @@ -60,12 +72,17 @@ void ClientModel::updateTimer() int newNumBlocks = getNumBlocks(); int newNumBlocksOfPeers = getNumBlocksOfPeers(); - if(cachedNumBlocks != newNumBlocks || cachedNumBlocksOfPeers != newNumBlocksOfPeers) + // check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state + if (cachedNumBlocks != newNumBlocks || cachedNumBlocksOfPeers != newNumBlocksOfPeers || + cachedReindexing != fReindex || cachedImporting != fImporting) { cachedNumBlocks = newNumBlocks; cachedNumBlocksOfPeers = newNumBlocksOfPeers; + cachedReindexing = fReindex; + cachedImporting = fImporting; - emit numBlocksChanged(newNumBlocks, newNumBlocksOfPeers); + // ensure we return the maximum of newNumBlocksOfPeers and newNumBlocks to not create weird displays in the GUI + emit numBlocksChanged(newNumBlocks, std::max(newNumBlocksOfPeers, newNumBlocks)); } } @@ -84,13 +101,11 @@ void ClientModel::updateAlert(const QString &hash, int status) CAlert alert = CAlert::getAlertByHash(hash_256); if(!alert.IsNull()) { - emit error(tr("Network Alert"), QString::fromStdString(alert.strStatusBar), false); + emit message(tr("Network Alert"), QString::fromStdString(alert.strStatusBar), CClientUIInterface::ICON_ERROR); } } - // Emit a numBlocksChanged when the status message changes, - // so that the view recomputes and updates the status bar. - emit numBlocksChanged(getNumBlocks(), getNumBlocksOfPeers()); + emit alertsChanged(getStatusBarWarnings()); } bool ClientModel::isTestNet() const @@ -103,6 +118,18 @@ bool ClientModel::inInitialBlockDownload() const return IsInitialBlockDownload(); } +enum BlockSource ClientModel::getBlockSource() const +{ + if (fReindex) + return BLOCK_SOURCE_REINDEX; + else if (fImporting) + return BLOCK_SOURCE_DISK; + else if (getNumConnections() > 0) + return BLOCK_SOURCE_NETWORK; + + return BLOCK_SOURCE_NONE; +} + int ClientModel::getNumBlocksOfPeers() const { return GetNumBlocksOfPeers(); @@ -128,6 +155,11 @@ QString ClientModel::formatBuildDate() const return QString::fromStdString(CLIENT_DATE); } +bool ClientModel::isReleaseVersion() const +{ + return CLIENT_VERSION_IS_RELEASE; +} + QString ClientModel::clientName() const { return QString::fromStdString(CLIENT_NAME); |