summaryrefslogtreecommitdiffstats
path: root/src/downloadManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/downloadManager.cpp')
-rw-r--r--src/downloadManager.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
index dca99d3..f7a6372 100644
--- a/src/downloadManager.cpp
+++ b/src/downloadManager.cpp
@@ -19,7 +19,8 @@ downloadManager::downloadManager()
else if (debug) qDebug() << "Download directory: " << downloadDir.path() << "exists.";
}
// ----------------------------------------------------------------------------------------
-void downloadManager::downloadFile(QString& filename){
+void downloadManager::downloadFile(QString& filename)
+{
if (debug) qDebug() << "Received downloadFile signal for:" << filename;
QUrl fileUrl;
fileUrl = baseURL.resolved(QUrl(filename));
@@ -27,7 +28,8 @@ void downloadManager::downloadFile(QString& filename){
this->processDownloadRequest(fileUrl);
}
// ----------------------------------------------------------------------------------------
-void downloadManager::downloadFile(QUrl& fileUrl){
+void downloadManager::downloadFile(QUrl& fileUrl)
+{
if (debug) qDebug() << "Received downloadFile signal for:" << fileUrl;
this->processDownloadRequest(fileUrl);
}
@@ -88,6 +90,7 @@ void downloadManager::startNextDownload()
}
lastProgress = 0;
+ currentProgress = 0;
dip = true;
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
@@ -105,9 +108,14 @@ void downloadManager::downloadReady()
// ----------------------------------------------------------------------------------------
void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
{
+ if (bytesIn > bytesTotal)
+ return;
+
/* Update progress only if difference higher than the updateInterval setting */
- int currentProgress = ((bytesIn * 100) / bytesTotal);
- if (currentProgress - lastProgress > updateInterval){
+ int tmp = ((bytesIn * 100) / bytesTotal);
+ if (tmp > 0)
+ currentProgress = tmp;
+ if (currentProgress - lastProgress >= updateInterval){
lastProgress = currentProgress;
emit updateProgress(currentDownload->url().toString(), currentProgress);
if (debug) qDebug() << "Download progress of " << currentDownload->url().toString()
@@ -118,7 +126,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
// ----------------------------------------------------------------------------------------
void downloadManager::downloadFinished()
{
- /* Header filename fetching & renaming, old-ish
+ /* Header filename fetching & renaming
const QByteArray cd = "Content-Disposition";
QByteArray cdc = currentDownload->rawHeader(cd);
int x = cdc.indexOf("filename=\"") + 10;
@@ -154,4 +162,5 @@ void downloadManager::downloadFinished()
}
startNextDownload();
}
+// ----------------------------------------------------------------------------------------