diff options
| author | Jonathan Bauer | 2011-03-16 01:43:47 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-16 01:43:47 +0100 |
| commit | 96b2528849d676ff0094dc06182031ac4506b937 (patch) | |
| tree | 2f7af1c476e2f9d7c51644ce7ed535e4870c7c94 /src | |
| parent | -test code (diff) | |
| download | fbgui-96b2528849d676ff0094dc06182031ac4506b937.tar.gz fbgui-96b2528849d676ff0094dc06182031ac4506b937.tar.xz fbgui-96b2528849d676ff0094dc06182031ac4506b937.zip | |
misc
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadManager.cpp | 31 | ||||
| -rw-r--r-- | src/downloadManager.h | 2 | ||||
| -rw-r--r-- | src/main.cpp | 18 |
3 files changed, 24 insertions, 27 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()){ diff --git a/src/downloadManager.h b/src/downloadManager.h index 2c0a021..2e26b70 100644 --- a/src/downloadManager.h +++ b/src/downloadManager.h @@ -48,7 +48,7 @@ private: QFile outfile; QDir downloadDir; QTime dltime; - bool dip, infoSent; + bool dip; int currentProgress, lastProgress; static int downloaded; diff --git a/src/main.cpp b/src/main.cpp index 8f2b6a5..3138838 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,6 @@ void printHelp() { - // Prints usage information. QTextStream qout(stdout); qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; @@ -28,12 +27,11 @@ int main(int argc, char *argv[]) app.setObjectName("test"); binPath = QApplication::applicationDirPath(); - // Translator, for later (maybe). QTranslator translator; translator.load(":" + QLocale::system().name()); app.installTranslator(&translator); - /* Parse cmdline argus. */ + /* parse command line arguments */ QMap<QString, QString> clOpts; int longIndex = 0; static const char *optString = "u:d:c:Dh"; @@ -67,14 +65,15 @@ int main(int argc, char *argv[]) } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } - // Print help + if (clOpts.contains("help")) - printHelp(); - // Debug mode + printHelp(); + if (clOpts.contains("debug")){ debug = true; qDebug() << "Debug mode activated."; } + /* "search" config file */ QString configFilePath; QFileInfo confInfo; if (clOpts.contains("configFile")) @@ -94,7 +93,7 @@ int main(int argc, char *argv[]) } if (debug) qDebug() << "Config file is: " << configFilePath; - // Read the config file, for now hardcoded expected name. + /* read the config file */ QSettings confFileSettings(configFilePath, QSettings::IniFormat); confFileSettings.setIniCodec("UTF-8"); @@ -112,7 +111,7 @@ int main(int argc, char *argv[]) } if (debug) qDebug() << "Base URL: " << baseURL.toString(); - // Setting target downloads directory. + /* setting directory for downloads*/ if (clOpts.contains("downloadDir")){ downloadPath = clOpts.value("downloadDir"); if (debug) qDebug() << "Download directory loaded from cmdline."; @@ -123,7 +122,7 @@ int main(int argc, char *argv[]) } else { - downloadPath = DEFAULT_DOWNLOAD_DIR; // Default download dir. + downloadPath = DEFAULT_DOWNLOAD_DIR; if (debug) qDebug() << "Download directory set by default."; } if (debug) qDebug() << "Download directory: " << downloadPath; @@ -132,6 +131,7 @@ int main(int argc, char *argv[]) updateInterval = confFileSettings.value("default/updateInterval").toInt(); if (debug) qDebug() << "Read updateInterval from confFile: " << updateInterval; } + else updateInterval = DEFAULT_UPDATE_INTERVAL; fbgui gui; return app.exec(); |
