summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui/client/connect.ui149
-rw-r--r--src/client/connectwindow/connectwindow.cpp31
-rw-r--r--src/client/connectwindow/connectwindow.h8
-rw-r--r--src/client/toolbar/toolbar.cpp67
-rw-r--r--src/client/toolbar/toolbar.h3
-rw-r--r--src/client/util/room.h23
-rw-r--r--src/client/util/util.h2
7 files changed, 201 insertions, 82 deletions
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 @@
<property name="windowTitle">
<string>Connect to PVS session</string>
</property>
- <layout class="QHBoxLayout" name="mainLayout">
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="acceptDrops">
@@ -32,29 +32,29 @@
<number>0</number>
</property>
<widget class="QWidget" name="page0">
- <layout class="QVBoxLayout" name="sl_p0_vl">
- <property name="spacing">
- <number>0</number>
- </property>
+ <layout class="QFormLayout" name="formLayout_2">
<property name="margin">
<number>0</number>
</property>
- <item>
- <widget class="QLabel" name="lblSessionName">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
<property name="text">
- <string>Automatically selected session</string>
+ <string>Auto-Connect is available.</string>
</property>
</widget>
</item>
- <item>
- <widget class="QLineEdit" name="lineEditName">
- <property name="readOnly">
- <bool>true</bool>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Room: </string>
</property>
</widget>
</item>
- <item>
- <spacer name="sw_p0_spacer">
+ <item row="2" column="1">
+ <widget class="QComboBox" name="comboBox_rooms"/>
+ </item>
+ <item row="1" column="0">
+ <spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@@ -66,34 +66,64 @@
</property>
</spacer>
</item>
- <item>
- <widget class="QLabel" name="lblStatus">
- <property name="text">
- <string>Ready to connect; please enter session name.</string>
+ <item row="4" column="0">
+ <spacer name="verticalSpacer_4">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
</property>
- </widget>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="page">
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="title">
- <string>Advanced Options</string>
- </property>
- <layout class="QFormLayout" name="formLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Specify Session Name</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="lineEdit_2"/>
- </item>
- </layout>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Manually connect with session name</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="4" column="0">
+ <spacer name="verticalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="0" colspan="2">
+ <widget class="QLineEdit" name="lineEditName"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Session Name</string>
+ </property>
</widget>
</item>
</layout>
@@ -133,50 +163,63 @@
</widget>
</item>
<item>
- <layout class="QVBoxLayout" name="buttons">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>6</number>
</property>
<item>
- <widget class="QPushButton" name="btn_connection">
+ <widget class="QPushButton" name="btn_hide">
<property name="text">
- <string>Connect</string>
+ <string>Cancel</string>
+ </property>
+ <property name="autoDefault">
+ <bool>false</bool>
</property>
<property name="default">
- <bool>true</bool>
+ <bool>false</bool>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="btn_advanced">
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="lblStatus">
<property name="text">
- <string>Advanced...</string>
+ <string/>
</property>
</widget>
</item>
<item>
- <spacer name="btns_spacer">
+ <spacer name="horizontalSpacer_2">
<property name="orientation">
- <enum>Qt::Vertical</enum>
+ <enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
- <width>20</width>
- <height>40</height>
+ <width>40</width>
+ <height>20</height>
</size>
</property>
</spacer>
</item>
<item>
- <widget class="QPushButton" name="btn_hide">
+ <widget class="QPushButton" name="btn_connection">
<property name="text">
- <string>Cancel</string>
- </property>
- <property name="autoDefault">
- <bool>false</bool>
+ <string>Connect</string>
</property>
<property name="default">
- <bool>false</bool>
+ <bool>true</bool>
</property>
</widget>
</item>
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<Room> 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 <QtGui>
+#include <QMap>
#include <QUdpSocket>
#include <QSslSocket>
#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<Room> 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 <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 "";
+ }
}
/*
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 <QtGui>
+#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<Room> 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_ */