From 4da044c24e0e4d7fa936c40185eb893f5d32bf47 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 31 Jan 2012 13:59:38 +0100 Subject: fix for empty log messages --- src/fbgui/networkdiscovery.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fbgui/networkdiscovery.cpp b/src/fbgui/networkdiscovery.cpp index 49aa148..0198086 100644 --- a/src/fbgui/networkdiscovery.cpp +++ b/src/fbgui/networkdiscovery.cpp @@ -553,7 +553,7 @@ void NetworkDiscovery::handleNewInput(QLocalSocket * client) { QString data(client->readLine()); data = data.trimmed(); - LOG4CXX_DEBUG(ndcLogger, data); + if (!data.isEmpty()) LOG4CXX_DEBUG(ndcLogger, data); QStringList lines = data.split("\n"); for (int i = 0; i < lines.length(); i++) { @@ -621,6 +621,7 @@ void NetworkDiscovery::handleNewInputLine(QLocalSocket * client, QString logMsg) _ifNameToClient.insert(interface, client); } + // st states // #define LOG_EMERG 0 /* system is unusable */ -- cgit v1.2.3-55-g7522 From 5794a550f022209036e329ed38f086c3d7bb9c98 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 31 Jan 2012 14:00:38 +0100 Subject: hm --- src/fbgui/fbgui.cpp | 23 +- src/fbgui/main.cpp | 583 +++++++++++++++++++++++++------------------------- src/fbgui/sysinfo.cpp | 12 ++ src/fbgui/sysinfo.h | 1 + 4 files changed, 315 insertions(+), 304 deletions(-) diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index 759c747..c7cbce6 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -11,7 +11,6 @@ using namespace log4cxx; using namespace log4cxx::helpers; LoggerPtr coreLogger(Logger::getLogger("fbgui.core")); - #include #include #include @@ -45,8 +44,6 @@ fbgui::~fbgui() { dmThread.quit(); } - - /** * init function. */ @@ -54,8 +51,10 @@ void fbgui::init() { // start fbgui LOG4CXX_DEBUG(coreLogger, "Initializing fbgui..."); - _watcher = new QFileSystemWatcher(this); + // init watcher + _watcher = new QFileSystemWatcher(this); + // setup layout and actions setupLayout(); createActions(); @@ -488,15 +487,15 @@ void fbgui::createDebugConsole() { _logFileIn = new QTextStream(_logFile); if (!_logFile->open(QFile::ReadOnly | QFile::Text)) { - //do error + LOG4CXX_DEBUG(coreLogger, "Could not open log file: " << logFilePath); + } + else { + _debugConsole->setPlainText(_logFileIn->readAll()); + _debugConsole->moveCursor(QTextCursor::End); + // watch log file + _watcher->addPath(logFilePath); + QObject::connect(_watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(refreshDebugConsole(const QString&))); } - _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) { diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index 6284054..d883469 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -20,299 +20,298 @@ using namespace log4cxx::helpers; LoggerPtr logger(Logger::getLogger("fbgui")); void printHelp() { - QTextStream qout(stdout); - qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; - qout << QObject::tr("Options:") << endl; - qout << "-c , --config= " << QObject::tr( - "Path to configuration file.") << endl; - qout << "-u , --url= " << QObject::tr( - "Sets the URL to be loaded.") << endl; - qout << "-d , --download= " << QObject::tr( - "Specify the download directory.") << endl; - qout << "-t " << QObject::tr( - "Specify location of the file triggering the URL load.") << endl; - qout << "-s " << QObject::tr( - "Specify location of the file containing the serial number.") << endl; - qout << "-D , --debug= " << QObject::tr( - "Activate debug mode. [0,1]") << endl; - qout << "-h, --help " << QObject::tr( - "Prints this help.") << endl; - qout.flush(); - exit( EXIT_SUCCESS); + QTextStream qout(stdout); + qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; + qout << QObject::tr("Options:") << endl; + qout << "-c , --config= " + << QObject::tr("Path to configuration file.") << endl; + qout << "-u , --url= " + << QObject::tr("Sets the URL to be loaded.") << endl; + qout << "-d , --download= " + << QObject::tr("Specify the download directory.") << endl; + qout + << "-t " + << QObject::tr( + "Specify location of the file triggering the URL load.") + << endl; + qout + << "-s " + << QObject::tr( + "Specify location of the file containing the serial number.") + << endl; + qout << "-D , --debug= " + << QObject::tr("Activate debug mode. [0,1]") << endl; + qout << "-h, --help " + << QObject::tr("Prints this help.") << endl; + qout.flush(); + exit(EXIT_SUCCESS); } int main(int argc, char *argv[]) { - // Initialisation of the QApplication: - // In QT, every application is composed of two separate - // components: the GUI-Client and the GUI-Server. - // - // The third parameter sets the application as the - // GUI-Server (aswell as the GUI-Client). - - QFileInfo loggingConfInfo = QFileInfo(QDir::home(), ".fbgui.logging.conf"); - QString loggingConfigFilePath; - if (loggingConfInfo.exists()) - loggingConfigFilePath = loggingConfInfo.absoluteFilePath(); - else { - loggingConfInfo = QFileInfo(QString("/etc/fbgui.logging.conf")); - if (loggingConfInfo.exists()) - loggingConfigFilePath = loggingConfInfo.absoluteFilePath(); - else - loggingConfigFilePath = ""; - } - - if (loggingConfigFilePath.length() > 0) { - // BasicConfigurator replaced with PropertyConfigurator. - PropertyConfigurator::configure(loggingConfigFilePath.toStdString()); - } else { - BasicConfigurator::configure(); - } - - QApplication app(argc, argv, QApplication::GuiServer); - app.setOrganizationName("team_projekt_2011"); - app.setApplicationName("prebootGUI"); - binPath = QApplication::applicationDirPath(); - - QTranslator translator; - translator.load(":" + QLocale::system().name()); - app.installTranslator(&translator); - - // parse command line arguments using getopt - QMap clOpts; - int longIndex = 0; - static const char *optString = "c:u:d:s:t:D:hl:nS:p:e:"; - static const struct option longOpts[] = { { "config", required_argument, - NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", - required_argument, NULL, 'd' }, { "serial", required_argument, NULL, - 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", - required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { - "log", required_argument, NULL, 'l' }, - { "nd", no_argument, NULL, 'n' }, { "server", required_argument, NULL, - 'S' }, { "autoup", no_argument, NULL, 'a' }, { - "socketserverpath", required_argument, NULL, 'p' }, { - "pathtoexe", required_argument, NULL, 'e' } }; - int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - while (opt != -1) { - switch (opt) { - case 'c': - clOpts.insert("configFile", optarg); - break; - case 'l': - clOpts.insert("logFile", optarg); - break; - case 'u': - clOpts.insert("url", optarg); - break; - case 'd': - clOpts.insert("downloadDir", optarg); - break; - case 's': - clOpts.insert("serialLocation", optarg); - break; - case 't': - clOpts.insert("trigger", optarg); - break; - case 'D': - clOpts.insert("debug", optarg); - break; - case 'h': - clOpts.insert("help", "help"); - break; - case 'n': - clOpts.insert("nd", "nd"); - break; - case 'S': - clOpts.insert("server", optarg); - break; - case 'a': - clOpts.insert("autoup", "autoup"); - break; - case 'p': - clOpts.insert("socketserverpath", optarg); - break; - case 'e': - clOpts.insert("pathtoexe", optarg); - break; - } - opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - } - - if (clOpts.contains("help")) - printHelp(); - - if (clOpts.contains("debug")) { - debugMode = clOpts.value("debug").toInt(); - // start basic debug output on terminal - // qxtLog->disableLoggerEngine("DEFAULT"); - // qxtLog->enableLogLevels(QxtLogger::DebugLevel); - // qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); - // qxtLog->initLoggerEngine("std_logger"); - // qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); - } else - debugMode = -1; - - // look for config file either in: - // - the path found in the configuration file - // - the user's home directory (as .fbgui.conf) - // - /etc/fbgui.conf - - QString configFilePath; - QFileInfo confInfo; - if (clOpts.contains("configFile")) - configFilePath = clOpts.value("configFile"); - else { - confInfo = QFileInfo(QDir::home(), ".fbgui.conf"); - if (confInfo.exists()) - configFilePath = confInfo.absoluteFilePath(); - else { - confInfo = QFileInfo(QString("/etc/fbgui.conf")); - if (confInfo.exists()) - configFilePath = QString("/etc/fbgui.conf"); - else - configFilePath = DEFAULT_CONFIG_PATH; - } - } - - // read the config file - QSettings confFileSettings(configFilePath, QSettings::IniFormat); - confFileSettings.setIniCodec("UTF-8"); - - // set base URL to be loaded - if (clOpts.contains("url")) - baseURL = QUrl(clOpts.value("url")); - else if (confFileSettings.contains("default/pbs_url")) - baseURL = confFileSettings.value("default/pbs_url").toUrl(); - else - baseURL = DEFAULT_URL; - - // set directory for downloads - if (clOpts.contains("downloadDir")) - downloadPath = clOpts.value("downloadDir"); - else if (confFileSettings.contains("default/download_directory")) - downloadPath - = confFileSettings.value("default/download_directory").toString(); - else - downloadPath = DEFAULT_DOWNLOAD_DIR; - - // set update interval for download progress functions of download manager. - if (confFileSettings.contains("default/update_interval")) - updateInterval - = confFileSettings.value("default/update_interval").toInt(); - else - updateInterval = DEFAULT_UPDATE_INTERVAL; - - // set which file to watch to trigger loading of URL - if (clOpts.contains("trigger")) - fileToTriggerURL = clOpts.value("trigger"); - else if (confFileSettings.contains("default/file_trigger")) - fileToTriggerURL - = confFileSettings.value("default/file_trigger").toString(); - else - fileToTriggerURL = DEFAULT_FILE_TRIGGER; - - // set serial location - if (clOpts.contains("serialLocation")) - serialLocation = clOpts.value("serialLocation"); - else if (confFileSettings.contains("default/serial_location")) - serialLocation - = confFileSettings.value("default/serial_location").toString(); - else - serialLocation = QString("/serial"); // tests - - // save ip config location (file generated by uchpc) - if (confFileSettings.contains("default/ip_config")) - ipConfigFilePath = confFileSettings.value("default/ip_config").toString(); - - // save path to log file - if (clOpts.contains("logFile")) - logFilePath = clOpts.value("logFile"); - else if (confFileSettings.contains("default/log_file")) - logFilePath = confFileSettings.value("default/log_file").toString(); - else - logFilePath = DEFAULT_LOG_FILE_PATH; - - // - if (clOpts.contains("server")) - gServerIp = clOpts.value("server"); - else if (confFileSettings.contains("default/server")) - gServerIp = confFileSettings.value("default/server").toString(); - else - gServerIp = "209.85.148.105"; //that is a google server. change this to a proper default address - - // - if (clOpts.contains("autoup")) - gAutoUp = true; - else if (confFileSettings.contains("default/autoup")) - gAutoUp = confFileSettings.value("default/autoup").toBool(); - else - gAutoUp = false; - - // - if (clOpts.contains("socketserverpath")) - gSocketServerPath = clOpts.value("socketserverpath"); - else if (confFileSettings.contains("default/socketserverpath")) - gSocketServerPath - = confFileSettings.value("default/socketserverpath").toString(); - else - gSocketServerPath = DEFAULT_QTSOCKETADDRESS; - - // - if (clOpts.contains("pathtoexe")) - gPathToDhcpExe = clOpts.value("pathtoexe"); - else if (confFileSettings.contains("default/pathtoexe")) - gPathToDhcpExe = confFileSettings.value("default/pathtoexe").toString(); - else - gPathToDhcpExe = DEFAULT_PATHTODHCPCDEXE; - - // write always a log file - // // activate file logger if debug mode activated. - // if (debugMode > -1) { - // start debug logging to file. - // qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath)); - // qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); - // } - - // print config - LOG4CXX_DEBUG(logger, "************* CONFIG INFO *************"); - LOG4CXX_DEBUG(logger, "configFilePath: " << configFilePath); - LOG4CXX_DEBUG(logger, "logFilePath: " << logFilePath); - LOG4CXX_DEBUG(logger, "ipConfigFilePath: " << ipConfigFilePath); - LOG4CXX_DEBUG(logger, "baseURL: " << baseURL.toString()); - LOG4CXX_DEBUG(logger, "downloadDir : " << downloadPath); - LOG4CXX_DEBUG(logger, "trigger: " << fileToTriggerURL); - LOG4CXX_DEBUG(logger, "serialLocation: " << serialLocation); - if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { - LOG4CXX_DEBUG(logger, "*******************************************"); - LOG4CXX_DEBUG(logger, "Network Discovery activated:"); - LOG4CXX_DEBUG(logger, "server: " << gServerIp); - LOG4CXX_DEBUG(logger, "autoup: " << gAutoUp); - LOG4CXX_DEBUG(logger, "socketserverpath: " << gSocketServerPath); - LOG4CXX_DEBUG(logger, "pathtoexe: " << gPathToDhcpExe); - } else { - LOG4CXX_DEBUG(logger, "Network Discovery deactivated."); - } - LOG4CXX_DEBUG(logger, "*******************************************"); - - // set invisible cursor - //QWSServer::instance()->setCursorVisible(false); - - // set default keyboard / mouse drivers. TODO: fix this, doesn't work... - //QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); - //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); - - - fbgui gui; - ndgui ngui; - - if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { - LOG4CXX_DEBUG(logger, "Initializing ndgui..."); - QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); - ngui.init(); - ngui.show(); - } else { - gui.init(); - gui.show(); - } - - return app.exec(); + // Initialisation of the QApplication: + // In QT, every application is composed of two separate + // components: the GUI-Client and the GUI-Server. + // + // The third parameter sets the application as the + // GUI-Server (aswell as the GUI-Client). + + QFileInfo loggingConfInfo = QFileInfo(QDir::home(), ".fbgui.logging.conf"); + QString loggingConfigFilePath; + if (loggingConfInfo.exists()) + loggingConfigFilePath = loggingConfInfo.absoluteFilePath(); + else { + loggingConfInfo = QFileInfo(QString("/etc/fbgui.logging.conf")); + if (loggingConfInfo.exists()) + loggingConfigFilePath = loggingConfInfo.absoluteFilePath(); + else + loggingConfigFilePath = ""; + } + + if (loggingConfigFilePath.length() > 0) { + // BasicConfigurator replaced with PropertyConfigurator. + PropertyConfigurator::configure(loggingConfigFilePath.toStdString()); + } else { + BasicConfigurator::configure(); + } + + QApplication app(argc, argv, QApplication::GuiServer); + app.setOrganizationName("team_projekt_2011"); + app.setApplicationName("prebootGUI"); + binPath = QApplication::applicationDirPath(); + + QTranslator translator; + translator.load(":" + QLocale::system().name()); + app.installTranslator(&translator); + + // parse command line arguments using getopt + QMap clOpts; + int longIndex = 0; + static const char *optString = "c:u:d:s:t:D:hl:nS:p:e:"; + static const struct option longOpts[] = { { "config", required_argument, + NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", + required_argument, NULL, 'd' }, { "serial", required_argument, NULL, + 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", + required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, + { "log", required_argument, NULL, 'l' }, { "nd", no_argument, NULL, + 'n' }, { "server", required_argument, NULL, 'S' }, { + "autoup", no_argument, NULL, 'a' }, { "socketserverpath", + required_argument, NULL, 'p' }, { "pathtoexe", + required_argument, NULL, 'e' } }; + int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + while (opt != -1) { + switch (opt) { + case 'c': + clOpts.insert("configFile", optarg); + break; + case 'l': + clOpts.insert("logFile", optarg); + break; + case 'u': + clOpts.insert("url", optarg); + break; + case 'd': + clOpts.insert("downloadDir", optarg); + break; + case 's': + clOpts.insert("serialLocation", optarg); + break; + case 't': + clOpts.insert("trigger", optarg); + break; + case 'D': + clOpts.insert("debug", optarg); + break; + case 'h': + clOpts.insert("help", "help"); + break; + case 'n': + clOpts.insert("nd", "nd"); + break; + case 'S': + clOpts.insert("server", optarg); + break; + case 'a': + clOpts.insert("autoup", "autoup"); + break; + case 'p': + clOpts.insert("socketserverpath", optarg); + break; + case 'e': + clOpts.insert("pathtoexe", optarg); + break; + } + opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + } + + if (clOpts.contains("help")) + printHelp(); + + if (clOpts.contains("debug")) { + debugMode = clOpts.value("debug").toInt(); + } else + debugMode = -1; + + // look for config file either in: + // - the path found in the configuration file + // - the user's home directory (as .fbgui.conf) + // - /etc/fbgui.conf + + QString configFilePath; + QFileInfo confInfo; + if (clOpts.contains("configFile")) + configFilePath = clOpts.value("configFile"); + else { + confInfo = QFileInfo(QDir::home(), ".fbgui.conf"); + if (confInfo.exists()) + configFilePath = confInfo.absoluteFilePath(); + else { + confInfo = QFileInfo(QString("/etc/fbgui.conf")); + if (confInfo.exists()) + configFilePath = QString("/etc/fbgui.conf"); + else + configFilePath = DEFAULT_CONFIG_PATH; + } + } + + // read the config file + QSettings confFileSettings(configFilePath, QSettings::IniFormat); + confFileSettings.setIniCodec("UTF-8"); + + // set base URL to be loaded + if (clOpts.contains("url")) + baseURL = QUrl(clOpts.value("url")); + else if (confFileSettings.contains("default/pbs_url")) + baseURL = confFileSettings.value("default/pbs_url").toUrl(); + else + baseURL = DEFAULT_URL; + + // set directory for downloads + if (clOpts.contains("downloadDir")) + downloadPath = clOpts.value("downloadDir"); + else if (confFileSettings.contains("default/download_directory")) + downloadPath = + confFileSettings.value("default/download_directory").toString(); + else + downloadPath = DEFAULT_DOWNLOAD_DIR; + + // set update interval for download progress functions of download manager. + if (confFileSettings.contains("default/update_interval")) + updateInterval = + confFileSettings.value("default/update_interval").toInt(); + else + updateInterval = DEFAULT_UPDATE_INTERVAL; + + // set which file to watch to trigger loading of URL + if (clOpts.contains("trigger")) + fileToTriggerURL = clOpts.value("trigger"); + else if (confFileSettings.contains("default/file_trigger")) + fileToTriggerURL = + confFileSettings.value("default/file_trigger").toString(); + else + fileToTriggerURL = DEFAULT_FILE_TRIGGER; + + // set serial location + if (clOpts.contains("serialLocation")) + serialLocation = clOpts.value("serialLocation"); + else if (confFileSettings.contains("default/serial_location")) + serialLocation = + confFileSettings.value("default/serial_location").toString(); + else + serialLocation = QString("/serial"); // tests + + // save ip config location (file generated by uchpc) + if (confFileSettings.contains("default/ip_config")) + ipConfigFilePath = + confFileSettings.value("default/ip_config").toString(); + + // save path to log file + if (clOpts.contains("logFile")) + logFilePath = clOpts.value("logFile"); + else if (confFileSettings.contains("default/log_file")) + logFilePath = confFileSettings.value("default/log_file").toString(); + else + logFilePath = DEFAULT_LOG_FILE_PATH; + + // + if (clOpts.contains("server")) + gServerIp = clOpts.value("server"); + else if (confFileSettings.contains("default/server")) + gServerIp = confFileSettings.value("default/server").toString(); + else + gServerIp = "209.85.148.105"; //that is a google server. change this to a proper default address + + // + if (clOpts.contains("autoup")) + gAutoUp = true; + else if (confFileSettings.contains("default/autoup")) + gAutoUp = confFileSettings.value("default/autoup").toBool(); + else + gAutoUp = false; + + // + if (clOpts.contains("socketserverpath")) + gSocketServerPath = clOpts.value("socketserverpath"); + else if (confFileSettings.contains("default/socketserverpath")) + gSocketServerPath = + confFileSettings.value("default/socketserverpath").toString(); + else + gSocketServerPath = DEFAULT_QTSOCKETADDRESS; + + // + if (clOpts.contains("pathtoexe")) + gPathToDhcpExe = clOpts.value("pathtoexe"); + else if (confFileSettings.contains("default/pathtoexe")) + gPathToDhcpExe = confFileSettings.value("default/pathtoexe").toString(); + else + gPathToDhcpExe = DEFAULT_PATHTODHCPCDEXE; + + // write always a log file + // // activate file logger if debug mode activated. + // if (debugMode > -1) { + // start debug logging to file. + // qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath)); + // qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); + // } + + // print config + LOG4CXX_DEBUG(logger, "************* CONFIG INFO *************"); + LOG4CXX_DEBUG(logger, "configFilePath: " << configFilePath); + LOG4CXX_DEBUG(logger, "logFilePath: " << logFilePath); + LOG4CXX_DEBUG(logger, "ipConfigFilePath: " << ipConfigFilePath); + LOG4CXX_DEBUG(logger, "baseURL: " << baseURL.toString()); + LOG4CXX_DEBUG(logger, "downloadDir : " << downloadPath); + LOG4CXX_DEBUG(logger, "trigger: " << fileToTriggerURL); + LOG4CXX_DEBUG(logger, "serialLocation: " << serialLocation); + if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { + LOG4CXX_DEBUG(logger, "*******************************************"); + LOG4CXX_DEBUG(logger, "Network Discovery activated:"); + LOG4CXX_DEBUG(logger, "server: " << gServerIp); + LOG4CXX_DEBUG(logger, "autoup: " << gAutoUp); + LOG4CXX_DEBUG(logger, "socketserverpath: " << gSocketServerPath); + LOG4CXX_DEBUG(logger, "pathtoexe: " << gPathToDhcpExe); + } else { + LOG4CXX_DEBUG(logger, "Network Discovery deactivated."); + }LOG4CXX_DEBUG(logger, "*******************************************"); + + // set invisible cursor + //QWSServer::instance()->setCursorVisible(false); + + // set default keyboard / mouse drivers. TODO: fix this, doesn't work... + //QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); + //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + + fbgui gui; + ndgui ngui; + + if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { + LOG4CXX_DEBUG(logger, "Initializing ndgui..."); + QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); + ngui.init(); + ngui.show(); + } else { + gui.init(); + gui.show(); + } + + return app.exec(); } diff --git a/src/fbgui/sysinfo.cpp b/src/fbgui/sysinfo.cpp index d1ac44f..1af6f76 100644 --- a/src/fbgui/sysinfo.cpp +++ b/src/fbgui/sysinfo.cpp @@ -46,11 +46,23 @@ const QString SysInfo::getInfo(const QString& infoName) { return getMainboardSerial(); else if (infoName == QString("usb")) return getUsbVendorIdProductIdSerialNumber(); + else if (infoName == QString("mac")) + return getMACAddress(); /* unknown code */ LOG4CXX_DEBUG(siLogger, "unknown requested"); return "info_error"; } +const QString SysInfo::getMACAddress() { + // Returns MAC address of eth0 for now + QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); + if (!qni.isValid()) { + //qxtLog->debug() << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; + return "no_eth0"; + } + //eth0_index = qni.index(); + return qni.hardwareAddress(); +} // ----------------------------------------------------------------------------------------------- // Mainboard / USB Infos using libsysfs // ----------------------------------------------------------------------------------------------- diff --git a/src/fbgui/sysinfo.h b/src/fbgui/sysinfo.h index a4c5a48..08717ac 100644 --- a/src/fbgui/sysinfo.h +++ b/src/fbgui/sysinfo.h @@ -41,6 +41,7 @@ public: private: // private system information readers + const QString getMACAddress(); const QString getMainboardSerial(); const QString getUsbVendorIdProductIdSerialNumber(); -- cgit v1.2.3-55-g7522 From 4044ea880cd0ef97251628a3bfd9e1787773d0ec Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 31 Jan 2012 14:01:39 +0100 Subject: build ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 12331fb..4078d0f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ Debug /doxygen/html/* /doxygen/latex/* /doxygen/man/* +/build -- cgit v1.2.3-55-g7522 From 0478dd670af2b2a76e09816f212b637510bd91c9 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 31 Jan 2012 14:07:18 +0100 Subject: testApp.sh fixed, adapt path to your build --- testApp.sh | 8 -------- 1 file changed, 8 deletions(-) diff --git a/testApp.sh b/testApp.sh index 132208c..d9a02b3 100755 --- a/testApp.sh +++ b/testApp.sh @@ -11,9 +11,6 @@ # -s , --serial= sets path to serial number file # # Note: all path are expected to be absolute. -<<<<<<< HEAD -QT_VERSION=Qt-4.8.0 -======= # # Adapt these to your own system. QT_VERSION=Qt-4.7.2 @@ -29,7 +26,6 @@ if [ "x$ARG" = "x-n" ]; then fi fi done ->>>>>>> 2abf1cec73371fb4a97a078a47f521d23fbf0775 # clean /tmp/fbgui [ -d /tmp/fbgui ] && rm -rf /tmp/fbgui @@ -50,10 +46,6 @@ display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}') # quick sleep to wait for qvfb loading sleep 0.2 # Start fbgui connecting to QVFb with display_id from above. -<<<<<<< HEAD -$working_path/../workspace/fbgui/src/fbgui/fbgui -display QVFb:$display_id $@ -======= $PATH_TO_FBGUI_BUILD/src/fbgui/fbgui -display QVFb:$display_id $@ -e $PATH_TO_FBGUI_BUILD/src/customdhcpcd/cdhcpcd ->>>>>>> 2abf1cec73371fb4a97a078a47f521d23fbf0775 # kill qvfb since fbgui stopped killall qvfb -- cgit v1.2.3-55-g7522 From 6493439e032556171ed0dab51edabb2c0eecc72a Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 31 Jan 2012 14:34:18 +0100 Subject: various logging fixes --- src/fbgui/interfaceconfiguration.cpp | 15 ++++++++--- src/fbgui/main.cpp | 19 ++++++++------ src/fbgui/ndgui.h | 3 ++- src/fbgui/networkmanager.cpp | 50 +++++++++++++++++++++--------------- src/fbgui/sysinfo.cpp | 2 ++ 5 files changed, 55 insertions(+), 34 deletions(-) diff --git a/src/fbgui/interfaceconfiguration.cpp b/src/fbgui/interfaceconfiguration.cpp index 3d09e52..d9d72df 100644 --- a/src/fbgui/interfaceconfiguration.cpp +++ b/src/fbgui/interfaceconfiguration.cpp @@ -12,6 +12,13 @@ #include "interfaceconfiguration.h" +#include +#include "qlog4cxx.h" + +using namespace log4cxx; +using namespace log4cxx::helpers; +LoggerPtr ndifLogger(Logger::getLogger("fbgui.nd.ifconf")); + interfaceconfiguration::interfaceconfiguration() { _tag = "[nd:InterfaceConfiguration]"; } @@ -34,10 +41,10 @@ bool interfaceconfiguration::readConfigOutOfFile(QString pathToConfig) { QFile file(pathToConfig); if (file.exists()) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << _tag << "couldn't open file:" << pathToConfig; + LOG4CXX_DEBUG(ndifLogger, _tag << "couldn't open file:" << pathToConfig); return false; } - qDebug() << _tag << "read config file"; + LOG4CXX_DEBUG(ndifLogger, _tag << "read config file"); while (!file.atEnd()) { QString line(file.readLine()); QStringList splitedLine = line.split("="); @@ -74,11 +81,11 @@ bool interfaceconfiguration::readConfigOutOfFile(QString pathToConfig) { } else if (name.compare("DHCPCHADDR") == 0) { this->dhcpchaddr = values; } else { - qDebug() << _tag << "read unknown name" << name << values; + LOG4CXX_DEBUG(ndifLogger, _tag << "read unknown name" << name << values); } } } else { - qDebug() << _tag << "file doesn't exist:" << pathToConfig; + LOG4CXX_DEBUG(ndifLogger, _tag << "file doesn't exist:" << pathToConfig); return false; } return true; diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index d883469..051ce65 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -55,6 +55,17 @@ int main(int argc, char *argv[]) { // The third parameter sets the application as the // GUI-Server (aswell as the GUI-Client). + QApplication app(argc, argv, QApplication::GuiServer); + app.setOrganizationName("team_projekt_2011"); + app.setApplicationName("prebootGUI"); + binPath = QApplication::applicationDirPath(); + + QTranslator translator; + translator.load(":" + QLocale::system().name()); + app.installTranslator(&translator); + + + // LOG4CXX Logger Init QFileInfo loggingConfInfo = QFileInfo(QDir::home(), ".fbgui.logging.conf"); QString loggingConfigFilePath; if (loggingConfInfo.exists()) @@ -74,14 +85,6 @@ int main(int argc, char *argv[]) { BasicConfigurator::configure(); } - QApplication app(argc, argv, QApplication::GuiServer); - app.setOrganizationName("team_projekt_2011"); - app.setApplicationName("prebootGUI"); - binPath = QApplication::applicationDirPath(); - - QTranslator translator; - translator.load(":" + QLocale::system().name()); - app.installTranslator(&translator); // parse command line arguments using getopt QMap clOpts; diff --git a/src/fbgui/ndgui.h b/src/fbgui/ndgui.h index 1cb285c..18fe5c7 100644 --- a/src/fbgui/ndgui.h +++ b/src/fbgui/ndgui.h @@ -73,6 +73,7 @@ signals: private slots: void setUserChoiceTrue(); + void toggleDebugConsole(); private: @@ -109,7 +110,7 @@ private: void setupLayout(); void createDebugConsole(); - void toggleDebugConsole(); + }; diff --git a/src/fbgui/networkmanager.cpp b/src/fbgui/networkmanager.cpp index ce2186a..8a3e529 100644 --- a/src/fbgui/networkmanager.cpp +++ b/src/fbgui/networkmanager.cpp @@ -10,6 +10,13 @@ #include "networkmanager.h" +#include +#include "qlog4cxx.h" + +using namespace log4cxx; +using namespace log4cxx::helpers; +LoggerPtr ndnmLogger(Logger::getLogger("fbgui.nd.nm")); + NetworkManager::NetworkManager() { // TODO Auto-generated constructor stub @@ -59,11 +66,12 @@ NetworkManager::replaceDefaultRoute(QString ifname, QString gateway, int mss, QByteArray ba_gw = gateway.toAscii(); char * gwaddr = ba_gw.data(); - qDebug() << "---doRoute() gwaddr" << gwaddr; + LOG4CXX_DEBUG(ndnmLogger, "---doRoute() gwaddr" << gwaddr); + //qDebug() << "---doRoute() gwaddr" << gwaddr; if (!(gw = nl_addr_parse(gwaddr, af))) { - qDebug() << "Invalid router address given:" << gwaddr; + LOG4CXX_DEBUG(ndnmLogger, "Invalid router address given:" << gwaddr); return -1; } @@ -72,7 +80,7 @@ NetworkManager::replaceDefaultRoute(QString ifname, QString gateway, int mss, if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc \n"; + LOG4CXX_DEBUG(ndnmLogger, "error with link cache alloc \n"); } iface_idx = rtnl_link_name2i(cache, ifn); @@ -88,7 +96,7 @@ NetworkManager::replaceDefaultRoute(QString ifname, QString gateway, int mss, } retval = rtnl_route_add(rtsock, route, NLM_F_REPLACE); - qDebug() << "return value:" << retval << ":" << strerror(-retval); + LOG4CXX_DEBUG(ndnmLogger, "return value:" << retval << ":" << strerror(-retval)); rtnl_route_put(route); nl_addr_put(gw); @@ -268,7 +276,7 @@ NetworkManager::bringInterfaceUpDown(QString ifname, bool up) if (!(request = rtnl_link_alloc())) { - qDebug() << "error. couldn't allocate a rtnl link"; + LOG4CXX_DEBUG(ndnmLogger, "error. couldn't allocate a rtnl link"); return -1; } @@ -286,20 +294,20 @@ NetworkManager::bringInterfaceUpDown(QString ifname, bool up) if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc "; + LOG4CXX_DEBUG(ndnmLogger, "error with link cache alloc "); } old = rtnl_link_get_by_name(cache, ifn); if (old) { - qDebug() << "change link"; + LOG4CXX_DEBUG(ndnmLogger, "change link"); retval = rtnl_link_change(rtsock, old, request, 0); } else { - qDebug() << "change failed"; + LOG4CXX_DEBUG(ndnmLogger, "change failed"); retval = -1; - qDebug() << "return value:" << retval << ":" << strerror(-retval); + LOG4CXX_DEBUG(ndnmLogger, "return value:" << retval << ":" << strerror(-retval)); } rtnl_link_put(old); @@ -383,7 +391,7 @@ NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress, if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc"; + LOG4CXX_DEBUG(ndnmLogger, "error with link cache alloc"); return -1; } @@ -391,7 +399,7 @@ NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress, if (!(addr = rtnl_addr_alloc())) { - qDebug() << "error with addr alloc"; + LOG4CXX_DEBUG(ndnmLogger, "error with addr alloc"); return -1; } @@ -400,11 +408,11 @@ NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress, nl_addr_put(local); if (err != 0) { - qDebug() << "error with set local addr"; + LOG4CXX_DEBUG(ndnmLogger, "error with set local addr"); } prefixLength = ip4_netmaskToPrefix(ipAddress, netmask); - qDebug() << "prefix length:" << prefixLength; + LOG4CXX_DEBUG(ndnmLogger, "prefix length:" << prefixLength); rtnl_addr_set_prefixlen(addr, prefixLength); local = nl_addr_parse(bcaddr, af); @@ -412,7 +420,7 @@ NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress, nl_addr_put(local); if (err != 0) { - qDebug() << "error with set broadcast addr"; + LOG4CXX_DEBUG(ndnmLogger, "error with set broadcast addr"); } rtnl_addr_set_ifindex(addr, iface_idx); @@ -420,7 +428,7 @@ NetworkManager::ip4_configureInterface(QString ifname, QString ipAddress, retval = sync_address(ifn, iface_idx, af, addr); if (retval < 0) { - qDebug() << "error in sync_address"; + LOG4CXX_DEBUG(ndnmLogger, "error in sync_address"); } rtnl_addr_put(addr); @@ -446,7 +454,7 @@ NetworkManager::ip4_netmaskToPrefix(QString ipAddr, QString netmask) if (netmask == "") { - qDebug() << "error: netmask is empty"; + LOG4CXX_DEBUG(ndnmLogger, "error: netmask is empty"); return retval; } nae.setIp(QHostAddress(ipAddr)); @@ -469,7 +477,7 @@ NetworkManager::ip6_addAddress(struct ip6_addr* ip6Addr, const char *iface) if ((cache = rtnl_link_alloc_cache(rtsock)) == NULL) { - qDebug() << "error with link cache alloc"; + LOG4CXX_DEBUG(ndnmLogger, "error with link cache alloc"); return -1; } @@ -638,7 +646,7 @@ nlh = nl_handle_alloc(); { //nm_log_err (log_domain, "(%s): error %d returned from rtnl_addr_delete(): %s", // iface, err, nl_geterror ()); - qDebug() << "error with delete addr"; + LOG4CXX_DEBUG(ndnmLogger, "error with delete addr"); } } @@ -671,7 +679,7 @@ if (buf_valid == 0) { //nm_log_dbg (log_domain, "(%s): adding address '%s/%d'", //iface, buf, nl_addr_get_prefixlen (nladdr)); - qDebug() << "buf valid adding addr"; + LOG4CXX_DEBUG(ndnmLogger, "buf valid adding addr"); } err = rtnl_addr_add(nlh, addr, 0); @@ -680,7 +688,7 @@ if (err < 0) //nm_log_err (log_domain, // "(%s): error %d returned from rtnl_addr_add():\n%s", // iface, err, nl_geterror ()); - qDebug() << "error with add addr" << strerror(-err); + LOG4CXX_DEBUG(ndnmLogger, "error with add addr" << strerror(-err)); } rtnl_addr_put(addr); @@ -710,7 +718,7 @@ NetworkManager::writeResolvConf(QString path, QString ifname, QFile file(path + "resolv.conf"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - qDebug() << "error couldn't open file:" << path; + LOG4CXX_DEBUG(ndnmLogger, "error couldn't open file:" << path); return -1; } QTextStream out(&file); diff --git a/src/fbgui/sysinfo.cpp b/src/fbgui/sysinfo.cpp index 1af6f76..6338025 100644 --- a/src/fbgui/sysinfo.cpp +++ b/src/fbgui/sysinfo.cpp @@ -94,6 +94,8 @@ const QString SysInfo::getMainboardSerial() { QVariantMap a; if(QString(attr->name) == QString("board_serial")) { out = QString(attr->value); + if (out.endsWith("\n")) + out.chop(1); } } LOG4CXX_DEBUG(siLogger, "Mainboard Serial: " + out); -- cgit v1.2.3-55-g7522 From 7cf5576531177f292543229d7b74282bc6660dcb Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 1 Feb 2012 15:30:46 +0100 Subject: new abstract class agui for common gui functions, new console class for debug console --- src/fbgui/agui.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/fbgui/agui.h | 54 +++++++++++++++++++++++++++++++ src/fbgui/console.cpp | 60 +++++++++++++++++++++++++++++++++++ src/fbgui/console.h | 32 +++++++++++++++++++ 4 files changed, 234 insertions(+) create mode 100644 src/fbgui/agui.cpp create mode 100644 src/fbgui/agui.h create mode 100644 src/fbgui/console.cpp create mode 100644 src/fbgui/console.h 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 +#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 +#include + +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 + +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_ */ -- cgit v1.2.3-55-g7522 From 1fe9c90f77990e740c205a5113340583146536e8 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 1 Feb 2012 15:31:48 +0100 Subject: adapted existing classes to reflect changes --- .gitignore | 2 + src/fbgui/CMakeLists.txt | 4 +- src/fbgui/fbgui.cpp | 236 +--------------------------------- src/fbgui/fbgui.h | 60 +-------- src/fbgui/html/js/networkDiscovery.js | 4 +- src/fbgui/main.cpp | 15 +-- src/fbgui/ndgui.cpp | 153 +++------------------- src/fbgui/ndgui.h | 29 +---- src/fbgui/networkdiscovery.cpp | 6 +- testApp.sh | 1 + 10 files changed, 46 insertions(+), 464 deletions(-) diff --git a/.gitignore b/.gitignore index cf2591d..8463a08 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ Debug /doxygen/man/* /build testApp.sh +testAppGDB.sh + diff --git a/src/fbgui/CMakeLists.txt b/src/fbgui/CMakeLists.txt index 8b19777..e0806b5 100644 --- a/src/fbgui/CMakeLists.txt +++ b/src/fbgui/CMakeLists.txt @@ -23,7 +23,9 @@ javascriptinterface.h ndgui.h networkdiscovery.h networkmanager.h -fbgui.h) +fbgui.h +agui.h +console.h) file(GLOB FBGUI_UIS *.ui) file(GLOB FBGUI_RCS *.qrc) diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index c7cbce6..ee74452 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -16,7 +16,6 @@ LoggerPtr coreLogger(Logger::getLogger("fbgui.core")); #include QThread dmThread; -QString logFilePath(""); QString ipConfigFilePath(""); QString binPath(""); QUrl baseURL(""); @@ -25,7 +24,8 @@ int updateInterval = -1; QString fileToTriggerURL(""); QString serialLocation(""); QString sessionID(""); -int debugMode = -1; +//int debugMode = -1; +//QString logFilePath(""); //------------------------------------------------------------------------------------------- /** @@ -38,9 +38,10 @@ int debugMode = -1; * @see JavascriptInterface * @see DownloadManager */ -fbgui::fbgui() { +fbgui::fbgui() : + agui(){ } -fbgui::~fbgui() { +fbgui::~fbgui(){ dmThread.quit(); } @@ -51,13 +52,6 @@ void fbgui::init() { // start fbgui LOG4CXX_DEBUG(coreLogger, "Initializing fbgui..."); - // init watcher - _watcher = new QFileSystemWatcher(this); - - // setup layout and actions - setupLayout(); - createActions(); - // initialize javascript interface JavascriptInterface* jsi = new JavascriptInterface( _webView->page()->mainFrame()); @@ -88,118 +82,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 @@ -310,57 +197,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) //------------------------------------------------------------------------------------------- @@ -455,65 +291,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)) { - LOG4CXX_DEBUG(coreLogger, "Could not open log file: " << logFilePath); - } - else { - _debugConsole->setPlainText(_logFileIn->readAll()); - _debugConsole->moveCursor(QTextCursor::End); - // 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(); -} diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h index 4891194..2feafa1 100644 --- a/src/fbgui/fbgui.h +++ b/src/fbgui/fbgui.h @@ -23,6 +23,8 @@ #include #include +#include "agui.h" + // Internal default settings #define DEFAULT_URL "http://www.google.com" #define DEFAULT_DOWNLOAD_DIR "/tmp/fbgui" @@ -45,7 +47,7 @@ extern QUrl baseURL; extern int debugMode; extern int updateInterval; -class fbgui: public QMainWindow +class fbgui : public agui { Q_OBJECT @@ -57,68 +59,12 @@ public slots: void init(); private: - //------------------- - // 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(); - // Create a debug console widget as QTextEdit in order to print debug messages - // directly within the GUI. This was needed since ttys can't really be used - // for debugging purposes in the preboot environment. - void createDebugConsole(); - - //---------------------------------------- - // control the display of components: - //---------------------------------------- - // watches for the file triggering the loading of the URL. - // the file can be specified by the corresponding option. - void watchForTrigger(); bool checkHost() const; void loadURL(); QByteArray generatePOSTData(); - //---------------------------------- - // widgets constituing the gui: - //---------------------------------- - // QWebView for displaying internet content - QWebView* _webView; - // QSplitter to split the main window in two resizable frames. - QSplitter* _splitter; - // QTextEdit implementing a minimalistic debug console. - QTextEdit* _debugConsole; - - //------------------ - // action list: - //------------------ - // closes the main window provoking the application to quit. - QAction* _quit; - // triggers toggleDebugConsole() - QAction* _toggleDebugConsole; - - // watcher to detect changes in the observed directory. - QFileSystemWatcher* _watcher; - QFile* _logFile; - QTextStream* _logFileIn; - private slots: - // toggles debug console when action _toggleDebugConsole happens. - void toggleDebugConsole(); - void refreshDebugConsole(const QString&); - - // This function is triggered by fileChanged Signal of _watcher. - // It deletes _watcher, since we don't need it anymore and tries to load URL. - void prepareURLLoad(const QString&); void loadURLDone(bool success); - - // shut off the system - void performShutDown(); - // reboot the system - void performReboot(); - // shows "loading system" page void loadSystem(); // prepares kexec by loading downloaded initramfs, kernel into kexec void prepareKexec(); diff --git a/src/fbgui/html/js/networkDiscovery.js b/src/fbgui/html/js/networkDiscovery.js index 10b4f19..d1ffad4 100644 --- a/src/fbgui/html/js/networkDiscovery.js +++ b/src/fbgui/html/js/networkDiscovery.js @@ -186,7 +186,7 @@ var abortBootDialog = function (m) { showLog(text);}, "Restart": function() {fbgui.restartSystem(); $(this).dialog("close"); }, - "Shut Down": function() { fbgui.shutDownSystem(); + "Shut Down": function() { fbgui.shutdownSystem(); $(this).dialog("close"); }, "Try Again": function() {fbgui.tryAgain(); $(this).dialog("close"); } @@ -221,7 +221,7 @@ var chooseInterfaceDialog = function (i) { showLog(text);}, "Restart": function() {fbgui.restartSystem(); $(this).dialog("close"); }, - "Shut Down": function() { fbgui.shutDownSystem(); + "Shut Down": function() { fbgui.shutdownSystem(); $(this).dialog("close"); }, "Continue": function() { var ifName = $("#nd_ifName_select :selected").text(); diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index 051ce65..e14e683 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -10,8 +10,10 @@ #include #include "qlog4cxx.h" +#include "agui.h" #include "fbgui.h" #include "ndgui.h" +#include "console.h" #include "../common/fbgui.h" @@ -48,6 +50,7 @@ void printHelp() { } int main(int argc, char *argv[]) { + // Initialisation of the QApplication: // In QT, every application is composed of two separate // components: the GUI-Client and the GUI-Server. @@ -268,14 +271,6 @@ int main(int argc, char *argv[]) { else gPathToDhcpExe = DEFAULT_PATHTODHCPCDEXE; - // write always a log file - // // activate file logger if debug mode activated. - // if (debugMode > -1) { - // start debug logging to file. - // qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath)); - // qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); - // } - // print config LOG4CXX_DEBUG(logger, "************* CONFIG INFO *************"); LOG4CXX_DEBUG(logger, "configFilePath: " << configFilePath); @@ -294,7 +289,8 @@ int main(int argc, char *argv[]) { LOG4CXX_DEBUG(logger, "pathtoexe: " << gPathToDhcpExe); } else { LOG4CXX_DEBUG(logger, "Network Discovery deactivated."); - }LOG4CXX_DEBUG(logger, "*******************************************"); + } + LOG4CXX_DEBUG(logger, "*******************************************"); // set invisible cursor //QWSServer::instance()->setCursorVisible(false); @@ -307,7 +303,6 @@ int main(int argc, char *argv[]) { ndgui ngui; if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { - LOG4CXX_DEBUG(logger, "Initializing ndgui..."); QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); ngui.init(); ngui.show(); diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index 4e0b3f6..34a3f2d 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -30,8 +30,8 @@ QString gPathToDhcpExe(""); /** * constructor */ -ndgui::ndgui(QMainWindow *parent) : - QMainWindow(parent) { +ndgui::ndgui() : + agui() { } @@ -41,11 +41,11 @@ ndgui::ndgui(QMainWindow *parent) : */ ndgui::~ndgui() { - delete _debugConsole; - delete _toggleDebugConsole; + //delete _debugConsole; + //delete _toggleDebugConsole; delete _allowUserChoice; delete _tryAgain; - delete _webView; + //delete _webView; delete _networkDiscovery; } @@ -57,13 +57,14 @@ ndgui::~ndgui() { */ void ndgui::init() { + LOG4CXX_DEBUG(ndLogger, "Initializing ndgui..."); + _started = false; _userChoice = false; _ifNameList.clear(); _manConfList.clear(); - setupLayout(); - createAction(); + addActions(); _networkDiscovery = new NetworkDiscovery(); connect(_networkDiscovery, SIGNAL(addInterface(const QString &)), this, @@ -90,101 +91,24 @@ void ndgui::init() { javaScriptWindowObjectCleared()), this, SLOT(attachToDOM())); connect(_webView, SIGNAL(loadFinished(bool)), this, SLOT(startSingleShot())); - setWindowTitle(tr("NetD")); - setAttribute(Qt::WA_QuitOnClose, true); - setWindowFlags(Qt::FramelessWindowHint); - showFullScreen(); if (debugMode > -1) { _webView->load(QUrl("qrc:html/networkdiscovery_debug.html")); } else { _webView->load(QUrl("qrc:html/networkdiscovery.html")); - } - _webView->show(); -} - - - -/** - * @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 ndgui::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 - - 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 { - _webView->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); - setCentralWidget(_webView); - } -} - - - -/** - * @brief 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 ndgui::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); - // enable custom logger engine -// qxtLog->addLoggerEngine("fb_logger", new LoggerEngine_fb(_debugConsole)); - //qxtLog->initLoggerEngine("fb_logger"); -// qxtLog->setMinimumLevel("fb_logger", QxtLogger::DebugLevel); - // 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())); -} - - - -/** - * @brief This method toggles the debug console. - * - * Toggle the visibility of the debug console if the action _toggleDebugConsole is triggered. - * - * @see fbgui::createDebugConsole() - */ -void ndgui::toggleDebugConsole() { - (_debugConsole->isVisible()) ? _debugConsole->hide() : _debugConsole->show(); + setWindowTitle(tr("NetD")); + showFullScreen(); } - /** - * @brief Create actions + * @brief Add actions * - * creates an action which you can trigger with the F5 and F9 Button. + * Add actions which you can trigger with the F5 and F9 Button. */ -void ndgui::createAction() { +void ndgui::addActions() { _allowUserChoice = new QAction(tr("&userChoice"), this); _allowUserChoice->setShortcut(QKeySequence(Qt::Key_F5)); connect(_allowUserChoice, SIGNAL(triggered()), this, SLOT(setUserChoiceTrue())); @@ -195,8 +119,6 @@ void ndgui::createAction() { this->addAction(_tryAgain); } - - /** * @brief set userChoice true * @@ -300,43 +222,6 @@ void ndgui::handleAllProcessesFinished() { } - -/** - * @brief restart the system - * - * this method will restart the system. - * triggered through a button click in the gui. - */ -void ndgui::restartSystem() { - QFile file("/proc/sysrq-trigger"); - if (file.open(QIODevice::WriteOnly)) { - file.write("b"); - file.close(); - } else { - LOG4CXX_DEBUG(ndLogger, "Could not open /proc/sysrq-trigger"); - } -} - - - -/** - * @brief shut down the system - * - * this method will restart the system. - * triggered through a button click in the gui. - */ -void ndgui::shutDownSystem() { - QFile file("/proc/sysrq-trigger"); - if (file.open(QIODevice::WriteOnly)) { - file.write("o"); - file.close(); - } else { - LOG4CXX_DEBUG(ndLogger, "Could not open /proc/sysrq-trigger"); - } -} - - - /** * @brief continue the boot sequence * @@ -358,7 +243,6 @@ void ndgui::continueBoot(QString ifName) { } - /** * @brief continue the boot sequence without further checking if the connection is still possible. */ @@ -369,7 +253,6 @@ void ndgui::continueBootWithoutCheck(QString ifName) { } - /** * @brief read the log file. Log File will be presented inside of a dialog. */ @@ -379,7 +262,6 @@ QString ndgui::readLogFile() { } - /** * @brief starts the whole application again. */ @@ -387,13 +269,13 @@ void ndgui::tryAgain() { LOG4CXX_DEBUG(ndLogger, " try again "); _networkDiscovery->prepareTryAgain(); if(debugMode > -1) { - delete _splitter; - delete _debugConsole; - delete _toggleDebugConsole; + //delete _splitter; + //delete _debugConsole; + //delete _toggleDebugConsole; } delete _allowUserChoice; delete _tryAgain; - delete _webView; + //delete _webView; delete _networkDiscovery; init(); @@ -401,7 +283,6 @@ void ndgui::tryAgain() { } - /*test html gui version*/ /** diff --git a/src/fbgui/ndgui.h b/src/fbgui/ndgui.h index 18fe5c7..2e214df 100644 --- a/src/fbgui/ndgui.h +++ b/src/fbgui/ndgui.h @@ -21,6 +21,7 @@ #include #include "fbgui.h" +#include "agui.h" #include "networkdiscovery.h" @@ -29,12 +30,12 @@ extern bool gAutoUp; extern QString gSocketServerPath; extern QString gPathToDhcpExe; -class ndgui: public QMainWindow +class ndgui: public agui { Q_OBJECT public: - ndgui(QMainWindow *parent = 0); + ndgui(); ~ndgui(); Q_INVOKABLE QVariantList getManualConfInterfaces(); Q_INVOKABLE int ip4_setManualConfiguration(QVariantMap result); @@ -49,8 +50,6 @@ public slots: void chooseInterfaceDialog(QString msg); void handleAllProcessesFinished(); - void restartSystem(); - void shutDownSystem(); void continueBoot(QString ifName); void continueBootWithoutCheck(QString ifName); void tryAgain(); @@ -73,20 +72,17 @@ signals: private slots: void setUserChoiceTrue(); - void toggleDebugConsole(); private: - QString _tag; + void addActions(); - void createAction(); + QString _tag; bool _userChoice; bool _started; - QWebView* _webView; - QAction* _allowUserChoice; QAction* _tryAgain; @@ -98,21 +94,6 @@ private: QList _manConfList; QString _manualConfInterfaces; - - // QSplitter to split the main window in two resizable frames. - QSplitter* _splitter; - // QTextEdit implementing a minimalistic debug console. - QTextEdit* _debugConsole; - - // triggers toggleDebugConsole() - QAction* _toggleDebugConsole; - - - void setupLayout(); - void createDebugConsole(); - - - }; #endif // NDGUI_H diff --git a/src/fbgui/networkdiscovery.cpp b/src/fbgui/networkdiscovery.cpp index 0198086..ccefb8a 100644 --- a/src/fbgui/networkdiscovery.cpp +++ b/src/fbgui/networkdiscovery.cpp @@ -544,7 +544,7 @@ bool NetworkDiscovery::checkConnectivityViaTcp(QString server) { /** * same function as handleNewInput() but with a client as parameter. * - * @param cleint + * @param client * a client */ void NetworkDiscovery::handleNewInput(QLocalSocket * client) { @@ -857,8 +857,8 @@ void NetworkDiscovery::prepareTryAgain() { } */ // reset everything - delete _networkManager; - delete _server; + //delete _networkManager; + //delete _server; foreach(QProcess* p, _clientProcessToIfNameMap.keys()) { delete p; diff --git a/testApp.sh b/testApp.sh index d9a02b3..8a4843a 100755 --- a/testApp.sh +++ b/testApp.sh @@ -14,6 +14,7 @@ # # Adapt these to your own system. QT_VERSION=Qt-4.7.2 +#PATH_TO_FBGUI_BUILD=/home/joe/fbgui/build PATH_TO_FBGUI_BUILD=/home/joe/workspace/fbgui # check if network discovery is activated and if running as root -- cgit v1.2.3-55-g7522 From 3084244f6af4492582c05d27819b6aa61e36c688 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 1 Feb 2012 15:46:36 +0100 Subject: sysInfo gets interface name for MAC adress from networkdiscovery --- src/fbgui/fbgui.cpp | 2 +- src/fbgui/fbgui.h | 1 + src/fbgui/main.cpp | 2 -- src/fbgui/ndgui.cpp | 4 +++- src/fbgui/sysinfo.cpp | 17 +++++------------ 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/fbgui/fbgui.cpp b/src/fbgui/fbgui.cpp index ee74452..7bf84e8 100644 --- a/src/fbgui/fbgui.cpp +++ b/src/fbgui/fbgui.cpp @@ -57,7 +57,7 @@ void fbgui::init() { _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())); diff --git a/src/fbgui/fbgui.h b/src/fbgui/fbgui.h index 2feafa1..46c3b9b 100644 --- a/src/fbgui/fbgui.h +++ b/src/fbgui/fbgui.h @@ -46,6 +46,7 @@ extern QString downloadPath; extern QUrl baseURL; extern int debugMode; extern int updateInterval; +extern QString interfaceName; class fbgui : public agui { diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index e14e683..6286b9f 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -10,10 +10,8 @@ #include #include "qlog4cxx.h" -#include "agui.h" #include "fbgui.h" #include "ndgui.h" -#include "console.h" #include "../common/fbgui.h" diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index 34a3f2d..67bfa79 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -24,7 +24,7 @@ QString gServerIp(""); bool gAutoUp = true; QString gSocketServerPath(""); QString gPathToDhcpExe(""); - +QString interfaceName(""); /** @@ -233,6 +233,7 @@ void ndgui::handleAllProcessesFinished() { void ndgui::continueBoot(QString ifName) { if (_networkDiscovery->checkConnectivity(ifName)) { LOG4CXX_DEBUG(ndLogger, " continue with interface: " << ifName); + interfaceName = ifName; emit initFbgui(); this->close(); } else { @@ -248,6 +249,7 @@ void ndgui::continueBoot(QString ifName) { */ void ndgui::continueBootWithoutCheck(QString ifName) { LOG4CXX_DEBUG(ndLogger, " continue with interface: " << ifName); + interfaceName = ifName; emit initFbgui(); this->close(); } diff --git a/src/fbgui/sysinfo.cpp b/src/fbgui/sysinfo.cpp index 6338025..807413b 100644 --- a/src/fbgui/sysinfo.cpp +++ b/src/fbgui/sysinfo.cpp @@ -41,7 +41,6 @@ SysInfo::~SysInfo() { * @see JavascriptInterface::getSysInfo(const QString& info) */ const QString SysInfo::getInfo(const QString& infoName) { - LOG4CXX_DEBUG(siLogger, "requested " << infoName); if (infoName == QString("mbserial")) return getMainboardSerial(); else if (infoName == QString("usb")) @@ -55,12 +54,12 @@ const QString SysInfo::getInfo(const QString& infoName) { } const QString SysInfo::getMACAddress() { // Returns MAC address of eth0 for now - QNetworkInterface qni = QNetworkInterface::interfaceFromName(QString("eth0")); + LOG4CXX_DEBUG(siLogger, "Requesting MAC of: " << interfaceName << " ..."); + QNetworkInterface qni = QNetworkInterface::interfaceFromName(interfaceName); if (!qni.isValid()) { - //qxtLog->debug() << "[sysinfo] MAC Address: No interface matching \"eth0\" found."; - return "no_eth0"; + LOG4CXX_DEBUG(siLogger, "No valid interface with name: " << interfaceName); + return "no_interface"; } - //eth0_index = qni.index(); return qni.hardwareAddress(); } // ----------------------------------------------------------------------------------------------- @@ -82,6 +81,7 @@ const QString SysInfo::getMACAddress() { * @see SysInfo::getInfo(const QString& infoName) */ const QString SysInfo::getMainboardSerial() { + LOG4CXX_DEBUG(siLogger, "Requesting Mainboard Serial..."); QString out = ""; struct sysfs_class_device *class_device = sysfs_open_class_device("dmi", "id"); @@ -214,11 +214,4 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { } libusb_free_device_list(devs, 1); //free the list, unref the devices in it libusb_exit(ctx); //close the session - - - /* - QByteArray json = serializer.serialize(list); - LOG4CXX_DEBUG(siLogger, tag + "json object: " + json); - return json; - */ } -- cgit v1.2.3-55-g7522 From 45af1710d08d9896468390a21f4e0a199c7573e5 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 3 Feb 2012 17:09:33 +0100 Subject: minor changes --- src/fbgui/agui.cpp | 6 ++---- src/fbgui/console.cpp | 8 ++++---- src/fbgui/console.h | 6 +++--- src/fbgui/javascriptinterface.cpp | 13 ------------- src/fbgui/javascriptinterface.h | 2 -- src/fbgui/main.cpp | 5 +++++ src/fbgui/ndgui.cpp | 11 ----------- testApp.sh | 2 +- 8 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/fbgui/agui.cpp b/src/fbgui/agui.cpp index 7759800..3f2fd68 100644 --- a/src/fbgui/agui.cpp +++ b/src/fbgui/agui.cpp @@ -40,13 +40,11 @@ agui::~agui() { 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->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); + Console* debugConsole = new Console(this); QSplitter* _splitter = new QSplitter(Qt::Vertical, this); _splitter->addWidget(_webView); _splitter->addWidget(debugConsole); diff --git a/src/fbgui/console.cpp b/src/fbgui/console.cpp index ffd425f..b4fcddf 100644 --- a/src/fbgui/console.cpp +++ b/src/fbgui/console.cpp @@ -7,7 +7,7 @@ #include "console.h" -console::console(QMainWindow* parent) : +Console::Console(QMainWindow* parent) : QTextEdit(parent) { setWindowFlags(Qt::FramelessWindowHint); @@ -39,12 +39,12 @@ console::console(QMainWindow* parent) : } } -console::~console() { +Console::~Console() { delete _logFile; delete _logFileIn; } -void console::refresh(const QString& fileName) { +void Console::refresh(const QString& fileName) { if (fileName == logFilePath) { while (!_logFileIn->atEnd()) { QString line = _logFileIn->readLine(); @@ -55,6 +55,6 @@ void console::refresh(const QString& fileName) { } } -void console::toggle() { +void Console::toggle() { (this->isVisible()) ? this->hide() : this->show(); } diff --git a/src/fbgui/console.h b/src/fbgui/console.h index cb6dd34..bc6ec50 100644 --- a/src/fbgui/console.h +++ b/src/fbgui/console.h @@ -13,13 +13,13 @@ extern QString logFilePath; -class console : public QTextEdit +class Console : public QTextEdit { Q_OBJECT public: - console(QMainWindow* parent = 0); - virtual ~console(); + Console(QMainWindow* parent = 0); + virtual ~Console(); private: QFile* _logFile; diff --git a/src/fbgui/javascriptinterface.cpp b/src/fbgui/javascriptinterface.cpp index 3afd3f6..8260fab 100644 --- a/src/fbgui/javascriptinterface.cpp +++ b/src/fbgui/javascriptinterface.cpp @@ -229,16 +229,3 @@ void JavascriptInterface::callbackOnFinished() { QString code = QString("\%1").arg(_callbackOnDownloadsFinished); _parent->evaluateJavaScript(code); } -//------------------------------------------------------------------------------------------------------- -/** - * This method triggers the URL load *FOR DEBUGGING/TESTING PURPOSES* - - */ -void JavascriptInterface::trigger() { - QFile file(fileToTriggerURL); - if (file.open(QIODevice::WriteOnly)) { - file.write("data\n"); - LOG4CXX_DEBUG(jsiLogger, "*trigger watcher*"); - } - file.close(); -} diff --git a/src/fbgui/javascriptinterface.h b/src/fbgui/javascriptinterface.h index 5d45964..b15c134 100644 --- a/src/fbgui/javascriptinterface.h +++ b/src/fbgui/javascriptinterface.h @@ -66,8 +66,6 @@ public slots: void downloadInfo(const QString& filename, const double& filesize); void notify(const QString& msg); - // functions to help test functionality - void trigger(); }; #endif // JAVASCRIPTINTERFACE_H_ diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index 6286b9f..d379c1e 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -61,6 +61,8 @@ int main(int argc, char *argv[]) { app.setApplicationName("prebootGUI"); binPath = QApplication::applicationDirPath(); + + QTranslator translator; translator.load(":" + QLocale::system().name()); app.installTranslator(&translator); @@ -290,6 +292,9 @@ int main(int argc, char *argv[]) { } LOG4CXX_DEBUG(logger, "*******************************************"); + //if (QSslSocket::supportsSsl()) + // LOG4CXX_DEBUG(logger, "SUPPORT SSL!"); + // set invisible cursor //QWSServer::instance()->setCursorVisible(false); diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index 67bfa79..a95d884 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -11,7 +11,6 @@ #include "ndgui.h" - #include #include "qlog4cxx.h" @@ -41,11 +40,8 @@ ndgui::ndgui() : */ ndgui::~ndgui() { - //delete _debugConsole; - //delete _toggleDebugConsole; delete _allowUserChoice; delete _tryAgain; - //delete _webView; delete _networkDiscovery; } @@ -181,8 +177,6 @@ void ndgui::handleConnectionEstablished(QString ifName) { _ifNameList.append(ifName); } - - /** * @brief determines if we continue the boot sequence or if we show the chooseInterface or abortBoot dialog * @@ -270,11 +264,6 @@ QString ndgui::readLogFile() { void ndgui::tryAgain() { LOG4CXX_DEBUG(ndLogger, " try again "); _networkDiscovery->prepareTryAgain(); - if(debugMode > -1) { - //delete _splitter; - //delete _debugConsole; - //delete _toggleDebugConsole; - } delete _allowUserChoice; delete _tryAgain; //delete _webView; diff --git a/testApp.sh b/testApp.sh index 8a4843a..790637e 100755 --- a/testApp.sh +++ b/testApp.sh @@ -13,7 +13,7 @@ # Note: all path are expected to be absolute. # # Adapt these to your own system. -QT_VERSION=Qt-4.7.2 +QT_VERSION=Qt-4.8.0 #PATH_TO_FBGUI_BUILD=/home/joe/fbgui/build PATH_TO_FBGUI_BUILD=/home/joe/workspace/fbgui -- cgit v1.2.3-55-g7522 From 32ada7c4adb37ebb82005f024d25cae129904df3 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Fri, 3 Feb 2012 17:30:16 +0100 Subject: fix merge error --- src/fbgui/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index c83dbdc..197ba68 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) { // parse command line arguments using getopt QMap clOpts; int longIndex = 0; - static const char *optString = "c:u:d:s:t:D:hl:nS:p:e:x"; + static const char *optString = "c:u:d:s:t:D:hl:nS:p:e:x"; static const struct option longOpts[] = { { "config", required_argument, NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", required_argument, NULL, 'd' }, { "serial", required_argument, NULL, @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) { 'n' }, { "server", required_argument, NULL, 'S' }, { "autoup", no_argument, NULL, 'a' }, { "socketserverpath", required_argument, NULL, 'p' }, { "pathtoexe", - "pathtoexe", required_argument, NULL, 'e' }, { "ssl", no_argument, NULL, 'x' } }; + required_argument, NULL, 'e' }, { "ssl", no_argument, NULL, 'x' } }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); while (opt != -1) { switch (opt) { -- cgit v1.2.3-55-g7522