summaryrefslogblamecommitdiffstats
path: root/src/server/serverapp/serverapp.h
blob: 3cb40b5645453c98d2dedee611f0632f4187845a (plain) (tree)
1
2
3
4
5
6
7
8
9
10






                       
                

             
                                                                                                                                     













                                                                          
                                                           



                      
                                                                                                                                    












                                                                             




                                     
                       
 

                            

                         


                                      







                                          





                                                                                   



                                                 


                                                                         

                                                   


      
#ifndef SERVERAPP_H
#define SERVERAPP_H

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

class QSettings;

struct Room {
	Room(const QMap<QString, QPoint> &cPos, const QSize &grid, const QSize &client, const QString &image, const 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 ServerApp instance */

#if defined(serverApp)
#undef serverApp
#endif
#define serverApp (static_cast<ServerApp*>(QCoreApplication::instance())) // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)

/* 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;

	QString _sessionName;
	QByteArray _sessionNameArray;
	QMap<QString, Room*> _rooms;
	QString _currentRoom;
	bool _doExit{};

	bool _managerOnly{};
	bool _isExam{};
	QString _iniPath;

	QStringList parseParameters();
	void loadRooms();

public:

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

	virtual QStringList arguments();


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

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

	bool shouldExit() const { return _doExit; }

};

#endif