main.cpp 1.61 KB
Newer Older
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
1
2
3
#include <QApplication>
#include <QString>
#include <iostream>
4
#include <getopt.h>
Gregor Lang's avatar
Gregor Lang committed
5
#include "download.h"
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
6
#include "resourcemanager.h"
Philipp Erhardt's avatar
Philipp Erhardt committed
7
#include "viewer.h"
Philipp Erhardt's avatar
Philipp Erhardt committed
8
#include "config.h"
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
9

10
11
12
13
14
15
16
17
18
19
20
21
using namespace std;


static void print_help(char *name) {
	cout << "Usage:" << endl;
	cout << "  " << name << " [OPTIONS] FILE" << endl;
	cout << endl;
	cout << "Options:" << endl;
	cout << "  -p, --page NUM      Start showing page NUM" << endl;
	cout << "  -f, --fullscreen    Start in fullscreen mode" << endl;
	cout << "  -h, --help          Print this help and exit" << endl;
}
Philipp Erhardt's avatar
Philipp Erhardt committed
22

Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
23
24
25
int main(int argc, char *argv[]) {
	QApplication app(argc, argv);

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
	// parse command line options
	struct option long_options[] = {
		{"page",		required_argument,	NULL,	'p'},
		{"fullscreen",	no_argument,		NULL,	'f'},
		{"help",		no_argument,		NULL,	'h'},
		{NULL, 0, NULL, 0}
	};
	int c;
	int option_index = 0;
	while (1) {
		c = getopt_long(argc, argv, "+p:fh", long_options, &option_index);
		if (c == -1) {
			break;
		}
		switch (c) {
			case 'p':
				// currently no warning message on wrong input
Philipp Erhardt's avatar
Philipp Erhardt committed
43
				CFG::get_instance()->set_value("start_page", atoi(optarg) - 1);
44
45
				break;
			case 'f':
Philipp Erhardt's avatar
Philipp Erhardt committed
46
				CFG::get_instance()->set_value("fullscreen", true);
47
48
49
50
51
52
53
54
55
56
57
58
				break;
			case 'h':
				print_help(argv[0]);
				return 0;
			default:
				// getopt prints an error message
				return 1;
		}
	}

	if (argv[optind] == NULL) {
		cerr << "Not enough arguments" << endl;
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
59
60
61
		return 1;
	}

Gregor Lang's avatar
Gregor Lang committed
62
63
	Download download;
	QString file = download.load(QString::fromUtf8(argv[optind]));
64
65
66
	if (file == NULL) {
		return 1;
	}
Gregor Lang's avatar
Gregor Lang committed
67
68

	Viewer katarakt(file);
Philipp Erhardt's avatar
Philipp Erhardt committed
69
70
71
	if (!katarakt.is_valid()) {
		return 1;
	}
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
72

Philipp Erhardt's avatar
fail    
Philipp Erhardt committed
73
	return app.exec();
Philipp Erhardt's avatar
initial  
Philipp Erhardt committed
74
75
}