summaryrefslogtreecommitdiffstats
path: root/src/fbgui/downloadmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui/downloadmanager.cpp')
-rw-r--r--src/fbgui/downloadmanager.cpp74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/fbgui/downloadmanager.cpp b/src/fbgui/downloadmanager.cpp
index 653bc7b..79b51fc 100644
--- a/src/fbgui/downloadmanager.cpp
+++ b/src/fbgui/downloadmanager.cpp
@@ -1,5 +1,14 @@
#include "downloadmanager.h"
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr dmLogger(Logger::getLogger("fbgui.dm"));
+
+
// static counter to save the number of successfully downloaded files.
int DownloadManager::_downloaded = 0;
// -------------------------------------------------------------------------------------------------------
@@ -13,7 +22,7 @@ int DownloadManager::_downloaded = 0;
// Lastly the given download directory's existance is checked. (see below)
DownloadManager::DownloadManager() {
- qxtLog->debug() << "Initializing download manager...";
+ LOG4CXX_DEBUG(dmLogger, "Initializing download manager...");
checkDownloadDirectory();
_qnam = new QNetworkAccessManager();
_qnam->moveToThread(&dmThread);
@@ -28,31 +37,30 @@ void DownloadManager::checkDownloadDirectory() {
// check if downloadPath exists, if not create it.
_downloadDir = QDir(downloadPath);
if (!_downloadDir.exists()) {
- qxtLog->debug() << "[dm] Download directory: " << _downloadDir.path() << " doesn't exist.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download directory: " << _downloadDir.path() << " doesn't exist.");
// try to create the directory
- if (QDir::current().mkdir(downloadPath))
- qxtLog->debug() << "[dm] Created download directory: " << _downloadDir.path();
- else {
- qxtLog->debug() << "[dm] Failed to create directory: " << _downloadDir.path();
+ if (QDir::current().mkdir(downloadPath)){
+ LOG4CXX_DEBUG(dmLogger, "[dm] Created download directory: " << _downloadDir.path());
+ } else {
+ LOG4CXX_DEBUG(dmLogger, "[dm] Failed to create directory: " << _downloadDir.path());
// try to save to /tmp/fbgui
_downloadDir.setPath(QDir::tempPath() + "/fbgui");
if (!_downloadDir.exists()) {
- if (QDir::current().mkdir(QDir::tempPath() + "/fbgui"))
- qxtLog->debug() << "[dm] Successfully created: " << _downloadDir.absolutePath();
- else {
+ if (QDir::current().mkdir(QDir::tempPath() + "/fbgui")) {
+ LOG4CXX_DEBUG(dmLogger, "[dm] Successfully created: " << _downloadDir.absolutePath());
+ } else {
// just in case
- qxtLog->debug() << "[dm] Failed to create: " << _downloadDir.absolutePath();
- qxtLog->debug() << "[dm] Exiting...";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Failed to create: " << _downloadDir.absolutePath());
+ LOG4CXX_DEBUG(dmLogger, "[dm] Exiting...");
exit( EXIT_FAILURE);
}
} else
- qxtLog->debug() << "[dm] " << _downloadDir.absolutePath() << " already exists.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] " << _downloadDir.absolutePath() << " already exists.");
}
} else
- qxtLog->debug() << "[dm] Download directory: " << _downloadDir.absolutePath()
- << " already exists.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download directory: " << _downloadDir.absolutePath() << " already exists.");
- qxtLog->debug() << "[dm] Saving downloads to: " << _downloadDir.absolutePath();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Saving downloads to: " << _downloadDir.absolutePath());
downloadPath = _downloadDir.absolutePath();
}
// -------------------------------------------------------------------------------------------------------
@@ -71,15 +79,14 @@ void DownloadManager::downloadFile(const QUrl& fileUrl) {
// -------------------------------------------------------------------------------------------------------
void DownloadManager::processDownloadRequest(const QUrl& url) {
if (url.isEmpty()) {
- qxtLog->debug() << "[dm] No URL specified for download.";
+ LOG4CXX_DEBUG(dmLogger, "[dm] No URL specified for download.");
return;
}
- qxtLog->debug() << "[dm] Enqueueing: " << url.toString();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Enqueueing: " << url.toString());
_downloadQueue.enqueue(url);
if (_dip) {
// download in progress, return.
- qxtLog->debug() << "[dm] Download in progress! Queued:" << url.toString() << "("
- << _downloadQueue.size() << " in queue)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download in progress! Queued:" << url.toString() << "(" << _downloadQueue.size() << " in queue)");
return;
}
// no running downloads: start next in queue
@@ -90,11 +97,10 @@ void DownloadManager::startNextDownload() {
//QWSServer::instance()->setCursorVisible(false);
if (_downloadQueue.isEmpty()) {
emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (1)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download manager ready. (1)");
return;
}
- qxtLog->debug() << "[dm] Starting next download: " << _downloadQueue.head().toString() << " ("
- << _downloadQueue.size() - 1 << " in queue.)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Starting next download: " << _downloadQueue.head().toString() << " (" << _downloadQueue.size() - 1 << " in queue.)");
// dequeue next URL to download.
QUrl url = _downloadQueue.dequeue();
@@ -105,17 +111,16 @@ void DownloadManager::startNextDownload() {
// check if filename exists on target file system
if (_downloadDir.exists(tmp)) {
- qxtLog->debug() << "[dm] File already exists: " << _downloadDir.absoluteFilePath(tmp);
+ LOG4CXX_DEBUG(dmLogger, "[dm] File already exists: " << _downloadDir.absoluteFilePath(tmp));
_outfile.setFileName(
QString(_downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(_downloaded));
} else
_outfile.setFileName(_downloadDir.absoluteFilePath(tmp));
- qxtLog->debug() << "[dm] Saving to: " << _outfile.fileName();
+ LOG4CXX_DEBUG(dmLogger, "[dm] Saving to: " << _outfile.fileName());
// try to open for writing
if (!_outfile.open(QIODevice::WriteOnly)) {
- qxtLog->debug() << "[dm] No write access to " << _outfile.fileName()
- << " . Skipping download...";
+ LOG4CXX_DEBUG(dmLogger, "[dm] No write access to " << _outfile.fileName() << " . Skipping download...");
return;
}
@@ -143,8 +148,7 @@ void DownloadManager::processMetaInfo() {
const QByteArray cltag = "Content-Length";
QByteArray clinfo = _currentDownload->rawHeader(cltag);
QFileInfo fi(_outfile);
- qxtLog->debug() << "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble()
- << ")";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download Info: " << fi.fileName() << " (Size: " << clinfo.toDouble() << ")");
emit downloadInfo(fi.fileName(), clinfo.toDouble());
}
// -------------------------------------------------------------------------------------------------------
@@ -155,8 +159,7 @@ void DownloadManager::downloadReady() {
// -------------------------------------------------------------------------------------------------------
void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) {
if (bytesIn > bytesTotal || bytesTotal <= 0) {
- qxtLog->debug() << "[dm] downloadProgress invalid values:" << "In:" << bytesIn
- << " / Total: " << bytesTotal;
+ LOG4CXX_DEBUG(dmLogger, "[dm] downloadProgress invalid values:" << "In:" << bytesIn << " / Total: " << bytesTotal);
return;
}
// calculate current speed
@@ -177,8 +180,7 @@ void DownloadManager::downloadProgress(qint64 bytesIn, qint64 bytesTotal) {
_lastProgress = _currentProgress;
emit
updateProgress(_currentProgress, speed, unit);
- qxtLog->debug() << "[dm] Download progress of " << _currentDownload->url().toString() << ": "
- << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download progress of " << _currentDownload->url().toString() << ": " << bytesIn << "/" << bytesTotal << "(" << _currentProgress << "\%)");
}
}
// -------------------------------------------------------------------------------------------------------
@@ -189,8 +191,7 @@ void DownloadManager::downloadFinished() {
_outfile.remove();
int statusCode =
_currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString()
- << " failed with HTTP error code: " << statusCode;
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download of " << _currentDownload->url().toString() << " failed with HTTP error code: " << statusCode);
emit
notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode));
_currentDownload->deleteLater();
@@ -198,8 +199,7 @@ void DownloadManager::downloadFinished() {
// end download
_outfile.close();
_downloaded++;
- qxtLog->debug() << "[dm] Download of " << _currentDownload->url().toString()
- << " finished. (downloaded = " << _downloaded << ")";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download of " << _currentDownload->url().toString() << " finished. (downloaded = " << _downloaded << ")");
emit
notify(QString("Successfully downloaded %1").arg(_currentDownload->url().toString()));
_currentDownload->deleteLater();
@@ -208,7 +208,7 @@ void DownloadManager::downloadFinished() {
// process next in queue, if any
if (_downloadQueue.isEmpty()) {
emit downloadQueueEmpty();
- qxtLog->debug() << "[dm] Download manager ready. (2)";
+ LOG4CXX_DEBUG(dmLogger, "[dm] Download manager ready. (2)");
return;
}
startNextDownload();