summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-06-17 12:05:16 +0200
committerBjörn Hagemeister2014-06-17 12:05:16 +0200
commit8602764f8f069ec3cb6c8965262c016557bedb32 (patch)
tree6da131a729709c552068a9dc646d59ad81c77ac5 /src/server
parentFixed SegFauls by setting _streamingSource to integer and just using the clie... (diff)
downloadpvs2-8602764f8f069ec3cb6c8965262c016557bedb32.tar.gz
pvs2-8602764f8f069ec3cb6c8965262c016557bedb32.tar.xz
pvs2-8602764f8f069ec3cb6c8965262c016557bedb32.zip
Removed _tutorFrame and _selectedFrame out of MainWindow to prevent possible SegFaults because of too many Pointers to ConnectionFrames.
Wrote to getters getTutorFrame() and getSelectedFrame(), which are just iterating over ConnectionFrames and looking for flags _isTutor and _isSelected.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/connectionframe/connectionframe.cpp12
-rw-r--r--src/server/connectionframe/connectionframe.h4
-rw-r--r--src/server/mainwindow/mainwindow.cpp127
-rw-r--r--src/server/mainwindow/mainwindow.h3
4 files changed, 94 insertions, 52 deletions
diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp
index b09139c..caf99fc 100644
--- a/src/server/connectionframe/connectionframe.cpp
+++ b/src/server/connectionframe/connectionframe.cpp
@@ -50,7 +50,7 @@ static QIcon *term = NULL, *cam = NULL, *eye = NULL, *lock = NULL;
* @param height
*/
ConnectionFrame::ConnectionFrame(QWidget *parent, int width, int height) :
- QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _selected(false), _isTutor(false)
+ QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false)
{
//defines the ui-stuff
@@ -295,9 +295,9 @@ void ConnectionFrame::timerEvent(QTimerEvent* event)
*/
void ConnectionFrame::setSelection(bool selected)
{
- if (_selected == selected)
+ if (_isSelected == selected)
return;
- _selected = selected;
+ _isSelected = selected;
this->updateAppearance();
}
@@ -322,7 +322,7 @@ void ConnectionFrame::updateAppearance()
if (_client == NULL)
{
// Unconnected Frame
- if (_selected)
+ if (_isSelected)
this->setStyleSheet(style_selectedStudent);
else
this->setStyleSheet(style_disconnected);
@@ -336,13 +336,13 @@ void ConnectionFrame::updateAppearance()
// Normal client, no special stuff active
- if (_selected && _isTutor){
+ if (_isSelected && _isTutor){
this->setStyleSheet(style_selectedTutor);
}
else if (_isTutor){
this->setStyleSheet(style_tutor);
}
- else if (_selected){
+ else if (_isSelected){
this->setStyleSheet(style_selectedStudent);
}
diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h
index 72f641d..353ebb8 100644
--- a/src/server/connectionframe/connectionframe.h
+++ b/src/server/connectionframe/connectionframe.h
@@ -32,7 +32,7 @@ private:
Client *_client;
int _timerId, _timerCounter;
- bool _selected;
+ bool _isSelected;
bool _isTutor;
static const int _startDragDistance = 40;
@@ -53,7 +53,7 @@ public:
void setSize(int width, int height);
void assignClient(Client *client);
void setSelection(bool selected);
- const inline bool selected() const { return _selected; }
+ const inline bool isSelected() const { return _isSelected; }
const QString& computerId() const { return _computerId; }
Client* client() const { return _client; }
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 6ac7422..4af9fe1 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -53,9 +53,6 @@ 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 = 0;
@@ -291,6 +288,12 @@ bool MainWindow::isManagerMachine(Client* client)
return false;
}
+/***************************************************************************//**
+ * 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.
+ */
Client* MainWindow::getClientFromId(int id)
{
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
@@ -304,6 +307,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
*/
@@ -370,9 +405,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);
}
}
}
@@ -451,15 +486,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();
}
/***************************************************************************//**
@@ -565,12 +603,12 @@ 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
- changeProjection(_tutorFrame->client(), Mode::Broadcast);
+ changeProjection(getTutorFrame()->client(), Mode::Broadcast);
}
/***************************************************************************//**
@@ -582,12 +620,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);
}
/***************************************************************************//**
@@ -598,18 +636,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());
}
/***************************************************************************//**
@@ -620,18 +658,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());
}
@@ -642,18 +680,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());
}
@@ -706,30 +744,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);
}
/***************************************************************************//**
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 64accd9..dbef1b1 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -39,7 +39,6 @@ private:
int _tbIconSize;
Qt::ToolBarArea _tbArea;
int _tileWidth, _tileHeight;
- ConnectionFrame *_tutorFrame, *_selectedFrame;
static const int _tilesX = 9;
static const int _tilesY = 7;
@@ -86,6 +85,8 @@ private:
void mouseReleaseEvent(QMouseEvent* e);
Client* getClientFromId(int id);
+ ConnectionFrame* getTutorFrame();
+ ConnectionFrame* getSelectedFrame();
protected slots:
void onTutorListDownloaded(QByteArray& tutorList);