diff options
| -rw-r--r-- | fbgui.conf | 2 | ||||
| -rw-r--r-- | src/fbgui.cpp | 55 | ||||
| -rw-r--r-- | src/fbgui.h | 9 | ||||
| -rw-r--r-- | src/html/loadAbout.html | 2 | ||||
| -rw-r--r-- | src/javascriptinterface.cpp | 1 |
5 files changed, 47 insertions, 22 deletions
@@ -2,4 +2,4 @@ pbs_url=http://132.230.4.27 download_directory=/tmp/fbgui update_interval=5 -file_trigger=/tmp/trigger_fbgui +file_trigger=/tmp/fbgui/trigger diff --git a/src/fbgui.cpp b/src/fbgui.cpp index f6b412a..7162e75 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -32,9 +32,9 @@ fbgui::fbgui() createActions(); _webView = new QWebView(this); - // dhcp file watcher, disabled for now. + // file watcher, disabled for now. //_webView->load(baseURL); - //watchDHCP(); + //watchFileTrigger(); // PBS test (working dont delete) QString serial; @@ -141,31 +141,58 @@ bool fbgui::checkHost() const qxtLog->debug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; return false; } - else + else{ + qxtLog->debug() << "Lookup of " << baseURL.host() << "succeeded."; return true; + } + } //------------------------------------------------------------------------------------------- -void fbgui::netAccessible(const QString& name) +void fbgui::checkForTrigger(const QString& dirname) { - //TODO change this to the actual file name... - QFileInfo fi(name + "/foo"); + // check if fileToTriggerURL exists in the directory where the change occured + QFileInfo tfi(fileToTriggerURL); + QFileInfo fi(dirname + "/" + tfi.fileName()); if (fi.exists()){ - qxtLog->debug() << "correct file!"; + qxtLog->debug() << fileToTriggerURL << " found!"; if (checkHost()){ - qxtLog->debug() << "Received DHCP lease, loading URL..."; + qxtLog->debug() << "Loading URL..."; _webView->load(baseURL); } } else + // do nothing / keep watching qxtLog->debug() << "weird file!"; } //------------------------------------------------------------------------------------------- -void fbgui::watchDHCP() +void fbgui::watchFileTrigger() { + // load filler page, TODO fancier page :) _webView->load(QUrl("qrc:/html/loadAbout.html")); - // TODO change directory to the right one... - qxtLog->debug() << "Watching " << fileToTriggerURL; - QStringList pathToWatch(fileToTriggerURL); - _watcher = new QFileSystemWatcher(pathToWatch, this); - QObject::connect(_watcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(netAccessible(const QString&))); + + // check if the directory to fileToTriggerURL exists + QFileInfo fi(fileToTriggerURL); + if (!fi.absoluteDir().exists()){ + qxtLog->debug() << fi.absolutePath() << " does not exists!"; + if (QDir::home().mkdir(fi.absolutePath())) + qxtLog->debug() << "Successfully created " << fi.absolutePath(); + else + qxtLog->debug() << "Failed to create " << fi.absolutePath(); + } + else + qxtLog->debug() << fi.absolutePath() << " exists!"; + + // check if fileToTriggerURL already exists + if (fi.exists()){ + // this should NOT happen. TODO handle case where it exists. + qxtLog->debug() << fileToTriggerURL << " exists already!"; + return; + } + else { + // watch the path where trigger file is expected + qxtLog->debug() << "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&))); + } } diff --git a/src/fbgui.h b/src/fbgui.h index 6a9e10b..40f105b 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -28,8 +28,8 @@ #define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui/downloads" #define DEFAULT_CONFIG_PATH "/etc/fbgui.conf" #define DEFAULT_UPDATE_INTERVAL 1; -#define DEFAULT_FILE_TRIGGER "/tmp/trigger_fbgui" #define DEFAULT_QRC_HTML_DIR ":/html" +#define DEFAULT_FILE_TRIGGER "/tmp/fbgui/trigger" // Global settings @@ -53,7 +53,7 @@ private: void setupDebugSplit(); void createActions(); bool checkHost() const; - void watchDHCP(); + void watchFileTrigger(); // widgets constituing the gui @@ -66,15 +66,12 @@ private: QAction* _toggleDebug; // - QNetworkAccessManager *mgr; - QNetworkReply *rep; QFileSystemWatcher* _watcher; private slots: // slots for processing actions void toggleDebug(); - - void netAccessible(const QString& name); + void checkForTrigger(const QString& dirname); }; #endif // FBGUI_H diff --git a/src/html/loadAbout.html b/src/html/loadAbout.html index 52fb769..6b4e00e 100644 --- a/src/html/loadAbout.html +++ b/src/html/loadAbout.html @@ -8,7 +8,7 @@ <h1>Waiting for an IP-Address</h1> <p> -Make shure that you honor the great work of the programmers. +Make sure that you honor the great work of the programmers. </p> </body> diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index ae976c6..0a92de6 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -54,6 +54,7 @@ void JavascriptInterface::updateProgressBar(const int& percent, const double& sp } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::setCallbackOnDlQueueFinished(QString& jsFunction){ + qxtLog->debug() << "Callback set: " << jsFunction; _callBackOnDownloadsFinished = jsFunction; } //------------------------------------------------------------------------------------------------------- |
