diff options
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 36 | ||||
-rw-r--r-- | src/server/mainwindow/mainwindow.h | 8 |
2 files changed, 25 insertions, 19 deletions
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<ConnectionFrame*>::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<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - if ( (*it)->client() != NULL) { + for (QList<ConnectionFrame*>::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(); } } diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h index 4b75241..8405e4a 100644 --- a/src/server/mainwindow/mainwindow.h +++ b/src/server/mainwindow/mainwindow.h @@ -49,8 +49,12 @@ private: static const qint64 _buttonBlockTime = 600; // Internal stuff - bool _broadcast; - bool _lockOthers; + enum class Mode { + Idle, + Broadcast, + Multicast, + LockedMulticast + } _mode; Client * _streamingSource; QMap<int, Client*> _watchers; |