From 07fba5a835228f95ff6eec8419c905e4586bb56d Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Mon, 25 Aug 2014 14:57:41 +0200 Subject: New Feature: Button for reloading room configuration of choosable room. --- src/server/mainwindow/mainwindow.cpp | 82 +++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 7c9d210..17e821a 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -24,6 +24,8 @@ #include "../sessionnamewindow/sessionnamewindow.h" #include "../connectionframe/connectionframe.h" #include "../helpwindow/helpwindow.h" +#include "../reloadroomwindow/reloadroomwindow.h" +#include "ui_reloadroom.h" // Network #include "../net/listenserver.h" #include "../net/client.h" @@ -61,6 +63,8 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _sessionNameWindow = new SessionNameWindow(this); _helpWindow = new HelpWindow(this); _helpWindow->setWindowTitle("Help"); + _reloadWindow = new ReloadRoomWindow(this); + _reloadWindow->setWindowTitle("Reload Room"); ui->setupUi(this); Global::setSessionName(); @@ -312,16 +316,23 @@ void MainWindow::tryToUseRoomTemplate() for (auto i : rooms) { - if (!_rooms.contains(i)) { - QList> posIpConfig; - _rooms.insert(i, posIpConfig); - } + qDebug() << "i: " << i; conf.beginGroup(i); if (!conf.contains("mgrIP")) { qDebug() << "Invalid config file!"; return; } - // Find the room that list the ip of this host as mgr + + // First store all room configurations in _rooms. + int size = conf.beginReadArray("client"); + for (int j = 0; j < size; j++) { + conf.setArrayIndex(j); + // qDebug() << "ip: " << conf.value("ip").toString() << " pos: " << conf.value("pos").toPoint(); + _rooms[i].append(qMakePair(conf.value("ip").toString(), conf.value("pos").toPoint())); + } + conf.endArray(); + + // Find the managerIP of current room. QString mgrIP = conf.value("mgrIP").toString(); foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { @@ -343,7 +354,6 @@ void MainWindow::tryToUseRoomTemplate() // Position is given in grid coordinates, createFrame take pixels QString computerId = conf.value("ip").toString(); QPoint coord = conf.value("pos").toPoint(); - _rooms[i].append(qMakePair(computerId, coord)); qDebug() << computerId; qDebug() << coord; qDebug() << _tileWidth ; @@ -685,9 +695,69 @@ void MainWindow::startVncServerIfNecessary(int from) void MainWindow::onButtonReloadRoomConfig() { + connect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk())); + connect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel())); + qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << _rooms.size(); + QList keyList = _rooms.keys(); + for (QList::iterator it = keyList.begin(); it != keyList.end() ; it++) { + _reloadWindow->ui->roomList->addItem(*it); + } _reloadWindow->show(); } +void MainWindow::onReloadRoomCancel() +{ + disconnect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk())); + disconnect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel())); + _reloadWindow->ui->roomList->clear(); + _reloadWindow->hide(); +} + +void MainWindow::onReloadRoomOk() +{ + int ret = QMessageBox::QMessageBox::question(this, "Warning", tr("Are you sure you want to reload the room?\n" + "Note that all clients will be deleted."), 0, 1, 2); + + if (ret == 1) { + disconnect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk())); + disconnect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel())); + // Delete all clients. + for (QList::iterator it = _clientFrames.begin(); it != _clientFrames.end(); it++) + { + (*it)->hide(); + (*it)->deleteLater(); + } + _clientFrames.clear(); + + // Load new room configuration. + QString roomToReload = _reloadWindow->ui->roomList->currentItem()->data(0).toString(); + // qDebug() << roomToReload; + + _reloadWindow->ui->roomList->clear(); + _reloadWindow->hide(); + + QList> room = _rooms[roomToReload]; + // qDebug() << " Room: " << room; + // qDebug() << "_rooms: " << _rooms; + for (QList>::iterator it = room.begin(); it != room.end(); ++it) + { + QString computerId = (*it).first; + QPoint pos = (*it).second; + + qDebug() << "ComputerID: " << computerId; + qDebug() << "Pos: " << pos; + + // Transform to pixels for createFrame(computerId, position). + pos.setX(pos.x() * _tileWidth); + pos.setY(pos.y() * _tileHeight); + + ConnectionFrame *cf = createFrame(computerId, pos); + cf->move(cf->getCurrentPosition()); + onPlaceFrame(false, cf); + } + } +} + /***************************************************************************//** * Display popup which explains possible actions about the buttons. */ -- cgit v1.2.3-55-g7522