Display a "freshness" indicator instead of nr of blocks

This commit is contained in:
Wladimir J. van der Laan 2011-07-08 18:05:10 +02:00
parent 8ffec99b07
commit 84c8506e90
5 changed files with 53 additions and 3 deletions

View file

@ -52,3 +52,9 @@ Designer: Jack Cai
License: Creative Commons Attribution No Derivatives (by-nd) License: Creative Commons Attribution No Derivatives (by-nd)
Site: http://findicons.com/icon/175944/home?id=176221# Site: http://findicons.com/icon/175944/home?id=176221#
Icon: src/qt/res/icons/synced.png,
src/qt/res/icons/notsynced.png
Icon Pack: Gloss: Basic
Designer: Momenticons
License: Creative Commons Attribution (by)
Site: http://www.momenticons.com/

View file

@ -29,6 +29,8 @@
<file alias="history">res/icons/history.png</file> <file alias="history">res/icons/history.png</file>
<file alias="overview">res/icons/overview.png</file> <file alias="overview">res/icons/overview.png</file>
<file alias="export">res/icons/export.png</file> <file alias="export">res/icons/export.png</file>
<file alias="synced">res/icons/synced.png</file>
<file alias="notsynced">res/icons/notsynced.png</file>
</qresource> </qresource>
<qresource prefix="/images"> <qresource prefix="/images">
<file alias="about">res/images/about.png</file> <file alias="about">res/images/about.png</file>

View file

@ -35,6 +35,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QProgressBar> #include <QProgressBar>
#include <QStackedWidget> #include <QStackedWidget>
#include <QDateTime>
#include <QDebug> #include <QDebug>
@ -109,11 +110,13 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
labelConnections = new QLabel(); labelConnections = new QLabel();
labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken); labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelConnections->setMinimumWidth(150); labelConnections->setMinimumWidth(150);
labelConnections->setMaximumWidth(150);
labelConnections->setToolTip(tr("Number of connections to other clients")); labelConnections->setToolTip(tr("Number of connections to other clients"));
labelBlocks = new QLabel(); labelBlocks = new QLabel();
labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken); labelBlocks->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelBlocks->setMinimumWidth(130); labelBlocks->setMinimumWidth(150);
labelBlocks->setMaximumWidth(150);
labelBlocks->setToolTip(tr("Number of blocks in the block chain")); labelBlocks->setToolTip(tr("Number of blocks in the block chain"));
// Progress bar for blocks download // Progress bar for blocks download
@ -314,7 +317,34 @@ void BitcoinGUI::setNumBlocks(int count)
progressBar->setVisible(false); progressBar->setVisible(false);
} }
labelBlocks->setText(tr("%n block(s)", "", count)); QDateTime now = QDateTime::currentDateTime();
QDateTime lastBlockDate = clientModel->getLastBlockDate();
int secs = lastBlockDate.secsTo(now);
QString text;
QString icon = ":/icons/notsynced";
// "Up to date" icon, and outdated icon
if(secs < 30*60)
{
text = "Up to date";
icon = ":/icons/synced";
}
else if(secs < 60*60)
{
text = tr("%n minute(s) ago","",secs/60);
}
else if(secs < 24*60*60)
{
text = tr("%n hour(s) ago","",secs/(60*60));
}
else
{
text = tr("%n day(s) ago","",secs/(60*60*24));
}
labelBlocks->setText("<img src=\""+icon+"\"> " + text);
labelBlocks->setToolTip(tr("%n block(s) in total, last block was generated %1", "", count)
.arg(QLocale::system().toString(lastBlockDate)));
} }
void BitcoinGUI::setNumTransactions(int count) void BitcoinGUI::setNumTransactions(int count)

View file

@ -7,6 +7,7 @@
#include "headers.h" #include "headers.h"
#include <QTimer> #include <QTimer>
#include <QDateTime>
ClientModel::ClientModel(CWallet *wallet, QObject *parent) : ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0) QObject(parent), wallet(wallet), optionsModel(0)
@ -30,6 +31,11 @@ int ClientModel::getNumBlocks() const
return nBestHeight; return nBestHeight;
} }
QDateTime ClientModel::getLastBlockDate() const
{
return QDateTime::fromTime_t(pindexBest->GetBlockTime());
}
void ClientModel::update() void ClientModel::update()
{ {
// Plainly emit all signals for now. To be more efficient this should check // Plainly emit all signals for now. To be more efficient this should check

View file

@ -8,6 +8,10 @@ class AddressTableModel;
class TransactionTableModel; class TransactionTableModel;
class CWallet; class CWallet;
QT_BEGIN_NAMESPACE
class QDateTime;
QT_END_NAMESPACE
// Interface to Bitcoin network client // Interface to Bitcoin network client
class ClientModel : public QObject class ClientModel : public QObject
{ {
@ -22,6 +26,8 @@ public:
int getNumConnections() const; int getNumConnections() const;
int getNumBlocks() const; int getNumBlocks() const;
QDateTime getLastBlockDate() const;
// Return true if client connected to testnet // Return true if client connected to testnet
bool isTestNet() const; bool isTestNet() const;
// Return true if core is doing initial block download // Return true if core is doing initial block download