summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorManuel Schneider2014-05-16 00:44:00 +0200
committerManuel Schneider2014-05-16 00:44:00 +0200
commit20a40ae90f6c0e4cac0345c57ac54f1bd671f633 (patch)
treef309be1cfe221d7e9fd8ecf2f5a7afaaad348576 /src/server/mainwindow/mainwindow.cpp
parentFix segmentation fault after looking all screens and there is one client disc... (diff)
downloadpvs2-20a40ae90f6c0e4cac0345c57ac54f1bd671f633.tar.gz
pvs2-20a40ae90f6c0e4cac0345c57ac54f1bd671f633.tar.xz
pvs2-20a40ae90f6c0e4cac0345c57ac54f1bd671f633.zip
Several changes:
* Change the messagebox text * Add button stub for exclusiveStudentToTutor * Split prepareProjection in broacast, unicast and exclusiveunicast (stub) * Make multiple used, hardcoded strings static const member of mainwindow * Replace multiple loops asking for selection and tutor by membervariable * references to the connectionframe of the latter * Complete missing error messages
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp349
1 files changed, 218 insertions, 131 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 47f9610..ca9ecca 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -36,6 +36,14 @@
// Auto-generated ui class
#include "ui_mainwindow.h"
+const QString MainWindow::sStrTutorNdef = tr("No tutor defined.");
+const QString MainWindow::sStrTutorOffline = tr("Tutor is offline.");
+const QString MainWindow::sStrSourceNdef = tr("Please select a projection source.");
+const QString MainWindow::sStrSourceOffline = tr("The projection source is offline.");
+const QString MainWindow::sStrDestNdef = tr("Please select a projection destination.");
+const QString MainWindow::sStrDestOffline = tr("The projection destination is offline.");
+const QString MainWindow::sStrSourceDestSame = tr("Selected projection target is tutor.");
+
/***************************************************************************//**
* Initialize MainWindow and ListenServer.
* @param ipListUrl
@@ -44,6 +52,10 @@
MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
QMainWindow(parent), ui(new Ui::MainWindow), _tbIconSize(24), _tbArea(Qt::LeftToolBarArea)
{
+
+ _tutorFrame = NULL;
+ _selectedFrame = NULL;
+
_sessionNameWindow = new SessionNameWindow(this);
ui->setupUi(this);
@@ -76,6 +88,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
connect(ui->action_BroadcastScreen, SIGNAL(triggered()), this, SLOT(onButtonStudentToAll()));
connect(ui->action_TutorToAll, SIGNAL(triggered()), this, SLOT(onButtonTutorToAll()));
connect(ui->action_StudentToTutor, SIGNAL(triggered()), this, SLOT(onButtonStudentToTutor()));
+ connect(ui->action_StudentToTutorExclusive, SIGNAL(triggered()), this, SLOT(onButtonStudentToTutorExclusive()));
connect(ui->action_TutorToStudent, SIGNAL(triggered()), this, SLOT(onButtonTutorToStudent()));
connect(ui->action_StopProjection, SIGNAL(triggered()), this, SLOT(onButtonStopProjection()));
connect(ui->action_SetAsTutor, SIGNAL(triggered()), this, SLOT(onButtonSetAsTutor()));
@@ -301,9 +314,9 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e)
const QSize frame(ui->frmRoom->size());
if (frame.width() > pos.x() && frame.height() > pos.y())
{
- for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); ++it)
- {
- (**it).setSelection(false);
+ if (_selectedFrame != NULL) {
+ _selectedFrame->setSelection(false);
+ _selectedFrame = NULL;
}
}
}
@@ -424,13 +437,16 @@ void MainWindow::onPlaceFrame(ConnectionFrame* frame)
*/
void MainWindow::onFrameClicked(ConnectionFrame* frame)
{
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- if (*it == frame)
- frame->setSelection(true);
- else
- (**it).setSelection(false);
- }
+ // If same frame is clicked again,, do nothing
+ if (_selectedFrame == frame)
+ return;
+
+ // If another frame has been selected, unselect it
+ // Set the ui selected and set a new reference
+ if (_selectedFrame != NULL)
+ _selectedFrame->setSelection(false);
+ _selectedFrame = frame;
+ _selectedFrame->setSelection(true);
}
/***************************************************************************//**
@@ -466,6 +482,113 @@ bool MainWindow::isValidClient(Client* client)
return false;
}
+
+/***************************************************************************//**
+ * @brief broadcast
+ * @param from
+ */
+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();
+ }
+ from->setDesiredProjectionSource(0);
+
+ qDebug("Broadcast 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");
+ from->startVncServer();
+ return;
+}
+
+/***************************************************************************//**
+ * @brief unicast
+ * @param from
+ * @param to
+ */
+void MainWindow::unicast(Client *from, Client *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);
+
+ 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
+ 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.
@@ -555,6 +678,26 @@ void MainWindow::prepareForProjection(Client * const from, Client * const to)
}
/***************************************************************************//**
+ * 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)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
+ else
+ broadcast(_tutorFrame->client());
+}
+
+/***************************************************************************//**
* 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.
@@ -562,131 +705,81 @@ void MainWindow::prepareForProjection(Client * const from, Client * const to)
*/
void MainWindow::onButtonStudentToAll()
{
- Client *from = NULL;
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- Client *c = (**it).client();
- if (c == NULL)
- continue;
- if ((**it).selected())
- from = c;
- else
- c->setProjectionSource(false);
- }
- if (from == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No projection source selected.")
- );
+ if ((*it)->client() != NULL && !(*it)->selected())
+ (*it)->client()->setProjectionSource(false);
+
+ if (_selectedFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
+ if (_selectedFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else
- prepareForProjection(from, NULL);
+ broadcast(_selectedFrame->client());
}
/***************************************************************************//**
- * Handle projection from one student to tutor.
- * Get the client to project from and get client, who is tutor, as to.
+ * 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::onButtonStudentToTutor()
+void MainWindow::onButtonTutorToStudent()
{
- Client *from = NULL;
- Client *to = NULL;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- Client *c = (**it).client();
- if (c == NULL)
- continue;
- if ((**it).selected())
- from = c;
- else if ((**it).isTutor())
- to = c;
- }
- if (from == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No projection source selected.")
- );
- else if (to == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No tutor defined, or tutor is offline.")
- );
- else if (to == from)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("Selected projection source is tutor.")
- );
+ if (_selectedFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrDestNdef);
+ else if (_tutorFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
+ else if (_selectedFrame == _tutorFrame)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
+ else if (_selectedFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrDestOffline);
+ else if (_tutorFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- prepareForProjection(from, to);
+ unicast(_tutorFrame->client(), _selectedFrame->client());
}
/***************************************************************************//**
- * 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.
+ * 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::onButtonTutorToAll()
+void MainWindow::onButtonStudentToTutor()
{
- //
- Client *from = NULL;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- Client *c = (**it).client();
- if (c == NULL)
- continue;
- if ((**it).isTutor())
- from = c;
- else
- c->setProjectionSource(false);
- }
- if (from == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No tutor defined, or tutor is offline.")
- );
+ if (_selectedFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
+ else if (_tutorFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
+ else if (_tutorFrame == _selectedFrame)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
+ else if (_selectedFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
+ else if (_tutorFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- prepareForProjection(from, NULL);
+ unicast(_selectedFrame->client(), _tutorFrame->client());
}
+
/***************************************************************************//**
- * 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).
+ * @brief MainWindow::onButtonStudentToTutorExclusive
*/
-void MainWindow::onButtonTutorToStudent()
+void MainWindow::onButtonStudentToTutorExclusive()
{
- Client *from = NULL;
- Client *to = NULL;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- Client *c = (**it).client();
- if (c == NULL)
- continue;
- if ((**it).selected())
- to = c;
- if ((**it).isTutor())
- from = c;
- }
- if (to == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No projection source selected.")
- );
- else if (from == NULL)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("No tutor defined, or tutor is offline.")
- );
- else if (to == from)
- QMessageBox::critical(this,
- tr("Projection"),
- tr("Selected projection target is tutor.")
- );
+ if (_selectedFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
+ else if (_tutorFrame == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
+ else if (_tutorFrame == _selectedFrame)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
+ else if (_selectedFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
+ else if (_tutorFrame->client() == NULL)
+ QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- prepareForProjection(from, to);
+ unicastExlusive(_tutorFrame->client(), _selectedFrame->client());
}
+
/***************************************************************************//**
* Handle Button StopProjection.
* Set ProjectionSource of each client to false and create a NetworkMessage to
@@ -761,27 +854,21 @@ void MainWindow::onButtonExit()
*/
void MainWindow::onButtonSetAsTutor()
{
- bool selected = false;
- ConnectionFrame *oldTutor = NULL;
- bool changedTutor = false;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- selected = (*it)->selected();
- if (!selected && (*it)->isTutor())
- {
- oldTutor = (*it);
- (*it)->setTutor(false);
- }
- if (selected && ((*it)->client() != NULL))
- {
- // This frame is marked to be Tutor.
- (*it)->setTutor(true);
- changedTutor = true;
- }
- }
- if (!changedTutor && oldTutor != NULL) {
- oldTutor->setTutor(true);
+ // If same frame is already tutor, do nothing
+ if (_selectedFrame == _tutorFrame)
+ return;
+
+ // If a frame has been selected unselect it
+ if (_selectedFrame->client() == NULL){
+ QMessageBox::critical(this, tr("Selection"), tr("The selected client is not connected."));
+ return;
}
+
+ // Else unset the old and set the new tutor
+ if (_tutorFrame != NULL)
+ _tutorFrame->setTutor(false);
+ _tutorFrame = _selectedFrame;
+ _tutorFrame->setTutor(true);
}
/***************************************************************************//**