summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-11-02 13:57:36 +0100
committerSimon Rettberg2016-11-02 13:57:36 +0100
commit1511f2ad55d5941e94af4accfb618b3245c158cd (patch)
tree20b6cc0326c7fe16b0a64f0474c0cc9f57ee9ae7 /src/server/mainwindow/mainwindow.cpp
parent[server] Show IP address in room layout right after loading it (diff)
downloadpvs2-1511f2ad55d5941e94af4accfb618b3245c158cd.tar.gz
pvs2-1511f2ad55d5941e94af4accfb618b3245c158cd.tar.xz
pvs2-1511f2ad55d5941e94af4accfb618b3245c158cd.zip
[server] Run "manager only" logic before creating main window
This prevents the window popping up for a split second when --manager-only is given and the machine it's running on is not configured as a manager.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp194
1 files changed, 47 insertions, 147 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();