summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorChristian Klinger2016-09-29 15:40:18 +0200
committerChristian Klinger2016-09-29 15:40:18 +0200
commit3d82bfc698165bb20f3c38d42f2b77ab855c1edf (patch)
tree2c170bcdd5c89259bb0b530fa11fdfe701c99850 /src/server
parentadded an information dialog that displays ip and hostname. (diff)
downloadpvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.gz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.tar.xz
pvs2-3d82bfc698165bb20f3c38d42f2b77ab855c1edf.zip
astyle.
Diffstat (limited to 'src/server')
-rw-r--r--src/server/connectionframe/connectionframe.cpp161
-rw-r--r--src/server/connectionframe/connectionframe.h8
-rw-r--r--src/server/helpwindow/helpwindow.h3
-rw-r--r--src/server/main.cpp5
-rw-r--r--src/server/mainwindow/mainwindow.cpp786
-rw-r--r--src/server/mainwindow/mainwindow.h48
-rw-r--r--src/server/net/certmanager.cpp184
-rw-r--r--src/server/net/certmanager.h58
-rw-r--r--src/server/net/client.cpp116
-rw-r--r--src/server/net/client.h9
-rw-r--r--src/server/net/discoverylistener.cpp30
-rw-r--r--src/server/net/filedownloader.cpp19
-rw-r--r--src/server/net/listenserver.cpp3
-rw-r--r--src/server/net/sslserver.cpp25
-rw-r--r--src/server/numerickeyboard/numerickeyboard.cpp34
-rw-r--r--src/server/numerickeyboard/numerickeyboard.h37
-rw-r--r--src/server/reloadroomwindow/reloadroomwindow.h3
-rw-r--r--src/server/sessionnamewindow/sessionnamewindow.cpp24
-rw-r--r--src/server/sessionnamewindow/sessionnamewindow.h9
-rw-r--r--src/server/util/global.cpp46
-rw-r--r--src/server/util/global.h54
21 files changed, 784 insertions, 878 deletions
diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp
index 3278e04..0a7b180 100644
--- a/src/server/connectionframe/connectionframe.cpp
+++ b/src/server/connectionframe/connectionframe.cpp
@@ -22,31 +22,31 @@
#include <cassert>
static QString style_student(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
QGroupBox { background-color: #AAA; margin: 2px; border-radius: 4px}"
);
static QString style_tutor(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
QGroupBox { background-color: #70C670; margin: 2px; border-radius: 4px}"
);
static QString style_selectedStudent(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black; } \
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black; } \
QGroupBox { background-color: #ccebff; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
);
static QString style_selectedTutor(
- "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
+ "QLabel{ background-color: #FFF; border-radius: 2px; color: black;} \
QGroupBox { background-color: #99ff99; margin: 0px; border-radius: 4px; border: 4px solid #6C8CF0;}"
);
static QString style_exam (
- "QLabel{ background-color: #919191; color: black; } \
+ "QLabel{ background-color: #919191; color: black; } \
QGroupBox { background-color: #d35400; margin: 1px; border-radius: 4px}"
);
static QString style_exam_selected (
- "QLabel{ background-color: #919191; color: black; } \
+ "QLabel{ background-color: #919191; color: black; } \
QGroupBox { background-color: #cc743a; margin: 1px; border-radius: 4px}"
);
static QString style_disconnected(
- "QLabel{ background-color: #919191; color: black; } \
+ "QLabel{ background-color: #919191; color: black; } \
QGroupBox { background-color: #7F7F7F; margin: 1px; border-radius: 4px}"
);
@@ -59,13 +59,12 @@ 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), _isSelected(false), _isTutor(false)
+ QGroupBox(parent), _client(NULL), _timerId(0), _timerCounter(0), _isSelected(false), _isTutor(false)
{
//defines the ui-stuff
// load icons first
- if (term == NULL)
- {
+ if (term == NULL) {
term = new QIcon(":terminal");
cam = new QIcon(":cf_cam");
eye = new QIcon(":cf_eye");
@@ -74,50 +73,49 @@ ConnectionFrame::ConnectionFrame(QWidget *parent, int width, int height) :
//this->setAttribute(Qt::WA_OpaquePaintEvent);
- _mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
- _mainLayout->setSpacing(1);
- _mainLayout->setMargin(3);
- _mainLayout->setAlignment(Qt::AlignHCenter);
- this->setStyleSheet(style_student);
-
- _iconLayout = new QBoxLayout(QBoxLayout::RightToLeft, NULL);
- _iconLayout->setSpacing(1);
- _iconLayout->setMargin(3);
-
- _lblUserName = new QLabel("Test", this);
- _lblUserName->setAlignment(Qt::AlignHCenter);
-
- _lblHostName = new QLabel("PC", this);
- _lblHostName->setAlignment(Qt::AlignHCenter);
-
- _lblExamMode = new QLabel(tr("EXAM-MODE"), this);
- _lblExamMode->setAlignment(Qt::AlignHCenter);
- _lblExamMode->setVisible(false);
-
- _icoCam = addIcon(cam);
- _icoEye = addIcon(eye);
- _icoLock = addIcon(lock);
-
- _iconLayout->addWidget(_icoCam);
- _iconLayout->addWidget(_icoEye);
- _iconLayout->addWidget(_icoLock);
- _iconLayout->addStretch();
-
- _mainLayout->addLayout(_iconLayout);
- _mainLayout->addStretch();
- _mainLayout->addWidget(_lblExamMode);
- _mainLayout->addStretch();
- _mainLayout->addWidget(_lblUserName);
- _mainLayout->addWidget(_lblHostName);
- this->setLayout(_mainLayout);
- this->setSize(width, height);
- this->updateAppearance();
+ _mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
+ _mainLayout->setSpacing(1);
+ _mainLayout->setMargin(3);
+ _mainLayout->setAlignment(Qt::AlignHCenter);
+ this->setStyleSheet(style_student);
+
+ _iconLayout = new QBoxLayout(QBoxLayout::RightToLeft, NULL);
+ _iconLayout->setSpacing(1);
+ _iconLayout->setMargin(3);
+
+ _lblUserName = new QLabel("Test", this);
+ _lblUserName->setAlignment(Qt::AlignHCenter);
+
+ _lblHostName = new QLabel("PC", this);
+ _lblHostName->setAlignment(Qt::AlignHCenter);
+
+ _lblExamMode = new QLabel(tr("EXAM-MODE"), this);
+ _lblExamMode->setAlignment(Qt::AlignHCenter);
+ _lblExamMode->setVisible(false);
+
+ _icoCam = addIcon(cam);
+ _icoEye = addIcon(eye);
+ _icoLock = addIcon(lock);
+
+ _iconLayout->addWidget(_icoCam);
+ _iconLayout->addWidget(_icoEye);
+ _iconLayout->addWidget(_icoLock);
+ _iconLayout->addStretch();
+
+ _mainLayout->addLayout(_iconLayout);
+ _mainLayout->addStretch();
+ _mainLayout->addWidget(_lblExamMode);
+ _mainLayout->addStretch();
+ _mainLayout->addWidget(_lblUserName);
+ _mainLayout->addWidget(_lblHostName);
+ this->setLayout(_mainLayout);
+ this->setSize(width, height);
+ this->updateAppearance();
}
ConnectionFrame::~ConnectionFrame()
{
- if (_client != NULL)
- {
+ if (_client != NULL) {
_client->deleteLater();
}
_iconLayout->deleteLater();
@@ -130,12 +128,12 @@ ConnectionFrame::~ConnectionFrame()
*/
QLabel* ConnectionFrame::addIcon(const QIcon* icon)
{
- QLabel *label = new QLabel(this);
- label->setPixmap(icon->pixmap(24, 24, QIcon::Normal, QIcon::On));
- label->setAttribute(Qt::WA_TranslucentBackground);
- label->hide();
- _icons.append(label);
- return label;
+ QLabel *label = new QLabel(this);
+ label->setPixmap(icon->pixmap(24, 24, QIcon::Normal, QIcon::On));
+ label->setAttribute(Qt::WA_TranslucentBackground);
+ label->hide();
+ _icons.append(label);
+ return label;
}
/**
@@ -196,16 +194,12 @@ void ConnectionFrame::showDefaultThumb()
void ConnectionFrame::mouseReleaseEvent(QMouseEvent* event)
{
event->accept();
- if (event->button() == Qt::LeftButton)
- {
+ if (event->button() == Qt::LeftButton) {
QApplication::setOverrideCursor(QCursor(Qt::OpenHandCursor));
// Only recognize a move if the distance is larger than _startDragDistance
- if ((this->pos() - _previousPosition).manhattanLength() > _startDragDistance )
- {
+ if ((this->pos() - _previousPosition).manhattanLength() > _startDragDistance ) {
emit frameMoved(true, this);
- }
- else
- {
+ } else {
qDebug("Clicked");
move(_previousPosition);
emit clicked(this);
@@ -239,12 +233,9 @@ void ConnectionFrame::leaveEvent(QEvent* event)
*/
void ConnectionFrame::mousePressEvent(QMouseEvent *event)
{
- if (event->button() == Qt::RightButton)
- {
+ if (event->button() == Qt::RightButton) {
// Menu...
- }
- else
- {
+ } else {
_clickPoint = event->pos();
_previousPosition = this->pos();
QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
@@ -263,7 +254,7 @@ void ConnectionFrame::mousePressEvent(QMouseEvent *event)
void ConnectionFrame::mouseMoveEvent(QMouseEvent *event)
{
QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
- move(mapToParent(event->pos()-_clickPoint));
+ move(mapToParent(event->pos() - _clickPoint));
event->accept();
}
@@ -286,7 +277,7 @@ void ConnectionFrame::paintEvent(QPaintEvent *event)
QGroupBox::paintEvent(event);
if (_remoteScreen.isNull()) {
return;
- }
+ }
QPainter painter(this);
painter.drawPixmap((this->width() - _remoteScreen.width()) / 2, 4, _remoteScreen);
@@ -339,19 +330,18 @@ void ConnectionFrame::setTutor(bool b)
*/
void ConnectionFrame::updateAppearance()
{
- if (_client == NULL)
- {
+ if (_client == NULL) {
// Unconnected Frame
if (_isSelected) {
this->setStyleSheet(style_selectedStudent);
- } else if (_isTutor) {
- this->setStyleSheet(style_tutor);
- }else {
+ } else if (_isTutor) {
+ this->setStyleSheet(style_tutor);
+ } else {
this->setStyleSheet(style_disconnected);
- }
+ }
for (QList<QLabel*>::iterator it(_icons.begin()); it != _icons.end(); ++it) {
(**it).hide();
- }
+ }
return;
}
_icoCam->setVisible(_client->isActiveVncServer());
@@ -362,23 +352,19 @@ void ConnectionFrame::updateAppearance()
_lblExamMode->setVisible(_client->isExamMode());
// Normal client, no special stuff active
- if (_isSelected && _isTutor){
+ if (_isSelected && _isTutor) {
this->setStyleSheet(style_selectedTutor);
- }
- else if (_isTutor){
+ } else if (_isTutor) {
this->setStyleSheet(style_tutor);
- }
- else if (_client->isExamMode()) {
+ } else if (_client->isExamMode()) {
if (_isSelected) {
this->setStyleSheet(style_exam_selected);
} else {
this->setStyleSheet(style_exam);
}
- }
- else if (_isSelected) {
+ } else if (_isSelected) {
this->setStyleSheet(style_selectedStudent);
- }
- else {
+ } else {
this->setStyleSheet(style_student);
}
}
@@ -393,8 +379,7 @@ void ConnectionFrame::updateAppearance()
*/
void ConnectionFrame::onClientDisconnected()
{
- if (_timerId != 0)
- {
+ if (_timerId != 0) {
killTimer(_timerId);
_timerId = 0;
}
diff --git a/src/server/connectionframe/connectionframe.h b/src/server/connectionframe/connectionframe.h
index 9ac71c0..4f4decb 100644
--- a/src/server/connectionframe/connectionframe.h
+++ b/src/server/connectionframe/connectionframe.h
@@ -10,7 +10,7 @@
class ConnectionFrame : public QGroupBox
{
-Q_OBJECT
+ Q_OBJECT
private:
@@ -31,7 +31,7 @@ private:
QPoint _previousPosition;
QPoint _currentPosition;
- QPoint _gridPosition;
+ QPoint _gridPosition;
Client *_client;
@@ -61,8 +61,8 @@ public:
void setSelection(bool selected);
const inline bool isSelected() const { return _isSelected; }
- inline void setGridPosition(QPoint pos) { _gridPosition = pos; }
- inline QPoint getGridPosition() const { return _gridPosition; };
+ inline void setGridPosition(QPoint pos) { _gridPosition = pos; }
+ inline QPoint getGridPosition() const { return _gridPosition; };
const inline void setCurrentPosition(QPoint position) { _currentPosition = position; }
const inline QPoint& getCurrentPosition() const { return _currentPosition; }
diff --git a/src/server/helpwindow/helpwindow.h b/src/server/helpwindow/helpwindow.h
index b2aeab7..528a4d3 100644
--- a/src/server/helpwindow/helpwindow.h
+++ b/src/server/helpwindow/helpwindow.h
@@ -3,7 +3,8 @@
#include <QDialog>
-namespace Ui {
+namespace Ui
+{
class Help;
}
diff --git a/src/server/main.cpp b/src/server/main.cpp
index 0c09f91..02fd399 100644
--- a/src/server/main.cpp
+++ b/src/server/main.cpp
@@ -8,7 +8,8 @@
using std::cout;
using std::endl;
-void usage() {
+void usage()
+{
cout << "USAGE pvsmgr [OPTIONS]" << endl;
cout << "OPTIONS: " << endl;
cout << "--manager-only" << endl;
@@ -33,7 +34,7 @@ int main(int argc, char** argv)
Global::manager_only = true;
break;
} else if (a.startsWith("--config=")) {
- Global::setIniPath(a.mid(9));
+ Global::setIniPath(a.mid(9));
} else if (a == "--usage" || a == "--help") {
usage();
exit(0);
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index b29addc..e1d3f1e 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -66,16 +66,16 @@ using std::endl;
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent), ui(new Ui::MainWindow), _tbIconSize(24), _tbArea(Qt::LeftToolBarArea)
{
- qDebug() << "MainWindow(parent)";
+ qDebug() << "MainWindow(parent)";
_mode = Mode::Multicast;
_streamingSource = 0;
- /* default value, these will be updated a room is loaded */
- _tilesX = 10;
- _tilesY = 10;
+ /* default value, these will be updated a room is loaded */
+ _tilesX = 10;
+ _tilesY = 10;
- _virtCols = 0;
- _virtRows = 0;
+ _virtCols = 0;
+ _virtRows = 0;
_sessionNameWindow = new SessionNameWindow(this);
_helpWindow = new HelpWindow(this);
@@ -124,24 +124,24 @@ MainWindow::MainWindow(QWidget* parent) :
connect(ui->action_Lock, SIGNAL(toggled(bool)), this, SLOT(onButtonLock(bool)));
connect(ui->action_Help, SIGNAL(triggered()), this, SLOT(onButtonHelp()));
connect(ui->actionReload_Room_Configuration, SIGNAL(triggered()), this, SLOT(onButtonReloadRoomConfig()));
- connect(ui->action_DeleteClient, SIGNAL(triggered()), this, SLOT(onDeleteClient()));
+ connect(ui->action_DeleteClient, SIGNAL(triggered()), this, SLOT(onDeleteClient()));
- // /* In exam-mode: disable most features */
+ // /* In exam-mode: disable most features */
// QSharedPointer<QSettings> conf = Global::getSettings();
- // if (conf->contains("examMode")) {
- // Global::setExam(conf->value("examMode").toBool());
- // }
+ // if (conf->contains("examMode")) {
+ // Global::setExam(conf->value("examMode").toBool());
+ // }
+
+ /* disable context-sensitive buttons by default */
+ _contextButtons
+ << ui->action_DeleteClient
+ << ui->action_StudentToTutor
+ << ui->action_StudentToTutorExclusive
+ << ui->action_SetAsTutor
+ << ui->action_TutorToStudent;
- /* disable context-sensitive buttons by default */
- _contextButtons
- << ui->action_DeleteClient
- << ui->action_StudentToTutor
- << ui->action_StudentToTutorExclusive
- << ui->action_SetAsTutor
- << ui->action_TutorToStudent;
-
- lockContextButtons();
+ lockContextButtons();
/* Stuff for the button lock */
//Setup a timeout
@@ -151,18 +151,18 @@ MainWindow::MainWindow(QWidget* parent) :
connect(_buttonLockTimer, SIGNAL(timeout()), this, SLOT(EnableButtons()));
// Define the locking buttons
_lockingButtons
- << ui->action_Lock
- << ui->action_TutorToAll
- << ui->action_StudentToTutor
- << ui->action_TutorToStudent
- << ui->action_StopProjection
- << ui->action_SetAsTutor;
+ << ui->action_Lock
+ << ui->action_TutorToAll
+ << ui->action_StudentToTutor
+ << ui->action_TutorToStudent
+ << ui->action_StopProjection
+ << ui->action_SetAsTutor;
// Clicking the session name label shows the edit field for it
connect(_sessionNameLabel, SIGNAL(clicked()), this, SLOT(onSessionNameClick()));
// Listen to updates to the session name through the session name window
connect(_sessionNameWindow, SIGNAL(updateSessionName()), this,
- SLOT(onSessionNameUpdate()));
+ SLOT(onSessionNameUpdate()));
setAttribute(Qt::WA_QuitOnClose);
setUnifiedTitleAndToolBarOnMac(true);
@@ -183,7 +183,8 @@ MainWindow::MainWindow(QWidget* parent) :
/** this function determines if the number of clients in exam mode comprise
* more than 50%. In that case the whole manager switches to exam mode,
* disabling many features in the toolbar **/
-void MainWindow::updateExamMode() {
+void MainWindow::updateExamMode()
+{
/* TODO */
int numerator = 0;
int denominator = 0;
@@ -229,18 +230,20 @@ MainWindow::~MainWindow()
}
/** Euclidean distance (why is this not implemented in QPoint?) */
-float distance(QPoint a, QPoint b) {
- int dx = a.x() - b.x();
- int dy = a.y() - b.y();
- int sum = dx*dx + dy*dy;
- return sqrt((float) sum);
+float distance(QPoint a, QPoint b)
+{
+ int dx = a.x() - b.x();
+ int dy = a.y() - b.y();
+ int sum = dx * dx + dy * dy;
+ return sqrt((float) sum);
}
-float distance(QPointF a, QPointF b) {
- int dx = a.x() - b.x();
- int dy = a.y() - b.y();
- int sum = dx*dx + dy*dy;
- return sqrt(sum);
+float distance(QPointF a, QPointF b)
+{
+ int dx = a.x() - b.x();
+ int dy = a.y() - b.y();
+ int sum = dx * dx + dy * dy;
+ return sqrt(sum);
}
@@ -253,72 +256,74 @@ float distance(QPointF a, QPointF b) {
* 'Algorithm': ideally, go in circles around the preferred point until you find
* a free spot. Lazy way: store all free positions in an array and find later
* there the closest (<- that's what I do)
- *
- * @param preferred in Pixels!
+ *
+ * @param preferred in Pixels!
* @param toIgnore, ignore this connectionframe when considering free slots
* @return the free slot
*/
-QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore) {
- const QSize& clientSize = Global::getCurrentRoom()->clientSize;
+QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore)
+{
+ const QSize& clientSize = Global::getCurrentRoom()->clientSize;
bool grid[_tilesX][_tilesY];
memset(grid, 0, sizeof(bool) * _tilesX * _tilesY); /* set everything to false */
- /* fill grid */
+ /* fill grid */
for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
- if (*it == toIgnore) { continue; }
-
- const QPoint& p = (*it)->getGridPosition();
-
- for (int x = p.x(); x < p.x() + clientSize.width(); x++) {
- for (int y = p.y(); y < p.y() + clientSize.height(); y++) {
- grid[x][y] = true;
- }
- }
- }
-
- QList<QPoint> freePositions;
- /* check all positions to see if they are available */
- for (int x = 0; x <= _tilesX - clientSize.width(); x++) {
- for ( int y = 0; y <= _tilesY - clientSize.height(); y++) {
- /* check if (x,y) is free */
- bool isFree = true;
- for (int dx = 0; dx < clientSize.width(); dx++) {
- for (int dy = 0; dy < clientSize.height(); dy++) {
- if (grid[x + dx][y + dy]) {
- isFree = false;
- goto endLoop; // double-break
- }
- }
- }
+ if (*it == toIgnore) { continue; }
+
+ const QPoint& p = (*it)->getGridPosition();
+
+ for (int x = p.x(); x < p.x() + clientSize.width(); x++) {
+ for (int y = p.y(); y < p.y() + clientSize.height(); y++) {
+ grid[x][y] = true;
+ }
+ }
+ }
+
+ QList<QPoint> freePositions;
+ /* check all positions to see if they are available */
+ for (int x = 0; x <= _tilesX - clientSize.width(); x++) {
+ for ( int y = 0; y <= _tilesY - clientSize.height(); y++) {
+ /* check if (x,y) is free */
+ bool isFree = true;
+ for (int dx = 0; dx < clientSize.width(); dx++) {
+ for (int dy = 0; dy < clientSize.height(); dy++) {
+ if (grid[x + dx][y + dy]) {
+ isFree = false;
+ goto endLoop; // double-break
+ }
+ }
+ }
endLoop:
- if (isFree) { freePositions << QPoint(x,y); }
- }
- }
- /* among all the free positions, find the closest */
- float min_distance = 10000;
- QPoint bestPosition = QPoint(-1, -1);
-
- for (QPoint freePos : freePositions) {
- QPoint freePosCenter( freePos.x() * getTileWidthPx() + getTileWidthPx() * clientSize.width() / 2,
- freePos.y() * getTileHeightPx() + getTileHeightPx() * clientSize.height() / 2);
- float dist = distance(freePosCenter, preferredPixels);
- if (dist < min_distance) {
- min_distance = dist;
- bestPosition = freePos;
- }
- }
- return bestPosition;
+ if (isFree) { freePositions << QPoint(x, y); }
+ }
+ }
+ /* among all the free positions, find the closest */
+ float min_distance = 10000;
+ QPoint bestPosition = QPoint(-1, -1);
+
+ for (QPoint freePos : freePositions) {
+ QPoint freePosCenter( freePos.x() * getTileWidthPx() + getTileWidthPx() * clientSize.width() / 2,
+ freePos.y() * getTileHeightPx() + getTileHeightPx() * clientSize.height() / 2);
+ float dist = distance(freePosCenter, preferredPixels);
+ if (dist < min_distance) {
+ min_distance = dist;
+ bestPosition = freePos;
+ }
+ }
+ return bestPosition;
}
/* place frame in the cloest available spot */
-void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferredPixels) {
+void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferredPixels)
+{
- QPoint bestPosition = closestFreeSlot(preferredPixels, frame);
+ QPoint bestPosition = closestFreeSlot(preferredPixels, frame);
- frame->setGridPosition(bestPosition);
- QPoint freePosPx(bestPosition.x() * getTileWidthPx(), bestPosition.y() * getTileHeightPx());
- frame->setCurrentPosition(freePosPx);
+ frame->setGridPosition(bestPosition);
+ QPoint freePosPx(bestPosition.x() * getTileWidthPx(), bestPosition.y() * getTileHeightPx());
+ frame->setCurrentPosition(freePosPx);
}
/***************************************************************************//**
@@ -330,8 +335,8 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferredPi
ConnectionFrame* MainWindow::createFrame()
{
// Allocate and resize
- int width = getTileWidthPx() * Global::getCurrentRoom()->clientSize.width();
- int height= getTileHeightPx() * Global::getCurrentRoom()->clientSize.height();
+ int width = getTileWidthPx() * Global::getCurrentRoom()->clientSize.width();
+ int height = getTileHeightPx() * Global::getCurrentRoom()->clientSize.height();
ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, width, height);
_clientFrames.append(cf);
@@ -350,14 +355,14 @@ ConnectionFrame* MainWindow::createFrame()
ConnectionFrame* MainWindow::createFrame(QString computerId, QPoint pxCoord, QPoint gridPosition)
{
// Allocate and resize
- const Room* room = Global::getCurrentRoom();
- int width = getTileWidthPx() * (room == NULL ? 1 : room->clientSize.width());
- int height = getTileHeightPx() * (room == NULL ? 1 : room->clientSize.height());
+ const Room* room = Global::getCurrentRoom();
+ int width = getTileWidthPx() * (room == NULL ? 1 : room->clientSize.width());
+ int height = getTileHeightPx() * (room == NULL ? 1 : room->clientSize.height());
- ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, width, height);
+ ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, width, height);
cf->setComputerId(computerId);
cf->setCurrentPosition(pxCoord);
- cf->setGridPosition(gridPosition);
+ cf->setGridPosition(gridPosition);
_clientFrames.append(cf);
cf->show();
connect(cf, SIGNAL(frameMoved(bool, ConnectionFrame *)), this, SLOT(onPlaceFrame(bool, ConnectionFrame *)));
@@ -399,7 +404,7 @@ void MainWindow::tellClientCurrentSituation(Client* client)
if (ui->action_Lock->isChecked() || _mode == Mode::LockedUnicast)
client->lockScreen(true);
- if (_mode == Mode::Broadcast){
+ if (_mode == Mode::Broadcast) {
client->setDesiredProjectionSource(_streamingSource);
if (_streamingSource != 0) {
client->startVncClient(getClientFromId(_streamingSource));
@@ -412,20 +417,21 @@ void MainWindow::tellClientCurrentSituation(Client* client)
/**
* returns the minimal grid size such that all clients fit on the grid
**/
-QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize) {
- /* collect the maximum coordinates */
- int x = 0;
- int y= 0;
-
- for (auto it = clientPositions.begin(); it != clientPositions.end(); ++it) {
- QPoint pos = it.value();
- if (pos.x() > x) { x = pos.x(); }
- if (pos.y() > y) { y = pos.y(); }
-
- }
- /* need a little extra space */
- QSize size(x + clientSize.width(), y + clientSize.height());
- return size;
+QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize)
+{
+ /* collect the maximum coordinates */
+ int x = 0;
+ int y = 0;
+
+ for (auto it = clientPositions.begin(); it != clientPositions.end(); ++it) {
+ QPoint pos = it.value();
+ if (pos.x() > x) { x = pos.x(); }
+ if (pos.y() > y) { y = pos.y(); }
+
+ }
+ /* need a little extra space */
+ QSize size(x + clientSize.width(), y + clientSize.height());
+ return size;
}
/***************************************************************************//**
@@ -433,17 +439,16 @@ QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clien
*/
void MainWindow::tryToUseRoomTemplate()
{
- qDebug() << "tryToUseRoomTemplate()";
+ qDebug() << "tryToUseRoomTemplate()";
QMap<QString, Room* > roomsList;
QSharedPointer<QSettings> conf = Global::getSettings();
if (!conf->contains("rooms")) { qDebug() << "Invalid config file (no rooms are set)!"; return; }
QStringList rooms = conf->value("rooms").toStringList();
- QString myRoom = "";
+ QString myRoom = "";
- for (QString roomId : rooms)
- {
+ for (QString roomId : rooms) {
conf->beginGroup(roomId);
QString roomName = conf->value("name").toString();
@@ -455,61 +460,61 @@ void MainWindow::tryToUseRoomTemplate()
qDebug() << "Invalid config file (room " << roomName << " needs a mgrIP)!";
return;
}
- QMap<QString, QPoint> clientPositions;
+ QMap<QString, QPoint> clientPositions;
// First store all room configurations in _rooms.
int size = conf->beginReadArray("client");
for (int j = 0; j < size; j++) {
conf->setArrayIndex(j);
// qDebug() << "ip: " << conf.value("ip").toString() << " pos: " << conf.value("pos").toPoint();
// roomsList[i].insert(conf.value("ip").toString(), conf.value("pos").toPoint());
- clientPositions.insert(conf->value("ip").toString(), conf->value("pos").toPoint());
+ clientPositions.insert(conf->value("ip").toString(), conf->value("pos").toPoint());
}
conf->endArray();
- /* read backgroundImage */
- QString image = conf->contains("backgroundImage") ? conf->value("backgroundImage").toString() : "";
+ /* read backgroundImage */
+ QString image = conf->contains("backgroundImage") ? conf->value("backgroundImage").toString() : "";
QString mgrIP = conf->value("mgrIP").toString();
- QString tutorIP = conf->value("tutorIP").toString();
-
- QSize gridSize;
- QSize clientSize(1,1);
- /* read some other properties of the room */
- if (conf->contains("gridSize")) {
- gridSize = conf->value("gridSize").toSize();
- }
- if (conf->contains("clientSize")) {
- clientSize = conf->value("clientSize").toSize();
- }
-
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
+ QString tutorIP = conf->value("tutorIP").toString();
+
+ QSize gridSize;
+ QSize clientSize(1, 1);
+ /* read some other properties of the room */
+ if (conf->contains("gridSize")) {
+ gridSize = conf->value("gridSize").toSize();
+ }
+ if (conf->contains("clientSize")) {
+ clientSize = conf->value("clientSize").toSize();
+ }
+
+ foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) {
if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString()) {
qDebug("Found this ip in config.");
- myRoom = roomName;
+ myRoom = roomName;
}
}
conf->endGroup();
- if (!gridSize.isValid()) {
- /* ok, let's choose the minimum gridSize to fit all clients */
- gridSize = minimalGridSize(clientPositions, clientSize);
- qDebug() << "had to use minimalGridSize(): = " << gridSize;
+ if (!gridSize.isValid()) {
+ /* ok, let's choose the minimum gridSize to fit all clients */
+ gridSize = minimalGridSize(clientPositions, clientSize);
+ qDebug() << "had to use minimalGridSize(): = " << gridSize;
- }
- Room* r = new Room(clientPositions, gridSize, clientSize, image, tutorIP);
- qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
- roomsList.insert(roomName, r);
+ }
+ Room* r = new Room(clientPositions, gridSize, clientSize, image, tutorIP);
+ qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
+ roomsList.insert(roomName, r);
}
Global::setRooms(roomsList);
- if (myRoom == "") {
- /* so apparently this is not a manager of a room */
- if (Global::manager_only) {
- cout << "exiting because of the argument --manager-only was set and this computer is not a manager" << endl;
- exit(0);
- }
- } else {
- switchRoomTo(myRoom);
- }
-
+ if (myRoom == "") {
+ /* so apparently this is not a manager of a room */
+ if (Global::manager_only) {
+ cout << "exiting because of the argument --manager-only was set and this computer is not a manager" << endl;
+ exit(0);
+ }
+ } else {
+ switchRoomTo(myRoom);
+ }
+
}
/***************************************************************************//**
@@ -520,10 +525,8 @@ void MainWindow::tryToUseRoomTemplate()
*/
Client* MainWindow::getClientFromId(int id)
{
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- if ((*it)->client() != NULL)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
+ if ((*it)->client() != NULL) {
if ((*it)->client()->id() == id)
return (*it)->client();
}
@@ -539,8 +542,7 @@ Client* MainWindow::getClientFromId(int id)
*/
ConnectionFrame* MainWindow::getTutorFrame()
{
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
if (((*it) != NULL) && ((*it)->isTutor()))
return (*it);
}
@@ -555,8 +557,7 @@ ConnectionFrame* MainWindow::getTutorFrame()
*/
ConnectionFrame* MainWindow::getSelectedFrame()
{
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
if (((*it) != NULL) && ((*it)->isSelected()))
return (*it);
}
@@ -597,17 +598,18 @@ enum AspectStatus { GRID_OK, GRID_TOO_WIDE, GRID_TOO_TALL };
* size. The parameters in here are hand-adjusted. Feel free to make it more or
* less sensitive.
* */
-AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize) {
- float aspectRoom = ((float) gridSize.height()) / ((float) gridSize.width());
- float aspectFrame = ((float) frameSize.height()) / ((float) frameSize.width());
-
- if (aspectRoom / aspectFrame < 0.8) {
- return GRID_TOO_WIDE;
- }
- if ( aspectFrame / aspectRoom < 0.8) {
- return GRID_TOO_TALL;
- }
- return GRID_OK;
+AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize)
+{
+ float aspectRoom = ((float) gridSize.height()) / ((float) gridSize.width());
+ float aspectFrame = ((float) frameSize.height()) / ((float) frameSize.width());
+
+ if (aspectRoom / aspectFrame < 0.8) {
+ return GRID_TOO_WIDE;
+ }
+ if ( aspectFrame / aspectRoom < 0.8) {
+ return GRID_TOO_TALL;
+ }
+ return GRID_OK;
}
@@ -617,80 +619,81 @@ AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize) {
*/
void MainWindow::resizeEvent(QResizeEvent* e)
{
- const Room* room = Global::getCurrentRoom();
- const QSize& clientSize = room->clientSize;
+ const Room* room = Global::getCurrentRoom();
+ const QSize& clientSize = room->clientSize;
if (ui->frmRoom->size().width() < 100 || ui->frmRoom->size().height() < 100 || _tilesX <= 0 || _tilesY <= 0) { return; }
- QSize newGridSize = room->gridSize;
-
- /* do we have to add virtual columns? */
- while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_WIDE) {
- /* add row */
- newGridSize.setHeight(newGridSize.height() + 1);
- }
- while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_TALL) {
- /* add column */
- newGridSize.setWidth(newGridSize.width() + 1);
- }
- this->_tilesX = newGridSize.width();
- this->_tilesY = newGridSize.height();
-
- /* Bring back frame that are now out of the screen */
- for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
- const QPoint gp = (*it)->getGridPosition();
- if ( gp.x() >= _tilesX || gp.y() >= _tilesY ) {
- qDebug() << "bring frame back";
- placeFrameInFreeSlot(*it, (*it)->getCurrentPosition());
- }
- }
+ QSize newGridSize = room->gridSize;
+
+ /* do we have to add virtual columns? */
+ while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_WIDE) {
+ /* add row */
+ newGridSize.setHeight(newGridSize.height() + 1);
+ }
+ while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_TALL) {
+ /* add column */
+ newGridSize.setWidth(newGridSize.width() + 1);
+ }
+ this->_tilesX = newGridSize.width();
+ this->_tilesY = newGridSize.height();
+
+ /* Bring back frame that are now out of the screen */
+ for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
+ const QPoint gp = (*it)->getGridPosition();
+ if ( gp.x() >= _tilesX || gp.y() >= _tilesY ) {
+ qDebug() << "bring frame back";
+ placeFrameInFreeSlot(*it, (*it)->getCurrentPosition());
+ }
+ }
/* Resize all connection windows */
- for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); ++it)
- {
- int newPosX = (*it)->getGridPosition().x() * getTileWidthPx();
- int newPosY = (*it)->getGridPosition().y() * getTileHeightPx();
- QPoint newPos(newPosX, newPosY);
-
- (*it)->setSize(getTileWidthPx() * clientSize.width(), getTileHeightPx() * clientSize.height());
- (*it)->move(newPos);
+ for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
+ int newPosX = (*it)->getGridPosition().x() * getTileWidthPx();
+ int newPosY = (*it)->getGridPosition().y() * getTileHeightPx();
+ QPoint newPos(newPosX, newPosY);
+
+ (*it)->setSize(getTileWidthPx() * clientSize.width(), getTileHeightPx() * clientSize.height());
+ (*it)->move(newPos);
}
- /* update background image label */
- if (_backgroundImage != NULL) {
- int w = ui->frmRoom->width() - 5; /* to make sure that we don't enlarge the window */
- int h = ui->frmRoom->height() - 5;
- ui->imageLabel->hide();
- ui->imageLabel->setScaledContents(true);
- ui->imageLabel->setPixmap(QPixmap::fromImage(*_backgroundImage).scaled(w,h, Qt::IgnoreAspectRatio));
- ui->imageLabel->show();
- } else {
- ui->imageLabel->clear();
- }
+ /* update background image label */
+ if (_backgroundImage != NULL) {
+ int w = ui->frmRoom->width() - 5; /* to make sure that we don't enlarge the window */
+ int h = ui->frmRoom->height() - 5;
+ ui->imageLabel->hide();
+ ui->imageLabel->setScaledContents(true);
+ ui->imageLabel->setPixmap(QPixmap::fromImage(*_backgroundImage).scaled(w, h, Qt::IgnoreAspectRatio));
+ ui->imageLabel->show();
+ } else {
+ ui->imageLabel->clear();
+ }
}
-void MainWindow::lockContextButtons() {
- for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
- (*it)->setEnabled(false);
- }
+void MainWindow::lockContextButtons()
+{
+ for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
+ (*it)->setEnabled(false);
+ }
}
-void MainWindow::unlockContextButtons() {
- for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
- (*it)->setEnabled(true);
- }
- /* and disable some again based on special rules */
- if (getSelectedFrame()->client() != NULL) {
- ui->action_DeleteClient->setEnabled(false);
- }
- if (getSelectedFrame()->client() == NULL) {
- ui->action_SetAsTutor->setEnabled(false);
- ui->action_StudentToTutorExclusive->setEnabled(false);
- ui->action_StudentToTutor->setEnabled(false);
- ui->action_TutorToStudent->setEnabled(false);
- }
+void MainWindow::unlockContextButtons()
+{
+ for (auto it = _contextButtons.begin(); it != _contextButtons.end(); ++it) {
+ (*it)->setEnabled(true);
+ }
+ /* and disable some again based on special rules */
+ if (getSelectedFrame()->client() != NULL) {
+ ui->action_DeleteClient->setEnabled(false);
+ }
+ if (getSelectedFrame()->client() == NULL) {
+ ui->action_SetAsTutor->setEnabled(false);
+ ui->action_StudentToTutorExclusive->setEnabled(false);
+ ui->action_StudentToTutor->setEnabled(false);
+ ui->action_TutorToStudent->setEnabled(false);
+ }
}
@@ -709,11 +712,9 @@ void MainWindow::mouseReleaseEvent(QMouseEvent* e)
if (pos.x() < 0 || pos.y() < 0)
return;
const QSize frame(ui->frmRoom->size());
- if (frame.width() > pos.x() && frame.height() > pos.y())
- {
- lockContextButtons();
- if (getSelectedFrame() != NULL)
- {
+ if (frame.width() > pos.x() && frame.height() > pos.y()) {
+ lockContextButtons();
+ if (getSelectedFrame() != NULL) {
getSelectedFrame()->setSelection(false);
}
}
@@ -749,9 +750,9 @@ void MainWindow::onPlaceFrame(bool activateTrash, ConnectionFrame* connectionFra
{
// if (_tilesX <= 0 || _tilesY <= 0) return;
const QPoint &preferredPixels = connectionFrame->frameGeometry().center();
- placeFrameInFreeSlot(connectionFrame, preferredPixels);
+ placeFrameInFreeSlot(connectionFrame, preferredPixels);
- resizeEvent(NULL);
+ resizeEvent(NULL);
}
/***************************************************************************//**
@@ -762,20 +763,19 @@ void MainWindow::onFrameClicked(ConnectionFrame* frame)
{
// If same frame is clicked again,, do nothing
if (getSelectedFrame() == frame)
- return;
+ return;
// If another frame has been selected, unselect it
// Set the ui selected and set a new reference
- if (getSelectedFrame() != NULL)
- {
+ if (getSelectedFrame() != NULL) {
getSelectedFrame()->setSelection(false);
}
frame->setSelection(true);
qDebug() << "ID of frame: " << frame->computerId();
qDebug() << "ID of selectedFrame: " << getSelectedFrame()->computerId();
- qDebug() << "position of selectedFrame: " << getSelectedFrame()->getGridPosition();
+ qDebug() << "position of selectedFrame: " << getSelectedFrame()->getGridPosition();
- unlockContextButtons();
+ unlockContextButtons();
}
/***************************************************************************//**
@@ -784,16 +784,13 @@ void MainWindow::onFrameClicked(ConnectionFrame* frame)
void MainWindow::onSessionNameClick()
{
_countSessionNameUpdate++;
- if (_countSessionNameUpdate > 1)
- {
+ if (_countSessionNameUpdate > 1) {
int ret = QMessageBox::question(this, "Warning", tr("Sure, You want to change SessionName again?\n"
- "All Clients will be deleted afterwards."), 0, 1, 2);
- if (ret == 1)
- {
+ "All Clients will be deleted afterwards."), 0, 1, 2);
+ if (ret == 1) {
_sessionNameWindow->show(Global::sessionName());
}
- }
- else
+ } else
_sessionNameWindow->show((Global::sessionName()));
}
@@ -804,11 +801,9 @@ void MainWindow::onSessionNameUpdate()
{
// Stop all projections and clear all clients, which where connected to old sessionName.
reset();
- if (_countSessionNameUpdate > 1)
- {
+ if (_countSessionNameUpdate > 1) {
{
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
(*it)->hide();
(*it)->deleteLater();
}
@@ -863,79 +858,78 @@ void MainWindow::onReloadRoomCancel()
_reloadWindow->hide();
}
-void MainWindow::switchRoomTo(QString roomToReload) {
- // qDebug() << roomToReload;
- Global::setCurrentRoom(roomToReload);
- Room *room = Global::getRooms()[roomToReload];
- /* set tiles */
- _tilesX = room->gridSize.width();
- _tilesY = room->gridSize.height();
-
-
- /* place connection frames */
- for (auto it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) {
- QString computerId = it.key();
- QPoint pos = it.value();
- QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
-
- ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
- cf->move(cf->getCurrentPosition());
- onPlaceFrame(false, cf);
- if (computerId == room->tutorIP) {
- qDebug() << "set computer with id " << computerId << " as tutor per configuration";
- if (getTutorFrame() != NULL) {
- getTutorFrame()->setTutor(false);
- }
- cf->setTutor(true);
- } else {
- //qDebug() << "not tutor because id is " << computerId << " and tutorIP is " << room->tutorIP;
- }
- }
-
- /* load background image */
- QString imgPath = Global::getCurrentRoom()->imagePath;
- qDebug() << "imgPath is " << imgPath;
-
- /* delete old image */
- if (_backgroundImage != NULL) {delete _backgroundImage; }
- _backgroundImage = NULL;
-
- if (imgPath != "") {
- qDebug() << "set background image path: " << imgPath;
- if (imgPath.endsWith("svg")) {
- /* render once with maximal screen size */
- const QSize &s = QApplication::desktop()->screenGeometry().size(); // ui->frmRoom->geometry().size();
- QSvgRenderer renderer(imgPath);
- _backgroundImage = new QImage(s, QImage::Format_ARGB32);
- _backgroundImage->fill(Qt::lightGray); /* background color */
- QPainter painter(_backgroundImage);
- renderer.render(&painter);
- } else {
- _backgroundImage = new QImage();
- _backgroundImage->load(imgPath);
- }
- }
-
- /* and force a resize event (this scales the image) */
- resizeEvent(NULL);
+void MainWindow::switchRoomTo(QString roomToReload)
+{
+ // qDebug() << roomToReload;
+ Global::setCurrentRoom(roomToReload);
+ Room *room = Global::getRooms()[roomToReload];
+ /* set tiles */
+ _tilesX = room->gridSize.width();
+ _tilesY = room->gridSize.height();
+
+
+ /* place connection frames */
+ for (auto it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) {
+ QString computerId = it.key();
+ QPoint pos = it.value();
+ QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
+
+ ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
+ cf->move(cf->getCurrentPosition());
+ onPlaceFrame(false, cf);
+ if (computerId == room->tutorIP) {
+ qDebug() << "set computer with id " << computerId << " as tutor per configuration";
+ if (getTutorFrame() != NULL) {
+ getTutorFrame()->setTutor(false);
+ }
+ cf->setTutor(true);
+ } else {
+ //qDebug() << "not tutor because id is " << computerId << " and tutorIP is " << room->tutorIP;
+ }
+ }
+
+ /* load background image */
+ QString imgPath = Global::getCurrentRoom()->imagePath;
+ qDebug() << "imgPath is " << imgPath;
+
+ /* delete old image */
+ if (_backgroundImage != NULL) {delete _backgroundImage; }
+ _backgroundImage = NULL;
+
+ if (imgPath != "") {
+ qDebug() << "set background image path: " << imgPath;
+ if (imgPath.endsWith("svg")) {
+ /* render once with maximal screen size */
+ const QSize &s = QApplication::desktop()->screenGeometry().size(); // ui->frmRoom->geometry().size();
+ QSvgRenderer renderer(imgPath);
+ _backgroundImage = new QImage(s, QImage::Format_ARGB32);
+ _backgroundImage->fill(Qt::lightGray); /* background color */
+ QPainter painter(_backgroundImage);
+ renderer.render(&painter);
+ } else {
+ _backgroundImage = new QImage();
+ _backgroundImage->load(imgPath);
+ }
+ }
+
+ /* and force a resize event (this scales the image) */
+ resizeEvent(NULL);
}
void MainWindow::onReloadRoomOk()
{
- if (_reloadWindow->ui->roomList->currentItem() == NULL)
- {
+ if (_reloadWindow->ui->roomList->currentItem() == NULL) {
QMessageBox::critical(this, "Warning", tr("No item selected, please select room!"), 0, 1);
return;
}
int ret = QMessageBox::QMessageBox::question(this, "Warning", tr("Are you sure you want to reload the room?\n"
- "Note that all clients will be deleted."), 0, 1, 2);
+ "Note that all clients will be deleted."), 0, 1, 2);
if (ret == 1) {
disconnect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk()));
disconnect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel()));
// Delete all clients.
- for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); it++)
- {
+ for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); it++) {
(*it)->hide();
(*it)->deleteLater();
}
@@ -943,19 +937,21 @@ void MainWindow::onReloadRoomOk()
// Load new room configuration.
QString roomToReload = _reloadWindow->ui->roomList->currentItem()->data(0).toString();
- switchRoomTo(roomToReload);
+ switchRoomTo(roomToReload);
_reloadWindow->ui->roomList->clear();
_reloadWindow->hide();
- }
+ }
}
-int MainWindow::getTileWidthPx() const {
- return ui->frmRoom->size().width() / _tilesX;
+int MainWindow::getTileWidthPx() const
+{
+ return ui->frmRoom->size().width() / _tilesX;
}
-int MainWindow::getTileHeightPx() const {
- return ui->frmRoom->size().height() / _tilesY;
+int MainWindow::getTileHeightPx() const
+{
+ return ui->frmRoom->size().height() / _tilesY;
}
/***************************************************************************//**
@@ -981,8 +977,7 @@ void MainWindow::onButtonTutorToAll()
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
else if (_clientFrames.size() == 1)
QMessageBox::critical(this, tr("Projection"), sStrNoDestAv);
- else
- {
+ else {
// If this mode is already active, reset everything
if (_mode == Mode::Broadcast) {
reset();
@@ -1018,8 +1013,7 @@ void MainWindow::onButtonTutorToStudent()
QMessageBox::critical(this, tr("Projection"), sStrDestOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- {
+ else {
// If this is the first call in this mode clear the watchers
if (_mode != Mode::Multicast) {
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
@@ -1057,11 +1051,9 @@ void MainWindow::onButtonStudentToTutor()
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- {
+ else {
// If this is not the first run in this mode and the current source is selected, stop the streaming.
- if (_mode == Mode::Unicast && getSelectedFrame()->client()->id() == _streamingSource)
- {
+ if (_mode == Mode::Unicast && getSelectedFrame()->client()->id() == _streamingSource) {
// Stop reset everything
_mode = Mode::None;
reset();
@@ -1071,7 +1063,7 @@ void MainWindow::onButtonStudentToTutor()
// Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
if ((*it)->client() != NULL)
- (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id():NO_SOURCE);
+ (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id() : NO_SOURCE);
DisableButtons();
_mode = Mode::Unicast;
@@ -1097,11 +1089,9 @@ void MainWindow::onButtonStudentToTutorExclusive()
QMessageBox::critical(this, tr("Projection"), sStrSourceOffline);
else if (getTutorFrame()->client() == NULL)
QMessageBox::critical(this, tr("Projection"), sStrTutorOffline);
- else
- {
+ else {
// If this is not the first run in this mode and the current source is selected, stop the streaming.
- if (_mode == Mode::Unicast && getSelectedFrame()->client()->id() == _streamingSource)
- {
+ if (_mode == Mode::Unicast && getSelectedFrame()->client()->id() == _streamingSource) {
// Stop reset everything
_mode = Mode::None;
reset();
@@ -1111,7 +1101,7 @@ void MainWindow::onButtonStudentToTutorExclusive()
// Unset all clients desired sources. Except the tutors desired source, this has to be the selecteds frame
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
if ((*it)->client() != NULL)
- (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id():NO_SOURCE);
+ (*it)->client()->setDesiredProjectionSource(getTutorFrame()->client()->id() == (*it)->client()->id() ? getSelectedFrame()->client()->id() : NO_SOURCE);
DisableButtons();
_mode = Mode::LockedUnicast;
@@ -1142,8 +1132,7 @@ void MainWindow::onButtonLock(bool checked)
// Stop all projections
reset();
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
if ((*it)->client() == NULL)
continue;
(*it)->client()->lockScreen(checked);
@@ -1167,20 +1156,16 @@ void MainWindow::onButtonSetAsTutor()
ui->action_Lock->setChecked(false);
// If no frame is selected, warning.
- if (getSelectedFrame() == 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 (getSelectedFrame()->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
- {
+ } else { // If selected client is locked, first unlock
getSelectedFrame()->client()->lockScreen(false);
}
@@ -1189,8 +1174,7 @@ void MainWindow::onButtonSetAsTutor()
return;
// Else unset the old and set the new tutor
- if (getTutorFrame() != NULL)
- {
+ if (getTutorFrame() != NULL) {
getTutorFrame()->setTutor(false);
}
getSelectedFrame()->setTutor(true);
@@ -1227,23 +1211,19 @@ void MainWindow::onClientAuthenticating(Client* client, ClientLogin* request)
bool inuse;
QString check = request->name;
int addnum = 1;
- do
- {
+ do {
inuse = false;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
Client *c = (**it).client();
if (c == NULL)
continue;
if (!c->isAuthed())
continue;
- if (c->ip() == request->ip)
- {
+ if (c->ip() == request->ip) {
request->accept = false;
return;
}
- if (c->name() == check)
- {
+ if (c->name() == check) {
inuse = true;
check = request->name + " (" + QString::number(++addnum) + ")";
break;
@@ -1273,17 +1253,14 @@ void MainWindow::onClientAuthenticated(Client* client)
connect(client, SIGNAL(vncClientStateChange(Client*)), this, SLOT(onVncClientStateChange(Client*)));
bool hasActiveTutor = false;
ConnectionFrame *existing = NULL;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
// qDebug() << "Existing frame ip: " << (*it)->computerId();
// qDebug() << "New Clients ip: " << client->ip();
// qDebug() << ((*it)->computerId() == client->ip());
- if ((*it)->computerId() == client->ip())
- {
+ if ((*it)->computerId() == client->ip()) {
existing = *it;
}
- if ((*it)->isTutor())
- {
+ if ((*it)->isTutor()) {
if ((*it)->client() != NULL)
hasActiveTutor = true;
}
@@ -1291,21 +1268,17 @@ void MainWindow::onClientAuthenticated(Client* client)
bool isTutor = false;
- if (!hasActiveTutor)
- {
- for (int i = 0; i < _tutorList.size(); i++)
- {
+ if (!hasActiveTutor) {
+ for (int i = 0; i < _tutorList.size(); i++) {
// Check if client is possible tutor
- if (client->ip() == _tutorList[i])
- {
+ if (client->ip() == _tutorList[i]) {
isTutor = true;
break;
}
}
}
// Clients ip already exists, but was not active.
- if (existing != NULL)
- {
+ if (existing != NULL) {
// qDebug() << "Should go into this if clause.";
existing->setTutor(isTutor);
existing->assignClient(client);
@@ -1325,8 +1298,7 @@ void MainWindow::onClientAuthenticated(Client* client)
if (x >= _tilesX || y >= _tilesY)
ok = false;
- if (ok)
- {
+ if (ok) {
if (x < 0)
x = 0;
if (y < 0)
@@ -1334,9 +1306,7 @@ void MainWindow::onClientAuthenticated(Client* client)
qDebug("Move E");
cf->move(x * getTileWidthPx(), y * getTileHeightPx());
onPlaceFrame(true, cf);
- }
- else
- {
+ } else {
// Move to any free tile
placeFrameInFreeSlot(cf);
}
@@ -1345,7 +1315,7 @@ void MainWindow::onClientAuthenticated(Client* client)
// Assign client instance
cf->assignClient(client);
- resizeEvent(NULL); // This is where all the positioning should be
+ resizeEvent(NULL); // This is where all the positioning should be
tellClientCurrentSituation(client);
updateExamMode();
@@ -1362,12 +1332,10 @@ void MainWindow::onVncServerStateChange(Client* client)
if (client == getClientFromId(_streamingSource))
EnableButtons();
- if (client->isActiveVncServer())
- {
+ if (client->isActiveVncServer()) {
// apply the desired projection sources
for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- if ( (*it)->client() != NULL) // Ignore offline clients
- {
+ if ( (*it)->client() != NULL) { // Ignore offline clients
if ( (*it)->client()->desiredProjectionSource() == client->id() )
(*it)->client()->startVncClient(client);
else
@@ -1377,14 +1345,10 @@ void MainWindow::onVncServerStateChange(Client* client)
}
// Dont forget to unlock the vnc server
client->lockScreen(false);
- }
- else
- {
+ } else {
// VNC server stopped on some client or failed to start - reset local pending projection information
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it)
- {
- if ((*it)->client() != NULL)
- {
+ for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
+ if ((*it)->client() != NULL) {
if ((*it)->client()->desiredProjectionSource() == client->id()) {
(*it)->client()->setDesiredProjectionSource(NO_SOURCE);
(*it)->client()->stopVncClient();
@@ -1397,7 +1361,7 @@ void MainWindow::onVncServerStateChange(Client* client)
client->lockScreen(client->desiredProjectionSource() == NO_SOURCE && _mode == Mode::LockedUnicast);
// If this was the current source remember that there is no source anymore and reset mode
- if (client == getClientFromId(_streamingSource)){
+ if (client == getClientFromId(_streamingSource)) {
_streamingSource = NO_SOURCE;
_mode = Mode::None;
}
@@ -1412,11 +1376,9 @@ void MainWindow::onVncServerStateChange(Client* client)
*/
void MainWindow::onVncClientStateChange(Client* client)
{
- if (client != NULL)
- {
+ if (client != NULL) {
// VNC Client stopped -> remove from watchers
- if (!client->isActiveVncClient())
- {
+ if (!client->isActiveVncClient()) {
// Only unset a desired Projection source if it has not changed meanwhile
if (client->projectionSource() == client->desiredProjectionSource())
client->setDesiredProjectionSource(NO_SOURCE);
@@ -1438,8 +1400,7 @@ void MainWindow::onVncClientStateChange(Client* client)
break;
}
- if ( !(serverHasWatchers || _mode == Mode::Broadcast) )
- {
+ if ( !(serverHasWatchers || _mode == Mode::Broadcast) ) {
Client* c = getClientFromId(client->projectionSource());
if (c != NULL)
c->stopVncServer();
@@ -1453,10 +1414,10 @@ void MainWindow::onVncClientStateChange(Client* client)
*/
void MainWindow::DisableButtons()
{
- qDebug() << "DisableButtons()";
+ qDebug() << "DisableButtons()";
_buttonLockTimer->start();
- foreach (QAction* a, _lockingButtons)
- a->setDisabled(true);
+ foreach (QAction * a, _lockingButtons)
+ a->setDisabled(true);
}
/***************************************************************************//**
@@ -1464,16 +1425,17 @@ void MainWindow::DisableButtons()
*/
void MainWindow::EnableButtons()
{
- qDebug() << "EnableButtons()";
+ qDebug() << "EnableButtons()";
_buttonLockTimer->stop();
- foreach (QAction* a, _lockingButtons)
- a->setEnabled(true);
+ foreach (QAction * a, _lockingButtons)
+ a->setEnabled(true);
}
-void MainWindow::onDeleteClient() {
+void MainWindow::onDeleteClient()
+{
// If no frame is selected, warning.
- ConnectionFrame* frame = getSelectedFrame();
+ ConnectionFrame* frame = getSelectedFrame();
if (frame == NULL) {
QMessageBox::critical(this, tr("Selection"), tr("No client is selected."));
return;
@@ -1482,20 +1444,20 @@ void MainWindow::onDeleteClient() {
QMessageBox::critical(this, tr("Selection"), tr("This client is still connected."));
return;
} else {
- qDebug() << "Now delete the client";
- int ret = QMessageBox::question(this, "Warning", tr("Sure, You want to delete selected client?"), 0, 1, 2);
- if (ret == 1) {
- frame->hide();
- frame->deleteLater();
- _clientFrames.removeOne(frame);
- lockContextButtons();
+ qDebug() << "Now delete the client";
+ int ret = QMessageBox::question(this, "Warning", tr("Sure, You want to delete selected client?"), 0, 1, 2);
+ if (ret == 1) {
+ frame->hide();
+ frame->deleteLater();
+ _clientFrames.removeOne(frame);
+ lockContextButtons();
updateExamMode();
- return;
- } else {
- frame->move(frame->getPreviousPosition());
+ return;
+ } else {
+ frame->move(frame->getPreviousPosition());
updateExamMode();
- return;
- }
+ return;
+ }
}
diff --git a/src/server/mainwindow/mainwindow.h b/src/server/mainwindow/mainwindow.h
index 3de0e1c..637628a 100644
--- a/src/server/mainwindow/mainwindow.h
+++ b/src/server/mainwindow/mainwindow.h
@@ -12,8 +12,9 @@ class DiscoveryListener;
class HelpWindow;
class ReloadRoomWindow;
-namespace Ui{
- class MainWindow;
+namespace Ui
+{
+class MainWindow;
}
/**
@@ -27,7 +28,7 @@ class MainWindow : public QMainWindow
public:
MainWindow(QWidget *parent = 0);
- ~MainWindow();
+ ~MainWindow();
private:
@@ -41,29 +42,30 @@ private:
Qt::ToolBarArea _tbArea;
int _tilesX;
int _tilesY;
- QImage* _backgroundImage = NULL;
+ QImage* _backgroundImage = NULL;
QLabel* _examModeLabel = NULL;
- /* virtual columns to preserve the aspect ratio of the loaded room */
- int _virtCols;
- int _virtRows;
+ /* virtual columns to preserve the aspect ratio of the loaded room */
+ int _virtCols;
+ int _virtRows;
// Button block stuff
QTimer *_buttonLockTimer;
QList<QAction*> _lockingButtons;
static const qint64 _buttonBlockTime = 2000;
- /* Context-sensitive Buttons */
- QList<QAction*> _contextButtons;
+ /* Context-sensitive Buttons */
+ QList<QAction*> _contextButtons;
// Management stuff
- enum class Mode {
- Broadcast,
- Multicast,
- Unicast,
- LockedUnicast,
- None
+ enum class Mode
+ {
+ Broadcast,
+ Multicast,
+ Unicast,
+ LockedUnicast,
+ None
} _mode;
int _streamingSource;
int _countSessionNameUpdate;
@@ -73,8 +75,8 @@ private:
DiscoveryListener *_discoveryListener;
QStringList _tutorList;
- QPoint closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore);
- void placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred = QPoint(0,0));
+ QPoint closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore);
+ void placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferred = QPoint(0, 0));
ConnectionFrame* createFrame();
ConnectionFrame* createFrame(QString computerId, QPoint position, QPoint gridPosition);
bool loadPosition(QSharedPointer<QSettings> settings, const QString& id, int& x, int& y);
@@ -92,19 +94,19 @@ private:
void resizeEvent(QResizeEvent *e);
void mouseReleaseEvent(QMouseEvent* e);
- int getTileWidthPx() const;
- int getTileHeightPx() const;
+ int getTileWidthPx() const;
+ int getTileHeightPx() const;
- void lockContextButtons();
- void unlockContextButtons();
+ void lockContextButtons();
+ void unlockContextButtons();
- void switchRoomTo(QString);
+ void switchRoomTo(QString);
protected slots:
void onSessionNameClick();
void onSessionNameUpdate();
- void onDeleteClient();
+ void onDeleteClient();
void onButtonLock(bool checked);
void onButtonStudentToTutor();
diff --git a/src/server/net/certmanager.cpp b/src/server/net/certmanager.cpp
index b85966a..e91fed3 100644
--- a/src/server/net/certmanager.cpp
+++ b/src/server/net/certmanager.cpp
@@ -1,94 +1,90 @@
-/*
- # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
- #
- # This program is free software distributed under the GPL version 2.
- # See http://openslx.org/COPYING
- #
- # If you have any feedback please consult http://openslx.org/feedback and
- # send your suggestions, praise, or complaints to feedback@openslx.org
- #
- # General information about OpenSLX can be found at http://openslx.org/
- # -----------------------------------------------------------------------------
- # src/util/CertManager.cpp
- # - Manage SSL certificates
- # - provide access by name
- # -----------------------------------------------------------------------------
- */
-
-#include "certmanager.h"
-#include "../util/util.h"
-#include <QMap>
-#include <QDir>
-#include <QDebug>
-#include <QFileInfo>
-#include <QSettings>
-#include <cstdlib>
-
-namespace CertManager
-{
-static QMap<QString, QSslCertificate> _certs;
-static QMap<QString, QSslKey> _keys;
-
-static void generateFiles(QString& key, QString& cert);
-static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert);
-
-bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &cert)
-{
- if (_keys.contains(name))
- {
- key = _keys[name];
- cert = _certs[name];
- return true;
- }
- QString certFile = QDir::homePath().append("/").append(CERTSTORAGE).append(name);
- QString keyFile = certFile;
- keyFile.append(".rsa");
- certFile.append(".crt");
- //
- if (!loadFiles(keyFile, certFile, key, cert))
- {
- generateFiles(keyFile, certFile);
- if (!loadFiles(keyFile, certFile, key, cert))
- qDebug() << "error while creating cert and key files\n";
- return false;
- }
- _certs.insert(name, cert);
- _keys.insert(name, key);
- return true;
-}
-
-static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert)
-{
- QFileInfo keyInfo(keyFile);
- QFileInfo certInfo(certFile);
- if (keyInfo.exists() && certInfo.exists())
- { // Both files exist, see if they're valid and return
- QFile kf(keyFile);
- kf.open(QFile::ReadOnly);
- key = QSslKey(&kf, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
- QList<QSslCertificate> certlist = QSslCertificate::fromPath(certFile);
- if (!key.isNull() && !certlist.empty())
- {
- cert = certlist.first();
- if (!cert.isNull())
- {
- return true;
- }
- }
- }
- return false;
-}
-
-static void generateFiles(QString& key, QString& cert)
-{
- char tmp[1000];
- remove(key.toLocal8Bit().data());
- remove(cert.toLocal8Bit().data());
- snprintf(tmp, 1000,
- "openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -subj '/C=DE/ST=BaWue/L=Freiburg/CN=openslx.org' -keyout \"%s\" -out \"%s\"",
- key.toLocal8Bit().data(), cert.toLocal8Bit().data());
- system(tmp);
- snprintf(tmp, 1000, "chmod 0600 \"%s\" \"%s\"", key.toLocal8Bit().data(), cert.toLocal8Bit().data());
- system(tmp);
-}
-}
+/*
+ # Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+ #
+ # This program is free software distributed under the GPL version 2.
+ # See http://openslx.org/COPYING
+ #
+ # If you have any feedback please consult http://openslx.org/feedback and
+ # send your suggestions, praise, or complaints to feedback@openslx.org
+ #
+ # General information about OpenSLX can be found at http://openslx.org/
+ # -----------------------------------------------------------------------------
+ # src/util/CertManager.cpp
+ # - Manage SSL certificates
+ # - provide access by name
+ # -----------------------------------------------------------------------------
+ */
+
+#include "certmanager.h"
+#include "../util/util.h"
+#include <QMap>
+#include <QDir>
+#include <QDebug>
+#include <QFileInfo>
+#include <QSettings>
+#include <cstdlib>
+
+namespace CertManager
+{
+static QMap<QString, QSslCertificate> _certs;
+static QMap<QString, QSslKey> _keys;
+
+static void generateFiles(QString& key, QString& cert);
+static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert);
+
+bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &cert)
+{
+ if (_keys.contains(name)) {
+ key = _keys[name];
+ cert = _certs[name];
+ return true;
+ }
+ QString certFile = QDir::homePath().append("/").append(CERTSTORAGE).append(name);
+ QString keyFile = certFile;
+ keyFile.append(".rsa");
+ certFile.append(".crt");
+ //
+ if (!loadFiles(keyFile, certFile, key, cert)) {
+ generateFiles(keyFile, certFile);
+ if (!loadFiles(keyFile, certFile, key, cert))
+ qDebug() << "error while creating cert and key files\n";
+ return false;
+ }
+ _certs.insert(name, cert);
+ _keys.insert(name, key);
+ return true;
+}
+
+static bool loadFiles(QString& keyFile, QString& certFile, QSslKey &key, QSslCertificate &cert)
+{
+ QFileInfo keyInfo(keyFile);
+ QFileInfo certInfo(certFile);
+ if (keyInfo.exists() && certInfo.exists()) {
+ // Both files exist, see if they're valid and return
+ QFile kf(keyFile);
+ kf.open(QFile::ReadOnly);
+ key = QSslKey(&kf, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
+ QList<QSslCertificate> certlist = QSslCertificate::fromPath(certFile);
+ if (!key.isNull() && !certlist.empty()) {
+ cert = certlist.first();
+ if (!cert.isNull()) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static void generateFiles(QString& key, QString& cert)
+{
+ char tmp[1000];
+ remove(key.toLocal8Bit().data());
+ remove(cert.toLocal8Bit().data());
+ snprintf(tmp, 1000,
+ "openssl req -x509 -nodes -days 3650 -newkey rsa:1024 -subj '/C=DE/ST=BaWue/L=Freiburg/CN=openslx.org' -keyout \"%s\" -out \"%s\"",
+ key.toLocal8Bit().data(), cert.toLocal8Bit().data());
+ system(tmp);
+ snprintf(tmp, 1000, "chmod 0600 \"%s\" \"%s\"", key.toLocal8Bit().data(), cert.toLocal8Bit().data());
+ system(tmp);
+}
+}
diff --git a/src/server/net/certmanager.h b/src/server/net/certmanager.h
index c69bc23..fee2691 100644
--- a/src/server/net/certmanager.h
+++ b/src/server/net/certmanager.h
@@ -1,29 +1,29 @@
-/*
-# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
-#
-# This program is free software distributed under the GPL version 2.
-# See http://openslx.org/COPYING
-#
-# If you have any feedback please consult http://openslx.org/feedback and
-# send your suggestions, praise, or complaints to feedback@openslx.org
-#
-# General information about OpenSLX can be found at http://openslx.org/
-# -----------------------------------------------------------------------------
-# src/util/CertManager.cpp
-# - Manage SSL certificates
-# - provide access by name
-# -----------------------------------------------------------------------------
-*/
-
-#ifndef CERTMANAGER_H_
-#define CERTMANAGER_H_
-
-#include <QtNetwork/QSslCertificate>
-#include <QtNetwork/QSslKey>
-
-namespace CertManager
-{
- bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &cert);
-}
-
-#endif /* CERTMANAGER_H_ */
+/*
+# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# src/util/CertManager.cpp
+# - Manage SSL certificates
+# - provide access by name
+# -----------------------------------------------------------------------------
+*/
+
+#ifndef CERTMANAGER_H_
+#define CERTMANAGER_H_
+
+#include <QtNetwork/QSslCertificate>
+#include <QtNetwork/QSslKey>
+
+namespace CertManager
+{
+bool getPrivateKeyAndCert(const QString &name, QSslKey &key, QSslCertificate &cert);
+}
+
+#endif /* CERTMANAGER_H_ */
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index 84c45a9..5cd5c30 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -33,13 +33,13 @@ Client::Client(QSslSocket* socket) : _socket(socket)
qDebug("*** Client %s created.", qPrintable(_socket->peerAddress().toString()));
// Connect important signals
connect(_socket, SIGNAL(disconnected()),
- this, SLOT(disconnect()));
+ this, SLOT(disconnect()));
connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)),
- this, SLOT(disconnect()));
+ this, SLOT(disconnect()));
connect(_socket, SIGNAL(sslErrors(const QList<QSslError> &)),
- this, SLOT(disconnect()));
+ this, SLOT(disconnect()));
connect(_socket, SIGNAL(readyRead()),
- this, SLOT(onDataArrival()));
+ this, SLOT(onDataArrival()));
// Send challenge
_challenge.resize(CHALLENGE_LEN);
for (int i = 0; i < CHALLENGE_LEN; ++i)
@@ -64,23 +64,18 @@ Client::~Client()
/******************************************************************************/
void Client::timerEvent(QTimerEvent* event)
{
- if (event->timerId() == _timerPingTimeout)
- {
- if (_pingTimeout < QDateTime::currentMSecsSinceEpoch())
- {
+ if (event->timerId() == _timerPingTimeout) {
+ if (_pingTimeout < QDateTime::currentMSecsSinceEpoch()) {
qDebug() << "Client" << _socket->peerAddress().toString() << "has a ping timeout.";
killTimer(_timerPingTimeout);
this->disconnect();
}
- }
- else if (event->timerId() == _timerIdAuthTimeout)
- {
+ } else if (event->timerId() == _timerIdAuthTimeout) {
// Client did not send login request within 3 seconds
killTimer(_timerIdAuthTimeout);
_timerIdAuthTimeout = 0;
this->disconnect();
- }
- else
+ } else
killTimer(event->timerId());
}
@@ -90,8 +85,7 @@ void Client::sendMessage(NetworkMessage& message)
if (_socket->state() != QAbstractSocket::ConnectedState)
return;
message.writeMessage(_socket);
- if (!message.writeComplete())
- {
+ if (!message.writeComplete()) {
qCritical() << "SendMessage to client " << _name << "@" << _socket->peerAddress().toString() << " failed!";
}
}
@@ -99,8 +93,7 @@ void Client::sendMessage(NetworkMessage& message)
/******************************************************************************/
void Client::requestThumb(const int width, const int height)
{
- if (_socket->state() != QAbstractSocket::ConnectedState)
- {
+ if (_socket->state() != QAbstractSocket::ConnectedState) {
qDebug("requestThumb called in bad state");
return;
}
@@ -115,25 +108,21 @@ void Client::requestThumb(const int width, const int height)
void Client::onDataArrival()
{
//
- if (_socket->state() != QAbstractSocket::ConnectedState)
- {
+ if (_socket->state() != QAbstractSocket::ConnectedState) {
qDebug("dataArrival called in bad state");
return;
}
bool ret;
- while (_socket->bytesAvailable() > 0)
- {
+ while (_socket->bytesAvailable() > 0) {
ret = _fromClient.readMessage(_socket); // let the message read data from socket
- if (ret == NM_READ_FAILED) // error parsing msg, disconnect client!
- {
+ if (ret == NM_READ_FAILED) { // error parsing msg, disconnect client!
this->disconnect();
return;
}
if (ret == NM_READ_INCOMPLETE)
return;
- if (_fromClient.readComplete()) // message is complete
- {
+ if (_fromClient.readComplete()) { // message is complete
this->handleMsg();
_fromClient.reset();
}
@@ -145,47 +134,35 @@ void Client::handleMsg()
{
_pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS;
const QString &id = _fromClient.getFieldString(_ID);
- if (id.isEmpty())
- {
+ if (id.isEmpty()) {
qDebug("Received message with empty ID field. ignored.");
return;
}
- if (_authed == 2)
- {
+ if (_authed == 2) {
// Following messages are only valid of the client is already authenticated
- if (id == _THUMB)
- {
+ if (id == _THUMB) {
QPixmap pixmap;
const QByteArray& rawImage = _fromClient.getFieldBytes("IMG");
/* size 0 means the client is in exam-mode and therefore doesn't send any thumbnail */
if (rawImage.size() > 0) {
- if (!pixmap.loadFromData(rawImage))
- {
+ if (!pixmap.loadFromData(rawImage)) {
qDebug("Could not decode thumbnail image from client.");
return;
}
_rawRemoteScreen = QByteArray(rawImage);
emit thumbUpdated(this, pixmap, rawImage);
}
- }
- else if (id == _VNCSERVER)
- {
+ } else if (id == _VNCSERVER) {
// Client tells about startup of vnc server
const int port = _fromClient.getFieldString("PORT").toInt();
- if (port <= 0)
- {
- if (_vncPort <= 0)
- {
- qDebug() << "Starting VNC server on client" << _name << " (" << _socket->peerAddress().toString()+_vncPort << ") failed.";
- }
- else
- {
+ if (port <= 0) {
+ if (_vncPort <= 0) {
+ qDebug() << "Starting VNC server on client" << _name << " (" << _socket->peerAddress().toString() + _vncPort << ") failed.";
+ } else {
qDebug() << "Client " << _name << " stopped its VNC server";
}
- }
- else
- {
+ } else {
_vncRoPass = _fromClient.getFieldString("ROPASS");
_vncRwPass = _fromClient.getFieldString("RWPASS");
qDebug() << "Client " << _name << " started its VNC server";
@@ -193,20 +170,15 @@ void Client::handleMsg()
_vncPort = port;
emit vncServerStateChange(this);
emit stateChanged();
- }
- else if (id == _VNCCLIENT)
- {
+ } else if (id == _VNCCLIENT) {
// Client tells us that it started or stopped displaying a remote screen via VNC
const int projectionSource = (int)_fromClient.getFieldString("CLIENTID").toInt();
- if (_fromClient.getFieldString("ENABLED").toInt() != 0)
- {
+ if (_fromClient.getFieldString("ENABLED").toInt() != 0) {
qDebug() << "Client " << _name << " started its VNC client (watching " << projectionSource << ")";
_projectionSource = projectionSource;
_isActiveVncClient = true;
emit vncClientStateChange(this);
- }
- else
- {
+ } else {
qDebug() << "Client " << _name << " stopped its VNC client (watched " << projectionSource << ")";
_isActiveVncClient = false;
emit vncClientStateChange(this);
@@ -217,10 +189,8 @@ void Client::handleMsg()
}
// Not authed yet, only care about login requests
- if (_authed == 1)
- {
- if (id == _LOGIN)
- {
+ if (_authed == 1) {
+ if (id == _LOGIN) {
killTimer(_timerIdAuthTimeout);
_timerIdAuthTimeout = 0;
ClientLogin request;
@@ -233,8 +203,7 @@ void Client::handleMsg()
qDebug() << "Login request by " << request.name << (request.examMode ? "(in exam mode)" : "");
// emit event, see if request is accepted
emit authenticating(this, &request);
- if (!request.accept)
- {
+ if (!request.accept) {
qDebug("Request denied.");
this->disconnect(); // Nope
return;
@@ -253,16 +222,14 @@ void Client::handleMsg()
}
// Did not pass challenge yet
- if (_authed == 0)
- {
+ if (_authed == 0) {
// Waiting for challenge reply by client
- if (id == _CHALLENGE)
- {
+ if (id == _CHALLENGE) {
QByteArray hash(_fromClient.getFieldBytes(_HASH));
QByteArray challenge(_fromClient.getFieldBytes(_CHALLENGE));
if (genSha1(&Global::sessionNameArray(), &_challenge) != hash
- && !(Global::getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString())))
- { // Challenge reply is invalid, drop client
+ && !(Global::getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString()))) {
+ // Challenge reply is invalid, drop client
NetworkMessage msgErr;
msgErr.buildErrorMessage("Challenge reply invalid.");
msgErr.writeMessage(_socket);
@@ -310,8 +277,7 @@ void Client::startVncClient(const Client * const to)
msg.setField("ROPASS", to->_vncRoPass);
msg.setField("CLIENTID", QString::number(to->_id));
msg.setField("CAPTION", to->_name + " @ " + to->_host);
- if (!to->_rawRemoteScreen.isEmpty())
- {
+ if (!to->_rawRemoteScreen.isEmpty()) {
msg.setField(_THUMB, to->_rawRemoteScreen);
}
sendMessage(msg);
@@ -333,18 +299,18 @@ void Client::stopVncClient()
*/
bool Client::isManagerMachine()
{
- foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
- if (address != QHostAddress(QHostAddress::LocalHost)
- && this != NULL
- && this->ip() == address.toString())
- return true;
+ foreach (const QHostAddress & address, QNetworkInterface::allAddresses())
+ if (address != QHostAddress(QHostAddress::LocalHost)
+ && this != NULL
+ && this->ip() == address.toString())
+ return true;
return false;
}
/******************************************************************************/
void Client::lockScreen(bool lock)
{
- if (!_isTutor && _locked != lock && !isManagerMachine()){
+ if (!_isTutor && _locked != lock && !isManagerMachine()) {
_locked = lock;
NetworkMessage msg;
msg.setField(_ID, _LOCK);
diff --git a/src/server/net/client.h b/src/server/net/client.h
index 872d0e1..e7c9c5c 100644
--- a/src/server/net/client.h
+++ b/src/server/net/client.h
@@ -12,8 +12,7 @@
#define NO_SOURCE 0
-struct ClientLogin
-{
+struct ClientLogin {
bool accept;
QString name;
QString host;
@@ -39,13 +38,13 @@ public:
inline const bool isActiveVncClient() const { return _isActiveVncClient; }
inline const bool isActiveVncServer() const { return _vncPort > 0; }
inline const bool isLocked() const { return _locked; }
- inline const int desiredProjectionSource(){ return _desiredSource; }
+ inline const int desiredProjectionSource() { return _desiredSource; }
inline const int projectionSource() const { return _projectionSource; }
inline const int isExamMode() const { return _isExamMode; }
// Setters
- inline void setTutor(bool enable){ _isTutor = enable; }
- inline void setDesiredProjectionSource(int id){_desiredSource = id;}
+ inline void setTutor(bool enable) { _isTutor = enable; }
+ inline void setDesiredProjectionSource(int id) {_desiredSource = id;}
inline void setExamMode(bool mode) { _isExamMode = mode; }
//Send message stuff
diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp
index 892ca53..8eb1091 100644
--- a/src/server/net/discoverylistener.cpp
+++ b/src/server/net/discoverylistener.cpp
@@ -55,21 +55,18 @@ DiscoveryListener::~DiscoveryListener()
static quint16 hash(const QHostAddress& host)
{
static quint16 seed1 = 0, seed2 = 0;
- while (seed1 == 0) // Make sure the algorithm uses different seeds each time the program is
- { // run to prevent hash collision attacks
+ while (seed1 == 0) { // Make sure the algorithm uses different seeds each time the program is
+ // run to prevent hash collision attacks
seed1 = (quint16)(qrand() & 0xffff);
seed2 = (quint16)(qrand() & 0xffff);
}
quint8 data[16], len;
- if (host.protocol() == QAbstractSocket::IPv4Protocol)
- {
+ if (host.protocol() == QAbstractSocket::IPv4Protocol) {
// IPv4
quint32 addr = host.toIPv4Address();
len = 4;
memcpy(data, &addr, len);
- }
- else if (QAbstractSocket::IPv6Protocol)
- {
+ } else if (QAbstractSocket::IPv6Protocol) {
// IPv6
len = 16;
// Fast version (might break with future qt versions)
@@ -79,9 +76,7 @@ static quint16 hash(const QHostAddress& host)
for (int i = 0; i < len; ++i)
data[i] = addr[i];
*/
- }
- else
- {
+ } else {
// Durr?
len = 2;
data[0] = (quint16)qrand();
@@ -89,8 +84,7 @@ static quint16 hash(const QHostAddress& host)
}
quint16 result = 0;
quint16 mod = seed1;
- for (quint8 i = 0; i < len; ++i)
- {
+ for (quint8 i = 0; i < len; ++i) {
result = ((result << 1) + data[i]) ^ mod; // because of the shift this algo is not suitable for len(input) > 8
mod += seed2 + data[i];
}
@@ -107,8 +101,7 @@ static quint16 hash(const QHostAddress& host)
*/
void DiscoveryListener::timerEvent(QTimerEvent* event)
{
- for (int i = 0; i < SPAM_MODERATE_AT_ONCE; ++i)
- {
+ for (int i = 0; i < SPAM_MODERATE_AT_ONCE; ++i) {
if (++_counterResetPos >= SD_PACKET_TABLE_SIZE)
_counterResetPos = 0;
if (_packetCounter[_counterResetPos] > 10)
@@ -130,14 +123,12 @@ void DiscoveryListener::onReadyRead()
char data[UDPBUFSIZ];
QHostAddress addr;
quint16 port;
- while (_socket.hasPendingDatagrams())
- {
+ while (_socket.hasPendingDatagrams()) {
const qint64 size = _socket.readDatagram(data, UDPBUFSIZ, &addr, &port);
if (size <= 0)
continue;
const quint16 bucket = hash(addr) % SD_PACKET_TABLE_SIZE;
- if (_packetCounter[bucket] > SPAM_CUTOFF)
- {
+ if (_packetCounter[bucket] > SPAM_CUTOFF) {
qDebug() << "SD: Potential (D)DoS from " << _socket.peerAddress().toString();
// emit some signal and pop up a big warning that someone is flooding/ddosing the PVS SD
// ... on the other hand, will the user understand? ;)
@@ -160,8 +151,7 @@ void DiscoveryListener::onReadyRead()
continue;
// If so, check if the submitted hash seems valid
if (genSha1(&Global::sessionNameArray(), &salt1, &iplist) != hash &&
- !(Global::getCurrentRoom()->clientPositions.contains(addr.toString())))
- {
+ !(Global::getCurrentRoom()->clientPositions.contains(addr.toString()))) {
// did not match local session name and client is not in same room.
continue;
}
diff --git a/src/server/net/filedownloader.cpp b/src/server/net/filedownloader.cpp
index aa27948..b930869 100644
--- a/src/server/net/filedownloader.cpp
+++ b/src/server/net/filedownloader.cpp
@@ -10,27 +10,32 @@
#include "filedownloader.h"
FileDownloader::FileDownloader(QObject *parent) :
- QObject(parent) {
+ QObject(parent)
+{
connect(&m_WebCtrl, SIGNAL(finished(QNetworkReply*)),
- SLOT(fileDownloaded(QNetworkReply*)));
+ SLOT(fileDownloaded(QNetworkReply*)));
}
-FileDownloader::~FileDownloader() {
+FileDownloader::~FileDownloader()
+{
}
-void FileDownloader::connectSlot(QObject* obj, const char* slot) {
+void FileDownloader::connectSlot(QObject* obj, const char* slot)
+{
QObject::connect(this, SIGNAL(downloaded(QByteArray&)),
- obj, slot);
+ obj, slot);
}
-void FileDownloader::fileDownloaded(QNetworkReply* pReply) {
+void FileDownloader::fileDownloaded(QNetworkReply* pReply)
+{
QByteArray downloadedData = pReply->readAll();
//emit a signal
pReply->deleteLater();
emit downloaded(downloadedData);
}
-void FileDownloader::downloadFile(const QUrl& fileUrl) {
+void FileDownloader::downloadFile(const QUrl& fileUrl)
+{
m_WebCtrl.get(QNetworkRequest(fileUrl));
}
diff --git a/src/server/net/listenserver.cpp b/src/server/net/listenserver.cpp
index ba56177..1ce5016 100644
--- a/src/server/net/listenserver.cpp
+++ b/src/server/net/listenserver.cpp
@@ -31,8 +31,7 @@ ListenServer::~ListenServer()
void ListenServer::newClientConnection()
{
QSslSocket* sock;
- while ((sock = (QSslSocket*)_server.nextPendingConnection()) != NULL)
- {
+ while ((sock = (QSslSocket*)_server.nextPendingConnection()) != NULL) {
Client* client = new Client(sock); // TODO: what happens with disconnected clients
emit newClient(client);
}
diff --git a/src/server/net/sslserver.cpp b/src/server/net/sslserver.cpp
index ffbf262..3d8f924 100644
--- a/src/server/net/sslserver.cpp
+++ b/src/server/net/sslserver.cpp
@@ -46,15 +46,12 @@ void SslServer::incomingConnection(int socketDescriptor)
serverSocket->setPeerVerifyMode(QSslSocket::VerifyNone);
serverSocket->setProtocol(QSsl::TlsV1SslV3);
//printf("Keylen %d\n", serverSocket->privateKey().length());
- if (serverSocket->setSocketDescriptor(socketDescriptor))
- {
+ if (serverSocket->setSocketDescriptor(socketDescriptor)) {
// Once the connection is successfully encrypted, raise our newConnection event
connect(serverSocket, SIGNAL(encrypted()), this, SIGNAL(newConnection()));
serverSocket->startServerEncryption();
_pending.push_back(serverSocket);
- }
- else
- {
+ } else {
serverSocket->deleteLater();
}
}
@@ -67,8 +64,7 @@ void SslServer::sslErrors(const QList<QSslError> & errors)
void SslServer::timerEvent(QTimerEvent* event)
{
// Remove all sockets marked for deletion
- while (!_delete.isEmpty())
- {
+ while (!_delete.isEmpty()) {
QSslSocket *sock = _delete.takeFirst();
sock->blockSignals(true);
sock->deleteLater();
@@ -79,8 +75,7 @@ void SslServer::timerEvent(QTimerEvent* event)
bool SslServer::hasPendingConnections()
{
- for (QList<QSslSocket*>::iterator it(_pending.begin()); it != _pending.end(); it++)
- {
+ for (QList<QSslSocket*>::iterator it(_pending.begin()); it != _pending.end(); it++) {
qDebug("State: %d - Encrypted: %d", (int)(*it)->state(), (*it)->isEncrypted());
if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted())
return true;
@@ -90,10 +85,8 @@ bool SslServer::hasPendingConnections()
QTcpSocket* SslServer::nextPendingConnection()
{
- for (QList<QSslSocket*>::iterator it(_pending.begin()); it != _pending.end(); it++)
- {
- if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted())
- {
+ for (QList<QSslSocket*>::iterator it(_pending.begin()); it != _pending.end(); it++) {
+ if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted()) {
QSslSocket *sock = *it;
QObject::disconnect(sock, SIGNAL(encrypted()), this, SIGNAL(newConnection()));
_pending.removeAll(sock);
@@ -101,10 +94,8 @@ QTcpSocket* SslServer::nextPendingConnection()
return sock;
}
}
- for (QList<QSslSocket*>::iterator it(_delete.begin()); it != _delete.end(); it++)
- {
- if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted())
- {
+ for (QList<QSslSocket*>::iterator it(_delete.begin()); it != _delete.end(); it++) {
+ if ((*it)->state() == QAbstractSocket::ConnectedState && (*it)->isEncrypted()) {
QSslSocket *sock = *it;
QObject::disconnect(sock, SIGNAL(encrypted()), this, SIGNAL(newConnection()));
_pending.removeAll(sock);
diff --git a/src/server/numerickeyboard/numerickeyboard.cpp b/src/server/numerickeyboard/numerickeyboard.cpp
index 3f59eb8..d819a58 100644
--- a/src/server/numerickeyboard/numerickeyboard.cpp
+++ b/src/server/numerickeyboard/numerickeyboard.cpp
@@ -7,30 +7,30 @@ using std::endl;
NumericKeyboard::NumericKeyboard(QWidget *parent) :
- QGroupBox(parent),
- ui(new Ui::NumericKeyboard)
+ QGroupBox(parent),
+ ui(new Ui::NumericKeyboard)
{
- ui->setupUi(this);
- /* das geht leider nicht ? */
+ ui->setupUi(this);
+ /* das geht leider nicht ? */
// connect(ui->button_0, SIGNAL (clicked(bool)), this, SLOT (relayDigit(0)));
- connect(ui->button_0, SIGNAL (clicked(bool)), this, SLOT (relayDigit0()));
- connect(ui->button_1, SIGNAL (clicked(bool)), this, SLOT (relayDigit1()));
- connect(ui->button_2, SIGNAL (clicked(bool)), this, SLOT (relayDigit2()));
- connect(ui->button_3, SIGNAL (clicked(bool)), this, SLOT (relayDigit3()));
- connect(ui->button_4, SIGNAL (clicked(bool)), this, SLOT (relayDigit4()));
- connect(ui->button_5, SIGNAL (clicked(bool)), this, SLOT (relayDigit5()));
- connect(ui->button_6, SIGNAL (clicked(bool)), this, SLOT (relayDigit6()));
- connect(ui->button_7, SIGNAL (clicked(bool)), this, SLOT (relayDigit7()));
- connect(ui->button_8, SIGNAL (clicked(bool)), this, SLOT (relayDigit8()));
- connect(ui->button_9, SIGNAL (clicked(bool)), this, SLOT (relayDigit9()));
+ connect(ui->button_0, SIGNAL (clicked(bool)), this, SLOT (relayDigit0()));
+ connect(ui->button_1, SIGNAL (clicked(bool)), this, SLOT (relayDigit1()));
+ connect(ui->button_2, SIGNAL (clicked(bool)), this, SLOT (relayDigit2()));
+ connect(ui->button_3, SIGNAL (clicked(bool)), this, SLOT (relayDigit3()));
+ connect(ui->button_4, SIGNAL (clicked(bool)), this, SLOT (relayDigit4()));
+ connect(ui->button_5, SIGNAL (clicked(bool)), this, SLOT (relayDigit5()));
+ connect(ui->button_6, SIGNAL (clicked(bool)), this, SLOT (relayDigit6()));
+ connect(ui->button_7, SIGNAL (clicked(bool)), this, SLOT (relayDigit7()));
+ connect(ui->button_8, SIGNAL (clicked(bool)), this, SLOT (relayDigit8()));
+ connect(ui->button_9, SIGNAL (clicked(bool)), this, SLOT (relayDigit9()));
- connect(ui->button_del, SIGNAL (clicked(bool)), this, SLOT(relayDelete()));
+ connect(ui->button_del, SIGNAL (clicked(bool)), this, SLOT(relayDelete()));
}
NumericKeyboard::~NumericKeyboard()
{
- delete ui;
+ delete ui;
}
void NumericKeyboard::relayDigit0() { emit digitTyped(0); }
@@ -43,4 +43,4 @@ void NumericKeyboard::relayDigit6() { emit digitTyped(6); }
void NumericKeyboard::relayDigit7() { emit digitTyped(7); }
void NumericKeyboard::relayDigit8() { emit digitTyped(8); }
void NumericKeyboard::relayDigit9() { emit digitTyped(9); }
-void NumericKeyboard::relayDelete() { emit digitDelete(); }
+void NumericKeyboard::relayDelete() { emit digitDelete(); }
diff --git a/src/server/numerickeyboard/numerickeyboard.h b/src/server/numerickeyboard/numerickeyboard.h
index dce7999..3ece99c 100644
--- a/src/server/numerickeyboard/numerickeyboard.h
+++ b/src/server/numerickeyboard/numerickeyboard.h
@@ -3,37 +3,38 @@
#include <QGroupBox>
-namespace Ui {
+namespace Ui
+{
class NumericKeyboard;
}
class NumericKeyboard : public QGroupBox
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit NumericKeyboard(QWidget *parent = 0);
- ~NumericKeyboard();
+ explicit NumericKeyboard(QWidget *parent = 0);
+ ~NumericKeyboard();
private:
- Ui::NumericKeyboard *ui;
+ Ui::NumericKeyboard *ui;
signals:
- void digitTyped(int);
- void digitDelete();
+ void digitTyped(int);
+ void digitDelete();
private slots:
- void relayDigit0();
- void relayDigit1();
- void relayDigit2();
- void relayDigit3();
- void relayDigit4();
- void relayDigit5();
- void relayDigit6();
- void relayDigit7();
- void relayDigit8();
- void relayDigit9();
- void relayDelete();
+ void relayDigit0();
+ void relayDigit1();
+ void relayDigit2();
+ void relayDigit3();
+ void relayDigit4();
+ void relayDigit5();
+ void relayDigit6();
+ void relayDigit7();
+ void relayDigit8();
+ void relayDigit9();
+ void relayDelete();
};
diff --git a/src/server/reloadroomwindow/reloadroomwindow.h b/src/server/reloadroomwindow/reloadroomwindow.h
index 9ce0aba..2d2ae85 100644
--- a/src/server/reloadroomwindow/reloadroomwindow.h
+++ b/src/server/reloadroomwindow/reloadroomwindow.h
@@ -3,7 +3,8 @@
#include <QDialog>
-namespace Ui {
+namespace Ui
+{
class ReloadRoom;
}
diff --git a/src/server/sessionnamewindow/sessionnamewindow.cpp b/src/server/sessionnamewindow/sessionnamewindow.cpp
index ba67557..6ffbeca 100644
--- a/src/server/sessionnamewindow/sessionnamewindow.cpp
+++ b/src/server/sessionnamewindow/sessionnamewindow.cpp
@@ -30,11 +30,11 @@ SessionNameWindow::SessionNameWindow(QWidget *parent) :
connect(ui->bboxOkCancel, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->cmdRandom, SIGNAL(clicked(bool)), this, SLOT(onGenerateRandomName()));
- /* add a virtual numeric keyboard */
- NumericKeyboard *keyboard = new NumericKeyboard();
- ui->keyboard_placeholder->addWidget(keyboard);
- connect(keyboard, SIGNAL(digitTyped(int)), this, SLOT(onDigitTyped(int)));
- connect(keyboard, SIGNAL(digitDelete()), this, SLOT(onDigitDelete()));
+ /* add a virtual numeric keyboard */
+ NumericKeyboard *keyboard = new NumericKeyboard();
+ ui->keyboard_placeholder->addWidget(keyboard);
+ connect(keyboard, SIGNAL(digitTyped(int)), this, SLOT(onDigitTyped(int)));
+ connect(keyboard, SIGNAL(digitDelete()), this, SLOT(onDigitDelete()));
}
@@ -76,14 +76,16 @@ void SessionNameWindow::onGenerateRandomName()
}
/** deletes the last digit of the saved sessionname */
-void SessionNameWindow::onDigitDelete() {
- QString text = ui->lineEditName->text();
- ui->lineEditName->setText(text.left(text.length() - 1));
+void SessionNameWindow::onDigitDelete()
+{
+ QString text = ui->lineEditName->text();
+ ui->lineEditName->setText(text.left(text.length() - 1));
}
/** appends the digit to the session name */
-void SessionNameWindow::onDigitTyped(int i) {
- QString text = ui->lineEditName->text();
- ui->lineEditName->setText(text + QString::number(i));
+void SessionNameWindow::onDigitTyped(int i)
+{
+ QString text = ui->lineEditName->text();
+ ui->lineEditName->setText(text + QString::number(i));
}
diff --git a/src/server/sessionnamewindow/sessionnamewindow.h b/src/server/sessionnamewindow/sessionnamewindow.h
index b3e6cdc..2338def 100644
--- a/src/server/sessionnamewindow/sessionnamewindow.h
+++ b/src/server/sessionnamewindow/sessionnamewindow.h
@@ -4,7 +4,8 @@
#include <QtGui>
-namespace Ui{
+namespace Ui
+{
class SessionName;
}
@@ -27,9 +28,9 @@ protected:
private slots:
void onOkClicked();
void onGenerateRandomName();
- void onDigitDelete();
- void onDigitTyped(int);
-
+ void onDigitDelete();
+ void onDigitTyped(int);
+
signals:
void updateSessionName();
diff --git a/src/server/util/global.cpp b/src/server/util/global.cpp
index 990eee1..97c0355 100644
--- a/src/server/util/global.cpp
+++ b/src/server/util/global.cpp
@@ -36,31 +36,33 @@ void Global::setCurrentRoom(QString room)
Global::_currentRoom = room;
}
-const Room* Global::getCurrentRoom() {
- if (_rooms.contains(_currentRoom)) {
- return _rooms[_currentRoom];
- } else {
- static Room* defaultRoom = NULL;
- if (defaultRoom == NULL) {
- defaultRoom = new Room(QMap<QString, QPoint>(), QSize(8, 6), QSize(1,1), "", "");
- }
- return defaultRoom;
- }
+const Room* Global::getCurrentRoom()
+{
+ if (_rooms.contains(_currentRoom)) {
+ return _rooms[_currentRoom];
+ } else {
+ static Room* defaultRoom = NULL;
+ if (defaultRoom == NULL) {
+ defaultRoom = new Room(QMap<QString, QPoint>(), QSize(8, 6), QSize(1, 1), "", "");
+ }
+ return defaultRoom;
+ }
}
-bool Global::manager_only = false;
+bool Global::manager_only = false;
bool Global::_isExam = false;
QString Global::_iniPath = "";
-QSharedPointer<QSettings> Global::getSettings() {
- QSharedPointer<QSettings> set;
- if (_iniPath == "") {
- /* default location (system scope) */
- set = QSharedPointer<QSettings>(new QSettings(QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2"));
- } else {
- /* use _iniPath to find ini file */
- set = QSharedPointer<QSettings>(new QSettings(Global::_iniPath, QSettings::IniFormat));
- }
- set->setIniCodec("UTF-8");
- return set;
+QSharedPointer<QSettings> Global::getSettings()
+{
+ QSharedPointer<QSettings> set;
+ if (_iniPath == "") {
+ /* default location (system scope) */
+ set = QSharedPointer<QSettings>(new QSettings(QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2"));
+ } else {
+ /* use _iniPath to find ini file */
+ set = QSharedPointer<QSettings>(new QSettings(Global::_iniPath, QSettings::IniFormat));
+ }
+ set->setIniCodec("UTF-8");
+ return set;
}
diff --git a/src/server/util/global.h b/src/server/util/global.h
index 6ab1c42..ce1c2ab 100644
--- a/src/server/util/global.h
+++ b/src/server/util/global.h
@@ -19,31 +19,32 @@
#include <QSharedPointer>
struct Room {
- Room(QMap<QString, QPoint> cPos, QSize grid, QSize client, QString image, QString tutor) :
- clientPositions(cPos),
- gridSize(grid),
- clientSize(client),
- imagePath(image),
- tutorIP(tutor){};
- QMap<QString, QPoint> clientPositions;
- QSize gridSize;
- QSize clientSize;
- QString imagePath;
- QString tutorIP;
+ Room(QMap<QString, QPoint> cPos, QSize grid, QSize client, QString image, QString tutor) :
+ clientPositions(cPos),
+ gridSize(grid),
+ clientSize(client),
+ imagePath(image),
+ tutorIP(tutor) {};
+ QMap<QString, QPoint> clientPositions;
+ QSize gridSize;
+ QSize clientSize;
+ QString imagePath;
+ QString tutorIP;
};
-class Global {
+class Global
+{
private:
- Global(){}
- ~Global(){}
+ Global() {}
+ ~Global() {}
static QString _sessionName;
static QByteArray _sessionNameArray;
static QMap<QString, Room*> _rooms;
static QString _currentRoom;
- static bool _isExam;
- static QString _iniPath;
+ static bool _isExam;
+ static QString _iniPath;
public:
static const QString& sessionName() { return Global::_sessionName; }
@@ -51,26 +52,27 @@ public:
static void setSessionName(const QString& name);
static void setSessionName();
- static bool manager_only;
+ static bool manager_only;
static void setRooms(const QMap<QString, Room*> & roomList);
- static const QMap<QString, Room*> & getRooms() {
+ static const QMap<QString, Room*> & getRooms()
+ {
return _rooms;
}
- static void setIniPath(QString s) {_iniPath = s;};
- static QString getIniPath() { return _iniPath; };
- static QSharedPointer<QSettings> getSettings();
+ static void setIniPath(QString s) {_iniPath = s;};
+ static QString getIniPath() { return _iniPath; };
+ static QSharedPointer<QSettings> getSettings();
- static bool isExam() { return _isExam; }
- static void setExam(bool b) { _isExam = b; }
+ static bool isExam() { return _isExam; }
+ static void setExam(bool b) { _isExam = b; }
static void setCurrentRoom(QString room);
static const QString& getCurrentRoomName() { return _currentRoom; }
- /* returns a pointer to the current room or a pointer to the constant "defaultRoom".
- * (NEVER returns NULL or undefined) */
- static const Room* getCurrentRoom();
+ /* returns a pointer to the current room or a pointer to the constant "defaultRoom".
+ * (NEVER returns NULL or undefined) */
+ static const Room* getCurrentRoom();
};