summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-05-19 16:38:34 +0200
committerChristian Klinger2016-05-19 16:38:34 +0200
commit2d6c50f2a764a3e5f171ef5e55423e6afbdf5c93 (patch)
tree93b4d679b653f1bf4b1e7c2b9e78c63780ffd275 /src/server/mainwindow/mainwindow.cpp
parentMerge branch 'bugfix/segfault-clientsize' (diff)
downloadpvs2-2d6c50f2a764a3e5f171ef5e55423e6afbdf5c93.tar.gz
pvs2-2d6c50f2a764a3e5f171ef5e55423e6afbdf5c93.tar.xz
pvs2-2d6c50f2a764a3e5f171ef5e55423e6afbdf5c93.zip
This fixes #2813.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp119
1 files changed, 51 insertions, 68 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 453c8e0..6d8d02f 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -378,6 +378,8 @@ void MainWindow::tryToUseRoomTemplate()
QStringList rooms = conf.value("rooms").toStringList();
qDebug() << rooms;
+ QString myRoom = "";
+
for (QString roomName : rooms)
{
conf.beginGroup(roomName);
@@ -412,35 +414,10 @@ void MainWindow::tryToUseRoomTemplate()
clientSize = conf.value("clientSize").toSize();
}
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
- {
- if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString())
- {
+ foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
+ if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString()) {
qDebug("Found this ip in config.");
- Global::setCurrentRoom(roomName);
- int size = conf.beginReadArray("client");
- for (int j = 0; j < size; ++j) {
- conf.setArrayIndex(j);
-
- /*
- *
- * CFG to test this
- * http://git.openslx.org/tm-scripts.git/plain/server/modules/pvs2-freiburg/opt/openslx/pvs2.ini
- *
- */
-
- // Add the frame
- // Position is given in grid coordinates, createFrame take pixels
- QString computerId = conf.value("ip").toString();
- QPoint gridPosition = conf.value("pos").toPoint();
-
- QPoint pxCoord(gridPosition.x() * getTileWidthPx(), gridPosition.y() * getTileHeightPx());
-
- ConnectionFrame *cf = createFrame(computerId, pxCoord, gridPosition);
- cf->move(cf->getCurrentPosition());
- onPlaceFrame(false, cf);
- }
- conf.endArray();
+ myRoom = roomName;
}
}
conf.endGroup();
@@ -456,6 +433,9 @@ void MainWindow::tryToUseRoomTemplate()
roomsList.insert(roomName, r);
}
Global::setRooms(roomsList);
+ if (myRoom != "") {
+ switchRoomTo(myRoom);
+ }
}
/***************************************************************************//**
@@ -845,6 +825,48 @@ void MainWindow::onReloadRoomCancel()
_reloadWindow->hide();
}
+void MainWindow::switchRoomTo(QString roomToReload) {
+ // qDebug() << roomToReload;
+ Global::setCurrentRoom(roomToReload);
+ Room *room = Global::getRooms()[roomToReload];
+ /* set tiles */
+ _tilesX = room->gridSize.width();
+ _tilesY = room->gridSize.height();
+
+
+ /* place connection frames */
+ for (QMap<QString, QPoint>::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it)
+ {
+ QString computerId = it.key();
+ QPoint pos = it.value();
+
+ /* Transform to pixels for createFrame(computerId, position).*/
+ QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
+
+ ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
+ cf->move(cf->getCurrentPosition());
+ onPlaceFrame(false, cf);
+ }
+
+ /* load background image */
+ QString imgPath = Global::getCurrentRoom()->imagePath;
+ qDebug() << "imgPath is " << imgPath;
+ if (imgPath == "") {
+ /* set empty pixmap*/
+ QPixmap empty;
+ ui->imageLabel->setPixmap(empty);
+ } else {
+ qDebug() << "set background image path: " << imgPath;
+ QImage backgroundImage;
+ backgroundImage.load(imgPath);
+ ui->imageLabel->setPixmap(QPixmap::fromImage(backgroundImage));
+ ui->imageLabel->setScaledContents(true);
+ }
+
+ /* and force a resize event (this scales the image) */
+ resizeEvent(NULL);
+}
+
void MainWindow::onReloadRoomOk()
{
if (_reloadWindow->ui->roomList->currentItem() == NULL)
@@ -868,50 +890,11 @@ void MainWindow::onReloadRoomOk()
// Load new room configuration.
QString roomToReload = _reloadWindow->ui->roomList->currentItem()->data(0).toString();
- // qDebug() << roomToReload;
- Global::setCurrentRoom(roomToReload);
+ switchRoomTo(roomToReload);
_reloadWindow->ui->roomList->clear();
_reloadWindow->hide();
-
- Room *room = Global::getRooms()[roomToReload];
- /* set tiles */
- _tilesX = room->gridSize.width();
- _tilesY = room->gridSize.height();
-
-
- /* place connection frames */
- for (QMap<QString, QPoint>::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it)
- {
- QString computerId = it.key();
- QPoint pos = it.value();
-
- /* Transform to pixels for createFrame(computerId, position).*/
- QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
-
- ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
- cf->move(cf->getCurrentPosition());
- onPlaceFrame(false, cf);
- }
-
- /* load background image */
- QString imgPath = Global::getCurrentRoom()->imagePath;
- if (imgPath == "") {
- /* set empty pixmap*/
- QPixmap empty;
- ui->imageLabel->setPixmap(empty);
- } else {
- qDebug() << "set background image path: " << imgPath;
- QImage backgroundImage;
- backgroundImage.load(imgPath);
- ui->imageLabel->setPixmap(QPixmap::fromImage(backgroundImage));
- ui->imageLabel->setScaledContents(true);
- }
-
- /* and force a resize event (this scales the image) */
- resizeEvent(NULL);
-
}
}