From e19dcdfed2da5405c714bc0af56927fa8e4c2442 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 26 Oct 2016 18:31:21 +0200 Subject: [client] Move ServerConnection instance to ClientApp --- src/client/connectwindow/connectwindow.cpp | 31 ++++++++++++++++-------------- src/client/connectwindow/connectwindow.h | 4 ++-- 2 files changed, 19 insertions(+), 16 deletions(-) (limited to 'src/client/connectwindow') diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 2f3797a..18ceb9c 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -10,6 +10,7 @@ #include "../../shared/network.h" #include "../../shared/util.h" #include "../net/serverconnection.h" +#include "../clientapp/clientapp.h" #include "connectwindow.h" #include "ui_connect.h" @@ -24,9 +25,9 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent) { _ui = new Ui::ConnectWindow; _timerHide = 0; - _connection = NULL; _state = Idle; _hashSslErrorCount = 0; + _pendingConnection = NULL; // Initialize the GUI _ui->setupUi(this); @@ -74,7 +75,7 @@ void ConnectWindow::updateUserInterface() if (_state == Connected) { _ui->btn_connection->setEnabled(true); _ui->btn_connection->setText(tr("&Disconnect")); - _ui->lblStatus->setText(tr("Connected to %1").arg(_connection->getPeerAdress())); + _ui->lblStatus->setText(tr("Connected to %1").arg(clientApp->connection()->getPeerAdress())); _ui->lineEditName->setEnabled(false); _ui->stackedWidget->setCurrentIndex(1); return; @@ -290,10 +291,10 @@ void ConnectWindow::onRoomSelection(int index) */ void ConnectWindow::onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) { - _connection = new ServerConnection(host, port, sessionName, certHash, autoConnect); - connect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); - connect(_connection, SIGNAL(disconnected()), this, SLOT(onConnectionDisconnected())); + _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*))); } @@ -308,21 +309,23 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state ++_hashSslErrorCount; _state = state; - this->updateUserInterface(); if (reset) { _state = Scanning; } if (state == Connected) { - QObject::disconnect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); - QObject::disconnect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); - emit connected(_connection); + QObject::disconnect(_pendingConnection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); + QObject::disconnect(_pendingConnection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); + emit connected(_pendingConnection); + _pendingConnection = NULL; this->updateUserInterface(); - _connection = NULL; _timerHide = startTimer(2000); + } else { + this->updateUserInterface(); } + } void ConnectWindow::onComboBox_keyPressed(QKeyEvent* e) @@ -335,18 +338,18 @@ void ConnectWindow::onComboBox_keyPressed(QKeyEvent* e) } /***************************************************************************//** - * If connection is closed set _connection = NULL. + * If connection is closed set _pendingConnection = NULL. * @param connection */ void ConnectWindow::onConnectionClosed(QObject* connection) { - _connection = NULL; + _pendingConnection = NULL; } /***************************************************************************//** * @brief ConnectWindow::onConnectionDisconnected */ -void ConnectWindow::onConnectionDisconnected() +void ConnectWindow::onConnectionDisconnected(ServerConnection*) { _state = Idle; this->updateUserInterface(); diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index aa89094..53af662 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -62,9 +62,9 @@ public: private: Ui::ConnectWindow *_ui; - ServerConnection *_connection; int _hashSslErrorCount; ServerDiscovery _serverDiscovery; + ServerConnection* _pendingConnection; ConnectionState _state; QByteArray _currentSession; QString _currentIp; @@ -89,7 +89,7 @@ protected slots: void onConnectionStateChange(ConnectWindow::ConnectionState state); void onConnectionClosed(QObject* connection); - void onConnectionDisconnected(); + void onConnectionDisconnected(ServerConnection* connection); // void onUdpReadyRead(); void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); -- cgit v1.2.3-55-g7522