summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2012-02-01 15:30:46 +0100
committerJonathan Bauer2012-02-01 15:30:46 +0100
commit7cf5576531177f292543229d7b74282bc6660dcb (patch)
tree11227e984bc687724e27077d9b351e2e139a812c
parentvarious logging fixes (diff)
downloadfbgui-7cf5576531177f292543229d7b74282bc6660dcb.tar.gz
fbgui-7cf5576531177f292543229d7b74282bc6660dcb.tar.xz
fbgui-7cf5576531177f292543229d7b74282bc6660dcb.zip
new abstract class agui for common gui functions, new console class for debug console
-rw-r--r--src/fbgui/agui.cpp88
-rw-r--r--src/fbgui/agui.h54
-rw-r--r--src/fbgui/console.cpp60
-rw-r--r--src/fbgui/console.h32
4 files changed, 234 insertions, 0 deletions
diff --git a/src/fbgui/agui.cpp b/src/fbgui/agui.cpp
new file mode 100644
index 0000000..7759800
--- /dev/null
+++ b/src/fbgui/agui.cpp
@@ -0,0 +1,88 @@
+/*
+ * agui.cpp
+ *
+ * Created on: Jan 31, 2012
+ * Author: joe
+ */
+
+#include "agui.h"
+#include "console.h"
+
+#include <log4cxx/logger.h>
+#include "qlog4cxx.h"
+
+using namespace log4cxx;
+using namespace log4cxx::helpers;
+LoggerPtr aguiCoreLogger(Logger::getLogger("agui.core"));
+
+QString logFilePath("");
+int debugMode = -1;
+
+agui::agui() {
+ setupLayout();
+ createActions();
+
+ setAttribute(Qt::WA_QuitOnClose, true);
+ setWindowFlags(Qt::FramelessWindowHint);
+}
+
+agui::~agui() {
+}
+
+/**
+ * @brief 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 agui::setupLayout() {
+ // setup layout of the gui: debug split or browser
+ _webView = new QWebView(this);
+ _webView->setContextMenuPolicy(Qt::NoContextMenu); // if this does not work try Qt::CustomContextMenu
+ _webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
+ LOG4CXX_DEBUG(aguiCoreLogger, "Debug Mode: " << debugMode);
+ if (debugMode > -1) {
+ // split main window in browser & debug console
+ //createDebugConsole();
+ console* debugConsole = new console(this);
+ QSplitter* _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 agui::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()));
+}
+//-------------------------------------------------------------------------------------------
+void agui::magicKey(const char* key){
+ QFile file("/proc/sysrq-trigger");
+ if (file.open(QIODevice::WriteOnly)) {
+ file.write(key);
+ file.close();
+ } else {
+ LOG4CXX_DEBUG(aguiCoreLogger, "Could not open /proc/sysrq-trigger");
+ }
+}
+
+void agui::rebootSystem() {
+ magicKey("b");
+}
+
+void agui::shutdownSystem() {
+ magicKey("o");
+}
diff --git a/src/fbgui/agui.h b/src/fbgui/agui.h
new file mode 100644
index 0000000..0639981
--- /dev/null
+++ b/src/fbgui/agui.h
@@ -0,0 +1,54 @@
+/*
+ * agui.h
+ *
+ * Created on: Jan 31, 2012
+ * Author: joe
+ */
+
+#ifndef AGUI_H_
+#define AGUI_H_
+
+#include <QtGui>
+#include <QtWebKit>
+
+extern QString logFilePath;
+extern int debugMode;
+
+class agui: public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ agui();
+ virtual ~agui();
+
+protected:
+ // QWebView for displaying internet content
+ QWebView* _webView;
+ //-------------------
+ // layout setup:
+ //-------------------
+ // Sets the layout depending on the debug mode:
+ // no debug or debugMode = 0 -> only browser shown.
+ // debugMode = 1 -> split main window in browser and debug console.
+ void setupLayout();
+ // Create all actions for the GUI. (Currently only quit.)
+ void createActions();
+
+ //------------------
+ // action list:
+ //------------------
+ // closes the main window provoking the application to quit.
+ QAction* _quit;
+
+private:
+ void magicKey(const char*);
+
+protected slots:
+ // shut off the system
+ void shutdownSystem();
+ // reboot the system
+ void rebootSystem();
+};
+
+#endif /* AGUI_H_ */
diff --git a/src/fbgui/console.cpp b/src/fbgui/console.cpp
new file mode 100644
index 0000000..ffd425f
--- /dev/null
+++ b/src/fbgui/console.cpp
@@ -0,0 +1,60 @@
+/*
+ * console.cpp
+ *
+ * Created on: Jan 31, 2012
+ * Author: joe
+ */
+
+#include "console.h"
+
+console::console(QMainWindow* parent) :
+ QTextEdit(parent) {
+
+ setWindowFlags(Qt::FramelessWindowHint);
+
+ // fanciness
+ QPalette pal;
+ pal.setColor(QPalette::Base, Qt::black);
+ setPalette(pal);
+ setTextColor(Qt::white);
+
+ // CTRL + D toggles debug window
+ QAction* _toggle = new QAction(tr("&toggleDebug"), parentWidget());
+ _toggle->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
+ parentWidget()->addAction(_toggle);
+ connect(_toggle, SIGNAL(triggered()), this, SLOT(toggle()));
+
+ // watcher to detect file change
+ QFileSystemWatcher* _watcher = new QFileSystemWatcher(this);
+ // read from log file
+ _logFile = new QFile(logFilePath);
+ _logFileIn = new QTextStream(_logFile);
+
+ if (!_logFile->open(QFile::ReadOnly | QFile::Text)) {
+ } else {
+ // watch log file
+ _watcher->addPath(logFilePath);
+ connect(_watcher, SIGNAL(fileChanged(const QString&)), this,
+ SLOT(refresh(const QString&)));
+ }
+}
+
+console::~console() {
+ delete _logFile;
+ delete _logFileIn;
+}
+
+void console::refresh(const QString& fileName) {
+ if (fileName == logFilePath) {
+ while (!_logFileIn->atEnd()) {
+ QString line = _logFileIn->readLine();
+ if (!line.isEmpty())
+ this->append(line);
+ }
+ this->moveCursor(QTextCursor::End);
+ }
+}
+
+void console::toggle() {
+ (this->isVisible()) ? this->hide() : this->show();
+}
diff --git a/src/fbgui/console.h b/src/fbgui/console.h
new file mode 100644
index 0000000..cb6dd34
--- /dev/null
+++ b/src/fbgui/console.h
@@ -0,0 +1,32 @@
+/*
+ * console.h
+ *
+ * Created on: Jan 31, 2012
+ * Author: joe
+ */
+
+#ifndef CONSOLE_H_
+#define CONSOLE_H_
+
+#include "fbgui.h"
+#include <QtGui>
+
+extern QString logFilePath;
+
+class console : public QTextEdit
+{
+ Q_OBJECT
+
+public:
+ console(QMainWindow* parent = 0);
+ virtual ~console();
+
+private:
+ QFile* _logFile;
+ QTextStream* _logFileIn;
+private slots:
+ void toggle();
+ void refresh(const QString& fileName);
+};
+
+#endif /* CONSOLE_H_ */