diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/downloadmanager.cpp | 3 | ||||
-rw-r--r-- | src/fbgui.cpp | 222 | ||||
-rw-r--r-- | src/html/loadAbout.html | 12 | ||||
-rw-r--r-- | src/javascriptinterface.cpp | 20 | ||||
-rw-r--r-- | src/javascriptinterface.h | 2 | ||||
-rw-r--r-- | src/loggerengine.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rwxr-xr-x | src/testApp.sh | 1 |
8 files changed, 148 insertions, 116 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index ae7504d..a203c1d 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -9,7 +9,7 @@ DownloadManager::DownloadManager(){ qnam = new QNetworkAccessManager(); dip = false; } -// ---------------------------------------------------------------------------------------- + // ---------------------------------------------------------------------------------------- void DownloadManager::checkDownloadDirectory() { @@ -44,6 +44,7 @@ void DownloadManager::checkDownloadDirectory() qxtLog->debug() << "Saving downloads to: " << downloadDir.absolutePath(); //downloadPath = downloadDir.absolutePath(); } +// ---------------------------------------------------------------------------------------- void DownloadManager::downloadFile(const QString& filename) { QUrl fileUrl(baseURL.resolved(QUrl(filename))); diff --git a/src/fbgui.cpp b/src/fbgui.cpp index 8cd6520..d209c2f 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -20,59 +20,34 @@ int debugMode = -1; //------------------------------------------------------------------------------------------- fbgui::fbgui() { + // test for libsys function - SysInfoLibsysfs* sil = new SysInfoLibsysfs(); - sil->getInfoAboutNetworkInterface(); - sil->getInfoAboutClassNet(); + //SysInfoLibsysfs* sil = new SysInfoLibsysfs(); + //sil->getInfoAboutNetworkInterface(); + //sil->getInfoAboutClassNet(); // 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); - - // file watcher, disabled for now. - //watchFileTrigger(); - - //--------------------------------------------------------------------------------------- - // PBS test begin - QString serial; - QFileInfo fi("/tmp/serial"); - if (fi.exists()) - { - qxtLog->debug() << "Found /tmp/serial !"; - - // If the file exists, than read the data - QFile file; - file.setFileName("/tmp/serial"); - file.open(QIODevice::ReadOnly); - serial = file.readAll(); - file.close(); - } - 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); - // PBS test end - //--------------------------------------------------------------------------------------- + // base of the gui + _webView = new QWebView(this); // debug console split or normal browser if (debugMode == 1) setupDebugSplit(); - else + else { setCentralWidget(_webView); + } + + // initialize javascript interface JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame()); @@ -91,11 +66,18 @@ fbgui::fbgui() jsi, SLOT(updateProgressBar(const int&, const double&, const QString&))); QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnDlQueueFinished())); + + createActions(); + _webView->load(QUrl("qrc:/html/loadAbout.html")); + // watch creation of fileToTriggerURL + watchFileTrigger(); + // set properties setWindowTitle("fbgui"); setAttribute(Qt::WA_QuitOnClose, true); setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); + } //------------------------------------------------------------------------------------------- void fbgui::createActions() @@ -106,74 +88,11 @@ void fbgui::createActions() this->addAction(_quit); connect(_quit, SIGNAL(triggered()), this, SLOT(close())); } -//------------------------------------------------------------------------------------------- -void fbgui::setupDebugSplit() -{ - _debugConsole = new QTextEdit(this); - _debugConsole->setWindowFlags(Qt::FramelessWindowHint); - QPalette pal; - pal.setColor(QPalette::Base, Qt::black); - _debugConsole->setPalette(pal); - _debugConsole->setTextColor(Qt::cyan); - _debugConsole->insertPlainText("Debug console initialized.\n"); - // enable custom logger engine - qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole)); - //qxtLog->initLoggerEngine("fb_logger"); - qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); - // display browser and debug in a splitter - _splitter = new QSplitter(Qt::Vertical, this); - _splitter->addWidget(_webView); - _splitter->addWidget(_debugConsole); - // CTRL + D toggles debug window - _toggleDebug = new QAction(tr("&toggleDebug"), this); - _toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - addAction(_toggleDebug); - connect(_toggleDebug, SIGNAL(triggered()), this, SLOT(toggleDebug())); - setCentralWidget(_splitter); -} -//------------------------------------------------------------------------------------------- -void fbgui::toggleDebug() -{ - if (_debugConsole->isVisible()) - _debugConsole->hide(); - else - _debugConsole->show(); -} -//------------------------------------------------------------------------------------------- -bool fbgui::checkHost() const -{ - // TODO instead of closing app, show error page from qrc - QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); - if (hostInfo.error() != QHostInfo::NoError){ - qxtLog->debug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; - return false; - } - else{ - qxtLog->debug() << "Lookup of " << baseURL.host() << " succeeded."; - return true; - } -} -//------------------------------------------------------------------------------------------- -void fbgui::checkForTrigger(const QString& dirname) -{ - // check if fileToTriggerURL exists in the directory where the change occured - QFileInfo tfi(fileToTriggerURL); - QFileInfo fi(dirname + "/" + tfi.fileName()); - if (fi.exists()){ - qxtLog->debug() << fileToTriggerURL << " found!"; - loadURL(); - } - else - // do nothing / keep watching - qxtLog->debug() << "weird file!"; -} + //------------------------------------------------------------------------------------------- void fbgui::watchFileTrigger() { - // load filler page, TODO fancier page :) - _webView->load(QUrl("qrc:/html/loadAbout.html")); - // check if the directory to fileToTriggerURL exists QFileInfo fi(fileToTriggerURL); if (!fi.absoluteDir().exists()){ @@ -188,9 +107,15 @@ void fbgui::watchFileTrigger() // check if fileToTriggerURL already exists if (fi.exists()){ - // this should NOT happen. TODO handle case where it exists. qxtLog->debug() << fileToTriggerURL << " exists already!"; - return; + // try to remove it + QFile file(fi.absoluteFilePath()); + if (file.remove()) + qxtLog->debug() << "Purged: " << file.fileName(); + else{ + qxtLog->debug() << "Could not remove: " << file.fileName(); + exit(EXIT_FAILURE); + } } else { // watch the path where trigger file is expected @@ -201,10 +126,99 @@ void fbgui::watchFileTrigger() } } //------------------------------------------------------------------------------------------- +void fbgui::checkForTrigger(const QString& dirname) +{ + // check if fileToTriggerURL exists in the directory where the change occured + QFileInfo tfi(fileToTriggerURL); + QFileInfo fi(dirname + "/" + tfi.fileName()); + if (fi.exists()){ + qxtLog->debug() << fileToTriggerURL << " detected."; + loadURL(); + } + else + // do nothing / keep watching + qxtLog->debug() << "weird file!"; +} +//------------------------------------------------------------------------------------------- +bool fbgui::checkHost() const +{ + QHostInfo hostInfo = QHostInfo::fromName(baseURL.host()); + if (hostInfo.error() != QHostInfo::NoError){ + qxtLog->debug() << "Lookup of " << baseURL.host() << "failed. Exiting..."; + return false; + } + else{ + qxtLog->debug() << "Lookup of " << baseURL.host() << " succeeded."; + return true; + } +} +//------------------------------------------------------------------------------------------- void fbgui::loadURL(){ - // TODO POST data stuff comes here + // TODO actual data... + // PBS POST data tests + QNetworkRequest req(baseURL); + QByteArray postData("mac=d8:d3:85:80:81:8b&hardwarehash=12341234123412341234123412341234&bootisoID=1&serial="); + + // serial number + QByteArray serial; + // fetch serial number from rootfs + // try to open, TODO configurable path + QFile file("/serial"); + if (!file.exists()){ + qxtLog->debug() << "No such file: " << file.fileName(); + serial = "10-23-43-55-67"; // tests + } + if (!file.open(QIODevice::ReadOnly)){ + qxtLog->debug() << "Could not open: " << file.fileName(); + serial = "10-23-43-55-67"; // tests + } + // everything ok, read data + serial = file.readAll(); + file.close(); + + if (serial.isEmpty()) + qxtLog->debug() << "No data in file: " << file.fileName(); + + //qxtLog->debug() << "Serial number is: " << serial; + + + // load if host is valid if (checkHost()){ qxtLog->debug() << "Loading URL..."; - _webView->load(baseURL); + _webView->load(req, QNetworkAccessManager::PostOperation, postData); } } +//------------------------------------------------------------------------------------------- +void fbgui::setupDebugSplit() +{ + _debugConsole = new QTextEdit(this); + _debugConsole->setWindowFlags(Qt::FramelessWindowHint); + QPalette pal; + pal.setColor(QPalette::Base, Qt::black); + _debugConsole->setPalette(pal); + _debugConsole->setTextColor(Qt::white); + _debugConsole->insertPlainText("Debug console initialized.\n"); + // enable custom logger engine + qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole)); + //qxtLog->initLoggerEngine("fb_logger"); + qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); + // display browser and debug in a splitter + _splitter = new QSplitter(Qt::Vertical, this); + _splitter->addWidget(_webView); + _splitter->addWidget(_debugConsole); + // CTRL + D toggles debug window + _toggleDebug = new QAction(tr("&toggleDebug"), this); + _toggleDebug->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); + addAction(_toggleDebug); + connect(_toggleDebug, SIGNAL(triggered()), this, SLOT(toggleDebug())); + //_webView->load(QUrl("qrc:/html/loadAbout.html")); + setCentralWidget(_splitter); +} +//------------------------------------------------------------------------------------------- +void fbgui::toggleDebug() +{ + if (_debugConsole->isVisible()) + _debugConsole->hide(); + else + _debugConsole->show(); +} diff --git a/src/html/loadAbout.html b/src/html/loadAbout.html index 6b4e00e..e4da455 100644 --- a/src/html/loadAbout.html +++ b/src/html/loadAbout.html @@ -1,8 +1,13 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> + <html> <head> - +<script type="text/javascript"> +function gogo(){ + fbgui.trigger(); +} +</script> </head> <body> <h1>Waiting for an IP-Address</h1> @@ -10,6 +15,9 @@ <p> Make sure that you honor the great work of the programmers. </p> - +<p> +<input type="button" name="go" value="click me" + onclick="gogo()"> +</p> </body> </html> diff --git a/src/javascriptinterface.cpp b/src/javascriptinterface.cpp index 0a92de6..281a39f 100644 --- a/src/javascriptinterface.cpp +++ b/src/javascriptinterface.cpp @@ -22,7 +22,6 @@ void JavascriptInterface::attachToDOM(){ } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::notify(const QString& msg){ - qxtLog->debug() << "Notifying: " << msg; QString code = QString("notify('\%1')").arg(msg); _parent->evaluateJavaScript(code); @@ -68,20 +67,19 @@ void JavascriptInterface::quit(){ } //------------------------------------------------------------------------------------------------------- void JavascriptInterface::loadJQuery(){ - QString js; QString pathToJsDir(DEFAULT_QRC_HTML_DIR); pathToJsDir.append("/js"); - QDir* qrcJSDir = new QDir(pathToJsDir); - QFileInfoList fiList = qrcJSDir->entryInfoList(); + QDir qrcJSDir(pathToJsDir); + QFileInfoList fiList = qrcJSDir.entryInfoList(); QFileInfo fi; foreach(fi, fiList) { if(fi.suffix() == "js") { - qDebug()<< fi.fileName(); - qxtLog->debug() << fi.fileName(); + //qDebug()<< fi.fileName(); + //qxtLog->debug() << fi.fileName(); if(fi.fileName()!="test.js") { QFile file; @@ -91,8 +89,16 @@ void JavascriptInterface::loadJQuery(){ file.close(); _parent->evaluateJavaScript(js); - qDebug()<< "evaluated " + fi.fileName(); + //qxtLog->debug() << "evaluated " + fi.fileName(); } } } } +void JavascriptInterface::trigger(){ + QFile file(fileToTriggerURL); + if (file.open(QIODevice::WriteOnly)){ + file.write("data\n"); + qxtLog->debug() << "*trigger watcher*"; + } + file.close(); +} diff --git a/src/javascriptinterface.h b/src/javascriptinterface.h index d51dccb..0999ce3 100644 --- a/src/javascriptinterface.h +++ b/src/javascriptinterface.h @@ -48,6 +48,8 @@ public slots: void notify(const QString& msg); const QString getSysInfo(const QString& info); void quit(); + + void trigger(); }; #endif // JAVASCRIPTINTERFACE_H_ diff --git a/src/loggerengine.cpp b/src/loggerengine.cpp index 4540678..e6bf402 100644 --- a/src/loggerengine.cpp +++ b/src/loggerengine.cpp @@ -27,6 +27,7 @@ void LoggerEngine_fb::setLogLevelEnabled(QxtLogger::LogLevels level, bool enable } bool LoggerEngine_fb::isInitialized() const{ //return _initialized; + return true; } void LoggerEngine_fb::writeFormatted(QxtLogger::LogLevel level, const QList<QVariant> & msgs){ diff --git a/src/main.cpp b/src/main.cpp index fc75aab..9e92361 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,8 +119,6 @@ int main(int argc, char *argv[]) else fileToTriggerURL = DEFAULT_FILE_TRIGGER; - qDebug() << "file to trigger: " << fileToTriggerURL; - // setting directory for downloads if (clOpts.contains("downloadDir")){ downloadPath = clOpts.value("downloadDir"); @@ -137,6 +135,7 @@ int main(int argc, char *argv[]) else updateInterval = DEFAULT_UPDATE_INTERVAL; // basic std out engine is ugly... not yet initialised so using qDebug + qDebug() << "debugMode: " << debugMode; qDebug() << "configFilePath: " << configFilePath; qDebug() << "baseURL: " << baseURL; qDebug() << "downloadDir : " << downloadPath; diff --git a/src/testApp.sh b/src/testApp.sh index 6a40772..b5303c8 100755 --- a/src/testApp.sh +++ b/src/testApp.sh @@ -6,6 +6,7 @@ # -d <dir>, --download=<dir> absolute dir for downloads. # -c <path>, --config=<path> path to config file. # +rm -rf /tmp/fbgui script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" # to get the path only - not the script name - add working_path=`dirname "$script_path"` |