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. --- gui/client/connect.ui | 149 +++++++++++++++++++---------- src/client/connectwindow/connectwindow.cpp | 31 +++++- src/client/connectwindow/connectwindow.h | 8 +- src/client/toolbar/toolbar.cpp | 67 +++++++------ src/client/toolbar/toolbar.h | 3 + src/client/util/room.h | 23 +++++ src/client/util/util.h | 2 + 7 files changed, 201 insertions(+), 82 deletions(-) create mode 100644 src/client/util/room.h diff --git a/gui/client/connect.ui b/gui/client/connect.ui index 8adfd2b..b5c8340 100644 --- a/gui/client/connect.ui +++ b/gui/client/connect.ui @@ -22,7 +22,7 @@ Connect to PVS session - + @@ -32,29 +32,29 @@ 0 - - - 0 - + 0 - - + + - Automatically selected session + Auto-Connect is available. - - - - true + + + + Room: - - + + + + + Qt::Vertical @@ -66,34 +66,64 @@ - - - - Ready to connect; please enter session name. + + + + Qt::Vertical - + + + 20 + 40 + + + - - - - - Advanced Options - - - - - - Specify Session Name - - - - - - - + + + + + Manually connect with session name + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Session Name + @@ -133,50 +163,63 @@ - + 6 - + - Connect + Cancel + + + false - true + false - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - Advanced... + - + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 - + - Cancel - - - false + Connect - false + true diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 818cbd2..716dd6e 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -40,7 +40,8 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) // Set actions of buttons connect(_ui->btn_connection, SIGNAL(clicked()), this, SLOT(onBtnConnection())); connect(_ui->btn_hide, SIGNAL(clicked()), this, SLOT(onBtnHide())); - connect(_ui->btn_advanced, SIGNAL(clicked()), this, SLOT(onBtnAdvanced())); + + connect(_ui->comboBox_rooms, SIGNAL(currentIndexChanged(int)), this, SLOT(onRoomSelection(int))); // React on discovery signal connect(&_serverDiscovery, SIGNAL(serverDetected(QString,quint16,QByteArray,QByteArray,bool)), @@ -145,6 +146,9 @@ void ConnectWindow::closeEvent(QCloseEvent *e) void ConnectWindow::doShow() { + /* reset to automatic connect window */ + _ui->stackedWidget->setCurrentIndex(0); + _ui->comboBox_rooms->setCurrentIndex(0); show(); showNormal(); activateWindow(); @@ -216,6 +220,21 @@ void ConnectWindow::onBtnConnection() } } +/** set the available rooms. + * If the list of rooms is empty, switches automatically to the "manual + * connection" page */ +void ConnectWindow::setAvailableRooms(QList m) { + if (!m.empty()) { + _ui->comboBox_rooms->clear(); + foreach (Room r, m) { + _ui->comboBox_rooms->addItem(r.name, r.mgr); + } + /* also add a pseudo-room "manual choice" */ + _ui->comboBox_rooms->addItem(tr("manual connection"), "manual_connection"); + } else { + _ui->stackedWidget->setCurrentIndex(1); + } +} /***************************************************************************//** * Handle click on Cancel/Hide Button. * Just hide the window. @@ -225,6 +244,16 @@ void ConnectWindow::onBtnHide() this->hide(); } +/** check if "manual_connection" is selected, then switch to manual + * connection page */ +void ConnectWindow::onRoomSelection(int index) { + qDebug() << "onRoomSelection"; + QString sessionName = _ui->comboBox_rooms->itemData(index).toString(); + if (sessionName == "manual_connection") { + qDebug() << "switch to manual connection"; + _ui->stackedWidget->setCurrentIndex(1); + } +} /***************************************************************************//** * @brief ConnectWindow::onServerDetected diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 9daa420..bdd564a 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -17,10 +17,12 @@ #define PVSCONNECTWINDOW_H_ #include +#include #include #include #include "../../shared/networkmessage.h" #include "../net/serverdiscovery.h" +#include "../util/room.h" namespace Ui{ class ConnectWindow; @@ -53,8 +55,9 @@ public: explicit ConnectWindow(QWidget *parent = NULL); virtual ~ConnectWindow(); - + void connectToSession(const QByteArray sessionName, QString mgrIP); + void setAvailableRooms(QList m); private: Ui::ConnectWindow *_ui; @@ -64,6 +67,7 @@ private: ConnectionState _state; QByteArray _currentSession; QString _currentIp; + QString _defaultSessionName; NetworkMessage _packet; bool _tryReconnect; int _timerHide; @@ -81,6 +85,8 @@ protected slots: void onBtnAdvanced(); void onBtnHide(); + void onRoomSelection(int index); + void onConnectionStateChange(ConnectWindow::ConnectionState state); void onConnectionClosed(QObject* connection); void onConnectionDisconnected(); 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 ""; + } } /* diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index c3c727c..1fba093 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -15,12 +15,14 @@ #define PVSCLIENTGUI_H_ #include +#include "../util/room.h" class ServerConnection; class VncWindow; class ConnectWindow; class BlankScreen; + namespace Ui{ class Toolbar; } @@ -51,6 +53,7 @@ private: void leaveEvent(QEvent* e); void enterEvent(QEvent* e); + QList myRooms(); QString identifyMgrIP(); void init(); diff --git a/src/client/util/room.h b/src/client/util/room.h new file mode 100644 index 0000000..bfc70d0 --- /dev/null +++ b/src/client/util/room.h @@ -0,0 +1,23 @@ +#ifndef ROOM_H +#define ROOM_H + +struct Room { + QString mgr; + QString name; + int priority; + Room (QString _name, QString _mgr, int _priority) { + mgr = _mgr; + name = _name; + priority = _priority; + }; +}; + +inline QDebug operator<<(QDebug debug, const Room& r) { + debug << r.name << "{mgr=" << r.mgr << ",prio=" << r.priority << "}"; + return debug; +} + +inline bool operator<(const Room& a, const Room& b) { + return a.priority < b.priority; +} +#endif diff --git a/src/client/util/util.h b/src/client/util/util.h index 19d1ac1..b90ce3d 100644 --- a/src/client/util/util.h +++ b/src/client/util/util.h @@ -20,4 +20,6 @@ QDir settingsDir(); //# } + + #endif /* UTIL_H_ */ -- cgit v1.2.3-55-g7522