From 9ceae8acea658d3e9d6bfe851e0d904c191c6f81 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 07:57:54 +0200 Subject: [PATCH 1/8] modified block DL progressbar to be dynamic and more precise --- src/qt/bitcoingui.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 91696310b4..464fb8c482 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -332,8 +332,12 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) setNumConnections(clientModel->getNumConnections()); connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); - setNumBlocks(clientModel->getNumBlocks()); - connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); + // don't display the sync. message, if we are not connected to the network + if (clientModel->getNumConnections() > 0) + { + setNumBlocks(clientModel->getNumBlocks()); + connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); + } // Report errors from network/worker thread connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString))); @@ -453,18 +457,33 @@ void BitcoinGUI::setNumBlocks(int count) { if(!clientModel) return; - int total = clientModel->getNumBlocksOfPeers(); + int nTotal = clientModel->getNumBlocksOfPeers(); + int nInitTotal = clientModel->getNumBlocksAtStartup(); + int nPercentageLeft = 100 - (count / (nTotal / 100)); QString tooltip; - if(count < total) + if(count < nTotal) { if (clientModel->getStatusBarWarnings() == "") { progressBarLabel->setVisible(true); - progressBarLabel->setText(tr("Synchronizing with network...")); progressBar->setVisible(true); - progressBar->setMaximum(total); - progressBar->setValue(count); + progressBar->setFormat(tr("%v of %m blocks (%p%)")); + progressBar->setAlignment(Qt::AlignCenter); + // display absolute bar if the difference between count and nTotal is > 10% + if (nPercentageLeft > 10) + { + progressBarLabel->setText(tr("Synchronizing with network... (abs. display)")); + progressBar->setMaximum(nTotal); + progressBar->setValue(count); + } + else + { + progressBarLabel->setText(tr("Synchronizing with network... (rel. display)")); + progressBar->setMaximum(nTotal - nInitTotal); + progressBar->setValue(count - nInitTotal); + } + } else { @@ -472,7 +491,7 @@ void BitcoinGUI::setNumBlocks(int count) progressBarLabel->setVisible(true); progressBar->setVisible(false); } - tooltip = tr("Downloaded %1 of %2 blocks of transaction history.").arg(count).arg(total); + tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% left).").arg(count).arg(nTotal).arg(nPercentageLeft); } else { From 068ed1e8384dd0e12ef68c0dc91c7064b6aae8ec Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 10:18:51 +0200 Subject: [PATCH 2/8] removed relative progressbar display and moved re-worked network detection code to setNumBlocks() --- src/qt/bitcoingui.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 464fb8c482..c8294cfe3d 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -332,12 +332,8 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel) setNumConnections(clientModel->getNumConnections()); connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int))); - // don't display the sync. message, if we are not connected to the network - if (clientModel->getNumConnections() > 0) - { - setNumBlocks(clientModel->getNumBlocks()); - connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); - } + setNumBlocks(clientModel->getNumBlocks()); + connect(clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(setNumBlocks(int))); // Report errors from network/worker thread connect(clientModel, SIGNAL(error(QString,QString)), this, SLOT(error(QString,QString))); @@ -455,10 +451,16 @@ void BitcoinGUI::setNumConnections(int count) void BitcoinGUI::setNumBlocks(int count) { - if(!clientModel) + // don't show / hide progressBar and it's label if we have no connection(s) to the network + if (!clientModel || clientModel->getNumConnections() == 0) + { + progressBarLabel->setVisible(false); + progressBar->setVisible(false); + return; + } + int nTotal = clientModel->getNumBlocksOfPeers(); - int nInitTotal = clientModel->getNumBlocksAtStartup(); int nPercentageLeft = 100 - (count / (nTotal / 100)); QString tooltip; @@ -467,23 +469,12 @@ void BitcoinGUI::setNumBlocks(int count) if (clientModel->getStatusBarWarnings() == "") { progressBarLabel->setVisible(true); + progressBarLabel->setText(tr("Synchronizing with network...")); progressBar->setVisible(true); progressBar->setFormat(tr("%v of %m blocks (%p%)")); progressBar->setAlignment(Qt::AlignCenter); - // display absolute bar if the difference between count and nTotal is > 10% - if (nPercentageLeft > 10) - { - progressBarLabel->setText(tr("Synchronizing with network... (abs. display)")); - progressBar->setMaximum(nTotal); - progressBar->setValue(count); - } - else - { - progressBarLabel->setText(tr("Synchronizing with network... (rel. display)")); - progressBar->setMaximum(nTotal - nInitTotal); - progressBar->setValue(count - nInitTotal); - } - + progressBar->setMaximum(nTotal); + progressBar->setValue(count); } else { From 5519660a0d80bdbfeadfe8c68303c936048635d0 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 15:28:53 +0200 Subject: [PATCH 3/8] changed progressbar text to "~n blocks remaining" --- src/qt/bitcoingui.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index c8294cfe3d..319a2f92ec 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -461,20 +461,23 @@ void BitcoinGUI::setNumBlocks(int count) } int nTotal = clientModel->getNumBlocksOfPeers(); - int nPercentageLeft = 100 - (count / (nTotal / 100)); QString tooltip; if(count < nTotal) { + int nCurMax = nTotal - count; + int nOnePercentCurMax = nCurMax / 100; + int nPercentageDone = (count / (nTotal / 100)); + if (clientModel->getStatusBarWarnings() == "") { progressBarLabel->setVisible(true); progressBarLabel->setText(tr("Synchronizing with network...")); progressBar->setVisible(true); - progressBar->setFormat(tr("%v of %m blocks (%p%)")); + progressBar->setFormat(tr("~%m blocks remaining")); progressBar->setAlignment(Qt::AlignCenter); - progressBar->setMaximum(nTotal); - progressBar->setValue(count); + progressBar->setMaximum(nCurMax); + progressBar->setValue(nOnePercentCurMax * nPercentageDone); } else { @@ -482,7 +485,7 @@ void BitcoinGUI::setNumBlocks(int count) progressBarLabel->setVisible(true); progressBar->setVisible(false); } - tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% left).").arg(count).arg(nTotal).arg(nPercentageLeft); + tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotal).arg(nPercentageDone); } else { From c7c0c93172e4ecfebf78432a2530599c77f8eddd Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 19:07:03 +0200 Subject: [PATCH 4/8] implemented OS independent progress bar style / moved one-time functions used on the bar to a better code location --- src/qt/bitcoingui.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 319a2f92ec..8e7f345046 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -138,17 +138,21 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): frameBlocksLayout->addWidget(labelBlocksIcon); frameBlocksLayout->addStretch(); - // Progress bar for blocks download - progressBarLabel = new QLabel(tr("Synchronizing with network...")); + // Progress bar and label for blocks download + progressBarLabel = new QLabel(); progressBarLabel->setVisible(false); progressBar = new QProgressBar(); - progressBar->setToolTip(tr("Block chain synchronization in progress")); progressBar->setVisible(false); statusBar()->addWidget(progressBarLabel); statusBar()->addWidget(progressBar); statusBar()->addPermanentWidget(frameBlocks); + // define progress bar format + progressBar->setFormat(tr("~%m blocks remaining")); + // define OS independent progress bar style (has to be after addWidget(), otherwise we crash) + progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 transparent, stop: 1 orange); margin: 0px; }"); + syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); // Clicking on a transaction on the overview page simply sends you to transaction history page @@ -471,13 +475,11 @@ void BitcoinGUI::setNumBlocks(int count) if (clientModel->getStatusBarWarnings() == "") { - progressBarLabel->setVisible(true); progressBarLabel->setText(tr("Synchronizing with network...")); - progressBar->setVisible(true); - progressBar->setFormat(tr("~%m blocks remaining")); - progressBar->setAlignment(Qt::AlignCenter); + progressBarLabel->setVisible(true); progressBar->setMaximum(nCurMax); progressBar->setValue(nOnePercentCurMax * nPercentageDone); + progressBar->setVisible(true); } else { From e9de46c43667de8bb2e5d9ef931a8b93132c41ff Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 20:29:07 +0200 Subject: [PATCH 5/8] color update for progress bar --- src/qt/bitcoingui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 8e7f345046..91ef9eb1da 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -151,7 +151,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): // define progress bar format progressBar->setFormat(tr("~%m blocks remaining")); // define OS independent progress bar style (has to be after addWidget(), otherwise we crash) - progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 transparent, stop: 1 orange); margin: 0px; }"); + progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }"); syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); From a7a69cd07a97dddd7dd74b0b1a6b2f82fe750261 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Mon, 2 Apr 2012 23:51:40 +0200 Subject: [PATCH 6/8] polished code and fixed progress display (was very jerky at the end of a sync) --- src/qt/bitcoingui.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 91ef9eb1da..2befcdf786 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -148,10 +148,8 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): statusBar()->addWidget(progressBar); statusBar()->addPermanentWidget(frameBlocks); - // define progress bar format - progressBar->setFormat(tr("~%m blocks remaining")); // define OS independent progress bar style (has to be after addWidget(), otherwise we crash) - progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 5px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }"); + progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 2px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }"); syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); @@ -464,21 +462,21 @@ void BitcoinGUI::setNumBlocks(int count) return; } - int nTotal = clientModel->getNumBlocksOfPeers(); + int nTotalBlocks = clientModel->getNumBlocksOfPeers(); QString tooltip; - if(count < nTotal) + if(count < nTotalBlocks) { - int nCurMax = nTotal - count; - int nOnePercentCurMax = nCurMax / 100; - int nPercentageDone = (count / (nTotal / 100)); + int nRemainingBlocks = nTotalBlocks - count; + int nPercentageDone = (count / ((nTotalBlocks / 100) + 0.5f)); if (clientModel->getStatusBarWarnings() == "") { progressBarLabel->setText(tr("Synchronizing with network...")); progressBarLabel->setVisible(true); - progressBar->setMaximum(nCurMax); - progressBar->setValue(nOnePercentCurMax * nPercentageDone); + progressBar->setFormat("~" + QString::number(nRemainingBlocks)+ tr(" blocks remaining")); + progressBar->setMaximum(nTotalBlocks); + progressBar->setValue(count); progressBar->setVisible(true); } else @@ -487,7 +485,7 @@ void BitcoinGUI::setNumBlocks(int count) progressBarLabel->setVisible(true); progressBar->setVisible(false); } - tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotal).arg(nPercentageDone); + tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone); } else { From ec9a4904f38c6c8b9a889e28bb7101dbc0eb5e97 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 3 Apr 2012 08:30:13 +0200 Subject: [PATCH 7/8] changed percentage done in tooltip to float to be more precise / allowed plurals in translation for "x block(s) remaining" --- src/qt/bitcoingui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 2befcdf786..6d710acea8 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -148,7 +148,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): statusBar()->addWidget(progressBar); statusBar()->addPermanentWidget(frameBlocks); - // define OS independent progress bar style (has to be after addWidget(), otherwise we crash) + // define OS independent progress bar style (has to be placed after addWidget(), otherwise we crash) progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 2px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }"); syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); @@ -468,13 +468,13 @@ void BitcoinGUI::setNumBlocks(int count) if(count < nTotalBlocks) { int nRemainingBlocks = nTotalBlocks - count; - int nPercentageDone = (count / ((nTotalBlocks / 100) + 0.5f)); + float nPercentageDone = count / (nTotalBlocks * 0.01f); if (clientModel->getStatusBarWarnings() == "") { progressBarLabel->setText(tr("Synchronizing with network...")); progressBarLabel->setVisible(true); - progressBar->setFormat("~" + QString::number(nRemainingBlocks)+ tr(" blocks remaining")); + progressBar->setFormat("~" + tr("%n block(s) remaining", "", nRemainingBlocks)); progressBar->setMaximum(nTotalBlocks); progressBar->setValue(count); progressBar->setVisible(true); @@ -485,7 +485,7 @@ void BitcoinGUI::setNumBlocks(int count) progressBarLabel->setVisible(true); progressBar->setVisible(false); } - tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone); + tooltip = tr("Downloaded %1 of %2 blocks of transaction history (%3% done).").arg(count).arg(nTotalBlocks).arg(nPercentageDone, 0, 'f', 2); } else { From 853a4a81b33a5c636c296f136822016cc65ab698 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 3 Apr 2012 09:42:34 +0200 Subject: [PATCH 8/8] clarified comment why we use an own progressbar style / included "~" in the tr() call --- src/qt/bitcoingui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 6d710acea8..04cf7031ed 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -149,6 +149,7 @@ BitcoinGUI::BitcoinGUI(QWidget *parent): statusBar()->addPermanentWidget(frameBlocks); // define OS independent progress bar style (has to be placed after addWidget(), otherwise we crash) + // we did this, because with some OSes default style, text on the progress bar is unreadable progressBar->setStyleSheet("QProgressBar { background-color: transparent; border: 1px solid grey; border-radius: 2px; padding: 1px; text-align: center; } QProgressBar::chunk { background: QLinearGradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 #FF8000, stop: 1 orange); margin: 0px; }"); syncIconMovie = new QMovie(":/movies/update_spinner", "mng", this); @@ -474,7 +475,7 @@ void BitcoinGUI::setNumBlocks(int count) { progressBarLabel->setText(tr("Synchronizing with network...")); progressBarLabel->setVisible(true); - progressBar->setFormat("~" + tr("%n block(s) remaining", "", nRemainingBlocks)); + progressBar->setFormat(tr("~%n block(s) remaining", "", nRemainingBlocks)); progressBar->setMaximum(nTotalBlocks); progressBar->setValue(count); progressBar->setVisible(true);