From 8611f238c6740e19dade61d3c71e7e80b5a3811c Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 27 May 2014 01:20:02 +0200 Subject: Use enums for modes since not all combinations of _broadcast and _lockOthers make sense. --- src/server/mainwindow/mainwindow.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 4c0a497..60623ea 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -56,8 +56,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _tutorFrame = NULL; _selectedFrame = NULL; - _broadcast = false; - _lockOthers = false; + _mode = Mode::Idle; _streamingSource = NULL; _sessionNameWindow = new SessionNameWindow(this); @@ -442,8 +441,7 @@ bool MainWindow::isValidClient(Client* client) */ void MainWindow::broadcast(Client *from) { - _broadcast = true; - _lockOthers = false; + _mode = Mode::Broadcast; // if there is a server running which is not "from" stop it. if (_streamingSource != NULL && _streamingSource != from) @@ -476,11 +474,11 @@ void MainWindow::broadcast(Client *from) */ void MainWindow::multicast(Client *from, Client *to, bool blockOthers) { - if (_broadcast) + // If first call in this mode clear the watchers + if (_mode != (blockOthers ? Mode::LockedMulticast : Mode::Multicast)) { _watchers.clear(); - - _broadcast = false; - _lockOthers = blockOthers; + _mode = blockOthers ? Mode::LockedMulticast : Mode::Multicast; + } // if there is a server running which is not "from" stop it. if (_streamingSource != NULL && _streamingSource != from) @@ -843,12 +841,13 @@ void MainWindow::onClientAuthenticated(Client* client) if (ui->action_Lock->isChecked()) client->lockScreen(true); - if (_broadcast){ + if (_mode == Mode::Broadcast){ _watchers.insert(client->id(), client); client->startVncClient(_streamingSource); - } else if (_lockOthers) - client->lockScreen(true); } + else if (_mode == Mode::LockedMulticast) + client->lockScreen(true); +} /***************************************************************************//** * Handle if VNC Server State has changed. @@ -862,7 +861,7 @@ void MainWindow::onVncServerStateChange(Client* client) return; if (client->isActiveVncServer()) { - if (_broadcast) + if (_mode == Mode::Broadcast) { for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { @@ -877,10 +876,13 @@ void MainWindow::onVncServerStateChange(Client* client) } } } - else // !_broadcast + else // !Mode::Broadcast --> Mode::LockedMC || Mode::MC { - for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if ( (*it)->client() != NULL) { + for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) + { + // Ignore offline clients + if ( (*it)->client() != NULL) + { if (_watchers.contains((*it)->client()->id())) { // Unlock destination and connect VNCclient @@ -895,7 +897,7 @@ void MainWindow::onVncServerStateChange(Client* client) else { // Lock others and stop their clients - (*it)->client()->lockScreen(_lockOthers); + (*it)->client()->lockScreen(_mode == Mode::LockedMulticast); (*it)->client()->stopVncClient(); } } @@ -927,7 +929,7 @@ void MainWindow::onVncClientStateChange(Client* client, int lastProjectionSource _watchers.remove(client->id()); // If noboody is watching the multicast stop VNC server - if (_watchers.isEmpty() && !_broadcast) + if (_watchers.isEmpty() && _mode != Mode::Broadcast) _streamingSource->stopVncServer(); } } -- cgit v1.2.3-55-g7522