From 410676d8ddbde432321bbcb062b6117d2b6e7b41 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 21 Mar 2011 20:07:07 +0100 Subject: back to loading baseURL until display logic is implemented. working pbs test, working watcher, both disabled for now. --- build.sh | 4 +++- src/fbgui.cpp | 41 +++++++++++++++++++++++++++-------------- src/fbgui.h | 7 ++++--- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/build.sh b/build.sh index 9d5ce6b..ee00518 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/bin/bash +# adapt your version if needed +QT_VERSION=QtEmbedded-4.7.1 -QT_VERSION=QtEmbedded-4.7.2 +rm fbgui.tgz mkdir -p pkg diff --git a/src/fbgui.cpp b/src/fbgui.cpp index bf4a12c..f4154f8 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" @@ -8,10 +9,10 @@ #include 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; //------------------------------------------------------------------------------------------- @@ -26,19 +27,32 @@ fbgui::fbgui() qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); qxtLog->debug() << "Initializing fbgui..."; } - // base of the gui createActions(); _webView = new QWebView(this); + + // dhcp file watcher, disabled for now. _webView->load(baseURL); //watchDHCP(); + + /* PBS test (working dont delete) + QUrl test("http://132.230.4.27/fbgui/index"); + mgr = new QNetworkAccessManager(); + mgr->setCookieJar(new QNetworkCookieJar(this)); + QNetworkCookieJar *jar = mgr->cookieJar(); + QNetworkRequest req(test); + QByteArray postData = "mac=d8:d3:85:80:81:8b&hardwarehash=12341234123412341234123412341234&bootisoID=1"; + _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())); @@ -117,13 +131,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 +148,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 /etc/fbgui"; + QStringList pathToWatch("/etc/fbgui"); + _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..53fd5c3 100644 --- a/src/fbgui.h +++ b/src/fbgui.h @@ -63,14 +63,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 -- cgit v1.2.3-55-g7522 From 0b047cb06b0574f74be2990458420b9632fb288f Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 22 Mar 2011 09:25:30 +0100 Subject: update to QT 4.7.2 --- build.sh | 3 +-- src/testApp.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/build.sh b/build.sh index ee00518..8ea3fc5 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,5 @@ #!/bin/bash -# adapt your version if needed -QT_VERSION=QtEmbedded-4.7.1 +QT_VERSION=QtEmbedded-4.7.2 rm fbgui.tgz diff --git a/src/testApp.sh b/src/testApp.sh index 61f7c2d..b714e5e 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -11,7 +11,7 @@ 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 & +/usr/local/Trolltech/Qt-4.7.2/bin/qvfb -width 1024 -height 768 -qwsdisplay :$display_id & sleep 0.1 # Start fbgui. $working_path/fbgui -display QVFb:$display_id $@ -- cgit v1.2.3-55-g7522 From 589d2da3d47514b1d0a9291e8d9b170a240040f5 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 22 Mar 2011 13:24:03 +0100 Subject: pbs test page, POST data (hardcoded atm) --- fbgui.conf | 6 +++--- src/downloadmanager.cpp | 12 ++++++++++++ src/downloadmanager.h | 2 ++ src/fbgui.cpp | 18 +++++++----------- src/fbgui.h | 2 ++ src/loggerengine.cpp | 35 +++++++++++++++++++---------------- src/main.cpp | 38 +++++++++++++++++++++++++++++--------- src/testApp.sh | 2 +- 8 files changed, 75 insertions(+), 40 deletions(-) diff --git a/fbgui.conf b/fbgui.conf index ef681ad..c903615 100644 --- a/fbgui.conf +++ b/fbgui.conf @@ -1,4 +1,4 @@ [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 diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 47582c8..0cd7c80 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,16 @@ 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 f4154f8..3ee9f83 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -8,6 +8,7 @@ #include #include +QString fileToTriggerURL(""); QString sessionID(""); QUrl baseURL(""); QString binPath(""); @@ -20,7 +21,7 @@ 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"); @@ -32,19 +33,14 @@ fbgui::fbgui() _webView = new QWebView(this); // dhcp file watcher, disabled for now. - _webView->load(baseURL); + //_webView->load(baseURL); //watchDHCP(); - - /* PBS test (working dont delete) - QUrl test("http://132.230.4.27/fbgui/index"); - mgr = new QNetworkAccessManager(); - mgr->setCookieJar(new QNetworkCookieJar(this)); - QNetworkCookieJar *jar = mgr->cookieJar(); - QNetworkRequest req(test); + // PBS test (working dont delete) + QNetworkRequest req(baseURL); QByteArray postData = "mac=d8:d3:85:80:81:8b&hardwarehash=12341234123412341234123412341234&bootisoID=1"; _webView->load(req, QNetworkAccessManager::PostOperation, postData); - */ + // debug console split or normal browser if (debugMode == 1) @@ -97,7 +93,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); diff --git a/src/fbgui.h b/src/fbgui.h index 53fd5c3..5751ea9 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/fbgui/net" // Global settings +extern QString fileToTriggerURL; extern QString sessionID; extern QString binPath; extern QString downloadPath; 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 & 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..d35909d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,12 +34,13 @@ int main(int argc, char *argv[]) // parse command line arguments QMap 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,44 @@ 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; + + // 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 b714e5e..6a40772 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -12,7 +12,7 @@ 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.2/bin/qvfb -width 1024 -height 768 -qwsdisplay :$display_id & -sleep 0.1 +sleep 0.5 # Start fbgui. $working_path/fbgui -display QVFb:$display_id $@ # Check if fbbrowser is not running, if so kill the qvfb. -- cgit v1.2.3-55-g7522 From f554d0dad108135657c8840f99d8059c6d2191ca Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 23 Mar 2011 11:00:40 +0100 Subject: test.html update to show an example of possible javascript calls --- src/html/test.html | 109 ++++++++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 59 deletions(-) diff --git a/src/html/test.html b/src/html/test.html index 1bdf99a..b2e7d54 100644 --- a/src/html/test.html +++ b/src/html/test.html @@ -2,96 +2,87 @@ "http://www.w3.org/TR/html4/strict.dtd"> - - - - - + + + - - - + +

-WebkitTest +fbgui test page

-

- - + +

- Die Zeit des Host: - - + +

- Mac Adresse des Host: - - + +

- Download File: - - +

+ +

+ +

- - -
- +
-- cgit v1.2.3-55-g7522 From 540d03a84da42b445d7f6c13e29b142fa2490043 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 23 Mar 2011 11:03:05 +0100 Subject: . --- src/html/test.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/html/test.html b/src/html/test.html index b2e7d54..ae8aece 100644 --- a/src/html/test.html +++ b/src/html/test.html @@ -25,7 +25,7 @@ function quit(){ } function downloadFile(){ var tmp=document.formular.downloadFilename.value; - //fbgui.setCallbackOnDlQueueFinished("foo();"); + fbgui.setCallbackOnDlQueueFinished("foo();"); fbgui.startDownload(tmp); } function foo(){ -- cgit v1.2.3-55-g7522 From 3c330186b1c9b8e6f58e29739918bf2b8a5f4f68 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 23 Mar 2011 12:15:24 +0100 Subject: trigger file path definable --- fbgui.conf | 1 + src/downloadmanager.cpp | 2 -- src/fbgui.cpp | 13 ++++++++++--- src/fbgui.h | 2 +- src/javascriptinterface.cpp | 1 + src/main.cpp | 1 + 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fbgui.conf b/fbgui.conf index c903615..a1717be 100644 --- a/fbgui.conf +++ b/fbgui.conf @@ -2,3 +2,4 @@ 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 0cd7c80..ab1b0ad 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -193,11 +193,9 @@ void DownloadManager::downloadFinished() // ---------------------------------------------------------------------------------------- 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()); - } } /******************************************************************************************************** diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 3ee9f83..d4b5c82 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -37,8 +37,15 @@ fbgui::fbgui() //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"; + QByteArray postData = "mac=d8:d3:85:80:81:8b&hardwarehash=12341234123412341234123412341234&bootisoID=1&serial="; _webView->load(req, QNetworkAccessManager::PostOperation, postData); @@ -146,8 +153,8 @@ void fbgui::watchDHCP() { _webView->load(QUrl("qrc:/html/loadAbout.html")); // TODO change directory to the right one... - qxtLog->debug() << "Watching /etc/fbgui"; - QStringList pathToWatch("/etc/fbgui"); + 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 5751ea9..0e660a5 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/fbgui/net" +#define DEFAULT_FILE_TRIGGER "/tmp/trigger_fbgui" // Global settings diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index 001753c..e9ae7d4 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -22,6 +22,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/main.cpp b/src/main.cpp index d35909d..fc75aab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,6 +119,7 @@ int main(int argc, char *argv[]) else fileToTriggerURL = DEFAULT_FILE_TRIGGER; + qDebug() << "file to trigger: " << fileToTriggerURL; // setting directory for downloads if (clOpts.contains("downloadDir")){ -- cgit v1.2.3-55-g7522