diff options
Diffstat (limited to 'src/client/connectwindow')
-rw-r--r-- | src/client/connectwindow/connectwindow.cpp | 36 | ||||
-rw-r--r-- | src/client/connectwindow/connectwindow.h | 22 | ||||
-rw-r--r-- | src/client/connectwindow/connectwindow.ui | 216 |
3 files changed, 248 insertions, 26 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 7674cc2..0bc6835 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -7,16 +7,21 @@ #include <QNetworkInterface> #include "../../shared/settings.h" -#include "../../shared/network.h" #include "../../shared/util.h" #include "../net/serverconnection.h" #include "../clientapp/clientapp.h" #include "connectwindow.h" -#include "ui_connect.h" +#include "ui_connectwindow.h" + +#include <QCloseEvent> #define UDPBUFSIZ 9000 #define SALT_LEN 18 +namespace Ui { + class ConnectWindow; +} + /** * Initialize Connection Window. * @param parent @@ -39,17 +44,16 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) _ui->stackedWidget->setCurrentIndex(0); // 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_connection, &QPushButton::clicked, this, &ConnectWindow::onBtnConnection); + connect(_ui->btn_hide, &QPushButton::clicked, this, &ConnectWindow::onBtnHide); - connect(_ui->comboBox_rooms, SIGNAL(currentIndexChanged(int)), this, SLOT(onRoomSelection(int))); + connect(_ui->comboBox_rooms, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectWindow::onRoomSelection); // React on discovery signal - connect(&_serverDiscovery, SIGNAL(serverDetected(QString, quint16, QByteArray, QByteArray, bool)), - this, SLOT(onServerDetected(QString, quint16, QByteArray, QByteArray, bool))); + connect(&_serverDiscovery, &ServerDiscovery::serverDetected, this, &ConnectWindow::onServerDetected); /* finally the most requested feature: connect on press of the enter key */ - connect(_ui->lineEditName, SIGNAL(returnPressed()), _ui->btn_connection, SIGNAL(clicked())); + connect(_ui->lineEditName, &QLineEdit::returnPressed, this, &ConnectWindow::onBtnConnection); /* by default don't show the manual connection box */ _ui->box_manual->setVisible(false); @@ -60,7 +64,7 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) /** * @brief ConnectWindow::~ConnectWindow */ -ConnectWindow::~ConnectWindow() {} +ConnectWindow::~ConnectWindow() = default; @@ -177,7 +181,7 @@ void ConnectWindow::showEvent(QShowEvent* /* event */ ) * if not --> connect to given sessionName. * @param sessionName */ -void ConnectWindow::connectToSession(const QByteArray sessionName, QString mgrIP) +void ConnectWindow::connectToSession(const QByteArray& sessionName, const QString &mgrIP) { if (_state != Idle) return; @@ -250,7 +254,7 @@ 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) +void ConnectWindow::setAvailableRooms(const QList<Room>& m) { _ui->comboBox_rooms->clear(); foreach (Room r, m) { @@ -294,9 +298,9 @@ void ConnectWindow::onRoomSelection(int index) void ConnectWindow::onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) { _pendingConnection = new ServerConnection(host, port, sessionName, certHash, autoConnect); - connect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - connect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); - connect(_pendingConnection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onConnectionDisconnected(ServerConnection*))); + connect(_pendingConnection, &ServerConnection::stateChange, this, &ConnectWindow::onConnectionStateChange); + connect(_pendingConnection, &ServerConnection::destroyed, this, &ConnectWindow::onConnectionClosed); + connect(_pendingConnection, &ServerConnection::disconnected, this, &ConnectWindow::onConnectionDisconnected); } @@ -317,8 +321,8 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state _state = Scanning; } if (state == Connected) { - QObject::disconnect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - QObject::disconnect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); + QObject::disconnect(_pendingConnection, &ServerConnection::stateChange, this, &ConnectWindow::onConnectionStateChange); + QObject::disconnect(_pendingConnection, &ServerConnection::destroyed, this, &ConnectWindow::onConnectionClosed); emit connected(_pendingConnection); _pendingConnection = nullptr; _timerHide = startTimer(2000); diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 9fcaf4e..4a0ae7d 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -16,7 +16,7 @@ #ifndef PVSCONNECTWINDOW_H_ #define PVSCONNECTWINDOW_H_ -#include <QtWidgets> +#include <QWidget> #include <QMap> #include <QUdpSocket> #include <QSslSocket> @@ -28,6 +28,7 @@ namespace Ui { class ConnectWindow; } + class ServerConnection; /** @@ -55,10 +56,10 @@ public: }; explicit ConnectWindow(QWidget *parent = nullptr); - virtual ~ConnectWindow(); + ~ConnectWindow() override; - void connectToSession(const QByteArray sessionName, QString mgrIP); - void setAvailableRooms(QList<Room> m); + void connectToSession(const QByteArray& sessionName, const QString &mgrIP); + void setAvailableRooms(const QList<Room>& m); private: Ui::ConnectWindow *_ui; @@ -70,18 +71,17 @@ private: QString _currentIp; QString _defaultSessionName; NetworkMessage _packet; - bool _tryReconnect; + bool _tryReconnect{}; int _timerHide; void updateUserInterface(); protected: - void timerEvent(QTimerEvent* event); - void closeEvent(QCloseEvent *e); - void showEvent(QShowEvent* event); + void timerEvent(QTimerEvent* event) override; + void closeEvent(QCloseEvent *e) override; + void showEvent(QShowEvent* event) override; protected slots: - void doShow(); void onBtnConnection(); void onBtnHide(); @@ -91,13 +91,15 @@ protected slots: void onConnectionClosed(QObject* connection); void onConnectionDisconnected(ServerConnection* connection); // void onUdpReadyRead(); - void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); + void onServerDetected(const QString& host, quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); public slots: /** actually connects the connection **/ void DoConnect(); /** actually disconnects the connection **/ void DoDisconnect(); + + void doShow(); signals: void disconnect(); void connected(ServerConnection* connection); diff --git a/src/client/connectwindow/connectwindow.ui b/src/client/connectwindow/connectwindow.ui new file mode 100644 index 0000000..0bfc654 --- /dev/null +++ b/src/client/connectwindow/connectwindow.ui @@ -0,0 +1,216 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ConnectWindow</class> + <widget class="QWidget" name="ConnectWindow"> + <property name="windowModality"> + <enum>Qt::WindowModal</enum> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>512</width> + <height>233</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>512</width> + <height>92</height> + </size> + </property> + <property name="windowTitle"> + <string>Connect to PVS session</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QStackedWidget" name="stackedWidget"> + <property name="acceptDrops"> + <bool>false</bool> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="page0"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QGroupBox" name="box_auto"> + <property name="title"> + <string>Connection</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Connect to</string> + </property> + </widget> + </item> + <item> + <widget class="QComboBox" name="comboBox_rooms"/> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="box_manual"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="title"> + <string>Manual Connection</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Session Name</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="lineEditName"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="page1"> + <layout class="QHBoxLayout" name="sw_p1_hl"> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QLabel" name="lblCheckmark"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="maximumSize"> + <size> + <width>94</width> + <height>72</height> + </size> + </property> + <property name="pixmap"> + <pixmap resource="../../pvsclient.qrc">:/dark-green-check-mark.svg</pixmap> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <property name="spacing"> + <number>6</number> + </property> + <item> + <widget class="QPushButton" name="btn_hide"> + <property name="text"> + <string>Close</string> + </property> + <property name="autoDefault"> + <bool>false</bool> + </property> + <property name="default"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <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/> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <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="QPushButton" name="btn_connection"> + <property name="text"> + <string>Connect</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + <property name="default"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <resources> + <include location="../../pvsclient.qrc"/> + </resources> + <connections/> +</ui> |