From 110265bc31b634faa73242f8d14ec7aaf95b8b15 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Wed, 23 Jul 2014 17:45:35 +0200 Subject: Read the configfile and place the frames according to the coordinates given in /etc/xdg/openslx/pvs2mgr.ini. --- src/server/mainwindow/mainwindow.cpp | 108 +++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 38 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index db161e6..55e4bce 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -80,9 +80,6 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : ui->action_Exit->setStatusTip(tr("Exit")); ui->action_Lock->setStatusTip(tr("Lock or Unlock all Clients")); - _tileWidth = 10; - _tileHeight = 10; - // Initialize FileDownloader. if (!ipListUrl.isEmpty()) { @@ -102,40 +99,6 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : connect(ui->action_Lock, SIGNAL(toggled(bool)), this, SLOT(onButtonLock(bool))); connect(ui->action_Help, SIGNAL(triggered()), this, SLOT(onButtonHelp())); - USER_SETTINGS(test); - int i = 1; - QMap ipPosList; - while (true) - { - test.beginGroup(QString("room%1").arg(i)); - if (!test.contains("mgrIP")) - break; - QString mgrIP = test.value("mgrIP").toString(); - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) - { - qDebug() << "in Adress loop" << address.toString(); - if (address != QHostAddress(QHostAddress::LocalHost) - && mgrIP == address.toString()) - { - qDebug("matched"); - int size = test.beginReadArray("client"); - for (int i = 0; i < size; ++i) { - test.setArrayIndex(i); - ipPosList[test.value("ip").toString()] = test.value("pos").toPoint(); - ConnectionFrame *cf = createFrame(test.value("ip").toString(), test.value("pos").toPoint()); - cf->move(cf->getCurrentPosition()); - onPlaceFrame(cf); - qDebug() << "IP: " << test.value("ip").toString(); - qDebug() << "pos: " << test.value("pos").toPoint(); - } - test.endArray(); - } - } - qDebug() << "ManagerIP: " << mgrIP; - test.endGroup(); - i++; - } - /* Stuff for the button lock */ //Setup a timeout _buttonLockTimer = new QTimer(this); @@ -167,6 +130,12 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : // Finally // this->onSessionNameUpdate(); + + _tileWidth = ui->frmRoom->size().width() / _tilesX; + _tileHeight = ui->frmRoom->size().height() / _tilesY; + + + tryToUseRoomTemplate(); } MainWindow::~MainWindow() @@ -323,6 +292,69 @@ void MainWindow::tellClientCurrentSituation(Client* client) } +/***************************************************************************//** + * @brief MainWindow::tryToUseRoomTemplate + */ +void MainWindow::tryToUseRoomTemplate() +{ + SYSTEM_SETTINGS(conf); + qDebug() << "Settings contain" << conf.allKeys(); + + if (!conf.contains("rooms")) { + qDebug() << "Invalid config file!"; + return; + } + QStringList rooms = conf.value("rooms").toStringList(); + qDebug() << rooms; + + for (auto i : rooms) + { + conf.beginGroup(i); + if (!conf.contains("mgrIP")) { + qDebug() << "Invalid config file!"; + return; + } + // Find the room that list the ip of this host as mgr + QString mgrIP = conf.value("mgrIP").toString(); + foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) + { + if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString()) + { + qDebug("Found this ip in config."); + int size = conf.beginReadArray("client"); + for (int i = 0; i < size; ++i) { + conf.setArrayIndex(i); + + /* + * + * CFG to test this + * http://git.openslx.org/tm-scripts.git/plain/server/modules/pvs2-freiburg/etc/xdg/openslx/pvs2mgr.ini + * + */ + + // Add the frame + // Position is given in grid coordinates, createFrame take pixels + qDebug() << conf.value("ip").toString(); + QPoint coord = conf.value("pos").toPoint(); + qDebug() << coord; + qDebug() << _tileWidth ; + qDebug() << _tileHeight ; + + coord.setX(coord.x() * _tileWidth); + coord.setY(coord.y() * _tileHeight); + qDebug() << coord ; + + ConnectionFrame *cf = createFrame(conf.value("ip").toString(), coord); + cf->move(cf->getCurrentPosition()); + onPlaceFrame(cf); + } + conf.endArray(); + } + } + conf.endGroup(); + } +} + /***************************************************************************//** * Returns connected client which belongs to given id. * Iterating over ConnectionFrames and comparing id to given id. @@ -538,7 +570,7 @@ void MainWindow::onPlaceFrame(ConnectionFrame* frame) } } } - qDebug("Move D"); + qDebug("Moved"); frame->move(x, y); savePosition(frame); const QPoint &newpos = frame->frameGeometry().topLeft(); -- cgit v1.2.3-55-g7522