summaryrefslogtreecommitdiffstats
path: root/src/server/serverapp/serverapp.h
blob: e0a13515899a271ebb8e99de6eb103b32e375568 (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
77
78
79
80
81
82
83
84
85
86
#ifndef SERVERAPP_H
#define SERVERAPP_H

#include <QApplication>
#include <QStringList>
#include <QMap>

#include "../mainwindow/mainwindow.h"

struct Room {
	Room(QMap<QString, QPoint> cPos, QSize grid, QSize client, QString image, QString tutor) :
		clientPositions(cPos),
		gridSize(grid),
		clientSize(client),
		imagePath(image),
		tutorIP(tutor) {};
	QMap<QString, QPoint> clientPositions;
	QSize gridSize;
	QSize clientSize;
	QString imagePath;
	QString tutorIP;
};


/* define a macro `serverApp` that can be used anywhere in the program and
 * returns a reference to the current ClientApp instance */

#if defined(serverApp)
#undef serverApp
#endif
#define serverApp (static_cast<ServerApp*>(QCoreApplication::instance()))

/* 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 ServerApp instance from anywhere with
 * the serverApp macro (like qApp) */
class ServerApp : public QApplication
{

	Q_OBJECT

private:
	QStringList _arguments;
	MainWindow* _mainWindow;

	QString _sessionName;
	QByteArray _sessionNameArray;
	QMap<QString, Room*> _rooms;
	QString _currentRoom;

	bool _managerOnly;
	bool _isExam;
	QString _iniPath;

	QStringList parseParameters();
	void loadRooms();

public:

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

	virtual QStringList arguments();


	/* getters */
	const QString& sessionName() 		    { return _sessionName; }
	const QByteArray& sessionNameArray()    { return _sessionNameArray; }
	const QMap<QString, Room*> & rooms()    { return _rooms; }
	const QString& getCurrentRoomName()     { return _currentRoom; }
	const QMap<QString, Room*>& getRooms()  { return _rooms; }
	bool isExam() 							{ return _isExam; }
	bool isManagerOnly()					{ return _managerOnly; }
	const Room* getCurrentRoom();
	QSharedPointer<QSettings> getSettings();

	/* setters */
	void setSessionName(const QString& name);
	void setSessionName();
	void setIniPath(QString s) { _iniPath = s; };
	void setCurrentRoom(const QString& room) { _currentRoom = room; }
	void setExam(bool exam) { _isExam = exam; }

};

#endif