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
@@ -481,7 +472,11 @@ CClientDlg::CClientDlg ( CClient* pNCliP,
481472 // other
482473 QObject::connect ( pClient, &CClient::ConClientListMesReceived, this , &CClientDlg::OnConClientListMesReceived );
483474
484- QObject::connect ( pClient, &CClient::Disconnected, this , &CClientDlg::OnDisconnected );
475+ QObject::connect ( pClient, &CClient::Connected, this , &CClientDlg::OnConnect );
476+
477+ QObject::connect ( pClient, &CClient::ConnectingFailed, this , &CClientDlg::OnConnectingFailed );
478+
479+ QObject::connect ( pClient, &CClient::Disconnected, this , &CClientDlg::OnDisconnect );
485480
486481 QObject::connect ( pClient, &CClient::ChatTextReceived, this , &CClientDlg::OnChatTextReceived );
487482
@@ -616,11 +611,8 @@ void CClientDlg::closeEvent ( QCloseEvent* Event )
616611 ConnectDlg.close ();
617612 AnalyzerConsole.close ();
618613
619- // if connected, terminate connection
620- if ( pClient->IsRunning () )
621- {
622- pClient->Stop ();
623- }
614+ // Disconnect if needed
615+ pClient->Disconnect ();
624616
625617 // make sure all current fader settings are applied to the settings struct
626618 MainMixerBoard->StoreAllFaderSettings ();
@@ -738,15 +730,11 @@ void CClientDlg::OnConnectDlgAccepted()
738730 }
739731 }
740732
741- // first check if we are already connected, if this is the case we have to
742- // disconnect the old server first
743- if ( pClient->IsRunning () )
744- {
745- Disconnect ();
746- }
733+ // Disconnect the client. We could be currently connected.
734+ pClient->Disconnect ();
747735
748736 // initiate connection
749- Connect ( strSelectedAddress, strMixerBoardLabel );
737+ pClient-> Connect ( strSelectedAddress, strMixerBoardLabel );
750738
751739 // reset flag
752740 bConnectDlgWasShown = false ;
@@ -758,11 +746,12 @@ void CClientDlg::OnConnectDisconBut()
758746 // the connect/disconnect button implements a toggle functionality
759747 if ( pClient->IsRunning () )
760748 {
761- Disconnect ();
762- SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign () );
749+ pClient->Stop ();
763750 }
764751 else
765752 {
753+ // If the client isn't running, we assume that we weren't connected. Thus show the connect dialog
754+ // TODO: Refactor to have robust error handling
766755 ShowConnectionSetupDialog ();
767756 }
768757}
@@ -870,7 +859,7 @@ void CClientDlg::OnLicenceRequired ( ELicenceType eLicenceType )
870859 // disconnect from that server.
871860 if ( !LicenceDlg.exec () )
872861 {
873- Disconnect ();
862+ pClient-> Disconnect ();
874863 }
875864
876865 // unmute the client output stream if local mute button is not pressed
@@ -1173,10 +1162,7 @@ void CClientDlg::OnSoundDeviceChanged ( QString strError )
11731162 if ( !strError.isEmpty () )
11741163 {
11751164 // the sound device setup has a problem, disconnect any active connection
1176- if ( pClient->IsRunning () )
1177- {
1178- Disconnect ();
1179- }
1165+ pClient->Disconnect ();
11801166
11811167 // show the error message of the device setup
11821168 QMessageBox::critical ( this , APP_NAME, strError, tr ( " Ok" ), nullptr );
@@ -1204,65 +1190,38 @@ void CClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int
12041190 ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr, iPingTime, iNumClients );
12051191}
12061192
1207- void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& strMixerBoardLabel )
1193+ void CClientDlg::OnConnect ( const QString& strMixerBoardLabel )
12081194{
1209- // set address and check if address is valid
1210- if ( pClient->SetServerAddr ( strSelectedAddress ) )
1211- {
1212- // try to start client, if error occurred, do not go in
1213- // running state but show error message
1214- try
1215- {
1216- if ( !pClient->IsRunning () )
1217- {
1218- pClient->Start ();
1219- }
1220- }
1221-
1222- catch ( const CGenErr& generr )
1223- {
1224- // show error message and return the function
1225- QMessageBox::critical ( this , APP_NAME, generr.GetErrorText (), " Close" , nullptr );
1226- return ;
1227- }
12281195
1229- // hide label connect to server
1230- lblConnectToServer->hide ();
1231- lbrInputLevelL->setEnabled ( true );
1232- lbrInputLevelR->setEnabled ( true );
1196+ // hide label connect to server
1197+ lblConnectToServer->hide ();
1198+ lbrInputLevelL->setEnabled ( true );
1199+ lbrInputLevelR->setEnabled ( true );
12331200
1234- // change connect button text to "disconnect"
1235- butConnect->setText ( tr ( " &Disconnect" ) );
1201+ // change connect button text to "disconnect"
1202+ butConnect->setText ( tr ( " &Disconnect" ) );
12361203
1237- // set server name in audio mixer group box title
1238- MainMixerBoard->SetServerName ( strMixerBoardLabel );
1204+ // set server name in audio mixer group box title
1205+ MainMixerBoard->SetServerName ( strMixerBoardLabel );
12391206
1240- // start timer for level meter bar and ping time measurement
1241- TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
1242- TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS );
1243- TimerPing.start ( PING_UPDATE_TIME_MS );
1244- TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer
1207+ // start timer for level meter bar and ping time measurement
1208+ TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
1209+ TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS );
1210+ TimerPing.start ( PING_UPDATE_TIME_MS );
1211+ TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer
12451212
1246- // audio feedback detection
1247- if ( pSettings->bEnableFeedbackDetection )
1248- {
1249- TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer
1250- bDetectFeedback = true ;
1251- }
1213+ // audio feedback detection
1214+ if ( pSettings->bEnableFeedbackDetection )
1215+ {
1216+ TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer
1217+ bDetectFeedback = true ;
12521218 }
12531219}
12541220
1255- void CClientDlg::Disconnect ()
1256- {
1257- // only stop client if currently running, in case we received
1258- // the stopped message, the client is already stopped but the
1259- // connect/disconnect button and other GUI controls must be
1260- // updated
1261- if ( pClient->IsRunning () )
1262- {
1263- pClient->Stop ();
1264- }
1221+ void CClientDlg::OnConnectingFailed ( const QString& strError ) { QMessageBox::critical ( this , APP_NAME, strError, tr ( " Close" ), nullptr ); }
12651222
1223+ void CClientDlg::OnDisconnect ()
1224+ {
12661225 // change connect button text to "connect"
12671226 butConnect->setText ( tr ( " C&onnect" ) );
12681227
@@ -1304,6 +1263,9 @@ void CClientDlg::Disconnect()
13041263
13051264 // clear mixer board (remove all faders)
13061265 MainMixerBoard->HideAll ();
1266+
1267+ // Reset the deco
1268+ SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign () );
13071269}
13081270
13091271void CClientDlg::UpdateDisplay ()
0 commit comments