summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorChristian Klinger2016-05-10 17:30:37 +0200
committerChristian Klinger2016-05-10 17:30:37 +0200
commit93cd9571c534bb48af3707e1dc6c8bab28461df7 (patch)
tree6e50373bf46d27071ea100229ced7f1c244caa12 /src/client
parentPriorities for rooms. (diff)
downloadpvs2-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')
-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
6 files changed, 105 insertions, 29 deletions
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_ */