summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-08-01 14:38:42 +0200
committerSimon Rettberg2018-08-01 14:38:42 +0200
commitfa4c4e6f8a71f9f18352623b80dda868395a5b83 (patch)
treef5daba7c06551f7998dd4d7eefd8052d077f2389
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
-rw-r--r--src/server/mainwindow/mainwindow.cpp93
-rw-r--r--src/server/mainwindow/mainwindow.h2
-rw-r--r--src/server/net/client.h20
3 files changed, 52 insertions, 63 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
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 43804a7..59d50fc 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -101,6 +101,8 @@ private:
void reloadCurrentRoom();
+ void vncOneOnOne(bool exclusive);
+
protected slots:
void disableButtons();
void enableButtons();
diff --git a/src/server/net/client.h b/src/server/net/client.h
index 32237bf..3d5158b 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -29,22 +29,22 @@ public:
~Client();
// Getters
- inline bool isAuthed() { return _authed == 2; }
+ inline bool isAuthed() const { return _authed == 2; }
inline const QString& name() const { return _name; }
inline const QString& host() const { return _host; }
inline const QString ip() const { return _socket->peerAddress().toString(); }
- inline int id() { return _id; }
- inline bool isActiveVncClient() { return _isActiveVncClient; }
- inline bool isActiveVncServer() { return _vncPort > 0; }
- inline bool isLocked() { return _locked; }
- inline int desiredProjectionSource() { return _desiredSource; }
- inline int projectionSource() { return _projectionSource; }
- inline int isExamMode() { return _isExamMode; }
- inline bool wantsAttention() { return _wantsAttention; }
+ inline int id() const { return _id; }
+ inline bool isActiveVncClient() const { return _isActiveVncClient; }
+ inline bool isActiveVncServer() const { return _vncPort > 0; }
+ inline bool isLocked() const { return _locked; }
+ inline int desiredProjectionSource() const { return _desiredSource; }
+ inline int projectionSource() const { return _projectionSource; }
+ inline int isExamMode() const { return _isExamMode; }
+ inline bool wantsAttention() const { return _wantsAttention; }
inline void removeAttention() { if (!_wantsAttention) return; removeAttentionInternal(); }
// Setters
- inline void setTutor(bool enable) { _isTutor = enable; }
+ inline void setTutor(bool enable) { _isTutor = enable; }
inline void setDesiredProjectionSource(int id) {_desiredSource = id;}
inline void setExamMode(bool mode) { _isExamMode = mode; }