summaryrefslogtreecommitdiffstats
path: root/src/client/connectwindow/connectwindow.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-10-26 18:31:21 +0200
committerSimon Rettberg2016-10-26 18:31:21 +0200
commite19dcdfed2da5405c714bc0af56927fa8e4c2442 (patch)
treef50f9223c03c2af4e5e3b72b7d69618e0148220a /src/client/connectwindow/connectwindow.cpp
parentFix GUI translation: Don't create persistent objects on stack :/ (diff)
downloadpvs2-e19dcdfed2da5405c714bc0af56927fa8e4c2442.tar.gz
pvs2-e19dcdfed2da5405c714bc0af56927fa8e4c2442.tar.xz
pvs2-e19dcdfed2da5405c714bc0af56927fa8e4c2442.zip
[client] Move ServerConnection instance to ClientApp
Diffstat (limited to 'src/client/connectwindow/connectwindow.cpp')
-rw-r--r--src/client/connectwindow/connectwindow.cpp31
1 files changed, 17 insertions, 14 deletions
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();