diff options
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 34 |
1 files 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<ConnectionFrame*>::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()); + } } } |