summaryrefslogblamecommitdiffstats
path: root/src/server/serverapp/serverapp.h
blob: e0a13515899a271ebb8e99de6eb103b32e375568 (plain) (tree)











































                                                                                                  






                                     
                          


                         


                                      













                                                                                           
                                                                                        
                                     
                                                



                                                 



                                                                         


      
#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