From 67670d83dc73cbc0db4e95dcfc7ff6e9d9a5983f Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 9 Mar 2011 20:04:43 +0100 Subject: javascriptInterface can be accessed by "fbgui" now (jsObject also for now..) --- src/DownloadManager.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/DownloadManager.cpp') diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index a80ab32..eb9832b 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -1,5 +1,6 @@ #include "DownloadManager.h" //#include +#include int DownloadManager::downloaded = 0; // ---------------------------------------------------------------------------------------- @@ -7,6 +8,7 @@ DownloadManager::DownloadManager() { qnam = new QNetworkAccessManager(); dip = false; + // the whole QDir thing is questionable.. downloadDir = QDir(downloadPath); // Check if downloadPath exists, if not create it. if (!downloadDir.exists()){ @@ -54,22 +56,23 @@ void DownloadManager::processDownloadRequest(QUrl& url) // ---------------------------------------------------------------------------------------- void DownloadManager::startNextDownload() { - if (debug) qDebug() << "Starting next download: " << dlQ.head().toString() - << "(" << dlQ.size() << "in queue.)"; if (dlQ.isEmpty()) { - if (debug) qDebug() << "Download queue empty! Exiting..."; + if (debug) qDebug() << "Download manager ready."; return; } + if (debug) qDebug() << "Starting next download: " << dlQ.head().toString() + << "(" << dlQ.size() << "in queue.)"; // Dequeue next URL to download. QUrl url = dlQ.dequeue(); + // Get filename from URL. QString tmp = url.path(); tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1); if (debug) qDebug() << "Extracted " << tmp << "from " << url.toString(); // TODO: check for if relative path, if so prepend binPath outfile.setFileName(downloadPath + "/" + tmp); - if (debug) qDebug() << "DM: Absolute path: " << downloadPath + "/" + tmp; + if (debug) qDebug() << "Trying to save to: " << downloadPath + "/" + tmp; if (outfile.exists()){ if (debug) qDebug() << "File already exists. Skipping: " << url.toString(); startNextDownload(); @@ -99,7 +102,7 @@ void DownloadManager::startNextDownload() QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished())); } // ---------------------------------------------------------------------------------------- -// Private slots for queueing functionality. +// Private slots // ---------------------------------------------------------------------------------------- // This slot listens to readyRead() emmited when data is available for reading. void DownloadManager::downloadReady() @@ -123,18 +126,20 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) // when all the data from the reply has been read. void DownloadManager::downloadFinished() { - // Second check if the download actually is finished. + // Second check if the download actually is finished just to be sure. if (currentDownload->isFinished()) if (debug) qDebug() << "Download of " << currentDownload->url().toString() << "finished." << endl; // Close output file. outfile.close(); currentDownload->deleteLater(); - ++downloaded; - // If queue is empty, we are done. + downloaded++; dip = false; - if (dlQ.isEmpty()) + // If queue is empty, we are done. + if (dlQ.isEmpty()){ + if (debug) qDebug() << "Download manager ready."; return; + } // Queue not empty: initialise next download. startNextDownload(); } -- cgit v1.2.3-55-g7522