summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Goby2011-03-23 12:18:01 +0100
committerNiklas Goby2011-03-23 12:18:01 +0100
commit06de7af9a08a7182e4ea253370d7ec377f0e5a18 (patch)
treed84b35a776166ea7df1715baeb26ba472955f1a3
parentsome tries with the qrc and jquery delivery (diff)
parenttrigger file path definable (diff)
downloadfbgui-06de7af9a08a7182e4ea253370d7ec377f0e5a18.tar.gz
fbgui-06de7af9a08a7182e4ea253370d7ec377f0e5a18.tar.xz
fbgui-06de7af9a08a7182e4ea253370d7ec377f0e5a18.zip
Merge branch 'master' of git.openslx.org:lsfks/master-teamprojekt/fbgui
-rwxr-xr-xbuild.sh3
-rw-r--r--fbgui.conf7
-rw-r--r--src/downloadmanager.cpp10
-rw-r--r--src/downloadmanager.h2
-rw-r--r--src/fbgui.cpp50
-rw-r--r--src/fbgui.h9
-rw-r--r--src/html/test.html109
-rw-r--r--src/javascriptinterface.cpp1
-rw-r--r--src/loggerengine.cpp35
-rw-r--r--src/main.cpp39
-rwxr-xr-xsrc/testApp.sh4
11 files changed, 159 insertions, 110 deletions
diff --git a/build.sh b/build.sh
index 9d5ce6b..8ea3fc5 100755
--- a/build.sh
+++ b/build.sh
@@ -1,7 +1,8 @@
#!/bin/bash
-
QT_VERSION=QtEmbedded-4.7.2
+rm fbgui.tgz
+
mkdir -p pkg
cd pkg
diff --git a/fbgui.conf b/fbgui.conf
index ef681ad..a1717be 100644
--- a/fbgui.conf
+++ b/fbgui.conf
@@ -1,4 +1,5 @@
[default]
-url=http://m.openslx.org
-downloadDirectory=/tmp/fbgui/downloads
-updateInterval=5
+pbs_url=http://132.230.4.27
+download_directory=/tmp/fbgui
+update_interval=5
+file_trigger=/tmp/trigger_fbgui
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 47582c8..ab1b0ad 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -164,6 +164,7 @@ void DownloadManager::downloadFinished()
// check for errors
if (currentDownload->error()){
currentDownload->deleteLater();
+ outfile.close();
outfile.remove();
int statusCode = currentDownload->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qxtLog->debug() << "Download of " << currentDownload->url().toString()
@@ -171,6 +172,7 @@ void DownloadManager::downloadFinished()
emit notify(QString("Download failed! HTTP Status Code: %1").arg(statusCode));
}
else{
+ completeKCL();
// end download
currentDownload->deleteLater();
outfile.close();
@@ -188,6 +190,14 @@ void DownloadManager::downloadFinished()
}
startNextDownload();
}
+// ----------------------------------------------------------------------------------------
+void DownloadManager::completeKCL(){
+ // check if current download is kcl
+ if (outfile.fileName() == downloadDir.absoluteFilePath("kcl")){
+ qxtLog->debug() << "Completing kernel command line ...";
+ outfile.write(" session=" + sessionID.toUtf8());
+ }
+}
/********************************************************************************************************
*
** dead code: Header filename fetching & renaming **
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index 0cc1a35..22140e6 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -39,6 +39,8 @@ private:
void checkDownloadDirectory();
// private control function for queueing mechanism.
void processDownloadRequest(const QUrl& url);
+ // function to complete the kcl file
+ void completeKCL();
// base objects for downloading
QNetworkAccessManager* qnam;
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index bf4a12c..d4b5c82 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -1,4 +1,5 @@
#include "fbgui.h"
+#include "sysinfo.h"
#include "loggerengine.h"
#include "downloadmanager.h"
#include "javascriptinterface.h"
@@ -7,11 +8,12 @@
#include <QtWebKit>
#include <QxtCore>
+QString fileToTriggerURL("");
QString sessionID("");
-QUrl baseURL(DEFAULT_URL);
+QUrl baseURL("");
QString binPath("");
-QString downloadPath("/tmp/fbgui/downloads");
-int updateInterval = DEFAULT_UPDATE_INTERVAL;
+QString downloadPath("");
+int updateInterval = -1;
int debugMode = -1;
//-------------------------------------------------------------------------------------------
@@ -19,26 +21,41 @@ fbgui::fbgui()
{
// setup basic debug
qxtLog->disableLoggerEngine("DEFAULT");
- qxtLog->enableLogLevels(QxtLogger::DebugLevel);
+ //qxtLog->enableLogLevels(QxtLogger::DebugLevel);
if (debugMode == 0){
qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std);
qxtLog->initLoggerEngine("std_logger");
qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel);
qxtLog->debug() << "Initializing fbgui...";
}
-
// base of the gui
createActions();
_webView = new QWebView(this);
- _webView->load(baseURL);
+
+ // dhcp file watcher, disabled for now.
+ //_webView->load(baseURL);
//watchDHCP();
+ // PBS test (working dont delete)
+ QFileInfo fi("/tmp/serial");
+ if (fi.exists())
+ qxtLog->debug() << "Found /tmp/serial !";
+ else
+ qxtLog->debug() << "No file /tmp/serial !";
+ // TODO append serial number to postData.
+
+ QNetworkRequest req(baseURL);
+ QByteArray postData = "mac=d8:d3:85:80:81:8b&hardwarehash=12341234123412341234123412341234&bootisoID=1&serial=";
+ _webView->load(req, QNetworkAccessManager::PostOperation, postData);
+
+
// debug console split or normal browser
if (debugMode == 1)
setupDebugSplit();
else
setCentralWidget(_webView);
+
// initialize javascript interface
JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame());
QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
@@ -83,7 +100,7 @@ void fbgui::setupDebugSplit()
_debugConsole->insertPlainText("Debug console initialized.\n");
// enable custom logger engine
qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole));
- qxtLog->initLoggerEngine("fb_logger");
+ //qxtLog->initLoggerEngine("fb_logger");
qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel);
// display browser and debug in a splitter
_splitter = new QSplitter(Qt::Vertical, this);
@@ -117,13 +134,14 @@ bool fbgui::checkHost() const
return true;
}
//-------------------------------------------------------------------------------------------
-void fbgui::ipReceived(const QString& name)
+void fbgui::netAccessible(const QString& name)
{
+ //TODO change this to the actual file name...
QFileInfo fi(name + "/foo");
if (fi.exists()){
qxtLog->debug() << "correct file!";
if (checkHost()){
- qxtLog->debug() << "DHCP active, loading URL...";
+ qxtLog->debug() << "Received DHCP lease, loading URL...";
_webView->load(baseURL);
}
}
@@ -133,12 +151,10 @@ void fbgui::ipReceived(const QString& name)
//-------------------------------------------------------------------------------------------
void fbgui::watchDHCP()
{
- qxtLog->debug() << "Watching /etc/fbgui";
- QStringList pathToWatch("/etc/fbgui");
- _fileSystemWatcher = new QFileSystemWatcher(pathToWatch, this);
- // QString path //has to be set to some file or directory
- // TODO change to the real path
- // _fileSystemWatcher->addPath(QApplication::applicationDirPath() + "/testChange/");
- QObject::connect(_fileSystemWatcher, SIGNAL(directoryChanged(const QString&)), this, SLOT(ipReceived(const QString&)));
- _webView->load(QUrl("qrc:/html/loadAbout.html"));
+ _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&)));
}
diff --git a/src/fbgui.h b/src/fbgui.h
index 52f244f..0e660a5 100644
--- a/src/fbgui.h
+++ b/src/fbgui.h
@@ -28,9 +28,11 @@
#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"
// Global settings
+extern QString fileToTriggerURL;
extern QString sessionID;
extern QString binPath;
extern QString downloadPath;
@@ -63,14 +65,15 @@ private:
QAction* _toggleDebug;
//
- QFileSystemWatcher* _fileSystemWatcher;
+ QNetworkAccessManager *mgr;
+ QNetworkReply *rep;
+ QFileSystemWatcher* _watcher;
private slots:
// slots for processing actions
void toggleDebug();
- void ipReceived(const QString& name);
-
+ void netAccessible(const QString& name);
};
#endif // FBGUI_H
diff --git a/src/html/test.html b/src/html/test.html
index 1bdf99a..ae8aece 100644
--- a/src/html/test.html
+++ b/src/html/test.html
@@ -2,96 +2,87 @@
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
-
- <link href="/css/ui-lightness/jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css"/>
- <script src="/js/jquery-1.5.1.min.js"></script>
- <script src="/js/jquery-ui-1.8.10.custom.min.js"></script>
-
+<link href="/css/ui-lightness/jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css"/>
+<script src="/js/jquery-1.5.1.min.js"></script>
+<script src="/js/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript">
var progress;
-function showHelloWorld(){
- jsObject.showHelloWorld();
-}
-
-function showTime(){
- jsObject.showTime();
+function getMAC(){
+ var tmp = fbgui.getSysInfo("mac");
+ document.formular.fbgui_out_mac.value = tmp;
}
-
-function printTime(time){
- document.formular.textfieldTime.value=time;
+function getIP(){
+ var tmp = fbgui.getSysInfo("ip");
+ document.formular.fbgui_out_ip.value = tmp;
}
-
-function getMacAddress(){
- jsObject.getMacAddress();
+function testjson(){
+ var tmp = fbgui.getSysInfo("json");
+ var t = eval('(' + tmp + ')');
+ alert(t[0].name);
}
-
-function printMacAddress(macAddress){
- document.formular.textfieldMac.value=macAddress;
+function quit(){
+ fbgui.quit();
}
-
-function quitProgramm(){
- jsObject.quitAll();
-}
-
function downloadFile(){
var tmp=document.formular.downloadFilename.value;
- jsObject.startDownload(tmp);
+ fbgui.setCallbackOnDlQueueFinished("foo();");
+ fbgui.startDownload(tmp);
+}
+function foo(){
+ alert("yay");
}
-function updateProgress(i){
- if (i >= 0 && i <= 100)
- {
- $("#progressbar").progressbar({ value: i });
- }
+function updateProgress(p, s, u){
+ if (p >= 0 && p <= 100)
+ $("#progressbar").progressbar({ value: p });
else
- {
$("#progressbar").progressbar({ value: 0 });
- }
}
-
+function downloadInfo(name, size){
+ alert('Downloading: ' + name + '(Total: ' + size + ')');
+}
+function notify(msg){
+ alert(msg);
+}
</script>
-
</head>
-<body onload="Fenster()";>
-
+
+<body>
<p><center>
-WebkitTest
+fbgui test page
</center></p>
-
<form name="formular">
<p>
- <input type="button" name="quitProgramm_Button" value="quit programm"
- onclick="quitProgramm()">
- <input type="button" name="showHelloWorld_Button" value="Hello World"
- onclick="showHelloWorld()">
+ <input type="button" name="quitFbgui" value="quit"
+ onclick="quit()">
+ <input type="button" name="testJSon" value="test JSon"
+ onclick="testjson()">
</p>
<p>
- Die Zeit des Host:
- <input type="text" name="textfieldTime">
- <input type="button" name="showTime_Button" value="Show Time"
- onclick="showTime()">
+ <input type="button" name="getMACButton" value="eth0 MAC:"
+ onclick="getMAC()">
+ <input type="text" name="fbgui_out_mac">
</p>
<p>
- Mac Adresse des Host:
- <input type="text" name="textfieldMac">
- <input type="button" name="getMacAddress_Button" value="Get Mac Address"
- onclick="getMacAddress()">
+ <input type="button" name="getIPButton" value="eth0 IPv4:"
+ onclick="getIP()">
+ <input type="text" name="fbgui_out_ip">
</p>
<p>
- Download File:
- <input type="text" name="downloadFilename">
- <input type="button" name="downloadButton" value="Download File"
+ <input type="button" name="downloadButton" value="Download file"
onclick="downloadFile()">
+ <input type="text" name="downloadFilename">
</p>
+
+ <p>
+ <input type="button" name="qrcAlertButton" value="Fire qrc Alert" onclick="qrcAlert()">
+ </p>
<script>
- $(document).ready(function() {
+ $(document).ready(function() {
$("#progressbar").progressbar({ value: 0 });
});
</script>
-
-
-<div id="progressbar"></div>
-
+<div id="progressbar" style="height: 15px;"></div>
</body>
</html>
diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp
index b395a6e..c3ac80c 100644
--- a/src/javascriptinterface.cpp
+++ b/src/javascriptinterface.cpp
@@ -23,6 +23,7 @@ void JavascriptInterface::attachToDOM(){
//-------------------------------------------------------------------------------------------------------
void JavascriptInterface::notify(const QString& msg){
+ qxtLog->debug() << "Notifying: " << msg;
QString code = QString("notify('\%1')").arg(msg);
_parent->evaluateJavaScript(code);
}
diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp
index 5638908..4540678 100644
--- a/src/loggerengine.cpp
+++ b/src/loggerengine.cpp
@@ -6,40 +6,43 @@
LoggerEngine_fb::LoggerEngine_fb(QTextEdit *parent) : QxtLoggerEngine(){
// TODO: silly parent storing ... to change!
_debugConsole = parent;
- _initialized = false;
- setLogLevelsEnabled(QxtLogger::DebugLevel);
- enableLogging();
+ //_initialized = false;
+ //setLogLevelsEnabled(QxtLogger::DebugLevel);
+ //enableLogging();
}
LoggerEngine_fb::~LoggerEngine_fb(){}
void LoggerEngine_fb::initLoggerEngine(){
- _initialized = true;
+ //_initialized = true;
return;
}
-void LoggerEngine_fb::killLoggerEngine(){return;}
+void LoggerEngine_fb::killLoggerEngine(){
+ return;
+}
void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable){
- QxtLoggerEngine::setLogLevelsEnabled(level, enable);
- if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
+ //QxtLoggerEngine::setLogLevelsEnabled(level, enable);
+ //if (!enable) QxtLoggerEngine::setLogLevelsEnabled(QxtLogger::DebugLevel);
}
bool LoggerEngine_fb::isInitialized() const{
- return _initialized;
+ //return _initialized;
}
void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs){
// TODO: handle different log levels
if (msgs.isEmpty()) return;
- Q_FOREACH(const QVariant& out, msgs)
- {
- if (!out.isNull())
+ if (level == QxtLogger::DebugLevel){
+ Q_FOREACH(const QVariant& out, msgs){
+ if (!out.isNull())
_debugConsole->insertPlainText(out.toString());
+ }
+ _debugConsole->insertPlainText(QString("\n"));
+ // autoscroll
+ QTextCursor c = _debugConsole->textCursor();
+ c.movePosition(QTextCursor::End);
+ _debugConsole->setTextCursor(c);
}
- _debugConsole->insertPlainText(QString("\n"));
- // autoscroll
- QTextCursor c = _debugConsole->textCursor();
- c.movePosition(QTextCursor::End);
- _debugConsole->setTextCursor(c);
}
//---------------------------------------------------------------------------------------------------
// Modified QxtBasicSTDLoggerEngine
diff --git a/src/main.cpp b/src/main.cpp
index c5269a7..fc75aab 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,12 +34,13 @@ int main(int argc, char *argv[])
// parse command line arguments
QMap<QString, QString> clOpts;
int longIndex = 0;
- static const char *optString = "u:d:c:D:h";
+ static const char *optString = "u:d:c:t:D:h";
static const struct option longOpts[] =
{
{"url", required_argument, NULL, 'u'},
{"download", required_argument, NULL, 'd'},
{"config", required_argument, NULL, 'c'},
+ {"trigger", required_argument, NULL, 't'},
{"debug", required_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'}
};
@@ -56,6 +57,10 @@ int main(int argc, char *argv[])
break;
case 'c':
clOpts.insert("configFile", optarg);
+ break;
+ case 't':
+ clOpts.insert("trigger", optarg);
+ break;
case 'D':
clOpts.insert("debug", optarg);
break;
@@ -99,29 +104,45 @@ int main(int argc, char *argv[])
if (clOpts.contains("url")) {
baseURL = QUrl(clOpts.value("url"));
}
- else if (confFileSettings.contains("default/url")) {
- baseURL = confFileSettings.value("default/url").toUrl();
+ else if (confFileSettings.contains("default/pbs_url")) {
+ baseURL = confFileSettings.value("default/pbs_url").toUrl();
}
else {
baseURL = DEFAULT_URL;
}
+ // sets which file to watch to trigger loading of URL
+ if (clOpts.contains("trigger"))
+ fileToTriggerURL = clOpts.value("trigger");
+ else if (confFileSettings.contains("default/file_trigger"))
+ fileToTriggerURL = confFileSettings.value("default/file_trigger").toString();
+ else
+ fileToTriggerURL = DEFAULT_FILE_TRIGGER;
+
+ qDebug() << "file to trigger: " << fileToTriggerURL;
+
// setting directory for downloads
if (clOpts.contains("downloadDir")){
downloadPath = clOpts.value("downloadDir");
}
- else if (confFileSettings.contains("default/downloadDirectory")){
- downloadPath = confFileSettings.value("default/downloadDirectory").toString();
+ else if (confFileSettings.contains("default/download_directory")){
+ downloadPath = confFileSettings.value("default/download_directory").toString();
}
- else {
+ else
downloadPath = DEFAULT_DOWNLOAD_DIR;
- }
- if (confFileSettings.contains("default/updateInterval")){
- updateInterval = confFileSettings.value("default/updateInterval").toInt();
+ if (confFileSettings.contains("default/update_interval")){
+ updateInterval = confFileSettings.value("default/update_interval").toInt();
}
else updateInterval = DEFAULT_UPDATE_INTERVAL;
+ // basic std out engine is ugly... not yet initialised so using qDebug
+ qDebug() << "configFilePath: " << configFilePath;
+ qDebug() << "baseURL: " << baseURL;
+ qDebug() << "downloadDir : " << downloadPath;
+ qDebug() << "trigger: " << fileToTriggerURL;
+
+ // start fbgui
fbgui gui;
gui.show();
return app.exec();
diff --git a/src/testApp.sh b/src/testApp.sh
index 61f7c2d..6a40772 100755
--- a/src/testApp.sh
+++ b/src/testApp.sh
@@ -11,8 +11,8 @@ script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
working_path=`dirname "$script_path"`
display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}')
# Start QT's virtual framebuffer with proper displayID
-/usr/local/Trolltech/Qt-4.7.1/bin/qvfb -width 1024 -height 768 -qwsdisplay :$display_id &
-sleep 0.1
+/usr/local/Trolltech/Qt-4.7.2/bin/qvfb -width 1024 -height 768 -qwsdisplay :$display_id &
+sleep 0.5
# Start fbgui.
$working_path/fbgui -display QVFb:$display_id $@
# Check if fbbrowser is not running, if so kill the qvfb.