From 4a2f54052e1cee06335293871d4c2fadf2f729bd Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Thu, 24 Mar 2011 16:12:32 +0100 Subject: now maybe? --- src/main.cpp | 263 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 129 insertions(+), 134 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a6dc1b2..2860e25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,156 +8,151 @@ void printHelp() { - QTextStream qout(stdout); - qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; - qout << QObject::tr("Options:") << endl; - qout << "-u , --url= " << QObject::tr("Set which URL to load.") << endl; - qout << "-d , --download= " << QObject::tr("Specify the download directory.") << endl; - qout << "-c , --config= " << QObject::tr("Path to config file.") << endl; - qout << "-D , --debug= " << QObject::tr("Activate debug mode.") << endl; - qout << "-h, --help " << QObject::tr("Prints usage information.") << endl; - qout.flush(); - exit(EXIT_SUCCESS); + QTextStream qout(stdout); + qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; + qout << QObject::tr("Options:") << endl; + qout << "-u , --url= " << QObject::tr("Set which URL to load.") << endl; + qout << "-d , --download= " << QObject::tr("Specify the download directory.") << endl; + qout << "-c , --config= " << QObject::tr("Path to config file.") << endl; + qout << "-D , --debug= " << QObject::tr("Activate debug mode.") << endl; + qout << "-h, --help " << QObject::tr("Prints usage information.") << endl; + qout.flush(); + exit(EXIT_SUCCESS); } int main(int argc, char *argv[]) { - QApplication app(argc, argv, QApplication::GuiServer); - app.setOrganizationName("team_projekt_2011"); - app.setApplicationName("prebootGUI"); - binPath = QApplication::applicationDirPath(); + 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); + QTranslator translator; + translator.load(":" + QLocale::system().name()); + app.installTranslator(&translator); - // parse command line arguments - 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); - } + // parse command line arguments + 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("help")) + printHelp(); - if (clOpts.contains("debug")) - debugMode = clOpts.value("debug").toInt(); - else - debugMode = -1; - - // look for config file - 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; - } - } + if (clOpts.contains("debug")) + debugMode = clOpts.value("debug").toInt(); + else + debugMode = -1; - // read the config file - QSettings confFileSettings(configFilePath, QSettings::IniFormat); - confFileSettings.setIniCodec("UTF-8"); + // look for config file + 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; + } + } - // 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; - } + // read the config file + QSettings confFileSettings(configFilePath, QSettings::IniFormat); + confFileSettings.setIniCodec("UTF-8"); - // 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(); - } + // 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 - downloadPath = DEFAULT_DOWNLOAD_DIR; + baseURL = DEFAULT_URL; - if (confFileSettings.contains("default/update_interval")){ - updateInterval = confFileSettings.value("default/update_interval").toInt(); - } - else updateInterval = DEFAULT_UPDATE_INTERVAL; + // 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; - // sets 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(); + if (confFileSettings.contains("default/update_interval")) + updateInterval = confFileSettings.value("default/update_interval").toInt(); else - fileToTriggerURL = DEFAULT_FILE_TRIGGER; + updateInterval = DEFAULT_UPDATE_INTERVAL; - // 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"); + // sets 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"); - // basic std out engine is ugly... not yet initialised so using qDebug - qDebug() << "************* CONFIG INFO *************"; - qDebug() << "configFilePath: " << configFilePath.toUtf8(); - qDebug() << "baseURL: " << baseURL.toString().toUtf8(); - qDebug() << "downloadDir : " << downloadPath.toUtf8(); - qDebug() << "trigger: " << fileToTriggerURL.toUtf8(); - qDebug() << "serialLocation: " << serialLocation.toUtf8(); - qDebug() << "*******************************************"; + // basic std out engine is ugly... not yet initialised so using qDebug + qDebug() << "************* CONFIG INFO *************"; + qDebug() << "configFilePath: " << configFilePath.toUtf8(); + qDebug() << "baseURL: " << baseURL.toString().toUtf8(); + qDebug() << "downloadDir : " << downloadPath.toUtf8(); + qDebug() << "trigger: " << fileToTriggerURL.toUtf8(); + qDebug() << "serialLocation: " << serialLocation.toUtf8(); + qDebug() << "*******************************************"; - // start fbgui - fbgui gui; - gui.show(); - return app.exec(); + // start fbgui + fbgui gui; + gui.show(); + return app.exec(); } -- cgit v1.2.3-55-g7522