From 6cb63e7e30906f428c601ba00fd15c14e07093cf Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Mon, 25 Aug 2014 18:08:15 +0200 Subject: Client is able to auto - connect to the same room belonging manager. --- src/client/toolbar/toolbar.cpp | 84 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) (limited to 'src/client/toolbar/toolbar.cpp') diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 837bc08..0f90492 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -4,18 +4,20 @@ * Created on: 21.01.2013 * Author: sr */ +#include #include "../../shared/settings.h" #include "../net/serverconnection.h" #include "../vnc/vncwindow.h" #include "../vnc/vncserver.h" +#include "../util/util.h" #include "toolbar.h" #include "ui_toolbar.h" /***************************************************************************//** - * @brief Constructor of the Toolbar. + * @brief * * Does exact teh same as Toolbar::Toolbar(QWidget *parent) but additionally * instantly tries to connect to a pvsmgr with the given sessionName. @@ -27,7 +29,36 @@ Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) : Toolbar(parent) { - _connectWindow->connectToSession(sessionName); + qDebug() << "sessionName - constructor"; + _connectWindow->connectToSession(sessionName, NULL); +} + +/***************************************************************************//** + * @brief Constructor of the Toolbar. + * + * Does exact the same as Toolbar::Toolbar(QWidget *parent) but additionally + * instantly tries to connect to the pvsmgr in its room without sessionName. + * @param autoConnect + * @param parent + */ +Toolbar::Toolbar(const bool autoConnect, QWidget *parent) : Toolbar(parent) +{ + qDebug() << "auto - constructor!"; + + if (autoConnect) { + // Getting manager ip. + QString mgrIp = identifyMgrIP(); + qDebug() << "mgrIP: " << mgrIp; + if (mgrIp != NULL) { + qDebug() << "Starting WITH specific mgrIP"; + _connectWindow->connectToSession("", mgrIp); + } else { + qDebug() << "Starting WITHOUT specific mgrIP"; + _connectWindow->connectToSession("", NULL); + } + } else { + _connectWindow->connectToSession("", NULL); + } } /***************************************************************************//** @@ -144,6 +175,55 @@ void Toolbar::enterEvent(QEvent* e) QWidget::enterEvent(e); } +QString Toolbar::identifyMgrIP() +{ + SYSTEM_SETTINGS(conf); + qDebug() << "Settings contain" << conf.allKeys(); + + if (!conf.contains("rooms")) { + qDebug() << "Invalid config file!"; + return NULL; + } + + QStringList rooms = conf.value("rooms").toStringList(); + qDebug() << rooms; + + for (auto i : rooms) + { + qDebug() << "i: " << i; + conf.beginGroup(i); + if (!conf.contains("mgrIP")) { + qDebug() << "Invalid config file!"; + return NULL; + } + + // Find the managerIP of current room. + QString mgrIP = conf.value("mgrIP").toString(); + foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) + { + int size = conf.beginReadArray("client"); + for (int j = 0; j < size; ++j) { + conf.setArrayIndex(j); + /* + * + * CFG to test this + * http://git.openslx.org/tm-scripts.git/plain/server/modules/pvs2-freiburg/etc/xdg/openslx/pvs2client.ini + * + */ + QString ip = conf.value("ip").toString(); + if (address != QHostAddress(QHostAddress::LocalHost) && ip == address.toString()) + { + qDebug("Found this ip in config."); + return mgrIP; + } + } + conf.endArray(); + } + conf.endGroup(); + } + return NULL; +} + /* * Slots */ -- cgit v1.2.3-55-g7522