diff options
author | Jonathan Bauer | 2011-03-06 12:09:30 +0100 |
---|---|---|
committer | Jonathan Bauer | 2011-03-06 12:09:30 +0100 |
commit | da19a5e696a3084cc9b1c28a6a8b9802af0568f2 (patch) | |
tree | 62a772388a202921f38869257053e1288b2a6b8a /src/main.cpp | |
parent | updated code structure, main loop now separate from fbgui class....... (diff) | |
download | fbgui-da19a5e696a3084cc9b1c28a6a8b9802af0568f2.tar.gz fbgui-da19a5e696a3084cc9b1c28a6a8b9802af0568f2.tar.xz fbgui-da19a5e696a3084cc9b1c28a6a8b9802af0568f2.zip |
main.cpp added
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..95981e0 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,76 @@ +#include <QApplication> +#include <QtCore> +#include <getopt.h> +#include <cstdlib> +#include <iostream> +#include "fbgui.h" + +QMap<QString, QString> options; +void printHelp() +{ + // Prints usage information. + QTextStream qout(stdout); + qout << QObject::tr("Usage: ./fbgui [OPTIONS]") << endl; + qout << QObject::tr("Options:") << endl; + qout << "-u <URL>, --url=<URL> " << QObject::tr("Set which URL to load.") << endl; + qout << "-h, --help " << QObject::tr("Prints usage information.") << endl; +} + +int main(int argc, char *argv[]) +{ + QApplication *app = new QApplication(argc, argv, QApplication::GuiServer); + app->setOrganizationName("team_projekt_2011"); + app->setApplicationName("fbgui"); + app->setObjectName("test"); + + /* Parse cmdline argus. */ + qDebug() << "Received " << argc << "arguments:"; + for (int i = 0; i < argc; i++) + qDebug() << i + 1 << ": " << argv[i]; + + int longIndex = 0; + static const char *optString = "u:h"; + static const struct option longOpts[] = + { + {"url", required_argument, NULL, 'u'}, + {"help", no_argument, NULL, 'h'} + }; + int opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + while (opt != -1) + { + switch(opt) + { + case 'u': + options.insert("url", optarg); + break; + case 'h': + options.insert("help", "help"); + break; + } + opt = getopt_long(argc, argv, optString, longOpts, &longIndex); + } + // + if (options.contains("help")) + { + printHelp(); + exit(EXIT_SUCCESS); + } + // + QUrl url; + if (options.contains("url")) + url = options.value("url"); + else + { + std::cout << "No URL specified. Exiting..."; + exit(EXIT_FAILURE); + } + // TODO: Read INI. + + + // Init fbgui + fbgui *gui = new fbgui(app); + gui->setParent(app); + qDebug() << "Obj name: " << gui->parent()->objectName(); + qDebug() << "Created fbgui..."; + return app->exec(); +} |