From 93cd9571c534bb48af3707e1dc6c8bab28461df7 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Tue, 10 May 2016 17:30:37 +0200 Subject: first new version of the connect window; needs some polish though. --- src/client/toolbar/toolbar.cpp | 67 +++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'src/client/toolbar/toolbar.cpp') diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 73a7588..4c74a4a 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -5,7 +5,7 @@ * Author: sr */ #include - +#include #include "../../shared/settings.h" #include "../net/serverconnection.h" #include "../vnc/vncwindow.h" @@ -51,6 +51,7 @@ Toolbar::Toolbar(const bool autoConnect, QWidget *parent) qDebug() << "auto - constructor!"; init(); + if (autoConnect) { // Try getting manager ip. QString mgrIp = identifyMgrIP(); @@ -97,7 +98,7 @@ void Toolbar::init() /* Create the connect window */ _connectWindow = new ConnectWindow(NULL); - + _connectWindow->setAvailableRooms(myRooms()); // Connect the signals connect(_connectWindow, SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); connect(_connectWindow, SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); @@ -189,56 +190,68 @@ void Toolbar::enterEvent(QEvent* e) QWidget::enterEvent(e); } -/** Identifies the responsible manager for this client by searching through the - * configuration file. The manager whose room has the highest priority is chosen. */ -QString Toolbar::identifyMgrIP() -{ - qDebug() << "identify mgr ip"; +/* +* CFG to test this +* http://git.openslx.org/tm-scripts.git/plain/server/modules/pvs2-freiburg/etc/xdg/openslx/pvs2client.ini +* +*/ + +/* returns a sorted list of available rooms. + * (Available means that this client is configured to be in that room) */ +QList Toolbar::myRooms() { + + QList myRooms; + SYSTEM_SETTINGS(conf); if (!conf.contains("rooms")) { qDebug() << "Invalid config file!"; - return ""; + return myRooms; } - QStringList rooms = conf.value("rooms").toStringList(); - // qDebug() << rooms; + QStringList roomNames = conf.value("rooms").toStringList(); /* go through all rooms and check if this client is a member of the room. */ - int last_priority = -1; - QString last_mgr_ip = ""; - for (auto i : rooms) { - conf.beginGroup(i); + for (auto roomName : roomNames) { + conf.beginGroup(roomName); if (!conf.contains("mgrIP")) { qDebug() << "Invalid config file!"; - return ""; + return myRooms; } - QString mgr_candidate= conf.value("mgrIP").toString(); + QString mgrIP = conf.value("mgrIP").toString(); int priority = conf.value("priority").toInt(); 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() && - priority > last_priority) { - last_priority = priority; - last_mgr_ip = mgr_candidate; + && ip == address.toString() ) { + /* add this room to the list */ + Room r(roomName, mgrIP, priority); + myRooms << r; + break; } } conf.endArray(); } conf.endGroup(); } - qDebug() << "best mgr ip is " << last_mgr_ip << " with priority = " << last_priority; - return last_mgr_ip; + /* sort */ + qStableSort(myRooms.begin(), myRooms.end(), qGreater()); + qDebug() << "myRooms() = " << myRooms; + return myRooms; +} +/** Identifies the responsible manager for this client by searching through the + * configuration file. The manager whose room has the highest priority is chosen. */ +QString Toolbar::identifyMgrIP() { + QList rooms = myRooms(); + if (!rooms.empty()) { + return rooms.first().mgr; + } else { + return ""; + } } /* -- cgit v1.2.3-55-g7522