Permalink
Browse files

Change progress bar from block-based to time-based

Also remove some sleeps
  • Loading branch information...
Tranz5 committed Oct 15, 2014
1 parent f5d7f66 commit 53c16708a5d863ca6f60f6c59aa682c13e0d0998
Showing with 34 additions and 37 deletions.
  1. +0 −3 src/net.cpp
  2. +31 −33 src/qt/bitcoingui.cpp
  3. +2 −0 src/qt/bitcoingui.h
  4. +1 −1 src/qt/guiconstants.h
View
@@ -1096,8 +1096,6 @@ void ThreadSocketHandler2(void* parg)
BOOST_FOREACH(CNode* pnode, vNodesCopy)
pnode->Release();
}
MilliSleep(10);
}
}
@@ -2087,7 +2085,6 @@ bool StopNode()
if (vnThreadsRunning[THREAD_MINTER] > 0) LogPrintf("ThreadStakeMinter still running\n");
while (vnThreadsRunning[THREAD_MESSAGEHANDLER] > 0 || vnThreadsRunning[THREAD_RPCHANDLER] > 0)
MilliSleep(20);
MilliSleep(50);
DumpAddresses();
return true;
}
View
@@ -67,6 +67,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent):
trayIcon(0),
notificator(0),
rpcConsole(0),
prevBlocks(0),
nWeight(0)
{
resize(850, 550);
@@ -806,6 +807,7 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
return;
}
bool fShowStatusBar = false;
QString tooltip;
QString importText;
@@ -821,38 +823,17 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
importText = tr("Reindexing blocks on disk...");
}
if(count < nTotalBlocks)
{
int nRemainingBlocks = nTotalBlocks - count;
float nPercentageDone = count / (nTotalBlocks * 0.01f);
progressBarLabel->setText(importText);
progressBarLabel->setVisible(true);
progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks));
progressBar->setMaximum(nTotalBlocks);
progressBar->setValue(count);
progressBar->setVisible(true);
tooltip = tr("Processed %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2);
QDateTime lastBlockDate = clientModel->getLastBlockDate();
QDateTime currentDate = QDateTime::currentDateTime();
int totalSecs = GetTime() - 1393221600;
int secs = lastBlockDate.secsTo(currentDate);
}
else
{
progressBarLabel->setVisible(false);
progressBar->setVisible(false);
if(count < nTotalBlocks) {
tooltip = tr("Processed %1 of %2 (estimated) blocks of transaction history.").arg(count).arg(nTotalBlocks);
} else {
tooltip = tr("Processed %1 blocks of transaction history.").arg(count);
}
QDateTime lastBlockDate = clientModel->getLastBlockDate();
int secs = lastBlockDate.secsTo(QDateTime::currentDateTime());
QString text;
// Represent time from last generated block in human readable text
if(secs <= 0) {
// Fully up to date. Leave text empty.
}
else
text=(GUIUtil::formatDurationStr(secs));
// Set icon state: spinning if catching up, tick otherwise
if(secs < 90*60 && count >= nTotalBlocks)
@@ -861,21 +842,36 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
labelBlocksIcon->setPixmap(QIcon(":/icons/synced").pixmap(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE));
walletStack->showOutOfSyncWarning(false);
progressBarLabel->setVisible(false);
progressBar->setVisible(false);
}
else
{
// Represent time from last generated block in human readable text
QString timeBehindText;
timeBehindText=(GUIUtil::formatDurationStr(secs));
progressBarLabel->setText(tr("Synchronizing with network..."));
progressBarLabel->setVisible(true);
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
progressBar->setMaximum(totalSecs);
progressBar->setValue(totalSecs - secs);
progressBar->setVisible(true);
fShowStatusBar = true;
tooltip = tr("Catching up...") + QString("<br>") + tooltip;
labelBlocksIcon->setMovie(syncIconMovie);
syncIconMovie->start();
if(count != prevBlocks)
syncIconMovie->jumpToNextFrame();
prevBlocks = count;
walletStack->showOutOfSyncWarning(true);
}
if(!text.isEmpty())
{
tooltip += QString("<br>");
tooltip += tr("Last received block was generated %1.").arg(text);
tooltip += tr("Last received block was generated %1 ago.").arg(timeBehindText);
tooltip += QString("<br>");
tooltip += tr("Transactions after this will not yet be visible.");
}
// Don't word-wrap this (fixed-width) tooltip
@@ -884,6 +880,8 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
labelBlocksIcon->setToolTip(tooltip);
progressBarLabel->setToolTip(tooltip);
progressBar->setToolTip(tooltip);
statusBar()->setVisible(fShowStatusBar);
}
void BitcoinGUI::message(const QString &title, const QString &message, unsigned int style, const QString &detail)
View
@@ -129,6 +129,8 @@ class BitcoinGUI : public QMainWindow
RPCConsole *rpcConsole;
QMovie *syncIconMovie;
/** Keep track of previous number of blocks, to detect progress */
int prevBlocks;
quint64 nWeight;
View
@@ -2,7 +2,7 @@
#define GUICONSTANTS_H
/* Milliseconds between model updates */
static const int MODEL_UPDATE_DELAY = 500;
static const int MODEL_UPDATE_DELAY = 250;
/* AskPassphraseDialog -- Maximum passphrase length */
static const int MAX_PASSPHRASE_SIZE = 1024;

0 comments on commit 53c1670

Please sign in to comment.