diff options
Diffstat (limited to 'src/client/connectwindow/connectwindow.cpp')
-rw-r--r-- | src/client/connectwindow/connectwindow.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 4e92570..c8f7efd 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -97,7 +97,7 @@ void ConnectWindow::updateState() { _ui->btn_connection->setEnabled(true); _ui->btn_connection->setText(tr("&Disconnect")); - _ui->lblStatus->setText(tr("Connected.")); + _ui->lblStatus->setText(tr("Connected to %1").arg(_connection->getPeerAdress())); _ui->lineEditName->setEnabled(false); _ui->stackedWidget->setCurrentIndex(1); return; @@ -175,7 +175,7 @@ void ConnectWindow::timerEvent(QTimerEvent* event) _salt2[i] = qrand() & 0xff; } _packet.reset(); - _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist)); + _packet.setField(_HASH, genSha1(&_sessionNameBytes, &salt1, &iplist)); _packet.setField(_SALT1, salt1); _packet.setField(_SALT2, _salt2); _packet.setField(_IPLIST, iplist); @@ -227,6 +227,24 @@ void ConnectWindow::showEvent(QShowEvent* event) _ui->lineEditName->setFocus(); } +/** + * Public function connect to session. + * Check if currently connected to server, + * if not --> connect to given sessionName. + * @param sessionName + */ +void ConnectWindow::connectToSession(const QByteArray sessionName) +{ + if (_connected || _state != Idle) + return; + + _discoveryInterval = 800; + _sessionNameBytes = sessionName; + _timerDiscover = startTimer(_discoveryInterval); + _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0; + this->setState(Scanning); +} + /* * Slots */ @@ -255,11 +273,7 @@ void ConnectWindow::onBtnConnection() else { // Connect (scan for session) - _discoveryInterval = 800; - _nameBytes = _ui->lineEditName->text().toUtf8(); - _timerDiscover = startTimer(_discoveryInterval); - _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0; - this->setState(Scanning); + connectToSession(_ui->lineEditName->text().toUtf8()); } } @@ -303,7 +317,7 @@ void ConnectWindow::onUdpReadyRead() continue; } // If so, check if the submitted hash seems valid - if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash) + if (genSha1(&_sessionNameBytes, &_salt2, &iplist, &port, &cert) != hash) { // did not match local session name, or other data was spoofed ++_hashErrorCount; @@ -312,7 +326,7 @@ void ConnectWindow::onUdpReadyRead() continue; } // Otherwise it's a valid reply, try to connect - _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert); + _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _sessionNameBytes, cert); connect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); } |