/* * agui.cpp * * Created on: Jan 31, 2012 * Author: joe */ #include "agui.h" #include "console.h" #include #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"); }