diff options
Diffstat (limited to 'src/fbgui.cpp')
| -rw-r--r-- | src/fbgui.cpp | 116 |
1 files changed, 56 insertions, 60 deletions
diff --git a/src/fbgui.cpp b/src/fbgui.cpp index f27a698..add6cfc 100644 --- a/src/fbgui.cpp +++ b/src/fbgui.cpp @@ -31,38 +31,41 @@ 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); @@ -81,7 +84,7 @@ fbgui::fbgui() setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); } -fbgui::~fbgui(){ +fbgui::~fbgui() { //dmThread.quit(); } //------------------------------------------------------------------------------------------- @@ -95,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)); @@ -134,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 loadURL(); - } - else { + } 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())); } //------------------------------------------------------------------------------------------- @@ -172,8 +171,7 @@ 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."; @@ -190,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; } } @@ -213,9 +211,8 @@ 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); @@ -238,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; @@ -254,14 +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(); } // 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="); @@ -274,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); @@ -292,10 +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() -{ - (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); +void fbgui::toggleDebugConsole() { + (_debugConsole->isVisible()) ? _debugConsole->hide() + : _debugConsole->show(); } |
