Skip to content
Permalink
Browse files

Don't report the same download progress twice, report progress for un…

…known download sizes
  • Loading branch information
nyalldawson committed Oct 25, 2017
1 parent 016a8a2 commit e24333ae1960a1c452af13efbdc92f8a29ebeac3
@@ -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 );
}
}
@@ -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 );

0 comments on commit e24333a

Please sign in to comment.
You can’t perform that action at this time.