summaryrefslogtreecommitdiffstats
path: root/src/client/clientapp/clientapp.h
blob: 0f7cb5bdef6e0a7247c2a5580bd44dca653869e9 (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
#include "../util/util.h"
#include "../net/serverconnection.h"

#include <QApplication>
#include <QSharedPointer>
#include <QSettings>

/* define a macro `clientApp` that can be used anywhere in the program and returns a reference to the current ClientApp instance */
#if defined(clientApp)
#undef clientApp
#endif
#define clientApp (static_cast<ClientApp*>(QCoreApplication::instance()))

class Toolbar;
class ConnectWindow;

/* this class is supposed to (after complete refactoring) to encapsulate all
 * state of the application.  At the moment, the state is distributed within
 * several widgets. With this class information access will also be easier as
 * it is possible to access the current ClientApp instance from anywhere with
 * the clientApp macro (like qApp)  macro */
class ClientApp : public QApplication
{

	Q_OBJECT

public:
	enum ConnectionMode { None, Auto, Session };

private:
	ConnectionMode _connectionMode; /* way of automatically connection to a session on startup*/
	bool _examMode;
	QString _sessionName; /* only set when _connectionMode == Session */
	Toolbar* _toolbar;
	ConnectWindow* _connectWindow;
	ServerConnection* _connection;
	QStringList _arguments;
	QString _iniPath;
	bool _isManagerPc;

	QStringList parseParameters();

	void readIsManagerPc();

public:

	ClientApp(int& argc, char** argv);

	bool isExamMode() const { return _examMode; };

	virtual QStringList arguments();

	QSharedPointer<QSettings> getSettings();

	ServerConnection* connection() const { return _connection; }

	ConnectWindow* connectWindow() const { return _connectWindow; }

	bool isConfiguredAsManager() { return _isManagerPc; }

	bool isConnectedToLocalManager() { return _connection != NULL && _connection->isLocalConnection(); }

private slots:

	void connected(ServerConnection* connection);
	void disconnected(ServerConnection* connection);

};