diff options
Diffstat (limited to 'src/client/connectwindow/connectwindow.cpp')
-rw-r--r-- | src/client/connectwindow/connectwindow.cpp | 31 |
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(); |