summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
blob: 95981e0f7c688cbd7f8e2bfb73a409d2f48e2259 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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();
}