diff options
| author | Jonathan Bauer | 2011-03-20 21:45:12 +0100 |
|---|---|---|
| committer | Jonathan Bauer | 2011-03-20 21:45:12 +0100 |
| commit | 9dc48f82aa681c10673341c2f7ce97d9e4a1f9e0 (patch) | |
| tree | d4ccb652c80041849a2cdf546a751d8cb9fda358 /src | |
| parent | comment & removed old tests (diff) | |
| download | fbgui-9dc48f82aa681c10673341c2f7ce97d9e4a1f9e0.tar.gz fbgui-9dc48f82aa681c10673341c2f7ce97d9e4a1f9e0.tar.xz fbgui-9dc48f82aa681c10673341c2f7ce97d9e4a1f9e0.zip | |
checks for existance of download dir, and tries to set to /tmp/fbgui if all fails. More notify()
Diffstat (limited to 'src')
| -rw-r--r-- | src/downloadManager.cpp | 38 | ||||
| -rw-r--r-- | src/downloadManager.h | 1 | ||||
| -rw-r--r-- | src/loggerEngine.cpp | 9 |
3 files changed, 30 insertions, 18 deletions
diff --git a/src/downloadManager.cpp b/src/downloadManager.cpp index 3d47990..4602c9d 100644 --- a/src/downloadManager.cpp +++ b/src/downloadManager.cpp @@ -13,7 +13,7 @@ downloadManager::downloadManager() // ---------------------------------------------------------------------------------------- void downloadManager::checkDownloadDirectory(){ /* check if downloadPath exists, if not create it. */ - QDir downloadDir = QDir(downloadPath); + downloadDir = QDir(downloadPath); if (!downloadDir.exists()){ qxtLog->debug() << "Download directory: " << downloadDir.path() << " doesn't exist."; QDir::current().mkdir(downloadPath); @@ -23,6 +23,17 @@ 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 */ + 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?) */ + qxtLog->debug() << "Fatal, no target for downloads. Exiting..."; + exit(EXIT_FAILURE); + } + } + qxtLog->debug() << "Saving downloads to: " << downloadDir.absolutePath(); } } else qxtLog->debug() << "Download directory: " << downloadDir.path() << " exists."; @@ -47,9 +58,9 @@ void downloadManager::processDownloadRequest(QUrl& url) } /* if download in progress, enqueue file and return. */ if (dip){ - qxtLog->debug() << "Download in progress! Enqueueing:" << url.toString() - << "(" << dlQ.size() << " in queue)"; dlQ.enqueue(url); + qxtLog->debug() << "Download in progress! Queued:" << url.toString() + << "(" << dlQ.size() << " in queue)"; return; } /* no running downloads: enqueue and start next download. */ @@ -71,22 +82,22 @@ void downloadManager::startNextDownload() /* dequeue next URL to download. */ QUrl url = dlQ.dequeue(); - /* get temporary 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 */ - QFileInfo fi(downloadPath + "/" + tmp); - if (fi.exists()){ - QString qs = QString(fi.absoluteFilePath() + ".\%1").arg(downloaded); - outfile.setFileName(qs); + if (downloadDir.exists(tmp)){ + qxtLog->debug() << "File already exists: " << downloadDir.absoluteFilePath(tmp); + outfile.setFileName(QString(downloadDir.absolutePath() + "/" + tmp + ".\%1").arg(downloaded)); } else - outfile.setFileName(downloadPath + "/" + tmp); + outfile.setFileName(downloadDir.absoluteFilePath(tmp)); + qxtLog->debug() << "Saving to: " << outfile.fileName(); + /* try to open for writing */ if (!outfile.open(QIODevice::WriteOnly)){ - qxtLog->debug() << "Couldn't open file! Skipping..."; - emit notify(QString("Couldn't open " + downloadPath + "/" + tmp + "! Skipping...")); + qxtLog->debug() << "No write access to " << outfile.fileName() << " . Skipping download..."; return; } @@ -104,7 +115,7 @@ void downloadManager::startNextDownload() QObject::connect(currentDownload, SIGNAL(finished()), this, SLOT(downloadFinished())); } // ---------------------------------------------------------------------------------------- -// Private slots +// Private slots to process downloads // ---------------------------------------------------------------------------------------- void downloadManager::processMetaInfo(){ /* fetch filesize from header & filename from url (for now) */ @@ -157,7 +168,7 @@ void downloadManager::downloadFinished() int statusCode = currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qxtLog->debug() << "Download of " << currentDownload->url().toString() << " failed with HTTP error code: " << statusCode; - emit notify(QString("HTTP Error: %1").arg(statusCode)); + emit notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode)); } else{ /* end download */ @@ -166,6 +177,7 @@ void downloadManager::downloadFinished() downloaded++; qxtLog->debug() << "Download of " << currentDownload->url().toString() << " finished. (downloaded = "<< downloaded << ")"; + emit notify(QString("Successfully downloaded %1").arg(currentDownload->url().toString())); } dip = false; /* process next in queue */ diff --git a/src/downloadManager.h b/src/downloadManager.h index 2ee980a..afd0da3 100644 --- a/src/downloadManager.h +++ b/src/downloadManager.h @@ -41,6 +41,7 @@ private: QQueue<QUrl> dlQ; QNetworkReply* currentDownload; QFile outfile; + QDir downloadDir; QString currentTargetFilename; QTime dltime; int currentProgress, lastProgress; diff --git a/src/loggerEngine.cpp b/src/loggerEngine.cpp index 7ec7c4d..e8c0184 100644 --- a/src/loggerEngine.cpp +++ b/src/loggerEngine.cpp @@ -1,9 +1,10 @@ #include "loggerEngine.h" /***************************************************************************************************** - Custom Logger Engine for debugging on framebuffer + Custom Logger Engine for debugging on framebuffer *****************************************************************************************************/ loggerEngine_fb::loggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){ + // TODO: silly parent storing ... to change! _debugConsole = parent; _initialized = false; setLogLevelsEnabled(QxtLogger::DebugLevel); @@ -16,9 +17,7 @@ void loggerEngine_fb::initLoggerEngine(){ return; } -void loggerEngine_fb::killLoggerEngine(){ - return; -} +void loggerEngine_fb::killLoggerEngine(){return;} void loggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){ QxtLoggerEngine::setLogLevelsEnabled(level, enable); @@ -44,7 +43,7 @@ void loggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVar _debugConsole->setTextCursor(c); } /***************************************************************************************************** - Modified QxtBasicSTDLoggerEngine + Modified QxtBasicSTDLoggerEngine *****************************************************************************************************/ loggerEngine_std::loggerEngine_std() : QxtBasicSTDLoggerEngine(){} |
