Pool Video Switch v2
Software video switch for distributed remote display in a lecture environment
serverapp.h
Go to the documentation of this file.
1 #ifndef SERVERAPP_H
2 #define SERVERAPP_H
3 
4 #include <QApplication>
5 #include <QStringList>
6 #include <QMap>
7 
8 class QSettings;
9 
10 struct Room {
11  Room(const QMap<QString, QPoint> &cPos, const QSize &grid, const QSize &client, const QString &image, const QString &tutor) :
12  clientPositions(cPos),
13  gridSize(grid),
14  clientSize(client),
15  imagePath(image),
16  tutorIP(tutor) {};
17  QMap<QString, QPoint> clientPositions;
18  QSize gridSize;
19  QSize clientSize;
20  QString imagePath;
21  QString tutorIP;
22 };
23 
24 
25 /* define a macro `serverApp` that can be used anywhere in the program and
26  * returns a reference to the current ServerApp instance */
27 
28 #if defined(serverApp)
29 #undef serverApp
30 #endif
31 #define serverApp (static_cast<ServerApp*>(QCoreApplication::instance())) // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
32 
33 /* this class is supposed to (after complete refactoring) to encapsulate all
34  * state of the application. At the moment, the state is distributed within
35  * several widgets. With this class information access will also be easier as
36  * it is possible to access the current ServerApp instance from anywhere with
37  * the serverApp macro (like qApp) */
38 class ServerApp : public QApplication
39 {
40 
41  Q_OBJECT
42 
43 private:
44  QStringList _arguments;
45 
46  QString _sessionName;
47  QByteArray _sessionNameArray;
48  QMap<QString, Room*> _rooms;
49  QString _currentRoom;
50  bool _doExit{};
51 
52  bool _managerOnly{};
53  bool _isExam{};
54  QString _iniPath;
55 
56  QStringList parseParameters();
57  void loadRooms();
58 
59 public:
60 
61  ServerApp(int& argc, char** argv);
62 
63  virtual QStringList arguments();
64 
65 
66  /* getters */
67  const QString &sessionName() const { return _sessionName; }
68  const QByteArray &sessionNameArray() const { return _sessionNameArray; }
69  const QMap<QString, Room *> &getRooms() const { return _rooms; }
70  bool isExam() const { return _isExam; }
71  const Room* getCurrentRoom() const;
72  QSettings * getSettings();
73 
74  /* setters */
75  void setSessionName(const QString& name);
76  void setSessionName();
77  void setCurrentRoom(const QString& room) { _currentRoom = room; }
78  void setExam(bool exam) { _isExam = exam; }
79 
80  bool shouldExit() const { return _doExit; }
81 
82 };
83 
84 #endif
QStringList parseParameters()
Definition: serverapp.cpp:53
QSize clientSize
Definition: serverapp.h:19
QString _iniPath
Definition: serverapp.h:54
QString imagePath
Definition: serverapp.h:20
const Room * getCurrentRoom() const
Definition: serverapp.cpp:140
bool _doExit
Definition: serverapp.h:50
bool _managerOnly
Definition: serverapp.h:52
Room(const QMap< QString, QPoint > &cPos, const QSize &grid, const QSize &client, const QString &image, const QString &tutor)
Definition: serverapp.h:11
void setExam(bool exam)
Definition: serverapp.h:78
void loadRooms()
Definition: serverapp.cpp:75
QSize gridSize
Definition: serverapp.h:18
QString tutorIP
Definition: serverapp.h:21
QMap< QString, QPoint > clientPositions
Definition: serverapp.h:16
const QByteArray & sessionNameArray() const
Definition: serverapp.h:68
virtual QStringList arguments()
Definition: serverapp.cpp:70
QString _currentRoom
Definition: serverapp.h:49
QStringList _arguments
Definition: serverapp.h:44
void setCurrentRoom(const QString &room)
Definition: serverapp.h:77
void setSessionName()
Definition: serverapp.cpp:158
bool isExam() const
Definition: serverapp.h:70
ServerApp(int &argc, char **argv)
Definition: serverapp.cpp:12
QByteArray _sessionNameArray
Definition: serverapp.h:47
bool _isExam
Definition: serverapp.h:53
bool shouldExit() const
Definition: serverapp.h:80
QMap< QString, Room * > _rooms
Definition: serverapp.h:48
QSettings * getSettings()
Definition: serverapp.cpp:165
QString _sessionName
Definition: serverapp.h:46
const QMap< QString, Room * > & getRooms() const
Definition: serverapp.h:69
Definition: room.h:6
const QString & sessionName() const
Definition: serverapp.h:67