1 #include "../mainwindow/mainwindow.h"
3 #include "../../shared/util.h"
6 #include <QNetworkInterface>
8 #include <QLibraryInfo>
10 static QSize
minimalGridSize(
const QMap<QString, QPoint>& clientPositions, QSize& clientSize);
15 setOrganizationName(
"openslx");
16 setOrganizationDomain(
"openslx.org");
17 setApplicationName(
"pvsmgr");
31 auto *qtTranslator =
new QTranslator(
this);
32 if (!qtTranslator->load(QLocale::system(),
"qt",
"_", QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
33 qDebug() <<
"Loading system translations failed" << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
35 installTranslator(qtTranslator);
38 auto *translator =
new QTranslator(
this);
39 if (!translator->load(QLocale::system(),
":",
"l_")) {
40 qDebug() <<
"Loading app translations failed";
42 installTranslator(translator);
46 QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope,
"/opt/");
48 qDebug() <<
"System settings are in:" << sys->fileName();
56 for (
const QString& a : QApplication::arguments()) {
57 if (a == QStringLiteral(
"--manager-only")) {
60 }
else if (a.startsWith(QStringLiteral(
"--config="))) {
79 if (!conf->contains(QStringLiteral(
"rooms"))) {
80 qDebug() <<
"Invalid config file (no rooms are set)!";
83 QStringList rooms = conf->value(
"rooms").toStringList();
85 for (
const QString& roomId : rooms) {
86 conf->beginGroup(roomId);
87 QString roomName = conf->value(
"name").toString();
90 if (roomName.isEmpty()) {
93 if (!conf->contains(
"mgrIP")) {
94 qDebug() <<
"Warning: Incomplete config file (room " << roomName <<
" needs a mgrIP)!";
96 QMap<QString, QPoint> clientPositions;
98 int size = conf->beginReadArray(
"client");
99 for (
int j = 0; j < size; j++) {
100 conf->setArrayIndex(j);
101 clientPositions.insert(conf->value(
"ip").toString(), conf->value(
"pos").toPoint());
106 QString image = conf->contains(
"backgroundImage") ? conf->value(
"backgroundImage").toString() :
"";
107 QString mgrIP = conf->value(
"mgrIP").toString();
108 QString tutorIP = conf->value(
"tutorIP").toString();
111 QSize clientSize(1, 1);
113 if (conf->contains(
"gridSize")) {
114 gridSize = conf->value(
"gridSize").toSize();
116 if (conf->contains(
"clientSize")) {
117 clientSize = conf->value(
"clientSize").toSize();
120 foreach (
const QHostAddress & address, QNetworkInterface::allAddresses()) {
121 if (!address.isBroadcast() && !address.isLoopback() && !address.isMulticast() && mgrIP == address.toString()) {
122 qDebug() <<
"Found own ip in config.";
128 if (!gridSize.isValid()) {
131 qDebug() <<
"had to use minimalGridSize(): = " << gridSize;
134 Room* r =
new Room(clientPositions, gridSize, clientSize, image, tutorIP);
135 qDebug() <<
"read new room: " << roomName <<
": " << gridSize <<
", " << clientSize;
136 _rooms.insert(roomName, r);
145 static Room* defaultRoom =
nullptr;
146 if (defaultRoom ==
nullptr) {
147 defaultRoom =
new Room(QMap<QString,
148 QPoint>(), QSize(8, 6), QSize(1, 1),
"",
"<none>");
160 const QString name = QString::number(
slxrand() % 9000 + 1000);
170 set =
new QSettings(QSettings::IniFormat, QSettings::SystemScope,
"openslx/pvs2",
"pvs2",
this);
173 set =
new QSettings(
_iniPath, QSettings::IniFormat,
this);
175 set->setIniCodec(
"UTF-8");
182 static QSize
minimalGridSize(
const QMap<QString, QPoint>& clientPositions, QSize& clientSize)
188 for (
const auto &pos : clientPositions) {
197 return QSize(x + clientSize.width(), y + clientSize.height());
QStringList parseParameters()
const Room * getCurrentRoom() const
virtual QStringList arguments()
static QSize minimalGridSize(const QMap< QString, QPoint > &clientPositions, QSize &clientSize)
returns the minimal grid size such that all clients fit on the grid
ServerApp(int &argc, char **argv)
QByteArray _sessionNameArray
QMap< QString, Room * > _rooms
QSettings * getSettings()