summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp275
1 files changed, 181 insertions, 94 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index a6c90c0..a52690f 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -44,6 +44,8 @@ const QString MainWindow::sStrSourceOffline = tr("The projection source is offli
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.");
+const QString MainWindow::sStrClientOnline = tr("Selected client is currently online.");
+const QString MainWindow::sStrNoDestAv = tr("No projection destination available.");
/***************************************************************************//**
* Initialize MainWindow and ListenServer.
@@ -53,11 +55,8 @@ const QString MainWindow::sStrSourceDestSame = tr("Selected projection target is
MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
QMainWindow(parent), ui(new Ui::MainWindow), _tbIconSize(24), _tbArea(Qt::LeftToolBarArea)
{
-
- _tutorFrame = NULL;
- _selectedFrame = NULL;
_mode = Mode::Multicast;
- _streamingSource = NULL;
+ _streamingSource = 0;
_sessionNameWindow = new SessionNameWindow(this);
_helpWindow = new HelpWindow(this);
@@ -81,6 +80,9 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
ui->action_Exit->setStatusTip(tr("Exit"));
ui->action_Lock->setStatusTip(tr("Lock or Unlock all Clients"));
+ _tileWidth = 10;
+ _tileHeight = 10;
+
// Initialize FileDownloader.
if (!ipListUrl.isEmpty())
{
@@ -128,9 +130,6 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
setUnifiedTitleAndToolBarOnMac(true);
this->showMaximized(); // show the Mainwindow maximized
- _tileWidth = 10;
- _tileHeight = 10;
-
_listenServer = new ListenServer(CLIENT_PORT);
connect(_listenServer, SIGNAL(newClient(Client*)), this, SLOT(onClientConnected(Client*)));
_discoveryListener = new DiscoveryListener();
@@ -266,27 +265,22 @@ void MainWindow::tellClientCurrentSituation(Client* client)
if (_mode == Mode::Broadcast){
// _watchers.insert(client->id(), client);
client->setWatcher(true);
- client->startVncClient(_streamingSource);
+ Client* c = getClientFromId(_streamingSource);
+ if (c != NULL) {
+ client->startVncClient(c);
+ }
}
else if (_mode == Mode::LockedMulticast)
client->lockScreen(true);
+
}
/***************************************************************************//**
- * Checks if client and manager runs on same machine.
- * @param client
- * @return Return true, if pvsmanager is running on client.
+ * Returns connected client which belongs to given id.
+ * Iterating over ConnectionFrames and comparing id to given id.
+ * @param id
+ * @return Client with given id, if not NULL.
*/
-bool MainWindow::isManagerMachine(Client* client)
-{
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
- if (address != QHostAddress(QHostAddress::LocalHost)
- && client != NULL
- && client->ip() == address.toString())
- return true;
- return false;
-}
-
Client* MainWindow::getClientFromId(int id)
{
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
@@ -300,6 +294,38 @@ Client* MainWindow::getClientFromId(int id)
return NULL;
}
+/***************************************************************************//**
+ * Return the Frame, which is currently beeing Tutor.
+ * Iterating over all ConnectionFrames, and looking for flag _isTutor.
+ * @return Frame with flag _isTutor = true,
+ * else NULL if no Tutor is available.
+ */
+ConnectionFrame* MainWindow::getTutorFrame()
+{
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ if (((*it) != NULL) && ((*it)->isTutor()))
+ return (*it);
+ }
+ return NULL;
+}
+
+/***************************************************************************//**
+ * Return the Frame, which is currently selected by user.
+ * Iterating over all ConnectionFrame and looking for flag _isSelected.
+ * @return Frame with flag _isSelected = true,
+ * else NULL if no frame is selected.
+ */
+ConnectionFrame* MainWindow::getSelectedFrame()
+{
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ if (((*it) != NULL) && ((*it)->isSelected()))
+ return (*it);
+ }
+ return NULL;
+}
+
/*
* Overridden methods
*/
@@ -345,6 +371,14 @@ void MainWindow::resizeEvent(QResizeEvent* e)
(*it)->move((oldpos.x() / _tileWidth) * nw, (oldpos.y() / _tileHeight) * nh);
(*it)->setSize(nw, nh);
}
+
+ // Resize trash and set position.
+ const int width = ui->frmRoom->geometry().width() - (nw + 1);
+ const int height = ui->frmRoom->geometry().height() - (nh + 1);
+ ui->trash->move(width, height);
+ ui->trash->resize(nw, nh);
+ // qDebug() << "Trash pos: " << ui->trash->pos();
+
_tileWidth = nw;
_tileHeight = nh;
}
@@ -366,9 +400,9 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e)
const QSize frame(ui->frmRoom->size());
if (frame.width() > pos.x() && frame.height() > pos.y())
{
- if (_selectedFrame != NULL) {
- _selectedFrame->setSelection(false);
- _selectedFrame = NULL;
+ if (getSelectedFrame() != NULL)
+ {
+ getSelectedFrame()->setSelection(false);
}
}
}
@@ -384,8 +418,8 @@ void MainWindow::reset()
(*it)->client()->lockScreen(false);
// Stop server (Clients get stopped on ACK)
- if (_streamingSource != NULL)
- _streamingSource->stopVncServer();
+ if (getClientFromId(_streamingSource) != NULL)
+ getClientFromId(_streamingSource)->stopVncServer();
}
/*
@@ -425,6 +459,35 @@ void MainWindow::onPlaceFrame(ConnectionFrame* frame)
y = 0;
else if (y > s.height() - _tileHeight)
y = (_tilesY - 1) * _tileHeight;
+
+ const QRect &trashCenter = ui->trash->geometry();
+ // Check if x coordinate is in trash position.
+ if (trashCenter.contains(p))
+ {
+ // Do not offer deleting online client.
+ if (frame->client() != NULL)
+ {
+ QMessageBox::critical(this, tr("Selection"), sStrClientOnline);
+ frame->move(frame->getPreviousPosition());
+ return;
+ }
+ else
+ {
+ int ret = QMessageBox::question(this, "Warning", "Sure, You want to delete selected client?", 0, 1, 2);
+ if (ret == 1)
+ {
+ frame->hide();
+ frame->deleteLater();
+ _clientFrames.removeOne(frame);
+ return;
+ }
+ else
+ {
+ frame->move(frame->getPreviousPosition());
+ return;
+ }
+ }
+ }
qDebug("Move D");
frame->move(x, y);
savePosition(frame);
@@ -447,15 +510,18 @@ void MainWindow::onPlaceFrame(ConnectionFrame* frame)
void MainWindow::onFrameClicked(ConnectionFrame* frame)
{
// If same frame is clicked again,, do nothing
- if (_selectedFrame == frame)
+ if (getSelectedFrame() == 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);
+ if (getSelectedFrame() != NULL)
+ {
+ getSelectedFrame()->setSelection(false);
+ }
+ frame->setSelection(true);
+ qDebug() << "ID of frame: " << frame->computerId();
+ qDebug() << "ID of selectedFrame: " << getSelectedFrame()->computerId();
}
/***************************************************************************//**
@@ -471,6 +537,14 @@ void MainWindow::onSessionNameClick()
*/
void MainWindow::onSessionNameUpdate()
{
+ // Stop all projections and clear all clients, which where connected to old sessionName.
+ reset();
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
+ {
+ (*it)->hide();
+ (*it)->deleteLater();
+ }
+ _clientFrames.clear();
_sessionNameLabel->setText(tr("Session Name: %1 [click to edit]").arg(Global::sessionName()));
}
@@ -489,7 +563,7 @@ void MainWindow::changeProjection(Client *from, Mode mode, Client *to)
// Set all clients as watchers
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
{
- if ((*it)->client() != NULL && (*it)->client() != _streamingSource)
+ if ((*it)->client() != NULL && (*it)->client() != getClientFromId(_streamingSource))
{
// _watchers.insert((*it)->client()->id(), (*it)->client());
(*it)->client()->setWatcher(true);
@@ -528,17 +602,20 @@ void MainWindow::changeProjection(Client *from, Mode mode, Client *to)
_mode = mode;
// if there is a server running which is not "from" stop it.
- if (_streamingSource != NULL && _streamingSource != from)
- _streamingSource->stopVncServer();
+ if (getClientFromId(_streamingSource) != NULL && getClientFromId(_streamingSource) != from)
+ getClientFromId(_streamingSource)->stopVncServer();
// Set new streaming source
- _streamingSource = from;
+ _streamingSource = from->id();
// If streaming source is already active avoid a restart
- if (_streamingSource->isActiveVncServer())
- this->onVncServerStateChange(_streamingSource);
- else // Could not take shortcut, (re)start VNC server on source
- _streamingSource->startVncServer();
+ Client* c = getClientFromId(_streamingSource);
+ if (c != NULL) {
+ if (c->isActiveVncServer())
+ this->onVncServerStateChange(c);
+ else // Could not take shortcut, (re)start VNC server on source
+ c->startVncServer();
+ }
}
/***************************************************************************//**
@@ -558,12 +635,14 @@ void MainWindow::onButtonTutorToAll()
{
ui->action_Lock->setChecked(false);
- if (_tutorFrame == NULL)
+ if (getTutorFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (_tutorFrame->client() == NULL)
+ else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
+ else if (_clientFrames.size() == 1)
+ QMessageBox::critical(this, tr("Projection"), sStrNoDestAv);
else
- changeProjection(_tutorFrame->client(), Mode::Broadcast);
+ changeProjection(getTutorFrame()->client(), Mode::Broadcast);
}
/***************************************************************************//**
@@ -575,12 +654,12 @@ void MainWindow::onButtonStudentToAll()
{
ui->action_Lock->setChecked(false);
- if (_selectedFrame == NULL)
+ if (getSelectedFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
- if (_selectedFrame->client() == NULL)
+ if (getSelectedFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else
- changeProjection(_selectedFrame->client(), Mode::Broadcast);
+ changeProjection(getSelectedFrame()->client(), Mode::Broadcast);
}
/***************************************************************************//**
@@ -591,18 +670,18 @@ void MainWindow::onButtonTutorToStudent()
{
ui->action_Lock->setChecked(false);
- if (_selectedFrame == NULL)
+ if (getSelectedFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrDestNdef);
- else if (_tutorFrame == NULL)
+ else if (getTutorFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (_selectedFrame == _tutorFrame)
+ else if (getSelectedFrame() == getTutorFrame())
QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
- else if (_selectedFrame->client() == NULL)
+ else if (getSelectedFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrDestOffline);
- else if (_tutorFrame->client() == NULL)
+ else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- changeProjection(_tutorFrame->client(), Mode::Multicast, _selectedFrame->client());
+ changeProjection(getTutorFrame()->client(), Mode::Multicast, getSelectedFrame()->client());
}
/***************************************************************************//**
@@ -613,18 +692,18 @@ void MainWindow::onButtonStudentToTutor()
{
ui->action_Lock->setChecked(false);
- if (_selectedFrame == NULL)
+ if (getSelectedFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
- else if (_tutorFrame == NULL)
+ else if (getTutorFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (_tutorFrame == _selectedFrame)
+ else if (getTutorFrame() == getSelectedFrame())
QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
- else if (_selectedFrame->client() == NULL)
+ else if (getSelectedFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
- else if (_tutorFrame->client() == NULL)
+ else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- changeProjection(_selectedFrame->client(), Mode::Multicast, _tutorFrame->client());
+ changeProjection(getSelectedFrame()->client(), Mode::Multicast, getTutorFrame()->client());
}
@@ -635,18 +714,18 @@ void MainWindow::onButtonStudentToTutorExclusive()
{
ui->action_Lock->setChecked(false);
- if (_selectedFrame == NULL)
+ if (getSelectedFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceNdef);
- else if (_tutorFrame == NULL)
+ else if (getTutorFrame() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorNdef);
- else if (_tutorFrame == _selectedFrame)
+ else if (getTutorFrame() == getSelectedFrame())
QMessageBox::critical(this, tr("Projection"), sStrSourceDestSame);
- else if (_selectedFrame->client() == NULL)
+ else if (getSelectedFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
- else if (_tutorFrame->client() == NULL)
+ else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else
- changeProjection(_selectedFrame->client(), Mode::LockedMulticast, _tutorFrame->client());
+ changeProjection(getSelectedFrame()->client(), Mode::LockedMulticast, getTutorFrame()->client());
}
@@ -674,9 +753,7 @@ void MainWindow::onButtonLock(bool checked)
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
{
- // Check if client is Tutor or the manager is also running on this machine.
- bool isManager = isManagerMachine((*it)->client());
- if ((*it)->client() == NULL || isManager)
+ if ((*it)->client() == NULL)
continue;
(*it)->client()->lockScreen(checked);
}
@@ -699,30 +776,33 @@ void MainWindow::onButtonSetAsTutor()
ui->action_Lock->setChecked(false);
// If no frame is selected, warning.
- if (_selectedFrame == NULL)
+ if (getSelectedFrame() == NULL)
{
QMessageBox::critical(this, tr("Selection"), tr("No client is selected."));
return;
}
// If frame of inactive client has been selected unselect it
- if (_selectedFrame->client() == NULL)
+ if (getSelectedFrame()->client() == NULL)
{
QMessageBox::critical(this, tr("Selection"), tr("The selected client is not connected."));
return;
}
else // If selected client is locked, first unlock
- _selectedFrame->client()->lockScreen(false);
+ {
+ getSelectedFrame()->client()->lockScreen(false);
+ }
// If same frame is already tutor, do nothing
- if (_selectedFrame == _tutorFrame)
+ if (getSelectedFrame() == getTutorFrame())
return;
// Else unset the old and set the new tutor
- if (_tutorFrame != NULL)
- _tutorFrame->setTutor(false);
- _tutorFrame = _selectedFrame;
- _tutorFrame->setTutor(true);
+ if (getTutorFrame() != NULL)
+ {
+ getTutorFrame()->setTutor(false);
+ }
+ getSelectedFrame()->setTutor(true);
}
/***************************************************************************//**
@@ -882,7 +962,7 @@ void MainWindow::onClientAuthenticated(Client* client)
*/
void MainWindow::onVncServerStateChange(Client* client)
{
- if (client == _streamingSource)
+ if (client == getClientFromId(_streamingSource))
EnableButtons();
if (client->isActiveVncServer())
@@ -910,7 +990,7 @@ void MainWindow::onVncServerStateChange(Client* client)
if ( (*it)->client() != NULL)
{
// if (_watchers.contains((*it)->client()->id()))
- if (getClientFromId((*it)->client()->id())->isWatcher())
+ if ((*it)->client()->isWatcher())
{
// Unlock destination and connect VNCclient
(*it)->client()->lockScreen(false);
@@ -924,8 +1004,7 @@ void MainWindow::onVncServerStateChange(Client* client)
else
{
// Lock others and stop their clients
- bool isManager = isManagerMachine((*it)->client());
- (*it)->client()->lockScreen(_mode == Mode::LockedMulticast && isManager != true);
+ (*it)->client()->lockScreen(_mode == Mode::LockedMulticast);
(*it)->client()->stopVncClient();
}
}
@@ -957,25 +1036,33 @@ void MainWindow::onVncServerStateChange(Client* client)
*/
void MainWindow::onVncClientStateChange(Client* client)
{
- // VNC Client stopped -> remove from watchers
- if (!client->isActiveVncClient()){
- // _watchers.remove(client->id());
- 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)
- {
- if ((*it)->client() != NULL)
+ if (client != NULL)
+ {
+ // VNC Client stopped -> remove from watchers
+ if (!client->isActiveVncClient()){
+ // _watchers.remove(client->id());
+ if (getClientFromId(client->id()) != NULL)
+ 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)
{
- if ((*it)->client()->isWatcher())
- noWatchers = false;
+ if ((*it)->client() != NULL)
+ {
+ if ((*it)->client()->isWatcher())
+ noWatchers = false;
+ }
+ }
+ if (noWatchers && _mode != Mode::Broadcast)
+ {
+ Client* c = getClientFromId(_streamingSource);
+ if (c != NULL)
+ c->stopVncServer();
}
}
- if (noWatchers && _mode != Mode::Broadcast)
- _streamingSource->stopVncServer();
}
}