summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2018-08-01 14:38:42 +0200
committerSimon Rettberg2018-08-01 14:38:42 +0200
commitfa4c4e6f8a71f9f18352623b80dda868395a5b83 (patch)
treef5daba7c06551f7998dd4d7eefd8052d077f2389 /src/server/mainwindow/mainwindow.cpp
parent[SERVER] Fix locking when locked unicast is current mode (diff)
downloadpvs2-fa4c4e6f8a71f9f18352623b80dda868395a5b83.tar.gz
pvs2-fa4c4e6f8a71f9f18352623b80dda868395a5b83.tar.xz
pvs2-fa4c4e6f8a71f9f18352623b80dda868395a5b83.zip
[server] Deduplicate code for student -> tutor streaming
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp93
1 files changed, 40 insertions, 53 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 62e15d2..a74e449 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -925,83 +925,70 @@ void MainWindow::onButtonTutorToStudent()
/***************************************************************************//**
* Handle projection from one student to tutor.
- * Get the client to project from and get client, who is tutor, as to.
*/
void MainWindow::onButtonStudentToTutor()
{
- ui->action_Lock->setChecked(false);
-
- if (getSelectedFrame() == nullptr)
- QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
- else if (getTutorFrame() == nullptr)
- QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (getTutorFrame() == getSelectedFrame())
- QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
- else if (getSelectedFrame()->client() == nullptr)
- QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
- else if (getTutorFrame()->client() == nullptr)
- QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else {
- // If this is not the first run in this mode and the current source is selected, stop the streaming.
- if (_mode == Mode::Unicast && getSelectedFrame()->client()->id() == _streamingSource) {
- // Stop reset everything
- _mode = Mode::None;
- reset();
- return;
- }
-
- // Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- if ((*it)->client() != nullptr)
- (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id() : NO_SOURCE);
-
- disableButtons();
- _mode = Mode::Unicast;
- startVncServerIfNecessary(getSelectedFrame()->client()->id());
- }
+ this->vncOneOnOne(false);
}
/***************************************************************************//**
- * @brief MainWindow::onButtonStudentToTutorExclusive
+ * Handle projection from one student to tutor, lock everyone else.
*/
void MainWindow::onButtonStudentToTutorExclusive()
{
- ui->action_Lock->setChecked(false);
+ this->vncOneOnOne(true);
+}
- if (getSelectedFrame() == nullptr)
+void MainWindow::vncOneOnOne(bool exclusive)
+{
+ if (getSelectedFrame() == nullptr) {
QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
- else if (getTutorFrame() == nullptr)
+ } else if (getTutorFrame() == nullptr) {
QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (getTutorFrame() == getSelectedFrame())
+ } else if (getTutorFrame() == getSelectedFrame()) {
QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
- else if (getSelectedFrame()->client() == nullptr)
+ } else if (getSelectedFrame()->client() == nullptr) {
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
- else if (getTutorFrame()->client() == nullptr)
+ } else if (getTutorFrame()->client() == nullptr) {
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else {
- Client *selectedClient = getSelectedFrame()->client();
- Client *tutorClient = getTutorFrame()->client();
- // If this is not the first run in this mode and the current source is selected, stop the streaming.
- if ((_mode == Mode::Unicast || _mode == Mode::LockedUnicast) && selectedClient->id() == _streamingSource) {
- // Stop reset everything
- _mode = Mode::None;
+ } else {
+ const bool wasLocked = ui->action_Lock->isChecked();
+ ui->action_Lock->setChecked(false);
+ Client *source = getSelectedFrame()->client();
+ Client *dest = getTutorFrame()->client();
+ const Mode mode = exclusive ? Mode::LockedUnicast : Mode::Unicast;
+
+ if (_mode == mode && source->id() == dest->desiredProjectionSource()) {
+ // Button clicked again with same selection, treat this as reset
reset();
return;
}
- // Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- if ((*it)->client() != nullptr)
- (*it)->client()->setDesiredProjectionSource(tutorClient->id() == (*it)->client()->id() ? selectedClient->id() : NO_SOURCE);
-
+ for (ConnectionFrame* f : _clientFrames) {
+ if (f->client() == nullptr) // Disconnected frame
+ continue;
+ if (source != f->client() && dest != f->client()) { //Not source or destination
+ f->client()->setDesiredProjectionSource(NO_SOURCE);
+ if (_mode == Mode::Unicast) { // Already in unlocked unicast mode
+ if (exclusive) { // Only change lock state (to locked) if switching to locked unicast
+ f->client()->lockScreen(true); // (don't change otherwise, would reset individually locked clients)
+ }
+ } else if (wasLocked) { // Was in "lock all" mode, update lock mode for everyone
+ f->client()->lockScreen(exclusive);
+ }
+ }
+ }
+ dest->lockScreen(false);
+ source->lockScreen(false);
+ dest->setDesiredProjectionSource(source->id());
+ source->setDesiredProjectionSource(NO_SOURCE);
disableButtons();
- _mode = Mode::LockedUnicast;
- startVncServerIfNecessary(selectedClient->id());
+ _mode = mode;
+ startVncServerIfNecessary(source->id());
}
}
-
/***************************************************************************//**
* Handle Button StopProjection.
* Set ProjectionSource of each client to false, stop the active VNC Server