diff options
author | Christian Klinger | 2016-05-10 17:30:37 +0200 |
---|---|---|
committer | Christian Klinger | 2016-05-10 17:30:37 +0200 |
commit | 93cd9571c534bb48af3707e1dc6c8bab28461df7 (patch) | |
tree | 6e50373bf46d27071ea100229ced7f1c244caa12 /src/client/toolbar/toolbar.cpp | |
parent | Priorities for rooms. (diff) | |
download | pvs2-93cd9571c534bb48af3707e1dc6c8bab28461df7.tar.gz pvs2-93cd9571c534bb48af3707e1dc6c8bab28461df7.tar.xz pvs2-93cd9571c534bb48af3707e1dc6c8bab28461df7.zip |
first new version of the connect window; needs some polish though.
Diffstat (limited to 'src/client/toolbar/toolbar.cpp')
-rw-r--r-- | src/client/toolbar/toolbar.cpp | 67 |
1 files changed, 40 insertions, 27 deletions
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 <QNetworkInterface> - +#include <QtAlgorithms> #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<Room> Toolbar::myRooms() { + + QList<Room> 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<Room>()); + 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<Room> rooms = myRooms(); + if (!rooms.empty()) { + return rooms.first().mgr; + } else { + return ""; + } } /* |