From 3e018bf61b264d7f02df0d436b2a6aa163a926d7 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 9 Mar 2011 21:04:51 +0100 Subject: DM: update sends only signals if the progress difference is >1% --- src/DownloadManager.cpp | 14 ++++++++++---- src/DownloadManager.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index 9f59010..ec723a9 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -96,6 +96,7 @@ void DownloadManager::startNextDownload() return; } dip = true; + currentProgress = 0; QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady())); QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64))); @@ -111,15 +112,20 @@ void DownloadManager::downloadReady() outfile.write(currentDownload->readAll()); } // ---------------------------------------------------------------------------------------- -// This slot listens to the downloadProgress(..) -// which provides information on the download progress of the file. +// This triggers sends the update progress back to the site. void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) { if (debug) qDebug() << "Download progress of " << currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal; - qint64 tmp = ((bytesIn * 100) / bytesTotal); - emit updateProgress(currentDownload->url().toString(), (int)tmp); + + int tmp = ((bytesIn * 100) / bytesTotal); + if (tmp > currentProgress){ + currentProgress = tmp; + emit updateProgress(currentDownload->url().toString(), tmp); + } + // Progress difference < 1% + return; } // ---------------------------------------------------------------------------------------- // This slot listens to the finished() which is emmited diff --git a/src/DownloadManager.h b/src/DownloadManager.h index 363b426..53c2014 100644 --- a/src/DownloadManager.h +++ b/src/DownloadManager.h @@ -31,6 +31,7 @@ private: QDir downloadDir; // Download-in-progress flag. bool dip; + int currentProgress; static int downloaded; signals: -- cgit v1.2.3-55-g7522