aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2011-07-08 18:05:10 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2011-07-08 18:05:23 +0200
commit84c8506e90c01b4ba38c19064389d8549593be2f (patch)
treebe3df9dae80d861245944dc257a7aff28002509d /src
parent8ffec99b071df945e4d6c59641a89a8bd409c4ec (diff)
Display a "freshness" indicator instead of nr of blocks
Diffstat (limited to 'src')
-rw-r--r--src/qt/bitcoin.qrc2
-rw-r--r--src/qt/bitcoingui.cpp36
-rw-r--r--src/qt/clientmodel.cpp6
-rw-r--r--src/qt/clientmodel.h6
4 files changed, 47 insertions, 3 deletions
diff --git a/src/qt/bitcoin.qrc b/src/qt/bitcoin.qrc
index e64744cda8..1522ce61e3 100644
--- a/src/qt/bitcoin.qrc
+++ b/src/qt/bitcoin.qrc
@@ -29,6 +29,8 @@
<file alias="history">res/icons/history.png</file>
<file alias="overview">res/icons/overview.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 prefix="/images">
<file alias="about">res/images/about.png</file>
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index cfdccbea6b..06c2034da5 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -35,6 +35,7 @@
#include <QMessageBox>
#include <QProgressBar>
#include <QStackedWidget>
+#include <QDateTime>
#include <QDebug>
@@ -109,11 +110,13 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
labelConnections = new QLabel();
labelConnections->setFrameStyle(QFrame::Panel | QFrame::Sunken);
labelConnections->setMinimumWidth(150);
+ labelConnections->setMaximumWidth(150);
labelConnections->setToolTip(tr("Number of connections to other clients"));
labelBlocks = new QLabel();
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"));
// Progress bar for blocks download
@@ -295,7 +298,7 @@ void BitcoinGUI::setNumConnections(int count)
default: icon = ":/icons/connect_4"; break;
}
labelConnections->setTextFormat(Qt::RichText);
- labelConnections->setText("<img src=\""+icon+"\"> " + tr("%n connection(s)", "", count));
+ labelConnections->setText("<img src=\""+icon+"\">" + tr("%n connection(s)", "", count));
}
void BitcoinGUI::setNumBlocks(int count)
@@ -314,7 +317,34 @@ void BitcoinGUI::setNumBlocks(int count)
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)
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
index 06ad5adfc8..8885b4cb5b 100644
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -7,6 +7,7 @@
#include "headers.h"
#include <QTimer>
+#include <QDateTime>
ClientModel::ClientModel(CWallet *wallet, QObject *parent) :
QObject(parent), wallet(wallet), optionsModel(0)
@@ -30,6 +31,11 @@ int ClientModel::getNumBlocks() const
return nBestHeight;
}
+QDateTime ClientModel::getLastBlockDate() const
+{
+ return QDateTime::fromTime_t(pindexBest->GetBlockTime());
+}
+
void ClientModel::update()
{
// Plainly emit all signals for now. To be more efficient this should check
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
index 659fa65762..6c2c275cef 100644
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -8,6 +8,10 @@ class AddressTableModel;
class TransactionTableModel;
class CWallet;
+QT_BEGIN_NAMESPACE
+class QDateTime;
+QT_END_NAMESPACE
+
// Interface to Bitcoin network client
class ClientModel : public QObject
{
@@ -22,6 +26,8 @@ public:
int getNumConnections() const;
int getNumBlocks() const;
+ QDateTime getLastBlockDate() const;
+
// Return true if client connected to testnet
bool isTestNet() const;
// Return true if core is doing initial block download