diff options
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/connectionframe/connectionframe.cpp | 1 | ||||
-rw-r--r-- | src/server/main.cpp | 33 | ||||
-rw-r--r-- | src/server/mainwindow/mainwindow.cpp | 72 | ||||
-rw-r--r-- | src/server/net/certmanager.cpp | 3 | ||||
-rw-r--r-- | src/server/net/client.cpp | 8 | ||||
-rw-r--r-- | src/server/net/discoverylistener.cpp | 8 | ||||
-rw-r--r-- | src/server/serverapp/serverapp.cpp | 91 | ||||
-rw-r--r-- | src/server/serverapp/serverapp.h | 87 | ||||
-rw-r--r-- | src/server/sessionnamewindow/sessionnamewindow.cpp | 4 | ||||
-rw-r--r-- | src/server/util/global.cpp | 68 | ||||
-rw-r--r-- | src/server/util/global.h | 79 | ||||
-rw-r--r-- | src/server/util/util.cpp | 14 | ||||
-rw-r--r-- | src/server/util/util.h | 16 |
13 files changed, 223 insertions, 261 deletions
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 <QPixmap> #include <QImage> #include <cassert> 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 <iostream> #include <stdlib.h> #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<QSettings> 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 <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) 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 <QMap> #include <QDir> #include <QDebug> 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 <QPixmap> @@ -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 <QTranslator> + + +#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<QSettings> 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<QString, + QPoint>(), 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<QSettings> ServerApp::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(_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 <QApplication> +#include <QStringList> +#include <QMap> + +#include "../mainwindow/mainwindow.h" + +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; +}; + + +/* 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<ServerApp*>(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<QString, Room*> _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<QString, Room*> & rooms() { return _rooms; } + const QString& getCurrentRoomName() { return _currentRoom; } + const QMap<QString, Room*>& 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<QString, Room*> & roomList) { _rooms = roomList; } + void setIniPath(QString s) { _iniPath = s; }; + void setCurrentRoom(const QString& room) { _currentRoom = room; } + void setExam(bool exam) { _isExam = exam; } + + QSharedPointer<QSettings> 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 <QtGui> #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 <QDebug> - -QString Global::_sessionName = QString(); -QByteArray Global::_sessionNameArray = QByteArray(); -QMap<QString, Room*> Global::_rooms = QMap<QString, Room*>(); -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<QString, Room*>& 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<QString, QPoint>(), QSize(8, 6), QSize(1, 1), "", ""); - } - return defaultRoom; - } -} -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; -} 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 <QString> -#include <QByteArray> -#include <QMap> -#include <QPair> -#include <QSettings> -#include <QPoint> -#include <QSize> -#include <QList> -#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; -}; - -class Global -{ -private: - Global() {} - ~Global() {} - - static QString _sessionName; - static QByteArray _sessionNameArray; - static QMap<QString, Room*> _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<QString, Room*> & roomList); - 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 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_ */ |