refactor sync progress ui to use signals, remove lock from masternode str ui

This commit is contained in:
UdjinM6 2016-02-19 21:09:54 +03:00
parent 06b6dce132
commit b654a6a320
6 changed files with 76 additions and 45 deletions

View File

@ -149,6 +149,7 @@ void CMasternodeSync::GetNextAsset()
case(MASTERNODE_SYNC_BUDGET): case(MASTERNODE_SYNC_BUDGET):
LogPrintf("CMasternodeSync::GetNextAsset - Sync has finished\n"); LogPrintf("CMasternodeSync::GetNextAsset - Sync has finished\n");
RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
uiInterface.NotifyAdditionalDataSyncProgressChanged(1);
break; break;
} }
RequestedMasternodeAttempt = 0; RequestedMasternodeAttempt = 0;
@ -251,7 +252,9 @@ void CMasternodeSync::Process()
if(fDebug) LogPrintf("CMasternodeSync::Process() - tick %d RequestedMasternodeAssets %d\n", tick, RequestedMasternodeAssets); if(fDebug) LogPrintf("CMasternodeSync::Process() - tick %d RequestedMasternodeAssets %d\n", tick, RequestedMasternodeAssets);
} }
//printf("CMasternodeSync::Process() TICK - %d %d \n", tick, RequestedMasternodeAssets); double nSyncProgress = double(RequestedMasternodeAttempt + (RequestedMasternodeAssets - 1) * 8) / (8*4);
LogPrintf("CMasternodeSync::Process() - tick %d RequestedMasternodeAttempt %d RequestedMasternodeAssets %d nSyncProgress %f\n", tick, RequestedMasternodeAttempt, RequestedMasternodeAssets, nSyncProgress);
uiInterface.NotifyAdditionalDataSyncProgressChanged(nSyncProgress);
if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset(); if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset();

View File

@ -546,6 +546,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL)); setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL));
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double))); connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double)), this, SLOT(setNumBlocks(int,QDateTime,double)));
connect(clientModel, SIGNAL(additionalDataSyncProgressChanged(double)), this, SLOT(setAdditionalDataSyncProgress(double)));
// 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)));
@ -856,44 +858,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
// Set icon state: spinning if catching up, tick otherwise // Set icon state: spinning if catching up, tick otherwise
QString theme = GUIUtil::getThemeName(); QString theme = GUIUtil::getThemeName();
// if(secs < 25*60) // 90*60 for bitcoin but we are 4x times faster
if(masternodeSync.IsBlockchainSynced())
{
QString strSyncStatus;
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
if(masternodeSync.IsSynced()) { if(!masternodeSync.IsBlockchainSynced())
progressBarLabel->setVisible(false);
progressBar->setVisible(false);
labelBlocksIcon->setPixmap(QIcon(":/icons/" + theme + "/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
} else {
int nAttempt;
int progress = 0;
labelBlocksIcon->setPixmap(QIcon(QString(
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
#ifdef ENABLE_WALLET
if(walletFrame)
walletFrame->showOutOfSyncWarning(false);
#endif // ENABLE_WALLET
nAttempt = masternodeSync.RequestedMasternodeAttempt < 8 ?
masternodeSync.RequestedMasternodeAttempt + 1 : 8;
progress = nAttempt + (masternodeSync.RequestedMasternodeAssets - 1) * 8;
progressBar->setMaximum(4 * 8);
progressBar->setFormat(tr("Synchronizing additional data: %p%"));
progressBar->setValue(progress);
}
strSyncStatus = QString(masternodeSync.GetSyncStatus().c_str());
progressBarLabel->setText(strSyncStatus);
tooltip = strSyncStatus + QString("<br>") + tooltip;
}
else
{ {
// Represent time from last generated block in human readable text // Represent time from last generated block in human readable text
QString timeBehindText; QString timeBehindText;
@ -955,6 +921,58 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
progressBar->setToolTip(tooltip); progressBar->setToolTip(tooltip);
} }
void BitcoinGUI::setAdditionalDataSyncProgress(double nSyncProgress)
{
if(!clientModel)
return;
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbelled text)
statusBar()->clearMessage();
QString tooltip;
// Set icon state: spinning if catching up, tick otherwise
QString theme = GUIUtil::getThemeName();
if(masternodeSync.IsBlockchainSynced())
{
QString strSyncStatus;
tooltip = tr("Up to date") + QString(".<br>") + tooltip;
if(masternodeSync.IsSynced()) {
progressBarLabel->setVisible(false);
progressBar->setVisible(false);
labelBlocksIcon->setPixmap(QIcon(":/icons/" + theme + "/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
} else {
labelBlocksIcon->setPixmap(platformStyle->SingleColorIcon(QString(
":/movies/spinner-%1").arg(spinnerFrame, 3, 10, QChar('0')))
.pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
spinnerFrame = (spinnerFrame + 1) % SPINNER_FRAMES;
#ifdef ENABLE_WALLET
if(walletFrame)
walletFrame->showOutOfSyncWarning(false);
#endif // ENABLE_WALLET
progressBar->setFormat(tr("Synchronizing additional data: %p%"));
progressBar->setMaximum(1000000000);
progressBar->setValue(nSyncProgress * 1000000000.0 + 0.5);
}
strSyncStatus = QString(masternodeSync.GetSyncStatus().c_str());
progressBarLabel->setText(strSyncStatus);
tooltip = strSyncStatus + QString("<br>") + tooltip;
}
// Don't word-wrap this (fixed-width) tooltip
tooltip = QString("<nobr>") + tooltip + QString("</nobr>");
labelBlocksIcon->setToolTip(tooltip);
progressBarLabel->setToolTip(tooltip);
progressBar->setToolTip(tooltip);
}
void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret) void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, bool *ret)
{ {
QString strTitle = tr("Dash Core"); // default title QString strTitle = tr("Dash Core"); // default title

View File

@ -165,6 +165,8 @@ public Q_SLOTS:
void handleRestart(QStringList args); void handleRestart(QStringList args);
/** Set number of blocks and last block date shown in the UI */ /** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress); void setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress);
/** Set additional data sync status shown in the UI */
void setAdditionalDataSyncProgress(double nSyncProgress);
/** 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

View File

@ -131,17 +131,10 @@ void ClientModel::updateTimer()
// the following calls will aquire the required lock // the following calls will aquire the required lock
Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage()); Q_EMIT mempoolSizeChanged(getMempoolSize(), getMempoolDynamicUsage());
Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent()); Q_EMIT bytesChanged(getTotalBytesRecv(), getTotalBytesSent());
// TODO: masternodeSync.RequestedMasternodeAttempt != prevAttempt || masternodeSync.RequestedMasternodeAssets != prevAssets)
} }
void ClientModel::updateMnTimer() 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); // TODO: refactor the same way as ClientModel::updateTimer()
if(!lockMain)
return;
QString newMasternodeCountString = getMasternodeCountString(); QString newMasternodeCountString = getMasternodeCountString();
if (cachedMasternodeCountString != newMasternodeCountString) if (cachedMasternodeCountString != newMasternodeCountString)
@ -296,6 +289,12 @@ static void BlockTipChanged(ClientModel *clientmodel, bool initialSync, const CB
} }
} }
static void NotifyAdditionalDataSyncProgressChanged(ClientModel *clientmodel, double nSyncProgress)
{
QMetaObject::invokeMethod(clientmodel, "additionalDataSyncProgressChanged", Qt::QueuedConnection,
Q_ARG(double, nSyncProgress));
}
void ClientModel::subscribeToCoreSignals() void ClientModel::subscribeToCoreSignals()
{ {
// Connect signals to client // Connect signals to client
@ -304,6 +303,7 @@ void ClientModel::subscribeToCoreSignals()
uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2)); uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2));
uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this)); uiInterface.BannedListChanged.connect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2)); uiInterface.NotifyBlockTip.connect(boost::bind(BlockTipChanged, this, _1, _2));
uiInterface.NotifyAdditionalDataSyncProgressChanged.connect(boost::bind(NotifyAdditionalDataSyncProgressChanged, this, _1));
} }
void ClientModel::unsubscribeFromCoreSignals() void ClientModel::unsubscribeFromCoreSignals()
@ -314,4 +314,5 @@ void ClientModel::unsubscribeFromCoreSignals()
uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2)); uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2));
uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this)); uiInterface.BannedListChanged.disconnect(boost::bind(BannedListChanged, this));
uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2)); uiInterface.NotifyBlockTip.disconnect(boost::bind(BlockTipChanged, this, _1, _2));
uiInterface.NotifyAdditionalDataSyncProgressChanged.disconnect(boost::bind(NotifyAdditionalDataSyncProgressChanged, this, _1));
} }

View File

@ -95,6 +95,7 @@ Q_SIGNALS:
void numConnectionsChanged(int count); void numConnectionsChanged(int count);
void strMasternodesChanged(const QString &strMasternodes); void strMasternodesChanged(const QString &strMasternodes);
void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress); void numBlocksChanged(int count, const QDateTime& blockDate, double nVerificationProgress);
void additionalDataSyncProgressChanged(double nSyncProgress);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes); void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);

View File

@ -82,6 +82,9 @@ public:
/** Number of network connections changed. */ /** Number of network connections changed. */
boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged; boost::signals2::signal<void (int newNumConnections)> NotifyNumConnectionsChanged;
/** Number of masternodes changed. */
boost::signals2::signal<void (int newNumMasternodes)> NotifyStrMasternodeCountChanged;
/** /**
* New, updated or cancelled alert. * New, updated or cancelled alert.
* @note called with lock cs_mapAlerts held. * @note called with lock cs_mapAlerts held.
@ -97,6 +100,9 @@ public:
/** New block has been accepted */ /** New block has been accepted */
boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip; boost::signals2::signal<void (bool, const CBlockIndex *)> NotifyBlockTip;
/** Additional data sync progress changed */
boost::signals2::signal<void (double nSyncProgress)> NotifyAdditionalDataSyncProgressChanged;
/** Banlist did change. */ /** Banlist did change. */
boost::signals2::signal<void (void)> BannedListChanged; boost::signals2::signal<void (void)> BannedListChanged;
}; };