summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-09-30 12:02:38 +0200
committerChristian Klinger2016-09-30 12:02:38 +0200
commit877607b07f30cbb8d7d8d06b1b91383095fdc144 (patch)
tree4c2ca41db4b9caa8e6c370237771d58bd99d7f13 /src/server/mainwindow/mainwindow.cpp
parentadded a pre-commit hook for astyle. (diff)
downloadpvs2-877607b07f30cbb8d7d8d06b1b91383095fdc144.tar.gz
pvs2-877607b07f30cbb8d7d8d06b1b91383095fdc144.tar.xz
pvs2-877607b07f30cbb8d7d8d06b1b91383095fdc144.zip
refactoring.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp72
1 files changed, 27 insertions, 45 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index e1d3f1e..59e47a4 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -23,6 +23,7 @@
#include <QPainter>
#include <QImage>
// Other custom UI elements
+#include "../serverapp/serverapp.h"
#include "../clicklabel/clicklabel.h"
#include "../sessionnamewindow/sessionnamewindow.h"
#include "../connectionframe/connectionframe.h"
@@ -35,8 +36,6 @@
#include "../net/filedownloader.h"
// Others
#include "../../shared/settings.h"
-#include "../util/util.h"
-#include "../util/global.h"
// Auto-generated ui class
#include "ui_mainwindow.h"
#include "ui_reloadroom.h"
@@ -85,7 +84,7 @@ MainWindow::MainWindow(QWidget* parent) :
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
- Global::setSessionName();
+ serverApp->setSessionName();
//conWin = new ConnectionWindow(ui->widget);
//ui->VconWinLayout->addWidget(conWin);
@@ -109,7 +108,7 @@ MainWindow::MainWindow(QWidget* parent) :
_examModeLabel->setFixedHeight(400);
ui->toolBar->insertWidget(ui->action_TutorToStudent, _examModeLabel);
- Global::setExam(false);
+ serverApp->setExam(false);
updateExamMode();
// Close button in tool bar
@@ -185,31 +184,21 @@ MainWindow::MainWindow(QWidget* parent) :
* disabling many features in the toolbar **/
void MainWindow::updateExamMode()
{
- /* TODO */
int numerator = 0;
int denominator = 0;
- for (QList<ConnectionFrame*>::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) {
+ for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
Client* c = (*it)->client();
if (c != NULL) {
bool b = c->isExamMode();
numerator += b ? 1 : 0;
denominator++;
}
-
}
- qDebug() << "updateExamMode(), ratio: " << numerator << "/" << denominator;
-
- /* TODO: Find clients */
- // static const QMap<QString, Room*> rooms = getRooms();
- // for (auto k : rooms.keys()) {
- // Room* r = rooms.value(k);
- // numerator += r->examMode;
- // denominator++;
- // }
- Global::setExam(numerator * 2 >= denominator && denominator > 0);
- bool e = Global::isExam();
+
+ serverApp->setExam(numerator * 2 >= denominator && denominator > 0);
+ bool e = serverApp->isExam();
qDebug() << "isExam is " << e;
ui->action_TutorToAll->setVisible(!e);
ui->action_StudentToTutor->setVisible(!e);
@@ -263,7 +252,7 @@ float distance(QPointF a, QPointF b)
*/
QPoint MainWindow::closestFreeSlot(QPoint preferredPixels, ConnectionFrame* toIgnore)
{
- const QSize& clientSize = Global::getCurrentRoom()->clientSize;
+ const QSize& clientSize = serverApp->getCurrentRoom()->clientSize;
bool grid[_tilesX][_tilesY];
memset(grid, 0, sizeof(bool) * _tilesX * _tilesY); /* set everything to false */
@@ -315,10 +304,9 @@ endLoop:
return bestPosition;
}
-/* place frame in the cloest available spot */
+/* place frame in the closest available spot */
void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame, QPoint preferredPixels)
{
-
QPoint bestPosition = closestFreeSlot(preferredPixels, frame);
frame->setGridPosition(bestPosition);
@@ -335,8 +323,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() * serverApp->getCurrentRoom()->clientSize.width();
+ int height = getTileHeightPx() * serverApp->getCurrentRoom()->clientSize.height();
ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, width, height);
_clientFrames.append(cf);
@@ -355,7 +343,7 @@ ConnectionFrame* MainWindow::createFrame()
ConnectionFrame* MainWindow::createFrame(QString computerId, QPoint pxCoord, QPoint gridPosition)
{
// Allocate and resize
- const Room* room = Global::getCurrentRoom();
+ const Room* room = serverApp->getCurrentRoom();
int width = getTileWidthPx() * (room == NULL ? 1 : room->clientSize.width());
int height = getTileHeightPx() * (room == NULL ? 1 : room->clientSize.height());
@@ -441,7 +429,7 @@ void MainWindow::tryToUseRoomTemplate()
{
qDebug() << "tryToUseRoomTemplate()";
QMap<QString, Room* > roomsList;
- QSharedPointer<QSettings> conf = Global::getSettings();
+ QSharedPointer<QSettings> conf = serverApp->getSettings();
if (!conf->contains("rooms")) { qDebug() << "Invalid config file (no rooms are set)!"; return; }
QStringList rooms = conf->value("rooms").toStringList();
@@ -465,8 +453,6 @@ void MainWindow::tryToUseRoomTemplate()
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());
}
conf->endArray();
@@ -504,10 +490,10 @@ void MainWindow::tryToUseRoomTemplate()
qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
roomsList.insert(roomName, r);
}
- Global::setRooms(roomsList);
+ serverApp->setRooms(roomsList);
if (myRoom == "") {
/* so apparently this is not a manager of a room */
- if (Global::manager_only) {
+ if (serverApp->isManagerOnly()) {
cout << "exiting because of the argument --manager-only was set and this computer is not a manager" << endl;
exit(0);
}
@@ -619,7 +605,7 @@ AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize)
*/
void MainWindow::resizeEvent(QResizeEvent* e)
{
- const Room* room = Global::getCurrentRoom();
+ const Room* room = serverApp->getCurrentRoom();
const QSize& clientSize = room->clientSize;
if (ui->frmRoom->size().width() < 100 || ui->frmRoom->size().height() < 100 || _tilesX <= 0 || _tilesY <= 0) { return; }
@@ -638,18 +624,16 @@ void MainWindow::resizeEvent(QResizeEvent* e)
this->_tilesX = newGridSize.width();
this->_tilesY = newGridSize.height();
- /* Bring back frame that are now out of the screen */
+ /* Bring back frames which 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) {
+ for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) {
int newPosX = (*it)->getGridPosition().x() * getTileWidthPx();
int newPosY = (*it)->getGridPosition().y() * getTileHeightPx();
QPoint newPos(newPosX, newPosY);
@@ -788,10 +772,10 @@ void MainWindow::onSessionNameClick()
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) {
- _sessionNameWindow->show(Global::sessionName());
+ _sessionNameWindow->show(serverApp->sessionName());
}
} else
- _sessionNameWindow->show((Global::sessionName()));
+ _sessionNameWindow->show((serverApp->sessionName()));
}
/***************************************************************************//**
@@ -810,7 +794,7 @@ void MainWindow::onSessionNameUpdate()
_clientFrames.clear();
}
}
- _sessionNameLabel->setText(tr("Session Name: %1 [click to edit]").arg(Global::sessionName()));
+ _sessionNameLabel->setText(tr("Session Name: %1 [click to edit]").arg(serverApp->sessionName()));
}
/***************************************************************************//**
@@ -842,8 +826,8 @@ void MainWindow::onButtonReloadRoomConfig()
{
connect(_reloadWindow->ui->buttonBox, SIGNAL(accepted()), this, SLOT(onReloadRoomOk()));
connect(_reloadWindow->ui->buttonBox, SIGNAL(rejected()), this, SLOT(onReloadRoomCancel()));
- qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << Global::getRooms().size();
- QList<QString> keyList = Global::getRooms().keys();
+ qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << serverApp->getRooms().size();
+ QList<QString> keyList = serverApp->getRooms().keys();
for (QList<QString>::iterator it = keyList.begin(); it != keyList.end() ; it++) {
_reloadWindow->ui->roomList->addItem(*it);
}
@@ -861,8 +845,8 @@ void MainWindow::onReloadRoomCancel()
void MainWindow::switchRoomTo(QString roomToReload)
{
// qDebug() << roomToReload;
- Global::setCurrentRoom(roomToReload);
- Room *room = Global::getRooms()[roomToReload];
+ serverApp->setCurrentRoom(roomToReload);
+ Room *room = serverApp->getRooms()[roomToReload];
/* set tiles */
_tilesX = room->gridSize.width();
_tilesY = room->gridSize.height();
@@ -883,13 +867,11 @@ void MainWindow::switchRoomTo(QString roomToReload)
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;
+ QString imgPath = serverApp->getCurrentRoom()->imagePath;
qDebug() << "imgPath is " << imgPath;
/* delete old image */
@@ -1293,7 +1275,7 @@ void MainWindow::onClientAuthenticated(Client* client)
int x, y;
bool ok;
- QSharedPointer<QSettings> sys = Global::getSettings();
+ QSharedPointer<QSettings> sys = serverApp->getSettings();
ok = loadPosition(sys, client->ip(), x, y);
if (x >= _tilesX || y >= _tilesY)