summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/server/mainwindow/mainwindow.cpp227
-rw-r--r--src/server/mainwindow/mainwindow.h6
-rw-r--r--src/server/net/client.cpp10
-rw-r--r--src/server/net/client.h7
4 files changed, 167 insertions, 83 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();
}
}
}
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 524a0b1..009e9d8 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -51,7 +51,9 @@ private:
enum class Mode {
Broadcast,
Multicast,
- LockedMulticast
+ Unicast,
+ LockedUnicast,
+ None
} _mode;
int _streamingSource;
QMap<int, Client*> _watchers;
@@ -76,7 +78,7 @@ private:
ConnectionFrame* createFrame();
bool loadPosition(QSettings& settings, const QString& id, int& x, int& y);
void savePosition(ConnectionFrame *cf);
- void changeProjection(Client *from, Mode mode = Mode::Broadcast, Client *to = NULL);
+ void startVncServerIfNecessary(int from);
void tellClientCurrentSituation(Client* client);
void reset();
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index 584b254..dd61b45 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -21,7 +21,8 @@ Client::Client(QSslSocket* socket) : _socket(socket)
{
assert(socket != NULL);
_authed = 0;
- _currentProjectionSource = 0;
+ _projectionSource = 0;
+ _isActiveVncClient = false;
_vncPort = 0;
_isTutor = false;
_locked = false;
@@ -193,13 +194,14 @@ void Client::handleMsg()
if (_fromClient.getFieldString("ENABLED").toInt() != 0)
{
qDebug() << "Client " << _name << " started its VNC client (watching " << projectionSource << ")";
- _currentProjectionSource = projectionSource;
+ _projectionSource = projectionSource;
+ _isActiveVncClient = true;
emit vncClientStateChange(this);
}
else
{
qDebug() << "Client " << _name << " stopped its VNC client (watched " << projectionSource << ")";
- _currentProjectionSource = 0;
+ _isActiveVncClient = false;
emit vncClientStateChange(this);
}
emit stateChanged();
@@ -304,7 +306,7 @@ void Client::startVncClient(const Client * const to)
/******************************************************************************/
void Client::stopVncClient()
{
- if (_currentProjectionSource != 0) {
+ if (_isActiveVncClient) {
NetworkMessage msg;
msg.setField(_ID, _VNCCLIENT);
sendMessage(msg);
diff --git a/src/server/net/client.h b/src/server/net/client.h
index 6872959..c4afd16 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -33,8 +33,8 @@ public:
inline const QString& host() const { return _host; }
inline const QString ip() const { return _socket->peerAddress().toString(); }
inline const int id() const { return _id; }
- inline const int currentProjectionSource() const { return _currentProjectionSource; }
- inline const bool isActiveVncClient() const { return _currentProjectionSource > 0; }
+ inline const int projectionSource() const { return _projectionSource; }
+ inline const bool isActiveVncClient() const { return _isActiveVncClient; }
inline const bool isActiveVncServer() const { return _vncPort > 0; }
inline const bool isLocked() const { return _locked; }
inline const bool isWatcher() const { return _isWatcher; }
@@ -65,7 +65,8 @@ private:
int _id; // this client's unique id
QString _vncRwPass, _vncRoPass;
int _vncPort; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server.
- int _currentProjectionSource; // VNCclient state. indicating that the client is displaying a remote screen via VNC
+ int _projectionSource; // VNCclient state. The source the client was or is connected to (depends on _isActiveVncClient)
+ bool _isActiveVncClient; // VNCclient state. indicating that the client is displaying a remote screen via VNC
bool _isTutor; // Flag indicating that the client has been set as a tutor
bool _isWatcher; // Flag indicates that the client should watch to VNC Server.