summaryrefslogtreecommitdiffstats
path: root/src/fbgui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui.cpp')
-rw-r--r--src/fbgui.cpp54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 206680f..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,30 +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"));
- 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&)));
+ }
}