From 877607b07f30cbb8d7d8d06b1b91383095fdc144 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Fri, 30 Sep 2016 12:02:38 +0200 Subject: refactoring. --- src/server/serverapp/serverapp.h | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/server/serverapp/serverapp.h (limited to 'src/server/serverapp/serverapp.h') diff --git a/src/server/serverapp/serverapp.h b/src/server/serverapp/serverapp.h new file mode 100644 index 0000000..be6b0ab --- /dev/null +++ b/src/server/serverapp/serverapp.h @@ -0,0 +1,87 @@ +#ifndef SERVERAPP_H +#define SERVERAPP_H + +#include +#include +#include + +#include "../mainwindow/mainwindow.h" + +struct Room { + Room(QMap cPos, QSize grid, QSize client, QString image, QString tutor) : + clientPositions(cPos), + gridSize(grid), + clientSize(client), + imagePath(image), + tutorIP(tutor) {}; + QMap 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(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; + QStringList parseParameters(); + MainWindow* _mainWindow; + + QString _sessionName; + QByteArray _sessionNameArray; + QMap _rooms; + QString _currentRoom; + + bool _manager_only; + bool _isExam; + QString _iniPath; + +public: + + ServerApp(int& argc, char** argv); + + virtual QStringList arguments(); + + + /* getters */ + const QString& sessionName() { return _sessionName; } + const QByteArray& sessionNameArray() { return _sessionNameArray; } + const QMap & rooms() { return _rooms; } + const QString& getCurrentRoomName() { return _currentRoom; } + const QMap& getRooms() { return _rooms; } + bool isExam() { return _isExam; } + bool isManagerOnly() { return _manager_only; } + const Room* getCurrentRoom(); + + /* setters */ + void setSessionName(const QString& name); + void setSessionName(); + void setRooms(const QMap & roomList) { _rooms = roomList; } + void setIniPath(QString s) { _iniPath = s; }; + void setCurrentRoom(const QString& room) { _currentRoom = room; } + void setExam(bool exam) { _isExam = exam; } + + QSharedPointer getSettings(); + + +}; + +#endif -- cgit v1.2.3-55-g7522