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