summaryrefslogtreecommitdiffstats
path: root/src/client/clientapp/clientapp.cpp
blob: 18ef0deee519734875f38edbef4a7af8e6b71701 (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
#include "clientapp.h"

ClientApp::ClientApp(int& argc, char** argv)
	: QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false)
{
	/* some values */
	setOrganizationName("openslx");
	setOrganizationDomain("openslx.org");
	setApplicationName("pvsclient");

	/* configuration */
	QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/");

	_arguments = parseParameters();


	/* TODO: Move the connection handling to ClientApp */
	if (_connectionMode == ConnectionMode::Auto) {
		_toolbar = new Toolbar(true); // auto connect client without session ID.
	} else if (_connectionMode == ConnectionMode::Session) {
		_toolbar = new Toolbar(_sessionName.toUtf8()); // connect client with given session ID.
	} else {
		_toolbar = new Toolbar(); // create normal client.
	}
	_toolbar->setVisible(!_examMode);

	/* set translator */
	/* use system locale as language to translate gui */
	QTranslator translator;
	translator.load(":pvsclient");
	installTranslator(&translator);

};

/* parse arguments and return a list with the unused arguments */
QStringList ClientApp::parseParameters()
{
	QStringList rest;
	for (QString a : QApplication::arguments()) {
		if (a == "--exam-mode") {
			_examMode = true;
		} else if (a == "--auto") {
			_connectionMode = ConnectionMode::Auto;
		} else if (a.startsWith("--session=")) {
			_connectionMode = ConnectionMode::Session;
			_sessionName = a.replace("--session=", "");
		} else {
			rest << a;
		}
	}
	return rest;
}

QStringList ClientApp::arguments()
{
	return _arguments;
}