show active/total MNs on info tab / update it in separate timer

This commit is contained in:
UdjinM6 2015-02-24 16:24:42 +03:00
parent 003a1b7d72
commit d2e3d67a1d
4 changed files with 44 additions and 6 deletions

View File

@ -13,6 +13,7 @@
#include "main.h"
#include "net.h"
#include "ui_interface.h"
#include "masternodeman.h"
#include <stdint.h>
@ -24,7 +25,7 @@ static const int64_t nClientStartupTime = GetTime();
ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
QObject(parent), optionsModel(optionsModel),
cachedNumBlocks(0),
cachedNumBlocks(0), cachedMasternodeCountString(""),
cachedReindexing(0), cachedImporting(0),
numBlocksAtStartup(-1), pollTimer(0)
{
@ -32,6 +33,11 @@ ClientModel::ClientModel(OptionsModel *optionsModel, QObject *parent) :
connect(pollTimer, SIGNAL(timeout()), this, SLOT(updateTimer()));
pollTimer->start(MODEL_UPDATE_DELAY);
pollMnTimer = new QTimer(this);
connect(pollMnTimer, SIGNAL(timeout()), this, SLOT(updateMnTimer()));
// no need to update as frequent as data for balances/txes/blocks
pollMnTimer->start(MODEL_UPDATE_DELAY * 4);
subscribeToCoreSignals();
}
@ -54,6 +60,11 @@ int ClientModel::getNumConnections(unsigned int flags) const
return nNum;
}
QString ClientModel::getMasternodeCountString() const
{
return QString::number((int)mnodeman.CountEnabled()) + " / " + QString::number((int)mnodeman.size());
}
int ClientModel::getNumBlocks() const
{
LOCK(cs_main);
@ -117,6 +128,24 @@ void ClientModel::updateTimer()
emit bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
}
void ClientModel::updateMnTimer()
{
// Get required lock upfront. This avoids the GUI from getting stuck on
// periodical polls if the core is holding the locks for a longer time -
// for example, during a wallet rescan.
TRY_LOCK(cs_main, lockMain);
if(!lockMain)
return;
QString newMasternodeCountString = getMasternodeCountString();
if (cachedMasternodeCountString != newMasternodeCountString)
{
cachedMasternodeCountString = newMasternodeCountString;
emit strMasternodesChanged(cachedMasternodeCountString);
}
}
void ClientModel::updateNumConnections(int numConnections)
{
emit numConnectionsChanged(numConnections);

View File

@ -46,6 +46,7 @@ public:
//! Return number of connections, default is in- and outbound (total)
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
QString getMasternodeCountString() const;
int getNumBlocks() const;
int getNumBlocksAtStartup();
@ -74,12 +75,14 @@ private:
OptionsModel *optionsModel;
int cachedNumBlocks;
QString cachedMasternodeCountString;
bool cachedReindexing;
bool cachedImporting;
int numBlocksAtStartup;
QTimer *pollTimer;
QTimer *pollMnTimer;
void subscribeToCoreSignals();
void unsubscribeFromCoreSignals();
@ -87,6 +90,7 @@ private:
signals:
void numConnectionsChanged(int count);
void numBlocksChanged(int count);
void strMasternodesChanged(const QString &strMasternodes);
void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
@ -95,6 +99,7 @@ signals:
public slots:
void updateTimer();
void updateMnTimer();
void updateNumConnections(int numConnections);
void updateAlert(const QString &hash, int status);
};

View File

@ -11,7 +11,6 @@
#include "rpcserver.h"
#include "rpcclient.h"
#include "masternodeman.h"
#include "json/json_spirit_value.h"
#include <openssl/crypto.h>
@ -276,6 +275,9 @@ void RPCConsole::setClientModel(ClientModel *model)
setNumBlocks(model->getNumBlocks());
connect(model, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int)));
setMasternodeCount(model->getMasternodeCountString());
connect(model, SIGNAL(strMasternodesChanged(QString)), this, SLOT(setMasternodeCount(QString)));
updateTrafficStats(model->getTotalBytesRecv(), model->getTotalBytesSent());
connect(model, SIGNAL(bytesChanged(quint64,quint64)), this, SLOT(updateTrafficStats(quint64, quint64)));
@ -373,11 +375,11 @@ void RPCConsole::setNumBlocks(int count)
ui->numberOfBlocks->setText(QString::number(count));
if(clientModel)
ui->lastBlockTime->setText(clientModel->getLastBlockDate().toString());
}
// set masternode count
QString masternodes = QString::number((int)mnodeman.size());
ui->masternodeCount->setText(masternodes);
void RPCConsole::setMasternodeCount(const QString &strMasternodes)
{
ui->masternodeCount->setText(strMasternodes);
}
void RPCConsole::on_lineEdit_returnPressed()

View File

@ -53,6 +53,8 @@ public slots:
void setNumConnections(int count);
/** Set number of blocks shown in the UI */
void setNumBlocks(int count);
/** Set number of masternodes shown in the UI */
void setMasternodeCount(const QString &strMasternodes);
/** Go forward or back in history */
void browseHistory(int offset);
/** Scroll console view to end */