summaryrefslogtreecommitdiffstats
path: root/src/client/clientapp/clientapp.cpp
blob: 05289e59b51f21f0dfe62765d0d323618ad8c820 (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 "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");
    
    _arguments = parseParameters();
    initConfiguration();


    /* 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;
}
void ClientApp::initConfiguration() {
    /* configuration */	
	QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/");
	do {
		// Make sure settings directory exists
		USER_SETTINGS(settings);
		QFileInfo fi(settings.fileName());
		QDir path(fi.path());
		qDebug() << "User settings are in:" << settings.fileName();
		if (!path.exists())
			path.mkpath(path.absolutePath());
		// Now check if settings file exists. If not, copy system default (if available)
		if (!fi.exists())
		{
			SYSTEM_SETTINGS(sys);
			qDebug() << "System settings are in:" << sys.fileName();
			QFileInfo sysfi(sys.fileName());
			if (sysfi.exists())
			{
				if (!QFile::copy(sys.fileName(), settings.fileName()))
					qDebug() << "Copying default settings from " << sys.fileName() << " to " << settings.fileName() << " failed.";
			}
		}
	} while (false);
}

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