summaryrefslogtreecommitdiffstats
path: root/src/downloadManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/downloadManager.cpp')
-rw-r--r--src/downloadManager.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
index 239bbea..0262efe 100644
--- a/src/downloadManager.cpp
+++ b/src/downloadManager.cpp
@@ -8,9 +8,8 @@ downloadManager::downloadManager()
{
qnam = new QNetworkAccessManager();
dip = false;
- infoSent = false;
downloadDir = QDir(downloadPath);
- /* Check if downloadPath exists, if not create it. */
+ /* check if downloadPath exists, if not create it. */
if (!downloadDir.exists()){
if (debug) qDebug() << "Download directory: " << downloadDir.path() << "doesn't exist.";
QDir::current().mkdir(downloadPath);
@@ -41,7 +40,7 @@ void downloadManager::processDownloadRequest(QUrl& url)
if (debug) qDebug() << "No URL specified for download.";
return;
}
- /* If download in progress, enqueue file and return. */
+ /* if download in progress, enqueue file and return. */
if (dip)
{
if (debug) qDebug() << "Download in progress! Enqueueing:" << url.toString()
@@ -49,7 +48,7 @@ void downloadManager::processDownloadRequest(QUrl& url)
dlQ.enqueue(url);
return;
}
- /* No running downloads: enqueue and start next download. */
+ /* no running downloads: enqueue and start next download. */
dlQ.enqueue(url);
if (debug) qDebug() << "Enqueueing:" << url.toString() << endl;
startNextDownload();
@@ -67,10 +66,10 @@ void downloadManager::startNextDownload()
if (debug) qDebug() << "Starting next download: " << dlQ.head().toString()
<< "(" << dlQ.size() << "in queue.)";
- /* Dequeue next URL to download. */
+ /* dequeue next URL to download. */
QUrl url = dlQ.dequeue();
- /* Get temporary filename from URL. */
+ /* get temporary filename from URL. */
QString tmp = url.path();
tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
if (debug) qDebug() << "Extracted " << tmp << "from " << url.toString();
@@ -82,7 +81,7 @@ void downloadManager::startNextDownload()
return;
}
- /* Send the request for the file */
+ /* send the request for the file */
QNetworkRequest request(url);
currentDownload = qnam->get(request);
lastProgress = 0;
@@ -99,18 +98,16 @@ void downloadManager::startNextDownload()
// Private slots
// ----------------------------------------------------------------------------------------
void downloadManager::processMetaInfo(){
+ /* fetch filesize from header & filename from url (for now) */
const QByteArray cltag = "Content-Length";
QByteArray clinfo = currentDownload->rawHeader(cltag);
- if (!infoSent){
- QFileInfo fi(outfile);
- emit downloadInfo(outfile.fileName(), clinfo.toDouble());
- infoSent = true;
- }
+ QFileInfo fi(outfile);
+ emit downloadInfo(outfile.fileName(), clinfo.toDouble());
}
// ----------------------------------------------------------------------------------------
void downloadManager::downloadReady()
{
- /* Data ready, save it */
+ /* data ready, save it */
outfile.write(currentDownload->readAll());
}
// ----------------------------------------------------------------------------------------
@@ -119,7 +116,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
// "fix" for the weird bytesTotal = -1 initial reading...
if (bytesIn > bytesTotal)
return;
- /* Calculate current speed */
+ /* calculate current speed */
double speed = bytesIn * 1000 / dltime.elapsed();
QString unit;
if (speed < 1024) {
@@ -131,7 +128,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
speed /= 1024*1024;
unit = "MB/s";
}
- /* Update progress only if difference higher than the updateInterval setting */
+ /* update progress only if difference higher than the updateInterval setting */
currentProgress = ((bytesIn * 100) / bytesTotal);
if (currentProgress - lastProgress >= updateInterval){
lastProgress = currentProgress;
@@ -144,7 +141,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
// ----------------------------------------------------------------------------------------
void downloadManager::downloadFinished()
{
-
+ /* check for errors */
if (currentDownload->error()){
if (debug) qDebug() << "Download of" << currentDownload->url().toString()
<< "failed with status code: " << currentDownload->error();
@@ -155,11 +152,11 @@ void downloadManager::downloadFinished()
// TODO Handle errors.
if (debug) qDebug() << "NetworkCode: " << currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ /* end download */
outfile.close();
currentDownload->deleteLater();
downloaded++;
dip = false;
- infoSent = false;
if (debug) qDebug() << "Download of " << currentDownload->url().toString()
<< "finished. (dlcount = "<< downloaded << ")";
if (dlQ.isEmpty()){