From 9ac8be8af1b9abd92f3a320ffdf40b5f0eb98d71 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 17 Aug 2009 17:39:40 +0000 Subject: [PATCH] put connect/disconnect button functionality in separate function --- src/llconclientdlg.cpp | 119 ++++++++++++++++++++++------------------- src/llconclientdlg.h | 1 + 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index f6ba0b3f..c6f361ef 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -335,61 +335,9 @@ void CLlconClientDlg::OnLineEditServerAddrActivated ( int index ) void CLlconClientDlg::OnConnectDisconBut() { - // start/stop client, set button text - if ( !pClient->IsRunning() ) - { - // set address and check if address is valid - if ( pClient->SetServerAddr ( LineEditServerAddr->currentText() ) ) - { - bool bStartOk = true; - - try - { - pClient->Start(); - } - - catch ( CGenErr generr ) - { - QMessageBox::critical ( - this, APP_NAME, generr.GetErrorText(), "Close", 0 ); - - bStartOk = false; - } - - if ( bStartOk ) - { - PushButtonConnect->setText ( CON_BUT_DISCONNECTTEXT ); - - // start timer for level meter bar - TimerSigMet.start ( LEVELMETER_UPDATE_TIME ); - } - } - else - { - // Restart timer to ensure that the text is visible at - // least the time for one complete interval - TimerStatus.start ( STATUSBAR_UPDATE_TIME ); - - // show the error in the status bar - TextLabelStatus->setText ( tr ( "Invalid address" ) ); - } - } - else - { - pClient->Stop(); - PushButtonConnect->setText ( CON_BUT_CONNECTTEXT ); - - // stop timer for level meter bars and reset them - TimerSigMet.stop(); - MultiColorLEDBarInputLevelL->setValue ( 0 ); - MultiColorLEDBarInputLevelR->setValue ( 0 ); - - // immediately update status bar - OnTimerStatus(); - - // clear mixer board (remove all faders) - MainMixerBoard->HideAll(); - } + // the connect/disconnect button implements a toggle functionality + // -> apply inverted running state + ConnectDisconnect ( !pClient->IsRunning() ); } void CLlconClientDlg::OnOpenGeneralSettings() @@ -471,6 +419,67 @@ void CLlconClientDlg::OnTimerSigMet() MultiColorLEDBarInputLevelR->setValue ( (int) ceil ( dCurSigLevelR ) ); } +void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart ) +{ + // start/stop client, set button text + if ( bDoStart ) + { + // set address and check if address is valid + if ( pClient->SetServerAddr ( LineEditServerAddr->currentText() ) ) + { + bool bStartOk = true; + + // try to start client, if error occurred, do not go in + // running state but show error message + try + { + pClient->Start(); + } + + catch ( CGenErr generr ) + { + QMessageBox::critical ( + this, APP_NAME, generr.GetErrorText(), "Close", 0 ); + + bStartOk = false; + } + + if ( bStartOk ) + { + PushButtonConnect->setText ( CON_BUT_DISCONNECTTEXT ); + + // start timer for level meter bar + TimerSigMet.start ( LEVELMETER_UPDATE_TIME ); + } + } + else + { + // Restart timer to ensure that the text is visible at + // least the time for one complete interval + TimerStatus.start ( STATUSBAR_UPDATE_TIME ); + + // show the error in the status bar + TextLabelStatus->setText ( tr ( "Invalid address" ) ); + } + } + else + { + pClient->Stop(); + PushButtonConnect->setText ( CON_BUT_CONNECTTEXT ); + + // stop timer for level meter bars and reset them + TimerSigMet.stop(); + MultiColorLEDBarInputLevelL->setValue ( 0 ); + MultiColorLEDBarInputLevelR->setValue ( 0 ); + + // immediately update status bar + OnTimerStatus(); + + // clear mixer board (remove all faders) + MainMixerBoard->HideAll(); + } +} + void CLlconClientDlg::UpdateDisplay() { // show connection status in status bar diff --git a/src/llconclientdlg.h b/src/llconclientdlg.h index b50684ef..e2c091f0 100755 --- a/src/llconclientdlg.h +++ b/src/llconclientdlg.h @@ -74,6 +74,7 @@ public: protected: void ShowChatWindow(); void UpdateAudioFaderSlider(); + void ConnectDisconnect ( const bool bDoStart ); CClient* pClient; bool bConnected;