summaryrefslogtreecommitdiffstats
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-04-15 16:47:09 +0200
committerJonathan Bauer2011-04-15 16:47:09 +0200
commitdb5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7 (patch)
tree40872f5f474dd80f07323fb452b88992eff3ecd8 /src/downloadmanager.cpp
parentDownload manager now threaded (Ticket #205) & change the watcher to create th... (diff)
downloadfbgui-db5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7.tar.gz
fbgui-db5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7.tar.xz
fbgui-db5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7.zip
fixes & misc
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index eb00354..9faad88 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -6,10 +6,13 @@ int DownloadManager::downloaded = 0;
DownloadManager::DownloadManager(){
qxtLog->debug() << "Initializing download manager...";
checkDownloadDirectory();
- qnam = new QNetworkAccessManager();
- qnam->moveToThread(&dmThread);
+ _qnam = new QNetworkAccessManager();
+ //_qnam->moveToThread(&dmThread);
dip = false;
}
+DownloadManager::~DownloadManager(){
+ delete _qnam;
+}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::checkDownloadDirectory()
{
@@ -66,7 +69,7 @@ void DownloadManager::processDownloadRequest(const QUrl& url)
qxtLog->debug() << "[dm] No URL specified for download.";
return;
}
- qxtLog->debug() << "[dm] Enqueueing:" << url.toString();
+ qxtLog->debug() << "[dm] Enqueueing: " << url.toString();
dlQ.enqueue(url);
if (dip){
// download in progress, return.
@@ -112,11 +115,11 @@ void DownloadManager::startNextDownload()
// send the request for the file
QNetworkRequest request(url);
- currentDownload = qnam->get(request);
+ currentDownload = _qnam->get(request);
lastProgress = 0;
currentProgress = 0;
dip = true;
- dltime.start();
+ _time.start();
QObject::connect(currentDownload, SIGNAL(readyRead()), this, SLOT(downloadReady()));
QObject::connect(currentDownload, SIGNAL(metaDataChanged()), this, SLOT(processMetaInfo()));
QObject::connect(currentDownload, SIGNAL(downloadProgress(qint64, qint64)),
@@ -132,7 +135,8 @@ void DownloadManager::processMetaInfo()
const QByteArray cltag = "Content-Length";
QByteArray clinfo = currentDownload->rawHeader(cltag);
QFileInfo fi(outfile);
- emit downloadInfo(outfile.fileName(), clinfo.toDouble());
+ qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() << ")";
+ emit downloadInfo(fi.fileName(), clinfo.toDouble());
}
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadReady()
@@ -143,9 +147,13 @@ void DownloadManager::downloadReady()
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal)
{
- if (bytesIn > bytesTotal) return;
+ if (bytesIn > bytesTotal || bytesTotal <= 0){
+ qxtLog->debug() << "[dm] downloadProgress invalid values:"
+ << "In:" << bytesIn << " / Total: " << bytesTotal;
+ return;
+ }
// calculate current speed
- double speed = bytesIn * 1000 / dltime.elapsed();
+ double speed = bytesIn * 1000 / _time.elapsed();
QString unit;
if (speed < 1024){
unit = "bytes/sec";