summaryrefslogtreecommitdiffstats
path: root/src/downloadManager.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-16 01:22:15 +0100
committerJonathan Bauer2011-03-16 01:22:15 +0100
commit50c0d85dbe0d604b00c35b67a5ddf6c19cd1c105 (patch)
tree1c1fb412d84f71e6be496388de3bafd3ec77972a /src/downloadManager.cpp
parentfbgui.conf (diff)
downloadfbgui-50c0d85dbe0d604b00c35b67a5ddf6c19cd1c105.tar.gz
fbgui-50c0d85dbe0d604b00c35b67a5ddf6c19cd1c105.tar.xz
fbgui-50c0d85dbe0d604b00c35b67a5ddf6c19cd1c105.zip
javascriptInterface: downloadInfo(filename, filesize) filesize in bytes
Diffstat (limited to 'src/downloadManager.cpp')
-rw-r--r--src/downloadManager.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp
index e17b459..25f012a 100644
--- a/src/downloadManager.cpp
+++ b/src/downloadManager.cpp
@@ -8,6 +8,7 @@ downloadManager::downloadManager()
{
qnam = new QNetworkAccessManager();
dip = false;
+ infoSent = false;
downloadDir = QDir(downloadPath);
/* Check if downloadPath exists, if not create it. */
if (!downloadDir.exists()){
@@ -89,6 +90,7 @@ void downloadManager::startNextDownload()
dip = true;
dltime.start();
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
+ QObject::connect(currentDownload, SIGNAL(metaDataChanged()), this, SLOT(processMetaInfo()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
this, SLOT(downloadProgress(qint64, qint64)));
QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished()));
@@ -96,8 +98,22 @@ void downloadManager::startNextDownload()
// ----------------------------------------------------------------------------------------
// Private slots
// ----------------------------------------------------------------------------------------
+void downloadManager::processMetaInfo(){
+ const QByteArray cltag = "Content-Length";
+ QByteArray clinfo = currentDownload->rawHeader(cltag);
+ qDebug() << "feel spammy?";
+ if (!infoSent){
+ if (debug) qDebug() << "MetaChanged: " << outfile.fileName() << "";
+ QFileInfo fi(outfile);
+ emit downloadInfo(outfile.fileName(), clinfo.toDouble());
+ infoSent = true;
+ }
+}
+// ----------------------------------------------------------------------------------------
void downloadManager::downloadReady()
-{
+{
+ /* Send file information */
+
/* Data ready, save it */
outfile.write(currentDownload->readAll());
}
@@ -119,13 +135,11 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
speed /= 1024*1024;
unit = "MB/s";
}
- if (debug) qDebug() << "speed: " << speed << unit;
/* Update progress only if difference higher than the updateInterval setting */
currentProgress = ((bytesIn * 100) / bytesTotal);
if (currentProgress - lastProgress >= updateInterval){
lastProgress = currentProgress;
-
- emit updateProgress(currentProgress, speed);
+ emit updateProgress(currentProgress, speed, unit);
if (debug) qDebug() << "Download progress of " << currentDownload->url().toString()
<< ": " << bytesIn << "/" << bytesTotal << "(" << currentProgress << "\%)";
}
@@ -135,9 +149,13 @@ void downloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
void downloadManager::downloadFinished()
{
- if (currentDownload->error())
+ if (currentDownload->error()){
if (debug) qDebug() << "Download of" << currentDownload->url().toString()
<< "failed with status code: " << currentDownload->error();
+ currentDownload->deleteLater();
+ outfile.remove();
+ return;
+ }
// TODO Handle errors.
if (debug) qDebug() << "NetworkCode: " << currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@@ -145,12 +163,12 @@ void downloadManager::downloadFinished()
currentDownload->deleteLater();
downloaded++;
dip = false;
+ infoSent = false;
if (debug) qDebug() << "Download of " << currentDownload->url().toString()
<< "finished. (dlcount = "<< downloaded << ")";
if (dlQ.isEmpty()){
emit downloadQueueEmpty();
if (debug) qDebug() << "Download manager ready. (2)";
-
return;
}
startNextDownload();