diff options
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 123 |
1 files changed, 44 insertions, 79 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 35dbf0b..7279869 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -56,7 +56,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _tutorFrame = NULL; _selectedFrame = NULL; - _mode = Mode::Idle; + _mode = Mode::Multicast; _streamingSource = NULL; _sessionNameWindow = new SessionNameWindow(this); @@ -453,84 +453,50 @@ bool MainWindow::isValidClient(Client* client) return false; } - /***************************************************************************//** - * @brief broadcast - * @param from - */ -void MainWindow::broadcast(Client *from) -{ - _mode = Mode::Broadcast; - - // if there is a server running which is not "from" stop it. - if (_streamingSource != NULL && _streamingSource != from) - _streamingSource->stopVncServer(); - _streamingSource = from; - - // Server must not listen to anybody - _streamingSource->stopVncClient(); - - - // Set desired projection source on all clients, if not "from" or oflline - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL && (*it)->client() != _streamingSource) - _watchers.insert((*it)->client()->id(), (*it)->client()); - - if (_streamingSource->isActiveVncServer()) - // From is already active - this->onVncServerStateChange(_streamingSource); - else - // Could not take shortcut, start VNC server on source - _streamingSource->startVncServer(); -} - - -/***************************************************************************//** - * @brief MainWindow::unicast + * @brief MainWindow::changeProjection * @param from + * @param mode * @param to - * @param blockOthers */ -void MainWindow::multicast(Client *from, Client *to, bool blockOthers) +void MainWindow::changeProjection(Client *from, Mode mode, Client *to) { - // If first call in this mode clear the watchers - if (_mode != (blockOthers ? Mode::LockedMulticast : Mode::Multicast)) { - _watchers.clear(); - _mode = blockOthers ? Mode::LockedMulticast : Mode::Multicast; + 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() != _streamingSource) + _watchers.insert((*it)->client()->id(), (*it)->client()); + } + 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(); + + // If "to" already watches "from" stop it + if (_watchers.contains(to->id())) + _watchers.remove(to->id()); + else // list "to" as watcher + _watchers.insert(to->id(), to); } + // Set the mode + _mode = mode; + // if there is a server running which is not "from" stop it. if (_streamingSource != NULL && _streamingSource != from) _streamingSource->stopVncServer(); - _streamingSource = from; - - // Projection source is never allowed to be an active VNC viewer - if (from->isActiveVncClient()) - from->stopVncClient(); - // Projection destination is never allowed to be an active VNC server - if (to->isActiveVncServer()) - to->stopVncServer(); - - from->stopVncClient(); - _watchers.insert(to->id(), to); - - if (blockOthers) { - // Set lock others - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL && (*it)->client() != from && (*it)->client() != to) - (*it)->client()->lockScreen(true); - } + // Set new streaming source + _streamingSource = from; - if (from->isActiveVncServer()) // From is already active - this->onVncServerStateChange(from); + // If streaming source is already active avoid a restart + if (_streamingSource->isActiveVncServer()) + this->onVncServerStateChange(_streamingSource); else // Could not take shortcut, (re)start VNC server on source - from->startVncServer(); - - if (blockOthers){ - // TODO: REDESIGN TO FIT THE REQUIREMENTS - } - + _streamingSource->startVncServer(); } /***************************************************************************//** @@ -553,7 +519,7 @@ void MainWindow::onButtonTutorToAll() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - broadcast(_tutorFrame->client()); + changeProjection(_tutorFrame->client(), Mode::Broadcast); } /***************************************************************************//** @@ -568,7 +534,7 @@ void MainWindow::onButtonStudentToAll() if (_selectedFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrSourceOffline); else - broadcast(_selectedFrame->client()); + changeProjection(_selectedFrame->client(), Mode::Broadcast); } /***************************************************************************//** @@ -588,7 +554,7 @@ void MainWindow::onButtonTutorToStudent() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_tutorFrame->client(), _selectedFrame->client()); + changeProjection(_tutorFrame->client(), Mode::Multicast, _selectedFrame->client()); } /***************************************************************************//** @@ -608,7 +574,7 @@ void MainWindow::onButtonStudentToTutor() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_selectedFrame->client(), _tutorFrame->client()); + changeProjection(_selectedFrame->client(), Mode::Multicast, _tutorFrame->client()); } @@ -628,7 +594,7 @@ void MainWindow::onButtonStudentToTutorExclusive() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - multicast(_tutorFrame->client(), _selectedFrame->client(), true); + changeProjection(_tutorFrame->client(), Mode::LockedMulticast, _selectedFrame->client()); } @@ -639,15 +605,14 @@ void MainWindow::onButtonStudentToTutorExclusive() */ void MainWindow::onButtonStopProjection() { + // Unlock all clients for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL) - continue; - c->stopVncClient(); - c->stopVncServer(); - c->lockScreen(false); - } + if ((*it)->client() != NULL) + (*it)->client()->lockScreen(false); + + // Stop server (Clients get stopped on ACK) + if (_streamingSource != NULL) + _streamingSource->startVncServer(); } /***************************************************************************//** |