diff --git a/src/client.cpp b/src/client.cpp index 1c039b4f33..48381e5ab1 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -907,51 +907,49 @@ void CClient::Stop() /// @method /// @brief Connects to strServerAddress -/// @emit Connecting (strServerName) if the client wasn't running and SetServerAddr returned true. +/// @emit Connecting (strServerName) if the client wasn't running and SetServerAddr was valid +/// @emit ConnectingFailed (error) if an error occurred /// @param strServerAddress - the server address to connect to /// @param strServerName - the String argument to be passed to Connecting() -/// @result true if client wasn't running and SetServerAddr returned true, false otherwise -bool CClient::Connect ( QString strServerAddress, QString strServerName ) +void CClient::Connect ( QString strServerAddress, QString strServerName ) { - if ( !IsRunning() ) - { - // Set server address and connect if valid address was supplied - if ( SetServerAddr ( strServerAddress ) ) + try { + if ( !IsRunning() ) { - - Start(); - - emit Connecting ( strServerName ); - - return true; + // Set server address and connect if valid address was supplied + if ( SetServerAddr ( strServerAddress ) ) + { + Start(); + emit Connecting ( strServerName ); + } + else { + throw CGenErr ( "Received invalid server address. Please check for typos in the provided server address." ); + } } } - - return false; + catch ( const CGenErr& generr ) + { + Disconnect(); + emit ConnectingFailed ( generr.GetErrorText() ); + } } /// @method -/// @brief Disconnects client +/// @brief Disconnects client. If the client is not running, it just stops Sound /// @emit Disconnected -/// @result true if client wasn't running, false otherwise -bool CClient::Disconnect() +void CClient::Disconnect() { + qDebug( "CClient::Disconnect executed" ); if ( IsRunning() ) { Stop(); - emit Disconnected(); - - return true; } else { - // make sure sound is stopped too + // make sure sound is stopped in any case Sound.Stop(); - emit Disconnected(); - - return false; } } diff --git a/src/client.h b/src/client.h index 72adfbcecf..4edf445d08 100644 --- a/src/client.h +++ b/src/client.h @@ -121,8 +121,8 @@ class CClient : public QObject void Start(); void Stop(); - bool Connect ( QString strServerAddress, QString strServerName ); - bool Disconnect(); + void Connect ( QString strServerAddress, QString strServerName ); + void Disconnect(); bool IsRunning() { return Sound.IsRunning(); } bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); } @@ -430,7 +430,9 @@ protected slots: void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); + void ConnectClient ( QString strServerAddress ); void Connecting ( QString strServerName ); + void ConnectingFailed ( QString errorMessage ); void Disconnected(); void SoundDeviceChanged ( QString strError ); diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 6489535a9b..309c5d5ca3 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -481,6 +481,8 @@ CClientDlg::CClientDlg ( CClient* pNCliP, QObject::connect ( pClient, &CClient::Connecting, this, &CClientDlg::OnConnect ); + QObject::connect ( pClient, &CClient::ConnectingFailed, this, &CClientDlg::OnConnectingFailed ); + QObject::connect ( pClient, &CClient::Disconnected, this, &CClientDlg::OnDisconnect ); QObject::connect ( pClient, &CClient::ChatTextReceived, this, &CClientDlg::OnChatTextReceived ); @@ -738,10 +740,7 @@ void CClientDlg::OnConnectDlgAccepted() // initiate connection // TODO: Refactor this for failing call on Connect() - if ( pClient->Connect ( strSelectedAddress, strMixerBoardLabel ) ) - { - OnConnect ( strMixerBoardLabel ); - } + pClient->Connect ( strSelectedAddress, strMixerBoardLabel ); // reset flag bConnectDlgWasShown = false; @@ -751,9 +750,13 @@ void CClientDlg::OnConnectDlgAccepted() void CClientDlg::OnConnectDisconBut() { // the connect/disconnect button implements a toggle functionality - if ( !pClient->Disconnect() ) + if ( pClient->IsRunning() ) + { + pClient->Disconnect(); + } + else { - // If the client didn't disconnect, we assume that we weren't connected. Thus show the connect dialog + // If the client isn't running, we assume that we weren't connected. Thus show the connect dialog // TODO: Refactor to have robust error handling ShowConnectionSetupDialog(); } @@ -1221,8 +1224,15 @@ void CClientDlg::OnConnect ( const QString& strMixerBoardLabel ) } } +void CClientDlg::OnConnectingFailed ( const QString& strError ) +{ + QMessageBox::critical ( this, APP_NAME, strError, "Close", nullptr ); +} + void CClientDlg::OnDisconnect() { + // channel.cpp also issues Disconnected() + // change connect button text to "connect" butConnect->setText ( tr ( "C&onnect" ) ); diff --git a/src/clientdlg.h b/src/clientdlg.h index 83acfb62a2..c8e67b3065 100644 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -126,6 +126,7 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase public slots: void OnConnect ( const QString& strServerName ); + void OnConnectingFailed ( const QString& strErrorText ); void OnDisconnect(); void OnConnectDisconBut(); void OnTimerSigMet();