summaryrefslogtreecommitdiffstats
path: root/src/fbgui.cpp
diff options
context:
space:
mode:
authorJonathan Bauer2011-03-24 00:44:44 +0100
committerJonathan Bauer2011-03-24 00:44:44 +0100
commit731213e4dfc4411312c5dc92df356bad0ad70669 (patch)
treec33a36fcf827affaaed39c88e7ac0c1e025d443b /src/fbgui.cpp
parenta new classes sysinfolibsysfs (diff)
downloadfbgui-731213e4dfc4411312c5dc92df356bad0ad70669.tar.gz
fbgui-731213e4dfc4411312c5dc92df356bad0ad70669.tar.xz
fbgui-731213e4dfc4411312c5dc92df356bad0ad70669.zip
improvements...
Diffstat (limited to 'src/fbgui.cpp')
-rw-r--r--src/fbgui.cpp222
1 files changed, 118 insertions, 104 deletions
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();
+}