diff options
| author | Niklas Goby | 2011-03-23 14:48:14 +0100 |
|---|---|---|
| committer | Niklas Goby | 2011-03-23 14:48:14 +0100 |
| commit | ffe9e4a14a917f04e9d22b96fcbf7f42d546fa09 (patch) | |
| tree | 489ce4adb6cac6ab07ef1b5b9e4d626bd96fc0c0 /src/fbgui.cpp | |
| parent | working jquery over qrc (diff) | |
| parent | file/dir checks for the file triggering (diff) | |
| download | fbgui-ffe9e4a14a917f04e9d22b96fcbf7f42d546fa09.tar.gz fbgui-ffe9e4a14a917f04e9d22b96fcbf7f42d546fa09.tar.xz fbgui-ffe9e4a14a917f04e9d22b96fcbf7f42d546fa09.zip | |
Merge branch 'master' of git.openslx.org:lsfks/master-teamprojekt/fbgui
Conflicts:
src/fbgui.h
Diffstat (limited to 'src/fbgui.cpp')
| -rw-r--r-- | src/fbgui.cpp | 55 |
1 files changed, 41 insertions, 14 deletions
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&))); + } } |
