From 877607b07f30cbb8d7d8d06b1b91383095fdc144 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Fri, 30 Sep 2016 12:02:38 +0200 Subject: refactoring. --- src/client/clientapp/clientapp.cpp | 1 + src/client/clientapp/clientapp.h | 2 +- src/client/util/util.cpp | 2 +- src/client/util/util.h | 1 - src/server/connectionframe/connectionframe.cpp | 1 - src/server/main.cpp | 33 ++------ src/server/mainwindow/mainwindow.cpp | 72 +++++++---------- src/server/net/certmanager.cpp | 3 +- src/server/net/client.cpp | 8 +- src/server/net/discoverylistener.cpp | 8 +- src/server/serverapp/serverapp.cpp | 91 ++++++++++++++++++++++ src/server/serverapp/serverapp.h | 87 +++++++++++++++++++++ src/server/sessionnamewindow/sessionnamewindow.cpp | 4 +- src/server/util/global.cpp | 68 ---------------- src/server/util/global.h | 79 ------------------- src/server/util/util.cpp | 14 ---- src/server/util/util.h | 16 ---- 17 files changed, 226 insertions(+), 264 deletions(-) create mode 100644 src/server/serverapp/serverapp.cpp create mode 100644 src/server/serverapp/serverapp.h delete mode 100644 src/server/util/global.cpp delete mode 100644 src/server/util/global.h delete mode 100644 src/server/util/util.cpp delete mode 100644 src/server/util/util.h (limited to 'src') diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp index 18ef0de..e1ef22c 100644 --- a/src/client/clientapp/clientapp.cpp +++ b/src/client/clientapp/clientapp.cpp @@ -11,6 +11,7 @@ ClientApp::ClientApp(int& argc, char** argv) /* configuration */ QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); + /* parse parameters and keep the unparsed ones */ _arguments = parseParameters(); diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h index 910eba2..e7e6e57 100644 --- a/src/client/clientapp/clientapp.h +++ b/src/client/clientapp/clientapp.h @@ -23,8 +23,8 @@ public: enum ConnectionMode { None, Auto, Session }; private: - bool _examMode; ConnectionMode _connectionMode; /* way of automatically connection to a session on startup*/ + bool _examMode; QString _sessionName; /* only set when _connectionMode == Session */ Toolbar* _toolbar; QStringList _arguments; diff --git a/src/client/util/util.cpp b/src/client/util/util.cpp index 9dcbebb..ec1ae8a 100644 --- a/src/client/util/util.cpp +++ b/src/client/util/util.cpp @@ -14,7 +14,7 @@ namespace Util //# QDir settingsDir() { - USER_SETTINGS(settings); + QSettings settings(QSettings::IniFormat, QSettings::UserScope, "openslx/pvs2", "pvs2"); QFileInfo fi(settings.fileName()); QDir path(fi.path()); return path; diff --git a/src/client/util/util.h b/src/client/util/util.h index dc604e8..1c91d56 100644 --- a/src/client/util/util.h +++ b/src/client/util/util.h @@ -7,7 +7,6 @@ // USER_SETTINGS(settings) // settings.value("somekey") -#define USER_SETTINGS(name) QSettings name (QSettings::IniFormat, QSettings::UserScope, "openslx/pvs2", "pvs2") #define SYSTEM_SETTINGS(name) QSettings name (QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2") #include diff --git a/src/server/connectionframe/connectionframe.cpp b/src/server/connectionframe/connectionframe.cpp index 0a7b180..a7427c6 100644 --- a/src/server/connectionframe/connectionframe.cpp +++ b/src/server/connectionframe/connectionframe.cpp @@ -16,7 +16,6 @@ #include "connectionframe.h" #include "../net/client.h" -#include "../util/global.h" #include #include #include diff --git a/src/server/main.cpp b/src/server/main.cpp index 02fd399..9c44adf 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -1,9 +1,8 @@ #include #include #include "mainwindow/mainwindow.h" -#include "util/util.h" -#include "util/global.h" #include "../shared/settings.h" +#include "serverapp/serverapp.h" using std::cout; using std::endl; @@ -23,22 +22,15 @@ void usage() int main(int argc, char** argv) { - QApplication app(argc, argv); - - app.setOrganizationName("openslx"); - app.setOrganizationDomain("openslx.org"); - app.setApplicationName("pvsmgr"); + ServerApp app(argc, argv); for (QString a : app.arguments()) { - if (a == "--manager-only") { - Global::manager_only = true; - break; - } else if (a.startsWith("--config=")) { - Global::setIniPath(a.mid(9)); - } else if (a == "--usage" || a == "--help") { + if (a == "--usage" || a == "--help") { usage(); exit(0); - } else if (!a.endsWith("pvsmgr")) { + } else if (a.endsWith("pvsmgr")) { + /* ignore */ + } else { qDebug() << "ignoring unknown argument: \"" << a << "\""; } } @@ -54,18 +46,5 @@ int main(int argc, char** argv) qsrand((uint)QDateTime::currentMSecsSinceEpoch()); - // Set the global path of the settings - QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); - QSharedPointer sys = Global::getSettings(); - qDebug() << "System settings are in:" << sys->fileName(); - QFileInfo sysfi(sys->fileName()); - - - // use system locale as language to translate gui - QTranslator translator; - translator.load(":pvsmgr"); - app.installTranslator(&translator); - - MainWindow pvsmgr; return app.exec(); } 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 #include // 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::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 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 roomsList; - QSharedPointer conf = Global::getSettings(); + QSharedPointer 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::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 keyList = Global::getRooms().keys(); + qDebug() << "in onButtonReloadRoomConfig!" << "size of room: " << serverApp->getRooms().size(); + QList keyList = serverApp->getRooms().keys(); for (QList::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 sys = Global::getSettings(); + QSharedPointer sys = serverApp->getSettings(); ok = loadPosition(sys, client->ip(), x, y); if (x >= _tilesX || y >= _tilesY) diff --git a/src/server/net/certmanager.cpp b/src/server/net/certmanager.cpp index e91fed3..933bbbc 100644 --- a/src/server/net/certmanager.cpp +++ b/src/server/net/certmanager.cpp @@ -15,8 +15,9 @@ # ----------------------------------------------------------------------------- */ +#define CERTSTORAGE ".config/openslx/pvs2/" + #include "certmanager.h" -#include "../util/util.h" #include #include #include diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index 5cd5c30..59211b7 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -6,7 +6,7 @@ */ #include "client.h" -#include "../util/global.h" +#include "../serverapp/serverapp.h" #include "../../shared/settings.h" #include "../../shared/util.h" #include @@ -227,8 +227,8 @@ void Client::handleMsg() 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()))) { + if (genSha1(&serverApp->sessionNameArray(), &_challenge) != hash + && !(serverApp->getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString()))) { // Challenge reply is invalid, drop client NetworkMessage msgErr; msgErr.buildErrorMessage("Challenge reply invalid."); @@ -239,7 +239,7 @@ void Client::handleMsg() // Now answer to challenge by client NetworkMessage msgChlng; msgChlng.setField(_ID, _CHALLENGE); - msgChlng.setField(_HASH, genSha1(&Global::sessionNameArray(), &challenge)); + msgChlng.setField(_HASH, genSha1(&serverApp->sessionNameArray(), &challenge)); msgChlng.writeMessage(_socket); _authed = 1; qDebug("client's challenge reply was valid, step <- 1"); diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp index 8eb1091..e8d286d 100644 --- a/src/server/net/discoverylistener.cpp +++ b/src/server/net/discoverylistener.cpp @@ -7,7 +7,7 @@ #include "discoverylistener.h" #include "certmanager.h" -#include "../util/global.h" +#include "../serverapp/serverapp.h" #include "../../shared/settings.h" #include "../../shared/network.h" #include "../../shared/util.h" @@ -150,8 +150,8 @@ void DiscoveryListener::onReadyRead() if (!Network::isAddressInList(QString::fromUtf8(iplist), addr.toString())) continue; // If so, check if the submitted hash seems valid - if (genSha1(&Global::sessionNameArray(), &salt1, &iplist) != hash && - !(Global::getCurrentRoom()->clientPositions.contains(addr.toString()))) { + if (genSha1(&serverApp->sessionNameArray(), &salt1, &iplist) != hash && + !(serverApp->getCurrentRoom()->clientPositions.contains(addr.toString()))) { // did not match local session name and client is not in same room. continue; } @@ -164,7 +164,7 @@ void DiscoveryListener::onReadyRead() QByteArray certhash(cert.digest(QCryptographicHash::Sha1)); // Reply to client _packet.reset(); - _packet.setField(_HASH, genSha1(&Global::sessionNameArray(), &salt2, &myiplist, &CLIENT_PORT_ARRAY, &certhash)); + _packet.setField(_HASH, genSha1(&serverApp->sessionNameArray(), &salt2, &myiplist, &CLIENT_PORT_ARRAY, &certhash)); _packet.setField(_IPLIST, myiplist); _packet.setField(_PORT, CLIENT_PORT_ARRAY); _packet.setField(_CERT, certhash); diff --git a/src/server/serverapp/serverapp.cpp b/src/server/serverapp/serverapp.cpp new file mode 100644 index 0000000..8ad896f --- /dev/null +++ b/src/server/serverapp/serverapp.cpp @@ -0,0 +1,91 @@ +#include + + +#include "serverapp.h" + +ServerApp::ServerApp(int& argc, char** argv) + : QApplication(argc, argv) +{ + setOrganizationName("openslx"); + setOrganizationDomain("openslx.org"); + setApplicationName("pvsmgr"); + + _arguments = parseParameters(); + + /* use system locale as language to translate gui */ + QTranslator translator; + translator.load(":pvsmgr"); + installTranslator(&translator); + + /* Set the global path of the settings */ + QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, "/opt/"); + QSharedPointer sys = getSettings(); + qDebug() << "System settings are in:" << sys->fileName(); + QFileInfo sysfi(sys->fileName()); + + _mainWindow = new MainWindow(); + +} + +QStringList ServerApp::parseParameters() +{ + QStringList rest; + for (QString a : arguments()) { + if (a == "--manager-only") { + _manager_only = true; + break; + } else if (a.startsWith("--config=")) { + _iniPath = a.mid(9); + } else { + rest << a; + } + } + return rest; + +} + +QStringList ServerApp::arguments() +{ + return _arguments; +} + +const Room* ServerApp::getCurrentRoom() +{ + if (_rooms.contains(_currentRoom)) { + return _rooms[_currentRoom]; + } else { + static Room* defaultRoom = NULL; + if (defaultRoom == NULL) { + defaultRoom = new Room(QMap(), QSize(8, 6), QSize(1, 1), "", ""); + } + return defaultRoom; + } +} +void ServerApp::setSessionName(const QString& name) +{ + _sessionName = name; + _sessionNameArray = name.toUtf8(); +} + +void ServerApp::setSessionName() +{ + const QString name = QString::number(qrand() % 9000 + 1000); + _sessionName = name; + _sessionNameArray = name.toUtf8(); +} + +QSharedPointer ServerApp::getSettings() +{ + QSharedPointer set; + if (_iniPath == "") { + /* default location (system scope) */ + set = QSharedPointer(new QSettings(QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2")); + } else { + /* use _iniPath to find ini file */ + set = QSharedPointer(new QSettings(_iniPath, QSettings::IniFormat)); + } + set->setIniCodec("UTF-8"); + return set; +} + diff --git a/src/server/serverapp/serverapp.h b/src/server/serverapp/serverapp.h new file mode 100644 index 0000000..be6b0ab --- /dev/null +++ b/src/server/serverapp/serverapp.h @@ -0,0 +1,87 @@ +#ifndef SERVERAPP_H +#define SERVERAPP_H + +#include +#include +#include + +#include "../mainwindow/mainwindow.h" + +struct Room { + Room(QMap cPos, QSize grid, QSize client, QString image, QString tutor) : + clientPositions(cPos), + gridSize(grid), + clientSize(client), + imagePath(image), + tutorIP(tutor) {}; + QMap clientPositions; + QSize gridSize; + QSize clientSize; + QString imagePath; + QString tutorIP; +}; + + +/* define a macro `serverApp` that can be used anywhere in the program and + * returns a reference to the current ClientApp instance */ + +#if defined(serverApp) +#undef serverApp +#endif +#define serverApp (static_cast(QCoreApplication::instance())) + +/* this class is supposed to (after complete refactoring) to encapsulate all + * state of the application. At the moment, the state is distributed within + * several widgets. With this class information access will also be easier as + * it is possible to access the current ServerApp instance from anywhere with + * the serverApp macro (like qApp) */ +class ServerApp : public QApplication +{ + + Q_OBJECT + +private: + QStringList _arguments; + QStringList parseParameters(); + MainWindow* _mainWindow; + + QString _sessionName; + QByteArray _sessionNameArray; + QMap _rooms; + QString _currentRoom; + + bool _manager_only; + bool _isExam; + QString _iniPath; + +public: + + ServerApp(int& argc, char** argv); + + virtual QStringList arguments(); + + + /* getters */ + const QString& sessionName() { return _sessionName; } + const QByteArray& sessionNameArray() { return _sessionNameArray; } + const QMap & rooms() { return _rooms; } + const QString& getCurrentRoomName() { return _currentRoom; } + const QMap& getRooms() { return _rooms; } + bool isExam() { return _isExam; } + bool isManagerOnly() { return _manager_only; } + const Room* getCurrentRoom(); + + /* setters */ + void setSessionName(const QString& name); + void setSessionName(); + void setRooms(const QMap & roomList) { _rooms = roomList; } + void setIniPath(QString s) { _iniPath = s; }; + void setCurrentRoom(const QString& room) { _currentRoom = room; } + void setExam(bool exam) { _isExam = exam; } + + QSharedPointer getSettings(); + + +}; + +#endif diff --git a/src/server/sessionnamewindow/sessionnamewindow.cpp b/src/server/sessionnamewindow/sessionnamewindow.cpp index 6ffbeca..cc4d751 100644 --- a/src/server/sessionnamewindow/sessionnamewindow.cpp +++ b/src/server/sessionnamewindow/sessionnamewindow.cpp @@ -16,8 +16,8 @@ #include #include "sessionnamewindow.h" +#include "../serverapp/serverapp.h" #include "../numerickeyboard/numerickeyboard.h" -#include "../util/global.h" #include "ui_sessionname.h" @@ -65,7 +65,7 @@ void SessionNameWindow::closeEvent(QCloseEvent *e) void SessionNameWindow::onOkClicked() { - Global::setSessionName(ui->lineEditName->text()); + serverApp->setSessionName(ui->lineEditName->text()); emit updateSessionName(); this->hide(); } diff --git a/src/server/util/global.cpp b/src/server/util/global.cpp deleted file mode 100644 index 97c0355..0000000 --- a/src/server/util/global.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * global.cpp - * - * Created on: 29.01.2013 - * Author: sr - */ - -#include "global.h" -#include - -QString Global::_sessionName = QString(); -QByteArray Global::_sessionNameArray = QByteArray(); -QMap Global::_rooms = QMap(); -QString Global::_currentRoom = QString(); - -void Global::setSessionName(const QString& name) -{ - Global::_sessionName = name; - Global::_sessionNameArray = name.toUtf8(); -} - -void Global::setSessionName() -{ - const QString name = QString::number(qrand() % 9000 + 1000); - Global::_sessionName = name; - Global::_sessionNameArray = name.toUtf8(); -} - -void Global::setRooms(const QMap& roomList) -{ - Global::_rooms = roomList; -} - -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(), QSize(8, 6), QSize(1, 1), "", ""); - } - return defaultRoom; - } -} -bool Global::manager_only = false; -bool Global::_isExam = false; - -QString Global::_iniPath = ""; - -QSharedPointer Global::getSettings() -{ - QSharedPointer set; - if (_iniPath == "") { - /* default location (system scope) */ - set = QSharedPointer(new QSettings(QSettings::IniFormat, QSettings::SystemScope, "openslx/pvs2", "pvs2")); - } else { - /* use _iniPath to find ini file */ - set = QSharedPointer(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 deleted file mode 100644 index ce1c2ab..0000000 --- a/src/server/util/global.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * global.h - * - * Created on: 29.01.2013 - * Author: sr - */ - -#ifndef GLOBAL_H_ -#define GLOBAL_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct Room { - Room(QMap cPos, QSize grid, QSize client, QString image, QString tutor) : - clientPositions(cPos), - gridSize(grid), - clientSize(client), - imagePath(image), - tutorIP(tutor) {}; - QMap clientPositions; - QSize gridSize; - QSize clientSize; - QString imagePath; - QString tutorIP; -}; - -class Global -{ -private: - Global() {} - ~Global() {} - - static QString _sessionName; - static QByteArray _sessionNameArray; - static QMap _rooms; - static QString _currentRoom; - - static bool _isExam; - static QString _iniPath; - -public: - static const QString& sessionName() { return Global::_sessionName; } - static const QByteArray& sessionNameArray() { return Global::_sessionNameArray; } - static void setSessionName(const QString& name); - static void setSessionName(); - - static bool manager_only; - - static void setRooms(const QMap & roomList); - static const QMap & getRooms() - { - return _rooms; - } - - static void setIniPath(QString s) {_iniPath = s;}; - static QString getIniPath() { return _iniPath; }; - static QSharedPointer getSettings(); - - 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(); -}; - - -#endif /* GLOBAL_H_ */ diff --git a/src/server/util/util.cpp b/src/server/util/util.cpp deleted file mode 100644 index 7ff9404..0000000 --- a/src/server/util/util.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Util.cpp - * - * Created on: 18.01.2013 - * Author: sr - */ - -#include "util.h" - -namespace Util -{ - -} - diff --git a/src/server/util/util.h b/src/server/util/util.h deleted file mode 100644 index e7a918b..0000000 --- a/src/server/util/util.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef UTIL_H_ -#define UTIL_H_ - -// Helper for getting a settings object in various places, so if you ever change the organization, location, -// file format or anything, you won't have to edit in 100 places. -// Use like this: -// settings.value("somekey") - -#define CERTSTORAGE ".config/openslx/pvs2/" - -namespace Util -{ - -} - -#endif /* UTIL_H_ */ -- cgit v1.2.3-55-g7522