diff options
Diffstat (limited to 'src/fbgui/fbgui.cpp')
-rw-r--r-- | src/fbgui/fbgui.cpp | 239 |
1 files changed, 6 insertions, 233 deletions
diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index 2adcca3..b4a8a13 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -11,13 +11,11 @@ using namespace log4cxx; using namespace log4cxx::helpers; LoggerPtr coreLogger(Logger::getLogger("fbgui.core")); - #include <iostream> #include <QThread> #include <QtWebKit> QThread dmThread; -QString logFilePath(""); QString ipConfigFilePath(""); QString binPath(""); QUrl baseURL(""); @@ -27,7 +25,8 @@ QString fileToTriggerURL(""); QString serialLocation(""); QString sessionID(""); bool sslSupport; -int debugMode = -1; +//int debugMode=-1; +//QString logFilePath(""); //------------------------------------------------------------------------------------------- /** @@ -40,14 +39,13 @@ int debugMode = -1; * @see JavascriptInterface * @see DownloadManager */ -fbgui::fbgui() { +fbgui::fbgui() : + agui(){ } -fbgui::~fbgui() { +fbgui::~fbgui(){ dmThread.quit(); } - - /** * init function. */ @@ -58,17 +56,12 @@ void fbgui::init() { if(sslSupport) LOG4CXX_DEBUG(coreLogger, "SSL enabled."); - _watcher = new QFileSystemWatcher(this); - - setupLayout(); - createActions(); - // initialize javascript interface JavascriptInterface* jsi = new JavascriptInterface( _webView->page()->mainFrame()); QObject::connect(jsi, SIGNAL(quitFbgui()), this, SLOT(close())); QObject::connect(jsi, SIGNAL(shutDownClient()), this, - SLOT(performShutDown())); + SLOT(shutdownSystem())); QObject::connect(_webView->page()->mainFrame(), SIGNAL( javaScriptWindowObjectCleared()), jsi, SLOT(attachToDOM())); @@ -93,118 +86,11 @@ void fbgui::init() { dm->moveToThread(&dmThread); dmThread.start(); - // show "waiting for internet" page until triggered. -// if (debugMode > -1) { -// _webView->load(QUrl("qrc:/html/preload-debug.html")); -// } else { -// _webView->load(QUrl("qrc:/html/preload.html")); -// } - - // watcher is not needed anymore since we guarantee internet connection with the networkDiscovery. - // start watching for fileToTriggerURL - //watchForTrigger(); loadURL(); // set properties setWindowTitle("fbgui"); - setAttribute(Qt::WA_QuitOnClose, true); - setWindowFlags(Qt::FramelessWindowHint); showFullScreen(); - this->show(); -} -//------------------------------------------------------------------------------------------- -// Layout / actions setup -//------------------------------------------------------------------------------------------- -/** - * This method sets the used Layout. - * - * This method sets the used Layout. Possible layout are: - * - browser mode: only the browser is visible - * - debug mode: the screen is divided into the browser and a debug - * out console - */ -void fbgui::setupLayout() { - // setup layout of the gui: debug split or browser - _webView = new QWebView(this); - 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 - setCentralWidget(_webView); -} -//------------------------------------------------------------------------------------------- -/** - * This method enables a shortcut for closing the program. - * The shortcut itself is not configurable: CTRL + X - */ -void fbgui::createActions() { - _quit = new QAction(tr("&quit"), this); - _quit->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); - this->addAction(_quit); - connect(_quit, SIGNAL(triggered()), this, SLOT(close())); -} -//------------------------------------------------------------------------------------------- -// File system watching -//------------------------------------------------------------------------------------------- -/** - * This method sets a "watchdog" to a special file. - * - * This method sets a "watchdog" to a special file. If needed it creates the - * file which it has to watch over. It than connects a QFileSystemWatcher with - * this file. If changes happen to this file, the - * fbgui::checkForTrigger(const QString& dirname) method will be called. - * - */ -void fbgui::watchForTrigger() { - // check if fileToTriggerURL already exists - QFile file(fileToTriggerURL); - if (file.exists()) { - LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " found."); - // try to load URL - loadURL(); - } else { - // create it - if (file.open(QIODevice::WriteOnly)) { - LOG4CXX_DEBUG(coreLogger, "Created: " << fileToTriggerURL); - file.close(); - } else { - LOG4CXX_DEBUG(coreLogger, "Creation of " << fileToTriggerURL << " failed!"); - LOG4CXX_DEBUG(coreLogger, "Exiting in 5 seconds..."); - QTimer::singleShot(5000, this, SLOT(close())); - } - } - // watch the path to trigger file - LOG4CXX_DEBUG(coreLogger, "[watcher] Watching " << fileToTriggerURL); - _watcher->addPath(fileToTriggerURL); - //_watcher = new QFileSystemWatcher(QStringList(fileToTriggerURL, logFilePath), this); -QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(prepareURLLoad(const QString&))); - -} -//------------------------------------------------------------------------------------------- -/** - * This method checks if the trigger was valid. - * - * This method checks if the trigger was valid. If yes, - * we have received an IP Address an can load the main screen. - * If not, something some error happened. - * - * @see fbgui::checkHost() - * @see fbgui::loadURL() - */ -void fbgui::prepareURLLoad(const QString& fileName) { - if (fileName == fileToTriggerURL) { - LOG4CXX_DEBUG(coreLogger, "[watcher] " << fileToTriggerURL << " changed!"); - // disconnect _watcher, his job is done - LOG4CXX_DEBUG(coreLogger, "[watcher] disconnected."); - _watcher->disconnect(this); - _watcher->deleteLater(); - // try to load URL - loadURL(); - } } //------------------------------------------------------------------------------------------- // Preparations for URL load @@ -418,57 +304,6 @@ QByteArray fbgui::generatePOSTData() { LOG4CXX_DEBUG(coreLogger, "[post] POST data: " << postData); return postData; } - -//------------------------------------------------------------------------------------------- -// Shutdown / Reboot of the client -//------------------------------------------------------------------------------------------- -// TODO One function for reboot and shutdown, with parameter for the action. -// for example: doSystemCall(_REBOOT_); -/** - * This method performs the shutdown of the client. - * - * This method performs the shutdown of the client. It is triggered by the - * JavascriptInterface::shutDownClient() signal which will be emited in the - * JavascriptInterface::shutDown() method. - * This method writes the character 'o' in /proc/sysrq-trigger - * which will shutdown the computer immediatly. - * (See linux magic keys) - * - * @see JavascriptInterface::shutDownClient() - * @see JavascriptInterface::shutDown() - */ -void fbgui::performShutDown() { - QFile file("/proc/sysrq-trigger"); - if (file.open(QIODevice::WriteOnly)) { - file.write("o"); - file.close(); - } else { - LOG4CXX_DEBUG(coreLogger, "Could not open /proc/sysrq-trigger"); - } -} -//------------------------------------------------------------------------------------------- -/** - * This method performs the reboot of the client. - * - * This method performs the reboot of the client. It is triggered by the - * JavascriptInterface::rebootClient() signal which will be emited in the - * JavascriptInterface::reboot() method. - * This method writes the character 'b' in /proc/sysrq-trigger - * which will shutdown the computer immediatly. - * (See linux magic keys) - * - * @see JavascriptInterface::rebootClient() - * @see JavascriptInterface::reboot() - */ -void fbgui::performReboot() { - QFile file("/proc/sysrq-trigger"); - if (file.open(QIODevice::WriteOnly)) { - file.write("b"); - file.close(); - } else { - LOG4CXX_DEBUG(coreLogger, "Could not open /proc/sysrq-trigger"); - } -} //------------------------------------------------------------------------------------------- // Preparing Kernel Switch per kexec (initiating Stage 3) //------------------------------------------------------------------------------------------- @@ -563,65 +398,3 @@ void fbgui::runKexec() { //TODO: Handle failure properly... } } -//------------------------------------------------------------------------------------------- -// Debug console setup / control -//------------------------------------------------------------------------------------------- -/** - * This method creates a debug console as a widget. - * - * It is basicly a QTextEdit widget as provided by QT's Framework. - * An action to toggle this widget is implemented (CTRL + D). - * - * @see fbgui::toggleDebugConsole() - */ -void fbgui::createDebugConsole() { - // create the debug console widget - _debugConsole = new QTextEdit(this); - _debugConsole->setWindowFlags(Qt::FramelessWindowHint); - // fanciness - QPalette pal; - pal.setColor(QPalette::Base, Qt::black); - _debugConsole->setPalette(pal); - _debugConsole->setTextColor(Qt::white); - // CTRL + D toggles debug window - _toggleDebugConsole = new QAction(tr("&toggleDebug"), this); - _toggleDebugConsole->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); - addAction(_toggleDebugConsole); - connect(_toggleDebugConsole, SIGNAL(triggered()), - this, SLOT(toggleDebugConsole())); - - // read from log file - _logFile = new QFile(logFilePath); - _logFileIn = new QTextStream(_logFile); - - if (!_logFile->open(QFile::ReadOnly | QFile::Text)) { - //do error - } - _debugConsole->setPlainText(_logFileIn->readAll()); - _debugConsole->moveCursor(QTextCursor::End); - LOG4CXX_DEBUG(coreLogger, "Log file opened."); - // watch log file - _watcher->addPath(logFilePath); - QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(refreshDebugConsole(const QString&))); - -} -//------------------------------------------------------------------------------------------- -void fbgui::refreshDebugConsole(const QString& fileName) { - if (fileName == logFilePath) { - while (!_logFileIn->atEnd()) { - _debugConsole->append(_logFileIn->readLine()); - } - _debugConsole->moveCursor(QTextCursor::End); - } -} -//------------------------------------------------------------------------------------------- -/** - * This method toggles the debug console. - * - * Toggle the visibility of the debug console if the action _toggleDebugConsole is triggered. - * - * @see fbgui::createDebugConsole() - */ -void fbgui::toggleDebugConsole() { - (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); -} |