summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-23 14:44:38 +0100
committerJonathan Bauer2011-03-23 14:44:38 +0100
commit0d2b58428d7488ba35598c46647eecda0f7f1c41 (patch)
tree89d2add8ac29429d41e3aaa79a25efaa44224bdd
parentMerge branch 'master' of git.openslx.org:lsfks/master-teamprojekt/fbgui (diff)
downloadfbgui-0d2b58428d7488ba35598c46647eecda0f7f1c41.tar.gz
fbgui-0d2b58428d7488ba35598c46647eecda0f7f1c41.tar.xz
fbgui-0d2b58428d7488ba35598c46647eecda0f7f1c41.zip
file/dir checks for the file triggering
-rw-r--r--fbgui.conf2
-rw-r--r--src/fbgui.cpp54
-rw-r--r--src/fbgui.h9
-rw-r--r--src/html/loadAbout.html2
4 files changed, 46 insertions, 21 deletions
diff --git a/fbgui.conf b/fbgui.conf
index a1717be..e93b471 100644
--- a/fbgui.conf
+++ b/fbgui.conf
@@ -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 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&)));
+ }
}
diff --git a/src/fbgui.h b/src/fbgui.h
index 0e660a5..03c1789 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -28,7 +28,7 @@
#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_FILE_TRIGGER "/tmp/fbgui/trigger"
// Global settings
@@ -52,7 +52,7 @@ private:
void setupDebugSplit();
void createActions();
bool checkHost() const;
- void watchDHCP();
+ void watchFileTrigger();
// widgets constituing the gui
@@ -65,15 +65,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>