diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/main.cpp b/src/main.cpp index 689b3e4..c5269a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,23 +25,22 @@ int main(int argc, char *argv[]) QApplication app(argc, argv, QApplication::GuiServer); app.setOrganizationName("team_projekt_2011"); app.setApplicationName("prebootGUI"); - app.setObjectName("test"); binPath = QApplication::applicationDirPath(); QTranslator translator; translator.load(":" + QLocale::system().name()); app.installTranslator(&translator); - /* parse command line arguments */ + // parse command line arguments QMap<QString, QString> clOpts; int longIndex = 0; - static const char *optString = "u:d:c:Dh"; + static const char *optString = "u:d:c:D:h"; static const struct option longOpts[] = { {"url", required_argument, NULL, 'u'}, {"download", required_argument, NULL, 'd'}, {"config", required_argument, NULL, 'c'}, - {"debug", no_argument, NULL, 'D'}, + {"debug", required_argument, NULL, 'D'}, {"help", no_argument, NULL, 'h'} }; int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); @@ -58,7 +57,7 @@ int main(int argc, char *argv[]) case 'c': clOpts.insert("configFile", optarg); case 'D': - clOpts.insert("debug", "debug"); + clOpts.insert("debug", optarg); break; case 'h': clOpts.insert("help", "help"); @@ -70,11 +69,12 @@ int main(int argc, char *argv[]) if (clOpts.contains("help")) printHelp(); - if (clOpts.contains("debug")){ - debug = true; - qDebug() << "Debug mode activated."; - } - /* "search" config file */ + if (clOpts.contains("debug")) + debugMode = clOpts.value("debug").toInt(); + else + debugMode = -1; + + // look for config file QString configFilePath; QFileInfo confInfo; if (clOpts.contains("configFile")) @@ -88,52 +88,41 @@ int main(int argc, char *argv[]) if (confInfo.exists()) configFilePath = QString("/etc/fbgui.conf"); else - /* temporary */ - configFilePath = QApplication::applicationDirPath() + "/fbgui.conf"; + configFilePath = DEFAULT_CONFIG_PATH; } } - if (debug) qDebug() << "Config file is: " << configFilePath; - /* read the config file */ + // read the config file QSettings confFileSettings(configFilePath, QSettings::IniFormat); confFileSettings.setIniCodec("UTF-8"); if (clOpts.contains("url")) { baseURL = QUrl(clOpts.value("url")); - if (debug) qDebug() << "URL loaded from cmdline."; } else if (confFileSettings.contains("default/url")) { baseURL = confFileSettings.value("default/url").toUrl(); - if (debug) qDebug() << "URL loaded from config file."; } else { baseURL = DEFAULT_URL; - if (debug) qDebug() << "URL set by default."; } - if (debug) qDebug() << "Base URL: " << baseURL.toString(); - /* setting directory for downloads*/ + // setting directory for downloads if (clOpts.contains("downloadDir")){ downloadPath = clOpts.value("downloadDir"); - if (debug) qDebug() << "Download directory loaded from cmdline."; } else if (confFileSettings.contains("default/downloadDirectory")){ downloadPath = confFileSettings.value("default/downloadDirectory").toString(); - if (debug) qDebug() << "Download directory loaded from config file."; } - else - { + else { downloadPath = DEFAULT_DOWNLOAD_DIR; - if (debug) qDebug() << "Download directory set by default."; } - if (debug) qDebug() << "Download directory: " << downloadPath; if (confFileSettings.contains("default/updateInterval")){ updateInterval = confFileSettings.value("default/updateInterval").toInt(); - if (debug) qDebug() << "Read updateInterval from confFile: " << updateInterval; } else updateInterval = DEFAULT_UPDATE_INTERVAL; fbgui gui; + gui.show(); return app.exec(); } |
