Skip to content

Commit

Permalink
Add intermediate refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ann0see committed Sep 15, 2024
1 parent 0b6a2bb commit 8bacce4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
48 changes: 23 additions & 25 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down Expand Up @@ -430,7 +430,9 @@ protected slots:

void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );

void ConnectClient ( QString strServerAddress );
void Connecting ( QString strServerName );
void ConnectingFailed ( QString errorMessage );
void Disconnected();

void SoundDeviceChanged ( QString strError );
Expand Down
22 changes: 16 additions & 6 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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" ) );

Expand Down
1 change: 1 addition & 0 deletions src/clientdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 8bacce4

Please sign in to comment.