From b2ba47cde2cb63163831f013947fa1edb4a29c8b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 15 Nov 2018 12:26:13 +0100 Subject: [server] Fix adding/removing students to active projection VNC server/client was not always properly started or stopped when adding/removing students to currently running projection with tutor as source. --- src/server/mainwindow/mainwindow.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index ec69a4c..0abfdff 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -893,22 +893,38 @@ void MainWindow::onButtonTutorToStudent() else if (getTutorFrame()->client() == nullptr) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else { + auto sourceClient = getTutorFrame()->client(); + auto destinationClient = getSelectedFrame()->client(); // If this is the first call in this mode clear the watchers if (_mode != Mode::Multicast) { - for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != nullptr) - (*it)->client()->setDesiredProjectionSource(NO_SOURCE); + for (auto c : _clientFrames) { + if (c->client() != nullptr) { + c->client()->stopVncClient(); + } + } } // If "to" already watches "from" stop it - if (getSelectedFrame()->client()->desiredProjectionSource() == getTutorFrame()->client()->id() ) - getSelectedFrame()->client()->setDesiredProjectionSource(NO_SOURCE); - else - getSelectedFrame()->client()->setDesiredProjectionSource(getTutorFrame()->client()->id()); + if (destinationClient->desiredProjectionSource() == sourceClient->id() ) { + destinationClient->stopVncClient(); + } else { + destinationClient->setDesiredProjectionSource(sourceClient->id()); + } disableButtons(); - _mode = Mode::Multicast; - startVncServerIfNecessary(getTutorFrame()->client()->id()); + int numClients = 0; + for (auto c : _clientFrames) { + if (c->client() != nullptr && c->client()->desiredProjectionSource() == sourceClient->id()) { + numClients++; + } + } + if (numClients == 0) { + _mode = Mode::None; + sourceClient->stopVncServer(); + } else { + _mode = Mode::Multicast; + startVncServerIfNecessary(sourceClient->id()); + } } } -- cgit v1.2.3-55-g7522