From db5c7e3c4b3d85b0e8d9890bcbd0477a31ada3b7 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 15 Apr 2011 16:47:09 +0200 Subject: fixes & misc --- src/downloadmanager.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/downloadmanager.cpp') 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"; -- cgit v1.2.3-55-g7522