diff options
author | Jonathan Bauer | 2012-01-24 15:02:26 +0100 |
---|---|---|
committer | Jonathan Bauer | 2012-01-24 15:02:26 +0100 |
commit | 0a70f0c2d4933205e3fb4c87daa129b9738ef861 (patch) | |
tree | e9837925e01edadc9fd898b241dfaae781d8ad60 | |
parent | new option -n to activate network discovery (diff) | |
download | fbgui-0a70f0c2d4933205e3fb4c87daa129b9738ef861.tar.gz fbgui-0a70f0c2d4933205e3fb4c87daa129b9738ef861.tar.xz fbgui-0a70f0c2d4933205e3fb4c87daa129b9738ef861.zip |
added nd template in config file & minor formatting
-rw-r--r-- | fbgui.conf | 4 | ||||
-rw-r--r-- | src/fbgui/main.cpp | 154 | ||||
-rwxr-xr-x | testApp.sh | 4 |
3 files changed, 87 insertions, 75 deletions
@@ -6,3 +6,7 @@ file_trigger=/tmp/fbgui_trigger serial_location=/serial ip_config=/tmp/ip_config log_file=/tmp/fbgui.log +server=209.85.148.105 +autoup=true +pathtoexe=~/fbgui/build/src/customdhcpcd/cdhcpcd +serverSocket=/var/tmp/qt_c_socket_custom diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index 4c7daf8..e7f9fae 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -23,16 +23,20 @@ void printHelp() { QTextStream qout(stdout); qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; qout << QObject::tr("Options:") << endl; - qout << "-c <path>, --config=<path> " << QObject::tr("Path to configuration file.") << endl; - qout << "-u <URL>, --url=<URL> " << QObject::tr("Sets the URL to be loaded.") << endl; - qout << "-d <path>, --download=<path> " << QObject::tr("Specify the download directory.") - << endl; + qout << "-c <path>, --config=<path> " << QObject::tr( + "Path to configuration file.") << endl; + qout << "-u <URL>, --url=<URL> " << QObject::tr( + "Sets the URL to be loaded.") << endl; + qout << "-d <path>, --download=<path> " << QObject::tr( + "Specify the download directory.") << endl; qout << "-t <path, --trigger=<path> " << QObject::tr( "Specify location of the file triggering the URL load.") << endl; qout << "-s <path, --serial=<path> " << QObject::tr( "Specify location of the file containing the serial number.") << endl; - qout << "-D <level>, --debug=<level> " << QObject::tr("Activate debug mode. [0,1]") << endl; - qout << "-h, --help " << QObject::tr("Prints this help.") << endl; + qout << "-D <level>, --debug=<level> " << QObject::tr( + "Activate debug mode. [0,1]") << endl; + qout << "-h, --help " << QObject::tr( + "Prints this help.") << endl; qout.flush(); exit( EXIT_SUCCESS); } @@ -45,28 +49,24 @@ int main(int argc, char *argv[]) { // 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 { + 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 (loggingConfInfo.exists()) + loggingConfigFilePath = loggingConfInfo.absoluteFilePath(); + else + loggingConfigFilePath = ""; + } - if (loggingConfigFilePath.length() > 0) - { + if (loggingConfigFilePath.length() > 0) { // BasicConfigurator replaced with PropertyConfigurator. PropertyConfigurator::configure(loggingConfigFilePath.toStdString()); - } - else - { + } else { BasicConfigurator::configure(); - } + } QApplication app(argc, argv, QApplication::GuiServer); app.setOrganizationName("team_projekt_2011"); @@ -81,16 +81,16 @@ int main(int argc, char *argv[]) { QMap<QString, QString> clOpts; int longIndex = 0; static const char *optString = "c:u:d:s:t:D:hl:n"; - 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' } - }; + 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) { @@ -122,17 +122,17 @@ int main(int argc, char *argv[]) { clOpts.insert("nd", "nd"); break; case 'S': - clOpts.insert("server", optarg); - break; + clOpts.insert("server", optarg); + break; case 'a': - clOpts.insert("autoup", "autoup"); - break; + clOpts.insert("autoup", "autoup"); + break; case 'p': - clOpts.insert("socketserverpath", optarg); - break; + clOpts.insert("socketserverpath", optarg); + break; case 'e': - clOpts.insert("pathtoexe", optarg); - break; + clOpts.insert("pathtoexe", optarg); + break; } opt = getopt_long(argc, argv, optString, longOpts, &longIndex); } @@ -143,11 +143,11 @@ int main(int argc, char *argv[]) { 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); + // 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; @@ -189,13 +189,15 @@ int main(int argc, char *argv[]) { if (clOpts.contains("downloadDir")) downloadPath = clOpts.value("downloadDir"); else if (confFileSettings.contains("default/download_directory")) - downloadPath = confFileSettings.value("default/download_directory").toString(); + 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(); + updateInterval + = confFileSettings.value("default/update_interval").toInt(); else updateInterval = DEFAULT_UPDATE_INTERVAL; @@ -203,7 +205,8 @@ int main(int argc, char *argv[]) { if (clOpts.contains("trigger")) fileToTriggerURL = clOpts.value("trigger"); else if (confFileSettings.contains("default/file_trigger")) - fileToTriggerURL = confFileSettings.value("default/file_trigger").toString(); + fileToTriggerURL + = confFileSettings.value("default/file_trigger").toString(); else fileToTriggerURL = DEFAULT_FILE_TRIGGER; @@ -211,7 +214,8 @@ int main(int argc, char *argv[]) { if (clOpts.contains("serialLocation")) serialLocation = clOpts.value("serialLocation"); else if (confFileSettings.contains("default/serial_location")) - serialLocation = confFileSettings.value("default/serial_location").toString(); + serialLocation + = confFileSettings.value("default/serial_location").toString(); else serialLocation = QString("/serial"); // tests @@ -229,44 +233,43 @@ int main(int argc, char *argv[]) { // if (clOpts.contains("server")) - gServerIp = clOpts.value("server"); + gServerIp = clOpts.value("server"); else if (confFileSettings.contains("default/server")) - gServerIp = confFileSettings.value("default/server").toString(); + gServerIp = confFileSettings.value("default/server").toString(); else - gServerIp = "209.85.148.105"; //that is a google server. change this to a proper default address + gServerIp = "209.85.148.105"; //that is a google server. change this to a proper default address // if (clOpts.contains("autoup")) - gAutoUp = true; + gAutoUp = true; else if (confFileSettings.contains("default/autoup")) - gAutoUp = confFileSettings.value("default/autoup").toBool(); + gAutoUp = confFileSettings.value("default/autoup").toBool(); else - gAutoUp = false; + gAutoUp = false; // if (clOpts.contains("socketserverpath")) - gSocketServerPath = clOpts.value("socketserverpath"); + gSocketServerPath = clOpts.value("socketserverpath"); else if (confFileSettings.contains("default/socketserverpath")) - gSocketServerPath = confFileSettings.value("default/socketserverpath").toString(); + gSocketServerPath + = confFileSettings.value("default/socketserverpath").toString(); else - gSocketServerPath = DEFAULT_QTSOCKETADDRESS; + gSocketServerPath = DEFAULT_QTSOCKETADDRESS; // if (clOpts.contains("pathtoexe")) - gPathToDhcpExe = clOpts.value("pathtoexe"); + gPathToDhcpExe = clOpts.value("pathtoexe"); else if (confFileSettings.contains("default/pathtoexe")) - gPathToDhcpExe = confFileSettings.value("default/pathtoexe").toString(); + gPathToDhcpExe = confFileSettings.value("default/pathtoexe").toString(); else - gPathToDhcpExe = DEFAULT_PATHTODHCPCDEXE; - - + 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); + // start debug logging to file. + // qxtLog->addLoggerEngine("file_logger", new LoggerEngine_file(logFilePath)); + // qxtLog->setMinimumLevel("file_logger", QxtLogger::DebugLevel); // } // print config @@ -278,10 +281,16 @@ int main(int argc, char *argv[]) { LOG4CXX_DEBUG(logger, "downloadDir : " << downloadPath); LOG4CXX_DEBUG(logger, "trigger: " << fileToTriggerURL); LOG4CXX_DEBUG(logger, "serialLocation: " << serialLocation); - LOG4CXX_DEBUG(logger, "server: " << gServerIp); - LOG4CXX_DEBUG(logger, "autoup: " << gAutoUp); - LOG4CXX_DEBUG(logger, "socketserverpath: " << gSocketServerPath); - LOG4CXX_DEBUG(logger, "pathtoexe: " << gPathToDhcpExe); + 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 @@ -300,8 +309,7 @@ int main(int argc, char *argv[]) { QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); ngui.init(); ngui.show(); - } - else { + } else { gui.init(); gui.show(); } @@ -14,8 +14,8 @@ QT_VERSION=Qt-4.7.2 # clean /tmp/fbgui -rm -rf /tmp/fbgui -rm /tmp/fbgui_trigger +[ -d /tmp/fbgui ] && rm -rf /tmp/fbgui +[ -f /tmp/fbgui_trigger ] && rm /tmp/fbgui_trigger # path to script (including script name) script_path="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" |