diff options
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 203 |
1 files changed, 29 insertions, 174 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index e6f7d9d..83a424e 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -442,190 +442,58 @@ void MainWindow::broadcast(Client *from) { // Projection source is never allowed to be an active VNC viewer if (from->isActiveVncClient()) - { - qDebug("From is active client, stopping..."); from->stopVncClient(); + + // Tell all clients to listen to server + for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it){ + if ((*it)->client() != NULL) + (*it)->client()->setProjectionSource(false); } - from->setDesiredProjectionSource(0); - qDebug("Broadcast requested..."); + from->setDesiredProjectionSource(0); from->setProjectionSource(true); - // Set desired projection source on all clients + // Set desired projection source on all clients, if not "from" or oflline for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; // Self or offline - c->setDesiredProjectionSource(from->id()); - } + if ((*it)->client() != NULL && (*it)->client()->id() != from->id()) + (*it)->client()->setDesiredProjectionSource(from->id()); - if (from->isActiveVncServer()) - { - // From is already active, if there is at least one active client, assume it is not - // shutting down, so we can directly tell the new client to connect to it - qDebug("Source is already running a VNC server...."); - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; // Self or offline - if (c->currentProjectionSource() != from->id()) - continue; // Other client - // Yep :-) - qDebug("Reusing because of active client"); - this->onVncServerStateChange(from); - return; - } - qDebug("But no active client found...."); - } - // Could not take shortcut, (re)start VNC server on source - qDebug("Starting VNC server on source machine"); - from->startVncServer(); - return; + if (from->isActiveVncServer()) // From is already active + this->onVncServerStateChange(from); + else // Could not take shortcut, (re)start VNC server on source + from->startVncServer(); } + /***************************************************************************//** - * @brief unicast + * @brief MainWindow::unicast * @param from * @param to + * @param blockOthers */ -void MainWindow::unicast(Client *from, Client *to) +void MainWindow::unicast(Client *from, Client *to, bool blockOthers) { // Projection source is never allowed to be an active VNC viewer if (from->isActiveVncClient()) - { - qDebug("From is active client, stopping..."); from->stopVncClient(); - } - from->setDesiredProjectionSource(0); - - to->setProjectionSource(false); - if (to->isActiveVncServer()) // TODO aint this not alway the - { - if (to->currentProjectionSource() == from->id()) // TODO SHALL to->VNCSERVER NOT BE CLOSED? - return; // Nothing to do + // Projection destination is never allowed to be an active VNC server + if (to->isActiveVncServer()) to->stopVncServer(); - } - to->setDesiredProjectionSource(from->id()); - - if (from->isActiveVncServer()) - { - // From is already active, if there is at least one active client, assume it is not - // shutting down, so we can directly tell the new client to connect to it - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; - if (c->currentProjectionSource() != from->id()) - continue; - // Yep :-) - this->onVncServerStateChange(from); - return; - } - } - // Could not take shortcut, (re)start VNC server on source - from->startVncServer(); -} -/***************************************************************************//** - * @brief unicastExlusive - * @param from - * @param to - */ -void MainWindow::unicastExlusive(Client *from, Client *to) -{ - -} - -/***************************************************************************//** - * Handle VNC settings for a projection from "from" to "to". - * Check if projection source is active vnc client. - * Check if projection is One --> Many or One --> One. - * @param from - * @param to - */ -void MainWindow::prepareForProjection(Client * const from, Client * const to) -{ - // Projection source is never allowed to be an active VNC viewer - if (from->isActiveVncClient()) - { - qDebug("From is active client, stopping..."); - from->stopVncClient(); - } from->setDesiredProjectionSource(0); + to->setProjectionSource(false); + to->setDesiredProjectionSource(from->id()); - if (to == NULL) - { - // One to many - qDebug("One to many requested..."); - from->setProjectionSource(true); - - // Set desired projection source on all clients - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; // Self or offline - c->setDesiredProjectionSource(from->id()); - } - - if (from->isActiveVncServer()) - { - // From is already active, if there is at least one active client, assume it is not - // shutting down, so we can directly tell the new client to connect to it - qDebug("Source is already running a VNC server...."); - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; // Self or offline - if (c->currentProjectionSource() != from->id()) - continue; // Other client - // Yep :-) - qDebug("Reusing because of active client"); - this->onVncServerStateChange(from); - return; - } - qDebug("But no active client found...."); - } - // Could not take shortcut, (re)start VNC server on source - qDebug("Starting VNC server on source machine"); + if (from->isActiveVncServer()) // From is already active + this->onVncServerStateChange(from); + else // Could not take shortcut, (re)start VNC server on source from->startVncServer(); - return; - } - - // One to one is desired, figure out what to do with current client - to->setProjectionSource(false); - if (to->isActiveVncServer()) - { - if (to->currentProjectionSource() == from->id()) - return; // Nothing to do - to->stopVncServer(); + if (blockOthers){ + // TODO: REDESIGN TO FIT THE REQUIREMENTS } - to->setDesiredProjectionSource(from->id()); - if (from->isActiveVncServer()) - { - // From is already active, if there is at least one active client, assume it is not - // shutting down, so we can directly tell the new client to connect to it - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - { - Client *c = (**it).client(); - if (c == NULL || c->id() == from->id()) - continue; - if (c->currentProjectionSource() != from->id()) - continue; - // Yep :-) - this->onVncServerStateChange(from); - return; - } - } - // Could not take shortcut, (re)start VNC server on source - from->startVncServer(); } /***************************************************************************//** @@ -640,14 +508,9 @@ void MainWindow::onButtonHelp() * Handle projection from tutor to all. * Get the client who is tutor and set the projectionSource of all * clients, except the tutor ones, to false. - * Call prepareForProjection(from, to). */ void MainWindow::onButtonTutorToAll() { - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL && !(**it).isTutor()) - (*it)->client()->setProjectionSource(false); - if (_tutorFrame == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorNdef); else if (_tutorFrame->client() == NULL) @@ -660,14 +523,9 @@ void MainWindow::onButtonTutorToAll() * Button projection from one student to all the others. * First get which client is projectionSource and set this one as from. * Set projection source for all clients,except the selected one, to false. - * Then call prepareForProjection(from, Null). */ void MainWindow::onButtonStudentToAll() { - for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) - if ((*it)->client() != NULL && !(*it)->selected()) - (*it)->client()->setProjectionSource(false); - if (_selectedFrame == NULL) QMessageBox::critical(this, tr("Projection"), sStrSourceNdef); if (_selectedFrame->client() == NULL) @@ -679,7 +537,6 @@ void MainWindow::onButtonStudentToAll() /***************************************************************************//** * Handle the projection from Tutor to specific student. * Set the client who is tutor as from and the selected client as to. - * Call prepareForProjection(from, to). */ void MainWindow::onButtonTutorToStudent() { @@ -700,7 +557,6 @@ void MainWindow::onButtonTutorToStudent() /***************************************************************************//** * Handle projection from one student to tutor. * Get the client to project from and get client, who is tutor, as to. - * Call prepareForProjection(from, to). */ void MainWindow::onButtonStudentToTutor() { @@ -735,7 +591,7 @@ void MainWindow::onButtonStudentToTutorExclusive() else if (_tutorFrame->client() == NULL) QMessageBox::critical(this, tr("Projection"), sStrTutorOffline); else - unicastExlusive(_tutorFrame->client(), _selectedFrame->client()); + unicast(_tutorFrame->client(), _selectedFrame->client(), true); } @@ -788,10 +644,9 @@ void MainWindow::onButtonLock(bool checked) // Check if client is Tutor or the manager is also running on this machine. bool isManagerMachine = false; - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { + foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) if (address != QHostAddress(QHostAddress::LocalHost) && c != NULL && c->ip() == address.toString()) - isManagerMachine = true; - } + isManagerMachine = true; if (c == NULL || (**it).isTutor() || isManagerMachine) continue; // Don't lock the tutor or the manager running machine. |