Skip to content

Commit

Permalink
Don't report the same download progress twice, report progress for un…
Browse files Browse the repository at this point in the history
…known download sizes
  • Loading branch information
nyalldawson committed Oct 25, 2017
1 parent 016a8a2 commit e24333a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/analysis/processing/qgsalgorithmfiledownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,24 @@ void QgsFileDownloaderAlgorithm::reportErrors( QStringList errors )

void QgsFileDownloaderAlgorithm::sendProgressFeedback()
{
if ( ! mReceived.isEmpty() && ! mTotal.isEmpty() )
mFeedback->pushInfo( tr( "%1 of %2 downloaded." ).arg( mReceived ).arg( mTotal ) );
if ( !mReceived.isEmpty() && mLastReport != mReceived )
{
mLastReport = mReceived;
if ( mTotal.isEmpty() )
mFeedback->pushInfo( tr( "%1 downloaded." ).arg( mReceived ) );
else
mFeedback->pushInfo( tr( "%1 of %2 downloaded." ).arg( mReceived ).arg( mTotal ) );
}
}

void QgsFileDownloaderAlgorithm::receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal )
{
if ( bytesTotal != 0 )
mReceived = humanSize( bytesReceived );
if ( bytesTotal > 0 )
{
if ( mTotal.isEmpty() )
mTotal = humanSize( bytesTotal );

mReceived = humanSize( bytesReceived );
mFeedback->setProgress( ( bytesReceived * 100 ) / bytesTotal );
}
}
Expand Down
1 change: 1 addition & 0 deletions src/analysis/processing/qgsalgorithmfiledownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class QgsFileDownloaderAlgorithm : public QgsProcessingAlgorithm, public QObject
QString mTotal;
QString mReceived;
QgsProcessingFeedback *mFeedback = nullptr;
QString mLastReport;
void reportErrors( QStringList errors );
void receiveProgressFromDownloader( qint64 bytesReceived, qint64 bytesTotal );
static QString humanSize( qint64 &bytes );
Expand Down

0 comments on commit e24333a

Please sign in to comment.