diff options
| author | Jonathan Bauer | 2011-03-09 20:04:43 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-09 20:04:43 +0100 |
| commit | 67670d83dc73cbc0db4e95dcfc7ff6e9d9a5983f (patch) | |
| tree | 58f39305a86d0d2d17adba5f7fd6dd57f96a8bdf /src/DownloadManager.cpp | |
| parent | misc (diff) | |
| download | fbgui-67670d83dc73cbc0db4e95dcfc7ff6e9d9a5983f.tar.gz fbgui-67670d83dc73cbc0db4e95dcfc7ff6e9d9a5983f.tar.xz fbgui-67670d83dc73cbc0db4e95dcfc7ff6e9d9a5983f.zip | |
javascriptInterface can be accessed by "fbgui" now (jsObject also for now..)
Diffstat (limited to 'src/DownloadManager.cpp')
| -rw-r--r-- | src/DownloadManager.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
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 <QDir> +#include <QFileInfo> 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(); } |
