summaryrefslogtreecommitdiffstats
path: root/src/DownloadManager.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-08 20:09:24 +0100
committerJonathan Bauer2011-03-08 20:09:24 +0100
commit6fde95f2921208361f3e5de1f419930bdefdc7fd (patch)
treee1d32448ea39c6fab2e911b53ac5814fa40b3d6b /src/DownloadManager.cpp
parentMerge branch 'master' of git.openslx.org:lsfks/master-teamprojekt/fbgui (diff)
downloadfbgui-6fde95f2921208361f3e5de1f419930bdefdc7fd.tar.gz
fbgui-6fde95f2921208361f3e5de1f419930bdefdc7fd.tar.xz
fbgui-6fde95f2921208361f3e5de1f419930bdefdc7fd.zip
host lookup, better MAC/IP info functions, IP one doesn't quite work yet
Diffstat (limited to 'src/DownloadManager.cpp')
-rw-r--r--src/DownloadManager.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp
index eec6909..a80ab32 100644
--- a/src/DownloadManager.cpp
+++ b/src/DownloadManager.cpp
@@ -3,6 +3,21 @@
int DownloadManager::downloaded = 0;
// ----------------------------------------------------------------------------------------
+DownloadManager::DownloadManager()
+{
+ qnam = new QNetworkAccessManager();
+ dip = false;
+ downloadDir = QDir(downloadPath);
+ // 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);
+ if (downloadDir.exists() && debug)
+ qDebug() << "Created download directory: " << downloadDir.path();
+ }
+ else if (debug) qDebug() << "Download directory: " << downloadDir.path() << "exists.";
+}
+// ----------------------------------------------------------------------------------------
void DownloadManager::downloadFile(QString& filename){
if (debug) qDebug() << "DM received signal for: " << filename;
QUrl fileUrl;
@@ -17,7 +32,12 @@ void DownloadManager::downloadFile(QUrl& fileUrl){
// ----------------------------------------------------------------------------------------
void DownloadManager::processDownloadRequest(QUrl& url)
{
- // Forge URL from the given filename and the base URL.
+ // Test on empty URL in case such a call happens, which should not
+ // happen given how javascriptInterface::startDownload(..) is implemented.
+ if (url.isEmpty()){
+ if (debug) qDebug() << "No URL specified for download.";
+ return;
+ }
// If download in progress, enqueue file and return.
if (dip)
{
@@ -36,7 +56,6 @@ 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...";
@@ -59,7 +78,7 @@ void DownloadManager::startNextDownload()
// If error upon opening, skip this file.
if (!outfile.open(QIODevice::WriteOnly))
{
- if (debug) qDebug() << "Couldn't open file! Exiting...";
+ if (debug) qDebug() << "Couldn't open file! Skipping: " << url.toString();
startNextDownload();
return;
}
@@ -80,7 +99,7 @@ void DownloadManager::startNextDownload()
QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
// ----------------------------------------------------------------------------------------
-// Slots for the signals emmited by currentDownload.
+// Private slots for queueing functionality.
// ----------------------------------------------------------------------------------------
// This slot listens to readyRead() emmited when data is available for reading.
void DownloadManager::downloadReady()
@@ -119,18 +138,4 @@ void DownloadManager::downloadFinished()
// Queue not empty: initialise next download.
startNextDownload();
}
-// ----------------------------------------------------------------------------------------
-// Constructor.
-DownloadManager::DownloadManager()
-{
- qnam = new QNetworkAccessManager();
- dip = false;
- downloadDir = QDir(downloadPath);
- // 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);
- if (downloadDir.exists() && debug) qDebug() << "Created download directory: " << downloadPath;
- }
- else if (debug) qDebug() << "Download directory: " << downloadDir.path() << "exists.";
-}
+