summaryrefslogtreecommitdiffstats
path: root/src/fbgui/agui.cpp
blob: 3f2fd68536a7cc09dc39e83e4a8b8df1a06d2062 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * 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);
	if (debugMode > -1) {
		// split main window in browser & debug console
		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");
}