summaryrefslogtreecommitdiffstats
path: root/src/fbgui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbgui.cpp')
-rw-r--r--src/fbgui.cpp138
1 files changed, 66 insertions, 72 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp
index 4dbbc58..add6cfc 100644
--- a/src/fbgui.cpp
+++ b/src/fbgui.cpp
@@ -10,7 +10,7 @@
#include <QtWebKit>
#include <QxtCore>
-QThread dmThread;
+//QThread dmThread;
QString binPath("");
QUrl baseURL("");
QString downloadPath("");
@@ -31,44 +31,48 @@ int debugMode = -1;
* @see JavascriptInterface
* @see DownloadManager
*/
-fbgui::fbgui()
-{
+fbgui::fbgui() {
// test for libsys function
//SysInfoLibsysfs* sil = new SysInfoLibsysfs();
//sil->getInfoAboutNetworkInterface();
//sil->getInfoMainboardSerial();
- //SysInfo si;
- //qxtLog->debug() << si.getInfo("mbserial");
- //si.getInfo("usb");
+ //SysInfo si;
+ //qxtLog->debug() << si.getInfo("mbserial");
+ //si.getInfo("usb");
setupLayout();
createActions();
// initialize javascript interface
- JavascriptInterface* jsi = new JavascriptInterface(_webView->page()->mainFrame());
+ JavascriptInterface* jsi = new JavascriptInterface(
+ _webView->page()->mainFrame());
QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close()));
- QObject::connect(_webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
- jsi, SLOT(attachToDOM()));
-
+ QObject::connect(_webView->page()->mainFrame(),
+ SIGNAL(javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM()));
// initialize download manager
DownloadManager* dm = new DownloadManager();
QObject::connect(dm, SIGNAL(downloadInfo(const QString&, const double&)),
- jsi, SLOT(downloadInfo(const QString&, const double&)));
- QObject::connect(dm, SIGNAL(notify(const QString&)),
- jsi, SLOT(notify(const QString&)));
- QObject::connect(jsi, SIGNAL(requestFile(const QString&)),
- dm, SLOT(downloadFile(const QString&)));
- QObject::connect(dm, SIGNAL(updateProgress(const int&, const double&, const QString&)),
- jsi, SLOT(updateProgressBar(const int&, const double&, const QString&)));
- QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi, SLOT(callbackOnFinished()));
+ jsi, SLOT(downloadInfo(const QString&, const double&)));
+ QObject::connect(dm, SIGNAL(notify(const QString&)), jsi,
+ SLOT(notify(const QString&)));
+ QObject::connect(jsi, SIGNAL(requestFile(const QString&)), dm,
+ SLOT(downloadFile(const QString&)));
+ QObject::connect(
+ dm,
+ SIGNAL(updateProgress(const int&, const double&, const QString&)),
+ jsi,
+ SLOT(updateProgressBar(const int&, const double&, const QString&)));
+ QObject::connect(dm, SIGNAL(downloadQueueEmpty()), jsi,
+ SLOT(callbackOnFinished()));
// move download manager to its own thread
- dm->moveToThread(&dmThread);
- dmThread.start();
+ //dm->moveToThread(&dmThread);
+ //dmThread.start();
- // show filler page
+ //_webView->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar);
+ // show page
_webView->load(QUrl("qrc:/html/preload.html"));
// start watching for fileToTriggerURL
watchForTrigger();
@@ -80,8 +84,8 @@ fbgui::fbgui()
setWindowFlags(Qt::FramelessWindowHint);
showFullScreen();
}
-fbgui::~fbgui(){
- dmThread.quit();
+fbgui::~fbgui() {
+ //dmThread.quit();
}
//-------------------------------------------------------------------------------------------
// Layout / actions setup
@@ -94,27 +98,24 @@ fbgui::~fbgui(){
* - debug mode: the screen is divided into the browser and a debug
* out console
*/
-void fbgui::setupLayout()
-{
+void fbgui::setupLayout() {
// setup layout of the gui: debug split or browser
_webView = new QWebView(this);
- if (debugMode == 1){
+ if (debugMode == 1) {
// split main window in browser & debug console
createDebugConsole();
_splitter = new QSplitter(Qt::Vertical, this);
_splitter->addWidget(_webView);
_splitter->addWidget(_debugConsole);
setCentralWidget(_splitter);
- }
- else
+ } else
setCentralWidget(_webView);
}
//-------------------------------------------------------------------------------------------
/**
* This method enables a shortcut for closing the program.
*/
-void fbgui::createActions()
-{
+void fbgui::createActions() {
// CTRL + X to kill the gui
_quit = new QAction(tr("&quit"), this);
_quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X));
@@ -133,31 +134,30 @@ void fbgui::createActions()
* fbgui::checkForTrigger(const QString& dirname) method will be called.
*
*/
-void fbgui::watchForTrigger()
-{
+void fbgui::watchForTrigger() {
// check if fileToTriggerURL already exists
QFile file(fileToTriggerURL);
- if (file.exists()){
- qxtLog->debug() << "[watcher] " << fileToTriggerURL << " exists already!";
+ if (file.exists()) {
+ qxtLog->debug() << "[watcher] " << fileToTriggerURL
+ << " exists already!";
// try to load URL
- if (checkHost()) loadURL();
- }
- else {
+ loadURL();
+ } else {
// create it
- if (file.open(QIODevice::WriteOnly)){
+ if (file.open(QIODevice::WriteOnly)) {
qxtLog->debug() << "[gui] Created: " << fileToTriggerURL;
file.close();
- }
- else {
- qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL << " failed! Exiting...";
- exit(EXIT_FAILURE);
+ } else {
+ qxtLog->debug() << "[gui] Creation of " << fileToTriggerURL
+ << " failed! Exiting...";
+ exit( EXIT_FAILURE);
}
}
// watch the path where trigger file is expected
qxtLog->debug() << "[watcher] Watching " << fileToTriggerURL;
_watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL), this);
- QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)),
- this, SLOT(prepareURLLoad()));
+ QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
+ SLOT(prepareURLLoad()));
}
//-------------------------------------------------------------------------------------------
@@ -171,15 +171,14 @@ void fbgui::watchForTrigger()
* @see fbgui::checkHost()
* @see fbgui::loadURL()
*/
-void fbgui::prepareURLLoad()
-{
+void fbgui::prepareURLLoad() {
qxtLog->debug() << "[watcher] " << fileToTriggerURL << " changed!";
// disconnect _watcher, his job is done
qxtLog->debug() << "[watcher] disconnected.";
_watcher->disconnect(this);
_watcher->deleteLater();
// try to load URL
- if (checkHost()) loadURL();
+ loadURL();
}
//-------------------------------------------------------------------------------------------
// Preparations for URL load
@@ -189,15 +188,15 @@ void fbgui::prepareURLLoad()
*
* This method checks if is connected to the internet.
*/
-bool fbgui::checkHost() const
-{
+bool fbgui::checkHost() const {
QHostInfo hostInfo = QHostInfo::fromName(baseURL.host());
- if (hostInfo.error() != QHostInfo::NoError){
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << "failed. Exiting...";
+ if (hostInfo.error() != QHostInfo::NoError) {
+ qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
+ << "failed. Exiting...";
return false;
- }
- else{
- qxtLog->debug() << "[gui] Lookup of " << baseURL.host() << " succeeded.";
+ } else {
+ qxtLog->debug() << "[gui] Lookup of " << baseURL.host()
+ << " succeeded.";
return true;
}
}
@@ -212,14 +211,14 @@ bool fbgui::checkHost() const
* @see fbgui::watchForTrigger()
* @see fbgui::generatePOSTData()
*/
-void fbgui::loadURL()
-{
- if (checkHost()){
+void fbgui::loadURL() {
+ if (checkHost()) {
qxtLog->debug() << "[gui] Loading URL...";
QByteArray postData = generatePOSTData();
QNetworkRequest req(baseURL);
// show arrow cursor
- qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
+ QWSServer::instance()->setCursorVisible(true);
+ //qApp->setOverrideCursor(QCursor(Qt::ArrowCursor));
_webView->load(req, QNetworkAccessManager::PostOperation, postData);
}
}
@@ -236,8 +235,7 @@ void fbgui::loadURL()
* @see SysInfo::getMACAddress()
* @see SysInfo::getMainboardSerial()
*/
-QByteArray fbgui::generatePOSTData()
-{
+QByteArray fbgui::generatePOSTData() {
qxtLog->debug() << "[gui] Generating POST data...";
// use MAC address as base data
SysInfo si;
@@ -252,15 +250,14 @@ QByteArray fbgui::generatePOSTData()
// fetch serial number from usb
QByteArray serial;
QFile file(serialLocation);
- if (!file.open(QIODevice::ReadOnly)){
+ if (!file.open(QIODevice::ReadOnly)) {
qxtLog->debug() << "[post] No such file: " << file.fileName();
- serial = "10-23-43-55-67"; // tests
}
// everything ok, read data
serial = file.readAll();
file.close();
serial.chop(1); // chop EOF
- qxtLog->debug() << "[post] Serial number is: " << serial;
+ qxtLog->debug() << "[post] Serial number is: " << serial;
// construct final byte array
QByteArray postData("mac=");
@@ -273,8 +270,7 @@ QByteArray fbgui::generatePOSTData()
//-------------------------------------------------------------------------------------------
// Debug console setup / control
//-------------------------------------------------------------------------------------------
-void fbgui::createDebugConsole()
-{
+void fbgui::createDebugConsole() {
// create the debug console widget
_debugConsole = new QTextEdit(this);
_debugConsole->setWindowFlags(Qt::FramelessWindowHint);
@@ -291,13 +287,11 @@ void fbgui::createDebugConsole()
_toggleDebugConsole = new QAction(tr("&toggleDebug"), this);
_toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
addAction(_toggleDebugConsole);
- connect(_toggleDebugConsole, SIGNAL(triggered()), this, SLOT(toggleDebugConsole()));
+ connect(_toggleDebugConsole, SIGNAL(triggered()), this,
+ SLOT(toggleDebugConsole()));
}
//-------------------------------------------------------------------------------------------
-void fbgui::toggleDebugConsole()
-{
- if (_debugConsole->isVisible())
- _debugConsole->hide();
- else
- _debugConsole->show();
+void fbgui::toggleDebugConsole() {
+ (_debugConsole->isVisible()) ? _debugConsole->hide()
+ : _debugConsole->show();
}