summaryrefslogtreecommitdiffstats
path: root/src/downloadManager.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-21 10:51:51 +0100
committerJonathan Bauer2011-03-21 10:51:51 +0100
commit635b5c64f3107d4c01ae314fb75e02c571b51c54 (patch)
tree4d2a3a679a569f9133ca8d3d5f5159b393accde3 /src/downloadManager.cpp
parentdebug modes. -D now needs an arg: 0 for regular terminal output, 1 for debug ... (diff)
downloadfbgui-635b5c64f3107d4c01ae314fb75e02c571b51c54.tar.gz
fbgui-635b5c64f3107d4c01ae314fb75e02c571b51c54.tar.xz
fbgui-635b5c64f3107d4c01ae314fb75e02c571b51c54.zip
transformed c syntax comments to c++ convention...
Diffstat (limited to 'src/downloadManager.cpp')
-rw-r--r--src/downloadManager.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
index 4602c9d..9b4c162 100644
--- a/src/downloadManager.cpp
+++ b/src/downloadManager.cpp
@@ -3,16 +3,16 @@
int downloadManager::downloaded = 0;
// ----------------------------------------------------------------------------------------
-downloadManager::downloadManager()
-{
+downloadManager::downloadManager(){
qxtLog->debug() << "Initializing download manager...";
checkDownloadDirectory();
qnam = new QNetworkAccessManager();
dip = false;
}
// ----------------------------------------------------------------------------------------
-void downloadManager::checkDownloadDirectory(){
- /* check if downloadPath exists, if not create it. */
+void downloadManager::checkDownloadDirectory()
+{
+ // check if downloadPath exists, if not create it.
downloadDir = QDir(downloadPath);
if (!downloadDir.exists()){
qxtLog->debug() << "Download directory: " << downloadDir.path() << " doesn't exist.";
@@ -22,13 +22,12 @@ void downloadManager::checkDownloadDirectory(){
}
else {
qxtLog->debug() << "Failed to create directory: " << downloadDir.path();
- emit notify(QString("Failed to create download directory!"));
- /* try to save to /tmp/fbgui */
+ // try to save to /tmp/fbgui
downloadDir.setPath(QDir::tempPath () + "/fbgui");
if (!downloadDir.exists()){
QDir::current().mkdir(QDir::tempPath () + "/fbgui");
if (!downloadDir.exists()){
- /* TODO: dont exit, this shouldn't happen anyway (right?) */
+ // TODO: dont exit, this shouldn't happen anyway (right?)
qxtLog->debug() << "Fatal, no target for downloads. Exiting...";
exit(EXIT_FAILURE);
}
@@ -56,14 +55,14 @@ void downloadManager::processDownloadRequest(QUrl& url)
qxtLog->debug() << "No URL specified for download.";
return;
}
- /* if download in progress, enqueue file and return. */
+ // if download in progress, enqueue file and return.
if (dip){
dlQ.enqueue(url);
qxtLog->debug() << "Download in progress! Queued:" << url.toString()
<< "(" << dlQ.size() << " in queue)";
return;
}
- /* no running downloads: enqueue and start next download. */
+ // no running downloads: enqueue and start next download.
dlQ.enqueue(url);
qxtLog->debug() << "Enqueueing:" << url.toString();
startNextDownload();
@@ -79,14 +78,14 @@ void downloadManager::startNextDownload()
qxtLog->debug() << "Starting next download: " << dlQ.head().toString()
<< " (" << dlQ.size() - 1 << " in queue.)";
- /* dequeue next URL to download. */
+ // dequeue next URL to download.
QUrl url = dlQ.dequeue();
- /* get filename from URL. */
+ // get filename from URL.
QString tmp = url.path();
tmp.remove(0, tmp.lastIndexOf(QChar('/')) + 1);
- /* check if filename exists on target file system */
+ // check if filename exists on target file system
if (downloadDir.exists(tmp)){
qxtLog->debug() << "File already exists: " << downloadDir.absoluteFilePath(tmp);
outfile.setFileName(QString(downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(downloaded));
@@ -95,13 +94,13 @@ void downloadManager::startNextDownload()
outfile.setFileName(downloadDir.absoluteFilePath(tmp));
qxtLog->debug() << "Saving to: " << outfile.fileName();
- /* try to open for writing */
+ // try to open for writing
if (!outfile.open(QIODevice::WriteOnly)){
qxtLog->debug() << "No write access to " << outfile.fileName() << " . Skipping download...";
return;
}
- /* send the request for the file */
+ // send the request for the file
QNetworkRequest request(url);
currentDownload = qnam->get(request);
lastProgress = 0;
@@ -117,8 +116,9 @@ void downloadManager::startNextDownload()
// ----------------------------------------------------------------------------------------
// Private slots to process downloads
// ----------------------------------------------------------------------------------------
-void downloadManager::processMetaInfo(){
- /* fetch filesize from header & filename from url (for now) */
+void downloadManager::processMetaInfo()
+{
+ // fetch filesize from header & filename from URL (for now)
const QByteArray cltag = "Content-Length";
QByteArray clinfo = currentDownload->rawHeader(cltag);
QFileInfo fi(outfile);
@@ -127,14 +127,14 @@ void downloadManager::processMetaInfo(){
// ----------------------------------------------------------------------------------------
void downloadManager::downloadReady()
{
- /* data ready, save it */
+ // data ready, save it
outfile.write(currentDownload->readAll());
}
// ----------------------------------------------------------------------------------------
void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
{
if (bytesIn > bytesTotal) return;
- /* calculate current speed */
+ // calculate current speed
double speed = bytesIn * 1000 / dltime.elapsed();
QString unit;
if (speed < 1024) {
@@ -148,7 +148,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;
@@ -161,7 +161,7 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
// ----------------------------------------------------------------------------------------
void downloadManager::downloadFinished()
{
- /* check for errors */
+ // check for errors
if (currentDownload->error()){
currentDownload->deleteLater();
outfile.remove();
@@ -171,7 +171,7 @@ void downloadManager::downloadFinished()
emit notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode));
}
else{
- /* end download */
+ // end download
currentDownload->deleteLater();
outfile.close();
downloaded++;
@@ -180,7 +180,7 @@ void downloadManager::downloadFinished()
emit notify(QString("Successfully downloaded %1").arg(currentDownload->url().toString()));
}
dip = false;
- /* process next in queue */
+ // process next in queue
if (dlQ.isEmpty()){
emit downloadQueueEmpty();
qxtLog->debug() << "Download manager ready. (2)";
@@ -188,7 +188,7 @@ void downloadManager::downloadFinished()
}
startNextDownload();
}
-/* ----------------------------------------------------------------------------------------
+/********************************************************************************************************
*
** dead code: Header filename fetching & renaming **