summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorManuel Schneider2014-07-21 21:19:22 +0200
committerManuel Schneider2014-07-21 22:41:56 +0200
commit5f310d3e0147532d734135771bafcb51a2f501ad (patch)
tree1c385a581c220316d1d33b2fcd4f731574edf40c /src/server/mainwindow/mainwindow.cpp
parentMerge branch 'master' of git.openslx.org:pvs2 (diff)
downloadpvs2-5f310d3e0147532d734135771bafcb51a2f501ad.tar.gz
pvs2-5f310d3e0147532d734135771bafcb51a2f501ad.tar.xz
pvs2-5f310d3e0147532d734135771bafcb51a2f501ad.zip
Rename modes. Move code in slots to avoid unnecessary branching. Give the client more information about past progjectionSource
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp227
1 files changed, 153 insertions, 74 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index a52690f..c78f8de 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -270,7 +270,7 @@ void MainWindow::tellClientCurrentSituation(Client* client)
client->startVncClient(c);
}
}
- else if (_mode == Mode::LockedMulticast)
+ else if (_mode == Mode::LockedUnicast)
client->lockScreen(true);
}
@@ -412,6 +412,8 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e)
*/
void MainWindow::reset()
{
+ _mode = Mode::None;
+
// Unlock all clients
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
if ((*it)->client() != NULL)
@@ -549,72 +551,27 @@ void MainWindow::onSessionNameUpdate()
}
/***************************************************************************//**
- * @brief MainWindow::changeProjection
+ * @brief MainWindow::startVncServerIfNecessary
* @param from
- * @param mode
- * @param to
*/
-void MainWindow::changeProjection(Client *from, Mode mode, Client *to)
+void MainWindow::startVncServerIfNecessary(int from)
{
- DisableButtons();
-
- if (mode == Mode::Broadcast)
- {
- // Set all clients as watchers
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- if ((*it)->client() != NULL && (*it)->client() != getClientFromId(_streamingSource))
- {
- // _watchers.insert((*it)->client()->id(), (*it)->client());
- (*it)->client()->setWatcher(true);
- }
- }
- }
- else // mode != Mode::Broadcast
- {
- // If this is the first call in this mode clear the watchers
- if ((mode == Mode::LockedMulticast && _mode != Mode::LockedMulticast)
- || (mode == Mode::Multicast && _mode != Mode::Multicast))
- {
- // _watchers.clear();
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- if ((*it)->client() != NULL)
- (*it)->client()->setWatcher(false);
- }
- }
-
- // If "to" already watches "from" stop it
- // if (_watchers.contains(to->id()))
- if (getClientFromId(to->id())->isWatcher())
- {
- // _watchers.remove(to->id());
- getClientFromId(to->id())->setWatcher(false);
- }
- else // list "to" as watcher
- {
- // _watchers.insert(to->id(), to);
- getClientFromId(to->id())->setWatcher(true);
- }
- }
-
- // Set the mode
- _mode = mode;
+ Client* os = getClientFromId(_streamingSource);
+ Client* ns = getClientFromId(from);
// if there is a server running which is not "from" stop it.
- if (getClientFromId(_streamingSource) != NULL && getClientFromId(_streamingSource) != from)
- getClientFromId(_streamingSource)->stopVncServer();
+ if (os != NULL && _streamingSource != from)
+ os->stopVncServer();
- // Set new streaming source
- _streamingSource = from->id();
+ // Set new streaming source
+ _streamingSource = from;
- // If streaming source is already active avoid a restart
- Client* c = getClientFromId(_streamingSource);
- if (c != NULL) {
- if (c->isActiveVncServer())
- this->onVncServerStateChange(c);
+ // If streaming source is already active avoid a restart
+ if (ns != NULL) {
+ if (ns->isActiveVncServer())
+ this->onVncServerStateChange(ns);
else // Could not take shortcut, (re)start VNC server on source
- c->startVncServer();
+ ns->startVncServer();
}
}
@@ -641,8 +598,30 @@ void MainWindow::onButtonTutorToAll()
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else if (_clientFrames.size() == 1)
QMessageBox::critical(this, tr("Projection"), sStrNoDestAv);
- else
- changeProjection(getTutorFrame()->client(), Mode::Broadcast);
+ else
+ {
+ DisableButtons();
+
+ if (_mode != Mode::Broadcast)
+ {
+ // Set all clients as watchers
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ if ((*it)->client() != NULL && (*it)->client() != getClientFromId(_streamingSource))
+ (*it)->client()->setWatcher(true);
+ }
+ }
+ else // If this mode is already active
+ {
+ // Stop reset everything
+ reset();
+ _mode = Mode::None;
+ return;
+ }
+
+ _mode = Mode::Broadcast;
+ startVncServerIfNecessary(getTutorFrame()->client()->id());
+ }
}
/***************************************************************************//**
@@ -658,8 +637,30 @@ void MainWindow::onButtonStudentToAll()
QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
if (getSelectedFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
- else
- changeProjection(getSelectedFrame()->client(), Mode::Broadcast);
+ else
+ {
+ DisableButtons();
+
+ if (_mode != Mode::Broadcast)
+ {
+ // Set all clients as watchers
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ if ((*it)->client() != NULL && (*it)->client() != getClientFromId(_streamingSource))
+ (*it)->client()->setWatcher(true);
+ }
+ }
+ else // If this mode is already active
+ {
+ // Stop reset everything
+ reset();
+ _mode = Mode::None;
+ return;
+ }
+
+ _mode = Mode::Broadcast;
+ startVncServerIfNecessary(getSelectedFrame()->client()->id());
+ }
}
/***************************************************************************//**
@@ -680,8 +681,37 @@ void MainWindow::onButtonTutorToStudent()
QMessageBox::critical(this, tr("Projection"), sStrDestOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- changeProjection(getTutorFrame()->client(), Mode::Multicast, getSelectedFrame()->client());
+ else
+ {
+ DisableButtons();
+
+ // If this is the first call in this mode clear the watchers
+ if (_mode != Mode::Multicast)
+ {
+ // _watchers.clear();
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ if ((*it)->client() != NULL)
+ (*it)->client()->setWatcher(false);
+ }
+ }
+
+ // If "to" already watches "from" stop it
+ // if (_watchers.contains(to->id()))
+ if (getClientFromId(getSelectedFrame()->client()->id())->isWatcher())
+ {
+ // _watchers.remove(to->id());
+ getClientFromId(getSelectedFrame()->client()->id())->setWatcher(false);
+ }
+ else // list "to" as watcher
+ {
+ // _watchers.insert(to->id(), to);
+ getClientFromId(getSelectedFrame()->client()->id())->setWatcher(true);
+ }
+
+ _mode = Mode::Multicast;
+ startVncServerIfNecessary(getTutorFrame()->client()->id());
+ }
}
/***************************************************************************//**
@@ -702,8 +732,33 @@ void MainWindow::onButtonStudentToTutor()
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- changeProjection(getSelectedFrame()->client(), Mode::Multicast, getTutorFrame()->client());
+ else{
+ DisableButtons();
+
+ if (_mode != Mode::Unicast)
+ {
+ // If this is the first run in this mode set the tutor as watcher
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ if ((*it)->client() != NULL)
+ (*it)->client()->setWatcher(getTutorFrame()->client()->id() == (*it)->client()->id());
+ _mode = Mode::Unicast;
+ }
+ else
+ {
+ // If this mode is already active and the current source is selected, stop the streaming.
+ if (getSelectedFrame()->client()->id() == _streamingSource )
+ {
+ // Stop reset everything
+ _mode = Mode::None;
+ reset();
+ return;
+ }
+ // If another client is selected solely the current streaming source shall be changed.
+ // This should be handled by startVncServerIfNecessary(...).
+ }
+
+ startVncServerIfNecessary(getSelectedFrame()->client()->id());
+ }
}
@@ -724,8 +779,34 @@ void MainWindow::onButtonStudentToTutorExclusive()
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- changeProjection(getSelectedFrame()->client(), Mode::LockedMulticast, getTutorFrame()->client());
+ else
+ {
+ DisableButtons();
+
+ if (_mode != Mode::LockedUnicast)
+ {
+ // If this is the first run in this mode set the tutor as watcher
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ if ((*it)->client() != NULL)
+ (*it)->client()->setWatcher(getTutorFrame()->client()->id() == (*it)->client()->id());
+ _mode = Mode::LockedUnicast;
+ }
+ else
+ {
+ // If this mode is already active and the current source is selected, stop the streaming.
+ if (getSelectedFrame()->client()->id() == _streamingSource )
+ {
+ // Stop reset everything
+ _mode = Mode::None;
+ reset();
+ return;
+ }
+ // If another client is selected solely the current streaming source shall be changed.
+ // This should be handled by startVncServerIfNecessary(...).
+ }
+
+ startVncServerIfNecessary(getSelectedFrame()->client()->id());
+ }
}
@@ -1004,7 +1085,7 @@ void MainWindow::onVncServerStateChange(Client* client)
else
{
// Lock others and stop their clients
- (*it)->client()->lockScreen(_mode == Mode::LockedMulticast);
+ (*it)->client()->lockScreen(_mode == Mode::LockedUnicast);
(*it)->client()->stopVncClient();
}
}
@@ -1045,8 +1126,6 @@ void MainWindow::onVncClientStateChange(Client* client)
getClientFromId(client->id())->setWatcher(false);
// If noboody is watching the multicast stop VNC server
- // if (_watchers.isEmpty() && _mode != Mode::Broadcast)
- // _streamingSource->stopVncServer();
bool noWatchers = true;
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
{
@@ -1059,8 +1138,8 @@ void MainWindow::onVncClientStateChange(Client* client)
if (noWatchers && _mode != Mode::Broadcast)
{
Client* c = getClientFromId(_streamingSource);
- if (c != NULL)
- c->stopVncServer();
+ if (c != NULL)
+ c->stopVncServer();
}
}
}