Skip to content

Commit

Permalink
Merge pull request bitcoin#2501 from Diapolo/progress
Browse files Browse the repository at this point in the history
rework ClientModel::getBlockSource() + BitcoinGUI::setNumBlocks()
  • Loading branch information
laanwj committed Apr 18, 2013
2 parents 52ae314 + 4881353 commit dc2de75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
38 changes: 16 additions & 22 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,31 +506,26 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
// Prevent orphan statusbar messages (e.g. hover Quit in main menu, wait until chain-sync starts -> garbelled text)
statusBar()->clearMessage();

// don't show / hide progress bar and its label if we have no connection to the network
enum BlockSource blockSource = clientModel ? clientModel->getBlockSource() : BLOCK_SOURCE_NONE;
if (blockSource == BLOCK_SOURCE_NONE || (blockSource == BLOCK_SOURCE_NETWORK && clientModel->getNumConnections() == 0))
{
progressBarLabel->setVisible(false);
progressBar->setVisible(false);

return;
// Acquire current block source
enum BlockSource blockSource = clientModel->getBlockSource();
switch (blockSource) {
case BLOCK_SOURCE_NETWORK:
progressBarLabel->setText(tr("Synchronizing with network..."));
break;
case BLOCK_SOURCE_DISK:
progressBarLabel->setText(tr("Importing blocks from disk..."));
break;
case BLOCK_SOURCE_REINDEX:
progressBarLabel->setText(tr("Reindexing blocks on disk..."));
break;
case BLOCK_SOURCE_NONE:
// Case: not Importing, not Reindexing and no network connection
progressBarLabel->setText(tr("No block source available..."));
break;
}

QString tooltip;

QString importText;
switch (blockSource) {
case BLOCK_SOURCE_NONE:
case BLOCK_SOURCE_NETWORK:
importText = tr("Synchronizing with network...");
break;
case BLOCK_SOURCE_DISK:
importText = tr("Importing blocks from disk...");
break;
case BLOCK_SOURCE_REINDEX:
importText = tr("Reindexing blocks on disk...");
}

QDateTime lastBlockDate = clientModel->getLastBlockDate();
QDateTime currentDate = QDateTime::currentDateTime();
int secs = lastBlockDate.secsTo(currentDate);
Expand Down Expand Up @@ -572,7 +567,6 @@ void BitcoinGUI::setNumBlocks(int count, int nTotalBlocks)
timeBehindText = tr("%n week(s)","",secs/(7*24*60*60));
}

progressBarLabel->setText(importText);
progressBarLabel->setVisible(true);
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
progressBar->setMaximum(1000000000);
Expand Down
7 changes: 5 additions & 2 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ enum BlockSource ClientModel::getBlockSource() const
{
if (fReindex)
return BLOCK_SOURCE_REINDEX;
if (fImporting)
else if (fImporting)
return BLOCK_SOURCE_DISK;
return BLOCK_SOURCE_NETWORK;
else if (getNumConnections() > 0)
return BLOCK_SOURCE_NETWORK;

return BLOCK_SOURCE_NONE;
}

int ClientModel::getNumBlocksOfPeers() const
Expand Down
4 changes: 2 additions & 2 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ QT_END_NAMESPACE

enum BlockSource {
BLOCK_SOURCE_NONE,
BLOCK_SOURCE_NETWORK,
BLOCK_SOURCE_REINDEX,
BLOCK_SOURCE_DISK,
BLOCK_SOURCE_REINDEX
BLOCK_SOURCE_NETWORK
};

/** Model for Bitcoin network client. */
Expand Down

0 comments on commit dc2de75

Please sign in to comment.