From 7cb508eb877ae0a696427073b1105ee8d9c19876 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 21 Apr 2011 23:35:02 +0200 Subject: uniformed ident 3-spaced.... --- src/main.cpp | 358 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 178 insertions(+), 180 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index baff7af..9b0a18a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,187 +8,185 @@ #include "fbgui.h" 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). - - 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:h"; - 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' } }; - int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); - while (opt != -1) { - switch (opt) { - case 'c': - clOpts.insert("configFile", 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; - } - 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 log - qxtLog->disableLoggerEngine("DEFAULT"); - qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); - qxtLog->initLoggerEngine("std_logger"); - qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); - qxtLog->enableLogLevels(QxtLogger::DebugLevel); - qxtLog->debug() << "Initializing fbgui..."; - } 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; - - 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(); - //else - // ipConfigFilePath = QString("/tmp/ip_config"); - - // print config - qxtLog->debug() << "************* CONFIG INFO *************"; - qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); - qxtLog->debug() << "ipConfigFilePath:" << ipConfigFilePath.toUtf8(); - qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); - qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); - qxtLog->debug() << "trigger: " << fileToTriggerURL.toUtf8(); - qxtLog->debug() << "serialLocation: " << serialLocation.toUtf8(); - qxtLog->debug() << "*******************************************"; - - // set invisible cursor - QWSServer::instance()->setCursorVisible(false); - QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); - QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); - // start fbgui - fbgui gui; - 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). + + 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:h"; + 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' } }; + int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + while (opt != -1) { + switch (opt) { + case 'c': + clOpts.insert("configFile", 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; + } + 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 log + qxtLog->disableLoggerEngine("DEFAULT"); + qxtLog->addLoggerEngine("std_logger", new LoggerEngine_std); + qxtLog->initLoggerEngine("std_logger"); + qxtLog->setMinimumLevel("std_logger", QxtLogger::DebugLevel); + qxtLog->enableLogLevels(QxtLogger::DebugLevel); + qxtLog->debug() << "Initializing fbgui..."; + } 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; + + 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(); + //else + // ipConfigFilePath = QString("/tmp/ip_config"); + + // print config + qxtLog->debug() << "************* CONFIG INFO *************"; + qxtLog->debug() << "configFilePath: " << configFilePath.toUtf8(); + qxtLog->debug() << "ipConfigFilePath:" << ipConfigFilePath.toUtf8(); + qxtLog->debug() << "baseURL: " << baseURL.toString().toUtf8(); + qxtLog->debug() << "downloadDir : " << downloadPath.toUtf8(); + qxtLog->debug() << "trigger: " << fileToTriggerURL.toUtf8(); + qxtLog->debug() << "serialLocation: " << serialLocation.toUtf8(); + qxtLog->debug() << "*******************************************"; + + // set invisible cursor + QWSServer::instance()->setCursorVisible(false); + QWSServer::instance()->setDefaultKeyboard("TTY:/dev/tty0"); + QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); + // start fbgui + fbgui gui; + gui.show(); + return app.exec(); } -- cgit v1.2.3-55-g7522