summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/server/mainwindow/mainwindow.cpp194
-rw-r--r--src/server/mainwindow/mainwindow.h3
-rw-r--r--src/server/serverapp/serverapp.cpp95
-rw-r--r--src/server/serverapp/serverapp.h9
4 files changed, 146 insertions, 155 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 6d9bdd3..cb2e4da 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -18,7 +18,6 @@
// QT stuff
#include <QtGui>
#include <QFileDialog>
-#include <QNetworkInterface>
#include <QSvgRenderer>
#include <QPainter>
#include <QImage>
@@ -176,7 +175,7 @@ MainWindow::MainWindow(QWidget* parent) :
this->onSessionNameUpdate(); // Just make lable visible.
_countSessionNameUpdate = 0;
- tryToUseRoomTemplate();
+ reloadCurrentRoom();
}
/** this function determines if the number of clients in exam mode comprise
@@ -379,106 +378,6 @@ void MainWindow::tellClientCurrentSituation(Client* client)
}
-/**
- * returns the minimal grid size such that all clients fit on the grid
- **/
-QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize)
-{
- /* collect the maximum coordinates */
- int x = 0;
- int y = 0;
-
- for (auto it = clientPositions.begin(); it != clientPositions.end(); ++it) {
- QPoint pos = it.value();
- if (pos.x() > x) { x = pos.x(); }
- if (pos.y() > y) { y = pos.y(); }
-
- }
- /* need a little extra space */
- QSize size(x + clientSize.width(), y + clientSize.height());
- return size;
-}
-
-/***************************************************************************//**
- * @brief MainWindow::tryToUseRoomTemplate
- */
-void MainWindow::tryToUseRoomTemplate()
-{
- qDebug() << "tryToUseRoomTemplate()";
- QMap<QString, Room* > roomsList;
- QSharedPointer<QSettings> conf = serverApp->getSettings();
-
- if (!conf->contains("rooms")) { qDebug() << "Invalid config file (no rooms are set)!"; return; }
- QStringList rooms = conf->value("rooms").toStringList();
-
- QString myRoom = "";
-
- for (QString roomId : rooms) {
- conf->beginGroup(roomId);
- QString roomName = conf->value("name").toString();
-
- /* fallback to the old format where the room id was actually just the name */
- if (roomName == "") {
- roomName = roomId;
- }
- if (!conf->contains("mgrIP")) {
- qDebug() << "Warning: Incomplete config file (room " << roomName << " needs a mgrIP)!";
- }
- QMap<QString, QPoint> clientPositions;
- // First store all room configurations in _rooms.
- int size = conf->beginReadArray("client");
- for (int j = 0; j < size; j++) {
- conf->setArrayIndex(j);
- clientPositions.insert(conf->value("ip").toString(), conf->value("pos").toPoint());
- }
- conf->endArray();
-
- /* read backgroundImage */
- QString image = conf->contains("backgroundImage") ? conf->value("backgroundImage").toString() : "";
- QString mgrIP = conf->value("mgrIP").toString();
- QString tutorIP = conf->value("tutorIP").toString();
-
- QSize gridSize;
- QSize clientSize(1, 1);
- /* read some other properties of the room */
- if (conf->contains("gridSize")) {
- gridSize = conf->value("gridSize").toSize();
- }
- if (conf->contains("clientSize")) {
- clientSize = conf->value("clientSize").toSize();
- }
-
- foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) {
- if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString()) {
- qDebug("Found this ip in config.");
- myRoom = roomName;
- }
- }
- conf->endGroup();
-
- if (!gridSize.isValid()) {
- /* ok, let's choose the minimum gridSize to fit all clients */
- gridSize = minimalGridSize(clientPositions, clientSize);
- qDebug() << "had to use minimalGridSize(): = " << gridSize;
-
- }
- Room* r = new Room(clientPositions, gridSize, clientSize, image, tutorIP);
- qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
- roomsList.insert(roomName, r);
- }
- serverApp->setRooms(roomsList);
- if (myRoom == "") {
- /* so apparently this is not a manager of a room */
- if (serverApp->isManagerOnly()) {
- cout << "exiting because of the argument --manager-only was set and this computer is not a manager" << endl;
- exit(0);
- }
- } else {
- switchRoomTo(myRoom);
- }
-
-}
-
/***************************************************************************//**
* Returns connected client which belongs to given id.
* Iterating over ConnectionFrames and comparing id to given id.
@@ -821,55 +720,55 @@ void MainWindow::onReloadRoomCancel()
_reloadWindow->hide();
}
-void MainWindow::switchRoomTo(QString roomToReload)
+void MainWindow::reloadCurrentRoom()
{
- // qDebug() << roomToReload;
- serverApp->setCurrentRoom(roomToReload);
- Room *room = serverApp->getRooms()[roomToReload];
- /* set tiles */
- _tilesX = room->gridSize.width();
- _tilesY = room->gridSize.height();
-
-
- /* place connection frames */
- for (auto it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) {
- QString computerId = it.key();
- QPoint pos = it.value();
- QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
-
- ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
- cf->move(cf->getCurrentPosition());
- onPlaceFrame(false, cf);
- if (computerId == room->tutorIP) {
- qDebug() << "set computer with id " << computerId << " as tutor per configuration";
- if (getTutorFrame() != NULL) {
- getTutorFrame()->setTutor(false);
- }
- cf->setTutor(true);
- }
- }
-
- /* load background image */
- QString imgPath = serverApp->getCurrentRoom()->imagePath;
- qDebug() << "imgPath is " << imgPath;
-
/* delete old image */
if (_backgroundImage != NULL) {delete _backgroundImage; }
_backgroundImage = NULL;
- if (imgPath != "") {
- qDebug() << "set background image path: " << imgPath;
- if (imgPath.endsWith("svg")) {
- /* render once with maximal screen size */
- const QSize &s = QApplication::desktop()->screenGeometry().size(); // ui->frmRoom->geometry().size();
- QSvgRenderer renderer(imgPath);
- _backgroundImage = new QImage(s, QImage::Format_ARGB32);
- _backgroundImage->fill(Qt::lightGray); /* background color */
- QPainter painter(_backgroundImage);
- renderer.render(&painter);
- } else {
- _backgroundImage = new QImage();
- _backgroundImage->load(imgPath);
+ const Room *room = serverApp->getCurrentRoom();
+ if (room != NULL) {
+ /* set tiles */
+ _tilesX = room->gridSize.width();
+ _tilesY = room->gridSize.height();
+
+
+ /* place connection frames */
+ for (auto it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) {
+ QString computerId = it.key();
+ QPoint pos = it.value();
+ QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
+
+ ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
+ cf->move(cf->getCurrentPosition());
+ onPlaceFrame(false, cf);
+ if (computerId == room->tutorIP) {
+ qDebug() << "set computer with id " << computerId << " as tutor per configuration";
+ if (getTutorFrame() != NULL) {
+ getTutorFrame()->setTutor(false);
+ }
+ cf->setTutor(true);
+ }
+ }
+
+ /* load background image */
+ QString imgPath = room->imagePath;
+ qDebug() << "imgPath is " << imgPath;
+
+ if (imgPath != "") {
+ qDebug() << "set background image path: " << imgPath;
+ if (imgPath.endsWith("svg")) {
+ /* render once with maximal screen size */
+ const QSize &s = QApplication::desktop()->screenGeometry().size(); // ui->frmRoom->geometry().size();
+ QSvgRenderer renderer(imgPath);
+ _backgroundImage = new QImage(s, QImage::Format_ARGB32);
+ _backgroundImage->fill(Qt::lightGray); /* background color */
+ QPainter painter(_backgroundImage);
+ renderer.render(&painter);
+ } else {
+ _backgroundImage = new QImage();
+ _backgroundImage->load(imgPath);
+ }
}
}
@@ -898,7 +797,8 @@ void MainWindow::onReloadRoomOk()
// Load new room configuration.
QString roomToReload = _reloadWindow->ui->roomList->currentItem()->data(0).toString();
- switchRoomTo(roomToReload);
+ serverApp->setCurrentRoom(roomToReload);
+ reloadCurrentRoom();
_reloadWindow->ui->roomList->clear();
_reloadWindow->hide();
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 5ecda61..b0ad498 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -81,7 +81,6 @@ private:
void savePosition(ConnectionFrame *cf);
void startVncServerIfNecessary(int from);
void tellClientCurrentSituation(Client* client);
- void tryToUseRoomTemplate();
void reset();
Client* getClientFromId(int id);
ConnectionFrame* getTutorFrame();
@@ -98,7 +97,7 @@ private:
void lockContextButtons();
void unlockContextButtons();
- void switchRoomTo(QString);
+ void reloadCurrentRoom();
protected slots:
void onSessionNameClick();
diff --git a/src/server/serverapp/serverapp.cpp b/src/server/serverapp/serverapp.cpp
index c645b39..3df996c 100644
--- a/src/server/serverapp/serverapp.cpp
+++ b/src/server/serverapp/serverapp.cpp
@@ -1,8 +1,10 @@
#include <QTranslator>
-
+#include <QNetworkInterface>
#include "serverapp.h"
+static QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize);
+
ServerApp::ServerApp(int& argc, char** argv)
: QApplication(argc, argv),
_mainWindow(NULL),
@@ -15,6 +17,15 @@ ServerApp::ServerApp(int& argc, char** argv)
_arguments = parseParameters();
+ loadRooms();
+
+ // If started in manager-only mode, and there is no current room
+ // after reading the config, exit right away
+ if (_managerOnly && _currentRoom == "") {
+ ::exit(0);
+ return;
+ }
+
// System strings
QTranslator *qtTranslator = new QTranslator(this);
qtTranslator->load("qt_" + QLocale::system().name(),
@@ -56,6 +67,68 @@ QStringList ServerApp::arguments()
return _arguments;
}
+void ServerApp::loadRooms()
+{
+ QSharedPointer<QSettings> conf = getSettings();
+
+ if (!conf->contains("rooms")) { qDebug() << "Invalid config file (no rooms are set)!"; return; }
+ QStringList rooms = conf->value("rooms").toStringList();
+
+ for (QString roomId : rooms) {
+ conf->beginGroup(roomId);
+ QString roomName = conf->value("name").toString();
+
+ /* fallback to the old format where the room id was actually just the name */
+ if (roomName == "") {
+ roomName = roomId;
+ }
+ if (!conf->contains("mgrIP")) {
+ qDebug() << "Warning: Incomplete config file (room " << roomName << " needs a mgrIP)!";
+ }
+ QMap<QString, QPoint> clientPositions;
+ // First store all room configurations in _rooms.
+ int size = conf->beginReadArray("client");
+ for (int j = 0; j < size; j++) {
+ conf->setArrayIndex(j);
+ clientPositions.insert(conf->value("ip").toString(), conf->value("pos").toPoint());
+ }
+ conf->endArray();
+
+ /* read backgroundImage */
+ QString image = conf->contains("backgroundImage") ? conf->value("backgroundImage").toString() : "";
+ QString mgrIP = conf->value("mgrIP").toString();
+ QString tutorIP = conf->value("tutorIP").toString();
+
+ QSize gridSize;
+ QSize clientSize(1, 1);
+ /* read some other properties of the room */
+ if (conf->contains("gridSize")) {
+ gridSize = conf->value("gridSize").toSize();
+ }
+ if (conf->contains("clientSize")) {
+ clientSize = conf->value("clientSize").toSize();
+ }
+
+ foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) {
+ if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString()) {
+ qDebug("Found this ip in config.");
+ _currentRoom = roomName;
+ }
+ }
+ conf->endGroup();
+
+ if (!gridSize.isValid()) {
+ /* ok, let's choose the minimum gridSize to fit all clients */
+ gridSize = minimalGridSize(clientPositions, clientSize);
+ qDebug() << "had to use minimalGridSize(): = " << gridSize;
+
+ }
+ Room* r = new Room(clientPositions, gridSize, clientSize, image, tutorIP);
+ qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
+ _rooms.insert(roomName, r);
+ }
+}
+
const Room* ServerApp::getCurrentRoom()
{
if (_rooms.contains(_currentRoom)) {
@@ -96,3 +169,23 @@ QSharedPointer<QSettings> ServerApp::getSettings()
return set;
}
+/**
+ * returns the minimal grid size such that all clients fit on the grid
+ **/
+static QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize)
+{
+ /* collect the maximum coordinates */
+ int x = 0;
+ int y = 0;
+
+ for (auto it = clientPositions.begin(); it != clientPositions.end(); ++it) {
+ QPoint pos = it.value();
+ if (pos.x() > x) { x = pos.x(); }
+ if (pos.y() > y) { y = pos.y(); }
+
+ }
+ /* need a little extra space */
+ QSize size(x + clientSize.width(), y + clientSize.height());
+ return size;
+}
+
diff --git a/src/server/serverapp/serverapp.h b/src/server/serverapp/serverapp.h
index a03b2e3..e0a1351 100644
--- a/src/server/serverapp/serverapp.h
+++ b/src/server/serverapp/serverapp.h
@@ -42,7 +42,6 @@ class ServerApp : public QApplication
private:
QStringList _arguments;
- QStringList parseParameters();
MainWindow* _mainWindow;
QString _sessionName;
@@ -54,6 +53,9 @@ private:
bool _isExam;
QString _iniPath;
+ QStringList parseParameters();
+ void loadRooms();
+
public:
ServerApp(int& argc, char** argv);
@@ -70,18 +72,15 @@ public:
bool isExam() { return _isExam; }
bool isManagerOnly() { return _managerOnly; }
const Room* getCurrentRoom();
+ QSharedPointer<QSettings> getSettings();
/* setters */
void setSessionName(const QString& name);
void setSessionName();
- void setRooms(const QMap<QString, Room*> & roomList) { _rooms = roomList; }
void setIniPath(QString s) { _iniPath = s; };
void setCurrentRoom(const QString& room) { _currentRoom = room; }
void setExam(bool exam) { _isExam = exam; }
- QSharedPointer<QSettings> getSettings();
-
-
};
#endif