diff options
author | Jonathan Bauer | 2011-04-14 17:20:05 +0200 |
---|---|---|
committer | Jonathan Bauer | 2011-04-14 17:20:05 +0200 |
commit | c1f72546e694f30c7ffa5cad35643df5e460a76b (patch) | |
tree | 3f4100c8d01d3e2a5704f141c06ae2ff9fe5d8ef /src/fbgui.cpp | |
parent | trigger watch fix & waiting cursor until URL (diff) | |
download | fbgui-c1f72546e694f30c7ffa5cad35643df5e460a76b.tar.gz fbgui-c1f72546e694f30c7ffa5cad35643df5e460a76b.tar.xz fbgui-c1f72546e694f30c7ffa5cad35643df5e460a76b.zip |
Download manager now threaded (Ticket #205) & change the watcher to create the trigger file and wait til it is modified, changing the file (f.e. writing something) triggers URL load
Diffstat (limited to 'src/fbgui.cpp')
-rw-r--r-- | src/fbgui.cpp | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 1bfad79..4dbbc58 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -6,9 +6,11 @@ #include "sysinfolibsysfs.h" #include <iostream> +#include <QThread> #include <QtWebKit> #include <QxtCore> +QThread dmThread; QString binPath(""); QUrl baseURL(""); QString downloadPath(""); @@ -49,6 +51,7 @@ fbgui::fbgui() QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM())); + // initialize download manager DownloadManager* dm = new DownloadManager(); QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)), @@ -61,11 +64,15 @@ fbgui::fbgui() jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished())); + // move download manager to its own thread + dm->moveToThread(&dmThread); + dmThread.start(); // show filler page _webView->load(QUrl("qrc:/html/preload.html")); // start watching for fileToTriggerURL watchForTrigger(); + //if (checkHost()) loadURL(); // set properties setWindowTitle("fbgui"); @@ -73,6 +80,9 @@ fbgui::fbgui() setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); } +fbgui::~fbgui(){ + dmThread.quit(); +} //------------------------------------------------------------------------------------------- // Layout / actions setup //------------------------------------------------------------------------------------------- @@ -125,33 +135,30 @@ void fbgui::createActions() */ void fbgui::watchForTrigger() { - // check if the directory to fileToTriggerURL exists - QFileInfo fi(fileToTriggerURL); - if (!fi.absoluteDir().exists()){ - qxtLog->debug() << "[watcher] " << fi.absolutePath() << " does not exists!"; - if (QDir::home().mkdir(fi.absolutePath())) - qxtLog->debug() << "[watcher] Successfully created " << fi.absolutePath(); - else - qxtLog->debug() << "[watcher] Failed to create " << fi.absolutePath(); - } - else - qxtLog->debug() << "[watcher] " << fi.absolutePath() << " exists!"; - // check if fileToTriggerURL already exists - if (fi.exists()){ + QFile file(fileToTriggerURL); + if (file.exists()){ qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!"; - // load URL + // try to load URL if (checkHost()) loadURL(); } else { - // watch the path where trigger file is expected - qxtLog->debug() << "[watcher] Watching " << fi.absolutePath() - << " for file: " << fi.fileName(); - QStringList pathToWatch(fi.absolutePath()); - _watcher = new QFileSystemWatcher(pathToWatch, this); - QObject::connect(_watcher, SIGNAL(directoryChanged(const QString&)), - this, SLOT(checkForTrigger(const QString&))); + // create it + if (file.open(QIODevice::WriteOnly)){ + qxtLog->debug() << "[gui] Created: " << fileToTriggerURL; + file.close(); + } + else { + qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed! Exiting..."; + exit(EXIT_FAILURE); + } } + // watch the path where trigger file is expected + qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL; + _watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this); + QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), + this, SLOT(prepareURLLoad())); + } //------------------------------------------------------------------------------------------- /** @@ -164,23 +171,15 @@ void fbgui::watchForTrigger() * @see fbgui::checkHost() * @see fbgui::loadURL() */ -void fbgui::checkForTrigger(const QString& dirname) +void fbgui::prepareURLLoad() { - // check if fileToTriggerURL exists in the directory where the change occured - QFileInfo tfi(fileToTriggerURL); - QFileInfo fi(dirname + "/" + tfi.fileName()); - if (fi.exists()){ - qxtLog->debug() << "[watcher] " << fileToTriggerURL << " detected."; - // disconnect _watcher, his job is done - qxtLog->debug() << "[watcher] disconnected."; - _watcher->disconnect(this); - _watcher->deleteLater(); // memory problems with watcher - // load URL if host exists - if (checkHost()) loadURL(); - } - else - // do nothing / keep watching - qxtLog->debug() << "[watcher] weird file!"; + qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!"; + // disconnect _watcher, his job is done + qxtLog->debug() << "[watcher] disconnected."; + _watcher->disconnect(this); + _watcher->deleteLater(); + // try to load URL + if (checkHost()) loadURL(); } //------------------------------------------------------------------------------------------- // Preparations for URL load @@ -215,14 +214,14 @@ bool fbgui::checkHost() const */ void fbgui::loadURL() { - - qxtLog->debug() << "[gui] Loading URL..."; - QByteArray postData = generatePOSTData(); - qxtLog->debug() << "[gui] POST data: " << postData; - QNetworkRequest req(baseURL); - // show arrow cursor - qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); - _webView->load(req, QNetworkAccessManager::PostOperation, postData); + if (checkHost()){ + qxtLog->debug() << "[gui] Loading URL..."; + QByteArray postData = generatePOSTData(); + QNetworkRequest req(baseURL); + // show arrow cursor + qApp->setOverrideCursor(QCursor(Qt::ArrowCursor)); + _webView->load(req, QNetworkAccessManager::PostOperation, postData); + } } //------------------------------------------------------------------------------------------- /** @@ -268,6 +267,7 @@ QByteArray fbgui::generatePOSTData() postData.append(si.getInfo("mac")); postData.append("&hardwarehash=" + hash.toHex()); postData.append("&serialnumber=" + serial); + qxtLog->debug() << "[post] POST data: " << postData; return postData; } //------------------------------------------------------------------------------------------- |