Browse Source

Merge pull request #5776

8517e97 [Qt] rework setNumBlocks to have blockDate as parameter (Philip Kaufmann)
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
f50120ab4d
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 9
      src/qt/bitcoingui.cpp
  2. 4
      src/qt/bitcoingui.h
  3. 18
      src/qt/clientmodel.cpp
  4. 5
      src/qt/clientmodel.h
  5. 9
      src/qt/rpcconsole.cpp
  6. 4
      src/qt/rpcconsole.h
  7. 2
      src/qt/sendcoinsdialog.cpp

9
src/qt/bitcoingui.cpp

@ -436,8 +436,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
setNumConnections(clientModel->getNumConnections()); setNumConnections(clientModel->getNumConnections());
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
setNumBlocks(clientModel->getNumBlocks()); setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate());
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(setNumBlocks(int,QDateTime)));
// Receive and report messages from client model // Receive and report messages from client model
connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int))); connect(clientModel, SIGNAL(message(QString,QString,unsigned int)), this, SLOT(message(QString,QString,unsigned int)));
@ -653,7 +653,7 @@ void BitcoinGUI::setNumConnections(int count)
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count)); labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Bitcoin network", "", count));
} }
void BitcoinGUI::setNumBlocks(int count) void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate)
{ {
if(!clientModel) if(!clientModel)
return; return;
@ -681,9 +681,8 @@ void BitcoinGUI::setNumBlocks(int count)
QString tooltip; QString tooltip;
QDateTime lastBlockDate = clientModel->getLastBlockDate();
QDateTime currentDate = QDateTime::currentDateTime(); QDateTime currentDate = QDateTime::currentDateTime();
qint64 secs = lastBlockDate.secsTo(currentDate); qint64 secs = blockDate.secsTo(currentDate);
tooltip = tr("Processed %n blocks of transaction history.", "", count); tooltip = tr("Processed %n blocks of transaction history.", "", count);

4
src/qt/bitcoingui.h

@ -143,8 +143,8 @@ signals:
public slots: public slots:
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */
void setNumConnections(int count); void setNumConnections(int count);
/** Set number of blocks shown in the UI */ /** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count); void setNumBlocks(int count, const QDateTime& blockDate);
/** Notify the user of an event from the core network or transaction handling code. /** Notify the user of an event from the core network or transaction handling code.
@param[in] title the message box / notification title @param[in] title the message box / notification title

18
src/qt/clientmodel.cpp

@ -18,7 +18,6 @@
#include <stdint.h> #include <stdint.h>
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QTimer> #include <QTimer>
@ -29,6 +28,7 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
optionsModel(optionsModel), optionsModel(optionsModel),
peerTableModel(0), peerTableModel(0),
cachedNumBlocks(0), cachedNumBlocks(0),
cachedBlockDate(QDateTime()),
cachedReindexing(0), cachedReindexing(0),
cachedImporting(0), cachedImporting(0),
pollTimer(0) pollTimer(0)
@ -79,10 +79,11 @@ quint64 ClientModel::getTotalBytesSent() const
QDateTime ClientModel::getLastBlockDate() const QDateTime ClientModel::getLastBlockDate() const
{ {
LOCK(cs_main); LOCK(cs_main);
if (chainActive.Tip()) if (chainActive.Tip())
return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime()); return QDateTime::fromTime_t(chainActive.Tip()->GetBlockTime());
else
return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network return QDateTime::fromTime_t(Params().GenesisBlock().GetBlockTime()); // Genesis block's time of current network
} }
double ClientModel::getVerificationProgress() const double ClientModel::getVerificationProgress() const
@ -97,21 +98,26 @@ void ClientModel::updateTimer()
// periodical polls if the core is holding the locks for a longer time - // periodical polls if the core is holding the locks for a longer time -
// for example, during a wallet rescan. // for example, during a wallet rescan.
TRY_LOCK(cs_main, lockMain); TRY_LOCK(cs_main, lockMain);
if(!lockMain) if (!lockMain)
return; return;
// Some quantities (such as number of blocks) change so fast that we don't want to be notified for each change. // 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. // Periodically check and update with a timer.
int newNumBlocks = getNumBlocks(); int newNumBlocks = getNumBlocks();
QDateTime newBlockDate = getLastBlockDate();
// check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state // check for changed number of blocks we have, number of blocks peers claim to have, reindexing state and importing state
if (cachedNumBlocks != newNumBlocks || if (cachedNumBlocks != newNumBlocks ||
cachedReindexing != fReindex || cachedImporting != fImporting) cachedBlockDate != newBlockDate ||
cachedReindexing != fReindex ||
cachedImporting != fImporting)
{ {
cachedNumBlocks = newNumBlocks; cachedNumBlocks = newNumBlocks;
cachedBlockDate = newBlockDate;
cachedReindexing = fReindex; cachedReindexing = fReindex;
cachedImporting = fImporting; cachedImporting = fImporting;
emit numBlocksChanged(newNumBlocks); emit numBlocksChanged(newNumBlocks, newBlockDate);
} }
emit bytesChanged(getTotalBytesRecv(), getTotalBytesSent()); emit bytesChanged(getTotalBytesRecv(), getTotalBytesSent());

5
src/qt/clientmodel.h

@ -6,6 +6,7 @@
#define BITCOIN_QT_CLIENTMODEL_H #define BITCOIN_QT_CLIENTMODEL_H
#include <QObject> #include <QObject>
#include <QDateTime>
class AddressTableModel; class AddressTableModel;
class OptionsModel; class OptionsModel;
@ -15,7 +16,6 @@ class TransactionTableModel;
class CWallet; class CWallet;
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDateTime;
class QTimer; class QTimer;
QT_END_NAMESPACE QT_END_NAMESPACE
@ -73,6 +73,7 @@ private:
PeerTableModel *peerTableModel; PeerTableModel *peerTableModel;
int cachedNumBlocks; int cachedNumBlocks;
QDateTime cachedBlockDate;
bool cachedReindexing; bool cachedReindexing;
bool cachedImporting; bool cachedImporting;
@ -83,7 +84,7 @@ private:
signals: signals:
void numConnectionsChanged(int count); void numConnectionsChanged(int count);
void numBlocksChanged(int count); void numBlocksChanged(int count, const QDateTime& blockDate);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);

9
src/qt/rpcconsole.cpp

@ -293,8 +293,8 @@ void RPCConsole::setClientModel(ClientModel *model)
setNumConnections(model->getNumConnections()); setNumConnections(model->getNumConnections());
connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); connect(model, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
setNumBlocks(model->getNumBlocks()); setNumBlocks(model->getNumBlocks(), model->getLastBlockDate());
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); connect(model, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(setNumBlocks(int,QDateTime)));
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent()); updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64))); connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@ -404,11 +404,10 @@ void RPCConsole::setNumConnections(int count)
ui->numberOfConnections->setText(connections); ui->numberOfConnections->setText(connections);
} }
void RPCConsole::setNumBlocks(int count) void RPCConsole::setNumBlocks(int count, const QDateTime& blockDate)
{ {
ui->numberOfBlocks->setText(QString::number(count)); ui->numberOfBlocks->setText(QString::number(count));
if(clientModel) ui->lastBlockTime->setText(blockDate.toString());
ui->lastBlockTime->setText(clientModel->getLastBlockDate().toString());
} }
void RPCConsole::on_lineEdit_returnPressed() void RPCConsole::on_lineEdit_returnPressed()

4
src/qt/rpcconsole.h

@ -63,8 +63,8 @@ public slots:
void message(int category, const QString &message, bool html = false); void message(int category, const QString &message, bool html = false);
/** Set number of connections shown in the UI */ /** Set number of connections shown in the UI */
void setNumConnections(int count); void setNumConnections(int count);
/** Set number of blocks shown in the UI */ /** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count); void setNumBlocks(int count, const QDateTime& blockDate);
/** Go forward or back in history */ /** Go forward or back in history */
void browseHistory(int offset); void browseHistory(int offset);
/** Scroll console view to end */ /** Scroll console view to end */

2
src/qt/sendcoinsdialog.cpp

@ -121,7 +121,7 @@ void SendCoinsDialog::setClientModel(ClientModel *clientModel)
this->clientModel = clientModel; this->clientModel = clientModel;
if (clientModel) { if (clientModel) {
connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(updateSmartFeeLabel())); connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime)), this, SLOT(updateSmartFeeLabel()));
} }
} }

Loading…
Cancel
Save