diff options
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
| -rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 177 |
1 files changed, 143 insertions, 34 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 55e4bce..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(); @@ -98,6 +102,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : connect(ui->action_SetAsTutor, SIGNAL(triggered()), this, SLOT(onButtonStopProjection())); connect(ui->action_Lock, SIGNAL(toggled(bool)), this, SLOT(onButtonLock(bool))); connect(ui->action_Help, SIGNAL(triggered()), this, SLOT(onButtonHelp())); + connect(ui->actionReload_Room_Configuration, SIGNAL(triggered()), this, SLOT(onButtonReloadRoomConfig())); /* Stuff for the button lock */ //Setup a timeout @@ -129,7 +134,9 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _discoveryListener = new DiscoveryListener(); // Finally -// this->onSessionNameUpdate(); + _countSessionNameUpdate = 0; + this->onSessionNameUpdate(); // Just make lable visible. + _countSessionNameUpdate = 0; _tileWidth = ui->frmRoom->size().width() / _tilesX; _tileHeight = ui->frmRoom->size().height() / _tilesY; @@ -209,7 +216,7 @@ ConnectionFrame* MainWindow::createFrame() ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, _tileWidth, _tileHeight); _clientFrames.append(cf); cf->show(); - connect(cf, SIGNAL(frameMoved(ConnectionFrame *)), this, SLOT(onPlaceFrame(ConnectionFrame *))); + connect(cf, SIGNAL(frameMoved(bool, ConnectionFrame *)), this, SLOT(onPlaceFrame(bool, ConnectionFrame *))); connect(cf, SIGNAL(clicked(ConnectionFrame *)), this, SLOT(onFrameClicked(ConnectionFrame *))); return cf; } @@ -228,7 +235,7 @@ ConnectionFrame* MainWindow::createFrame(QString computerId, QPoint position) cf->setCurrentPosition(position); _clientFrames.append(cf); cf->show(); - connect(cf, SIGNAL(frameMoved(ConnectionFrame *)), this, SLOT(onPlaceFrame(ConnectionFrame *))); + connect(cf, SIGNAL(frameMoved(bool, ConnectionFrame *)), this, SLOT(onPlaceFrame(bool, ConnectionFrame *))); connect(cf, SIGNAL(clicked(ConnectionFrame *)), this, SLOT(onFrameClicked(ConnectionFrame *))); return cf; } @@ -309,12 +316,23 @@ void MainWindow::tryToUseRoomTemplate() for (auto i : rooms) { + 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()) { @@ -322,8 +340,8 @@ void MainWindow::tryToUseRoomTemplate() { qDebug("Found this ip in config."); int size = conf.beginReadArray("client"); - for (int i = 0; i < size; ++i) { - conf.setArrayIndex(i); + for (int j = 0; j < size; ++j) { + conf.setArrayIndex(j); /* * @@ -334,8 +352,9 @@ void MainWindow::tryToUseRoomTemplate() // Add the frame // Position is given in grid coordinates, createFrame take pixels - qDebug() << conf.value("ip").toString(); + QString computerId = conf.value("ip").toString(); QPoint coord = conf.value("pos").toPoint(); + qDebug() << computerId; qDebug() << coord; qDebug() << _tileWidth ; qDebug() << _tileHeight ; @@ -344,9 +363,9 @@ void MainWindow::tryToUseRoomTemplate() coord.setY(coord.y() * _tileHeight); qDebug() << coord ; - ConnectionFrame *cf = createFrame(conf.value("ip").toString(), coord); + ConnectionFrame *cf = createFrame(computerId, coord); cf->move(cf->getCurrentPosition()); - onPlaceFrame(cf); + onPlaceFrame(false, cf); } conf.endArray(); } @@ -525,7 +544,7 @@ void MainWindow::onTutorListDownloaded(QByteArray& tutorList) * Place Frame to from user specified position. * @param frame */ -void MainWindow::onPlaceFrame(ConnectionFrame* frame) +void MainWindow::onPlaceFrame(bool activateTrash, ConnectionFrame* frame) { if (_tilesX <= 0 || _tilesY <= 0) return; @@ -542,31 +561,34 @@ void MainWindow::onPlaceFrame(ConnectionFrame* frame) else if (y > s.height() - _tileHeight) y = (_tilesY - 1) * _tileHeight; - const QRect &trashCenter = ui->trash->geometry(); - // Check if x coordinate is in trash position. - if (trashCenter.contains(p)) + // Check if x coordinate is in trash position. Check only if activateTrash = true! + if (activateTrash) { - // Do not offer deleting online client. - if (frame->client() != NULL) - { - QMessageBox::critical(this, tr("Selection"), sStrClientOnline); - frame->move(frame->getPreviousPosition()); - return; - } - else + const QRect &trashCenter = ui->trash->geometry(); + if (trashCenter.contains(p)) { - int ret = QMessageBox::question(this, "Warning", "Sure, You want to delete selected client?", 0, 1, 2); - if (ret == 1) + // Do not offer deleting online client. + if (frame->client() != NULL) { - frame->hide(); - frame->deleteLater(); - _clientFrames.removeOne(frame); + QMessageBox::critical(this, tr("Selection"), sStrClientOnline); + frame->move(frame->getPreviousPosition()); return; } else { - frame->move(frame->getPreviousPosition()); - return; + int ret = QMessageBox::question(this, "Warning", "Sure, You want to delete selected client?", 0, 1, 2); + if (ret == 1) + { + frame->hide(); + frame->deleteLater(); + _clientFrames.removeOne(frame); + return; + } + else + { + frame->move(frame->getPreviousPosition()); + return; + } } } } @@ -611,7 +633,18 @@ void MainWindow::onFrameClicked(ConnectionFrame* frame) */ void MainWindow::onSessionNameClick() { - _sessionNameWindow->show(Global::sessionName()); + _countSessionNameUpdate++; + if (_countSessionNameUpdate > 1) + { + int ret = QMessageBox::question(this, "Warning", "Sure, You want to change SessionName again?\n" + "All Clients will be deleted afterwards.", 0, 1, 2); + if (ret == 1) + { + _sessionNameWindow->show(Global::sessionName()); + } + } + else + _sessionNameWindow->show((Global::sessionName())); } /***************************************************************************//** @@ -621,12 +654,17 @@ void MainWindow::onSessionNameUpdate() { // Stop all projections and clear all clients, which where connected to old sessionName. reset(); - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) + if (_countSessionNameUpdate > 1) { - (*it)->hide(); - (*it)->deleteLater(); + { + for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) + { + (*it)->hide(); + (*it)->deleteLater(); + } + _clientFrames.clear(); + } } - _clientFrames.clear(); _sessionNameLabel->setText(tr("Session Name: %1 [click to edit]").arg(Global::sessionName())); } @@ -655,6 +693,71 @@ 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<QString> keyList = _rooms.keys(); + for (QList<QString>::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<ConnectionFrame*>::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<QPair<QString, QPoint>> room = _rooms[roomToReload]; + // qDebug() << " Room: " << room; + // qDebug() << "_rooms: " << _rooms; + for (QList<QPair<QString, QPoint>>::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. */ @@ -969,8 +1072,13 @@ void MainWindow::onClientAuthenticated(Client* client) ConnectionFrame *existing = NULL; for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { + // qDebug() << "Existing frame ip: " << (*it)->computerId(); + // qDebug() << "New Clients ip: " << client->ip(); + // qDebug() << ((*it)->computerId() == client->ip()); if ((*it)->computerId() == client->ip()) + { existing = *it; + } if ((*it)->isTutor()) { if ((*it)->client() != NULL) @@ -994,6 +1102,7 @@ void MainWindow::onClientAuthenticated(Client* client) // Clients ip already exists, but was not active. if (existing != NULL) { + // qDebug() << "Should go into this if clause."; existing->setTutor(isTutor); existing->assignClient(client); tellClientCurrentSituation(client); @@ -1027,7 +1136,7 @@ void MainWindow::onClientAuthenticated(Client* client) y = 0; qDebug("Move E"); cf->move(x * _tileWidth, y * _tileHeight); - onPlaceFrame(cf); + onPlaceFrame(true, cf); } else { |
