2727/* Implementation *************************************************************/
2828CClientDlg::CClientDlg ( CClient* pNCliP,
2929 CClientSettings* pNSetP,
30- const QString& strConnOnStartupAddress,
3130 const QString& strMIDISetup,
3231 const bool bNewShowComplRegConnList,
3332 const bool bShowAnalyzerConsole,
@@ -272,14 +271,6 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
272271 TimerCheckAudioDeviceOk.setSingleShot ( true ); // only check once after connection
273272 TimerDetectFeedback.setSingleShot ( true );
274273
275- // Connect on startup ------------------------------------------------------
276- if ( !strConnOnStartupAddress.isEmpty () )
277- {
278- // initiate connection (always show the address in the mixer board
279- // (no alias))
280- Connect ( strConnOnStartupAddress, strConnOnStartupAddress );
281- }
282-
283274 // File menu --------------------------------------------------------------
284275 QMenu* pFileMenu = new QMenu ( tr ( " &File" ), this );
285276
@@ -483,7 +474,11 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
483474 // other
484475 QObject::connect ( pClient, &CClient::ConClientListMesReceived, this , &CClientDlg::OnConClientListMesReceived );
485476
486- QObject::connect ( pClient, &CClient::Disconnected, this , &CClientDlg::OnDisconnected );
477+ QObject::connect ( pClient, &CClient::Connected, this , &CClientDlg::OnConnect );
478+
479+ QObject::connect ( pClient, &CClient::ConnectingFailed, this , &CClientDlg::OnConnectingFailed );
480+
481+ QObject::connect ( pClient, &CClient::Disconnected, this , &CClientDlg::OnDisconnect );
487482
488483 QObject::connect ( pClient, &CClient::ChatTextReceived, this , &CClientDlg::OnChatTextReceived );
489484
@@ -618,11 +613,8 @@ void CClientDlg::closeEvent ( QCloseEvent* Event )
618613 ConnectDlg.close ();
619614 AnalyzerConsole.close ();
620615
621- // if connected, terminate connection
622- if ( pClient->IsRunning () )
623- {
624- pClient->Stop ();
625- }
616+ // Disconnect if needed
617+ pClient->Disconnect ();
626618
627619 // make sure all current fader settings are applied to the settings struct
628620 MainMixerBoard->StoreAllFaderSettings ();
@@ -740,15 +732,11 @@ void CClientDlg::OnConnectDlgAccepted()
740732 }
741733 }
742734
743- // first check if we are already connected, if this is the case we have to
744- // disconnect the old server first
745- if ( pClient->IsRunning () )
746- {
747- Disconnect ();
748- }
735+ // Disconnect the client. We could be currently connected.
736+ pClient->Disconnect ();
749737
750738 // initiate connection
751- Connect ( strSelectedAddress, strMixerBoardLabel );
739+ pClient-> Connect ( strSelectedAddress, strMixerBoardLabel );
752740
753741 // reset flag
754742 bConnectDlgWasShown = false ;
@@ -760,11 +748,12 @@ void CClientDlg::OnConnectDisconBut()
760748 // the connect/disconnect button implements a toggle functionality
761749 if ( pClient->IsRunning () )
762750 {
763- Disconnect ();
764- SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign () );
751+ pClient->Stop ();
765752 }
766753 else
767754 {
755+ // If the client isn't running, we assume that we weren't connected. Thus show the connect dialog
756+ // TODO: Refactor to have robust error handling
768757 ShowConnectionSetupDialog ();
769758 }
770759}
@@ -869,7 +858,7 @@ void CClientDlg::OnLicenceRequired ( ELicenceType eLicenceType )
869858 // disconnect from that server.
870859 if ( !LicenceDlg.exec () )
871860 {
872- Disconnect ();
861+ pClient-> Disconnect ();
873862 }
874863
875864 // unmute the client output stream if local mute button is not pressed
@@ -1172,10 +1161,7 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
11721161 if ( !strError.isEmpty () )
11731162 {
11741163 // the sound device setup has a problem, disconnect any active connection
1175- if ( pClient->IsRunning () )
1176- {
1177- Disconnect ();
1178- }
1164+ pClient->Disconnect ();
11791165
11801166 // show the error message of the device setup
11811167 QMessageBox::critical ( this , APP_NAME, strError, tr ( " Ok" ), nullptr );
@@ -1203,65 +1189,38 @@ void CClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int
12031189 ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr, iPingTime, iNumClients );
12041190}
12051191
1206- void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& strMixerBoardLabel )
1192+ void CClientDlg::OnConnect ( const QString& strMixerBoardLabel )
12071193{
1208- // set address and check if address is valid
1209- if ( pClient->SetServerAddr ( strSelectedAddress ) )
1210- {
1211- // try to start client, if error occurred, do not go in
1212- // running state but show error message
1213- try
1214- {
1215- if ( !pClient->IsRunning () )
1216- {
1217- pClient->Start ();
1218- }
1219- }
1220-
1221- catch ( const CGenErr& generr )
1222- {
1223- // show error message and return the function
1224- QMessageBox::critical ( this , APP_NAME, generr.GetErrorText (), " Close" , nullptr );
1225- return ;
1226- }
12271194
1228- // hide label connect to server
1229- lblConnectToServer->hide ();
1230- lbrInputLevelL->setEnabled ( true );
1231- lbrInputLevelR->setEnabled ( true );
1195+ // hide label connect to server
1196+ lblConnectToServer->hide ();
1197+ lbrInputLevelL->setEnabled ( true );
1198+ lbrInputLevelR->setEnabled ( true );
12321199
1233- // change connect button text to "disconnect"
1234- butConnect->setText ( tr ( " &Disconnect" ) );
1200+ // change connect button text to "disconnect"
1201+ butConnect->setText ( tr ( " &Disconnect" ) );
12351202
1236- // set server name in audio mixer group box title
1237- MainMixerBoard->SetServerName ( strMixerBoardLabel );
1203+ // set server name in audio mixer group box title
1204+ MainMixerBoard->SetServerName ( strMixerBoardLabel );
12381205
1239- // start timer for level meter bar and ping time measurement
1240- TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
1241- TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS );
1242- TimerPing.start ( PING_UPDATE_TIME_MS );
1243- TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer
1206+ // start timer for level meter bar and ping time measurement
1207+ TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
1208+ TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS );
1209+ TimerPing.start ( PING_UPDATE_TIME_MS );
1210+ TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer
12441211
1245- // audio feedback detection
1246- if ( pSettings->bEnableFeedbackDetection )
1247- {
1248- TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer
1249- bDetectFeedback = true ;
1250- }
1212+ // audio feedback detection
1213+ if ( pSettings->bEnableFeedbackDetection )
1214+ {
1215+ TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer
1216+ bDetectFeedback = true ;
12511217 }
12521218}
12531219
1254- void CClientDlg::Disconnect ()
1255- {
1256- // only stop client if currently running, in case we received
1257- // the stopped message, the client is already stopped but the
1258- // connect/disconnect button and other GUI controls must be
1259- // updated
1260- if ( pClient->IsRunning () )
1261- {
1262- pClient->Stop ();
1263- }
1220+ void CClientDlg::OnConnectingFailed ( const QString& strError ) { QMessageBox::critical ( this , APP_NAME, strError, tr ( " Close" ), nullptr ); }
12641221
1222+ void CClientDlg::OnDisconnect ()
1223+ {
12651224 // change connect button text to "connect"
12661225 butConnect->setText ( tr ( " C&onnect" ) );
12671226
@@ -1303,6 +1262,9 @@ void CClientDlg::Disconnect()
13031262
13041263 // clear mixer board (remove all faders)
13051264 MainMixerBoard->HideAll ();
1265+
1266+ // Reset the deco
1267+ SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign () );
13061268}
13071269
13081270void CClientDlg::UpdateDisplay ()
0 commit comments