From b12ce7e4d55e0f6d70bfa960c480e3e3509d9885 Mon Sep 17 00:00:00 2001 From: pgScorpio Date: Sun, 8 Sep 2024 11:48:03 +0200 Subject: [PATCH] Fix connection status issue (#2519) This is a manual port of https://github.com/jamulussoftware/jamulus/pull/2550 by @pgScorpio Co-authored-by: ann0see <20726856+ann0see@users.noreply.github.com> --- src/channel.cpp | 31 ++++++- src/channel.h | 3 +- src/client.cpp | 174 +++++++++++++++++++++----------------- src/client.h | 16 ++-- src/clientdlg.cpp | 137 +++++++++--------------------- src/clientdlg.h | 14 ++- src/clientsettingsdlg.cpp | 22 ++--- src/main.cpp | 32 ++++--- 8 files changed, 209 insertions(+), 220 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index 53f91766a8..c2ff6ef5b2 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -37,6 +37,7 @@ CChannel::CChannel ( const bool bNIsServer ) : bIsEnabled ( false ), bIsServer ( bNIsServer ), bIsIdentified ( false ), + bDisconnectAndDisable ( false ), iAudioFrameSizeSamples ( DOUBLE_SYSTEM_FRAME_SIZE_SAMPLES ), SignalLevelMeter ( false, 0.5 ) // server mode with mono out and faster smoothing { @@ -125,7 +126,8 @@ void CChannel::SetEnable ( const bool bNEnStat ) QMutexLocker locker ( &Mutex ); // set internal parameter - bIsEnabled = bNEnStat; + bIsEnabled = bNEnStat; + bDisconnectAndDisable = false; // The support for the packet sequence number must be reset if the client // disconnects from a server since we do not yet know if the next server we @@ -506,11 +508,24 @@ void CChannel::Disconnect() // we only have to disconnect the channel if it is actually connected if ( IsConnected() ) { + // for a Client, block further audio data and disable the channel as soon as Disconnect() is called + // TODO: Add reasoning from #2550 + + bDisconnectAndDisable = !bIsServer; + // set time out counter to a small value > 0 so that the next time a // received audio block is queried, the disconnection is performed // (assuming that no audio packet is received in the meantime) iConTimeOut = 1; // a small number > 0 } + else if ( !bIsServer ) + { + // For clients (?) set defaults + + bDisconnectAndDisable = false; + bIsEnabled = false; + iConTimeOut = 0; + } } void CChannel::PutProtocolData ( const int iRecCounter, const int iRecID, const CVector& vecbyMesBodyData, const CHostAddress& RecHostAddr ) @@ -534,7 +549,7 @@ EPutDataStat CChannel::PutAudioData ( const CVector& vecbyData, const i // Only process audio data if: // - for client only: the packet comes from the server we want to talk to // - the channel is enabled - if ( ( bIsServer || ( GetAddress() == RecHostAddr ) ) && IsEnabled() ) + if ( ( bIsServer || ( GetAddress() == RecHostAddr ) ) && IsEnabled() && !bDisconnectAndDisable ) { MutexSocketBuf.lock(); { @@ -622,6 +637,11 @@ EGetDataStat CChannel::GetData ( CVector& vecbyData, const int iNumByte eGetStatus = GS_CHAN_NOW_DISCONNECTED; iConTimeOut = 0; // make sure we do not have negative values + if ( bDisconnectAndDisable ) + { + bDisconnectAndDisable = false; + bIsEnabled = false; + } // reset network transport properties ResetNetworkTransportProperties(); } @@ -643,6 +663,13 @@ EGetDataStat CChannel::GetData ( CVector& vecbyData, const int iNumByte { // channel is disconnected eGetStatus = GS_CHAN_NOT_CONNECTED; + + if ( bDisconnectAndDisable ) + { + bDisconnectAndDisable = false; + bIsEnabled = false; + iConTimeOut = 0; + } } } MutexSocketBuf.unlock(); diff --git a/src/channel.h b/src/channel.h index 9f70bfee6f..360b2aba1c 100644 --- a/src/channel.h +++ b/src/channel.h @@ -76,7 +76,7 @@ class CChannel : public QObject void PrepAndSendPacket ( CHighPrioSocket* pSocket, const CVector& vecbyNPacket, const int iNPacketLen ); - void ResetTimeOutCounter() { iConTimeOut = iConTimeOutStartVal; } + void ResetTimeOutCounter() { iConTimeOut = bDisconnectAndDisable ? 1 : iConTimeOutStartVal; } bool IsConnected() const { return iConTimeOut > 0; } void Disconnect(); @@ -216,6 +216,7 @@ class CChannel : public QObject bool bIsEnabled; bool bIsServer; bool bIsIdentified; + bool bDisconnectAndDisable; int iNetwFrameSizeFact; int iNetwFrameSize; diff --git a/src/client.cpp b/src/client.cpp index d3d2c51c9a..d3451f795b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -27,7 +27,6 @@ /* Implementation *************************************************************/ CClient::CClient ( const quint16 iPortNumber, const quint16 iQosNumber, - const QString& strConnOnStartupAddress, const QString& strMIDISetup, const bool bNoAutoJackConnect, const QString& strNClientName, @@ -184,13 +183,6 @@ CClient::CClient ( const quint16 iPortNumber, // start the socket (it is important to start the socket after all // initializations and connections) Socket.Start(); - - // do an immediate start if a server address is given - if ( !strConnOnStartupAddress.isEmpty() ) - { - SetServerAddr ( strConnOnStartupAddress ); - Start(); - } } CClient::~CClient() @@ -337,7 +329,7 @@ void CClient::CreateServerJitterBufferMessage() void CClient::OnCLPingReceived ( CHostAddress InetAddr, int iMs ) { // make sure we are running and the server address is correct - if ( IsRunning() && ( InetAddr == Channel.GetAddress() ) ) + if ( Channel.IsEnabled() && ( InetAddr == Channel.GetAddress() ) ) { // take care of wrap arounds (if wrapping, do not use result) const int iCurDiff = EvaluatePingMessage ( iMs ); @@ -474,26 +466,6 @@ void CClient::StartDelayTimer() } } -bool CClient::SetServerAddr ( QString strNAddr ) -{ - CHostAddress HostAddress; -#ifdef CLIENT_NO_SRV_CONNECT - if ( NetworkUtil().ParseNetworkAddress ( strNAddr, HostAddress, bEnableIPv6 ) ) -#else - if ( NetworkUtil().ParseNetworkAddressWithSrvDiscovery ( strNAddr, HostAddress, bEnableIPv6 ) ) -#endif - { - // apply address to the channel - Channel.SetAddress ( HostAddress ); - - return true; - } - else - { - return false; // invalid address - } -} - bool CClient::GetAndResetbJitterBufferOKFlag() { // get the socket buffer put status flag and reset it @@ -626,12 +598,16 @@ QString CClient::SetSndCrdDev ( const QString strNewDev ) Sound.Start(); } - // in case of an error inform the GUI about it if ( !strError.isEmpty() ) { - emit SoundDeviceChanged ( strError ); + // due to error, disconnect + Disconnect(); } + // in case of an error, this will inform the GUI about it + + emit SoundDeviceChanged(); + return strError; } @@ -758,8 +734,18 @@ void CClient::OnSndCrdReinitRequest ( int iSndCrdResetType ) } MutexDriverReinit.unlock(); + if ( !strError.isEmpty() ) + { +#ifndef HEADLESS + QMessageBox::critical ( 0, APP_NAME, strError, tr ( "Ok" ) ); +#else + qCritical() << qUtf8Printable ( strError ); + exit ( 1 ); +#endif + } + // inform GUI about the sound card device change - emit SoundDeviceChanged ( strError ); + emit SoundDeviceChanged(); } void CClient::OnHandledSignal ( int sigNum ) @@ -773,11 +759,8 @@ void CClient::OnHandledSignal ( int sigNum ) { case SIGINT: case SIGTERM: - // if connected, terminate connection (needed for headless mode) - if ( IsRunning() ) - { - Stop(); - } + // if connected, terminate connection + Disconnect(); // this should trigger OnAboutToQuit QCoreApplication::instance()->exit(); @@ -862,50 +845,89 @@ void CClient::OnClientIDReceived ( int iChanID ) emit ClientIDReceived ( iChanID ); } -void CClient::Start() +bool CClient::Connect ( QString strServerAddress, QString strServerName ) { - // init object - Init(); + if ( !Channel.IsEnabled() ) + { + CHostAddress HostAddress; + + if ( NetworkUtil().ParseNetworkAddress ( strServerAddress, HostAddress, bEnableIPv6 ) ) + { + // init object + Init(); - // enable channel - Channel.SetEnable ( true ); + // apply address to the channel + Channel.SetAddress ( HostAddress ); - // start audio interface - Sound.Start(); + // enable channel + Channel.SetEnable ( true ); + + // start audio interface + Sound.Start(); + + // Notify ClientDlg + emit Connecting ( strServerName ); + + return true; + } + } + + return false; } -void CClient::Stop() +bool CClient::Disconnect() { - // stop audio interface - Sound.Stop(); - - // disable channel - Channel.SetEnable ( false ); - - // wait for approx. 100 ms to make sure no audio packet is still in the - // network queue causing the channel to be reconnected right after having - // received the disconnect message (seems not to gain much, disconnect is - // still not working reliably) - QTime DieTime = QTime::currentTime().addMSecs ( 100 ); - while ( QTime::currentTime() < DieTime ) - { - // exclude user input events because if we use AllEvents, it happens - // that if the user initiates a connection and disconnection quickly - // (e.g. quickly pressing enter five times), the software can get into - // an unknown state - QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); - } - - // Send disconnect message to server (Since we disable our protocol - // receive mechanism with the next command, we do not evaluate any - // respond from the server, therefore we just hope that the message - // gets its way to the server, if not, the old behaviour time-out - // disconnects the connection anyway). - ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); - - // reset current signal level and LEDs - bJitterBufferOK = true; - SignalLevelMeter.Reset(); + if ( Channel.IsEnabled() ) + { + // start disconnection + Channel.Disconnect(); + + // Channel.Disconnect() should automatically disable Channel as soon as disconnected. + // Note that this only works if Sound is Active ! + + QTime DieTime = QTime::currentTime().addMSecs ( 500 ); + while ( ( QTime::currentTime() < DieTime ) && Channel.IsEnabled() ) + { + // exclude user input events because if we use AllEvents, it happens + // that if the user initiates a connection and disconnection quickly + // (e.g. quickly pressing enter five times), the software can get into + // an unknown state + QCoreApplication::processEvents ( QEventLoop::ExcludeUserInputEvents, 100 ); + } + + // Now stop the audio interface + Sound.Stop(); + + // in case we timed out, log warning and make sure Channel is disabled + if ( Channel.IsEnabled() ) + { + Channel.SetEnable ( false ); + } + + // Send disconnect message to server (Since we disable our protocol + // receive mechanism with the next command, we do not evaluate any + // respond from the server, therefore we just hope that the message + // gets its way to the server, if not, the old behaviour time-out + // disconnects the connection anyway). + ConnLessProtocol.CreateCLDisconnection ( Channel.GetAddress() ); + + // reset current signal level and LEDs + bJitterBufferOK = true; + SignalLevelMeter.Reset(); + + emit Disconnected(); + + return true; + } + else + { + // make sure sound is stopped too + Sound.Stop(); + + emit Disconnected(); + + return false; + } } void CClient::Init() @@ -921,7 +943,7 @@ void CClient::Init() bFraSiFactSafeSupported = true; #else bFraSiFactPrefSupported = ( Sound.Init ( iFraSizePreffered ) == iFraSizePreffered ); - bFraSiFactDefSupported = ( Sound.Init ( iFraSizeDefault ) == iFraSizeDefault ); + bFraSiFactDefSupported = ( Sound.Init ( iFraSizeDefault ) == iFraSizeDefault ); bFraSiFactSafeSupported = ( Sound.Init ( iFraSizeSafe ) == iFraSizeSafe ); #endif diff --git a/src/client.h b/src/client.h index 1fc33d8430..e467623f52 100644 --- a/src/client.h +++ b/src/client.h @@ -110,7 +110,6 @@ class CClient : public QObject public: CClient ( const quint16 iPortNumber, const quint16 iQosNumber, - const QString& strConnOnStartupAddress, const QString& strMIDISetup, const bool bNoAutoJackConnect, const QString& strNClientName, @@ -119,19 +118,17 @@ class CClient : public QObject virtual ~CClient(); - void Start(); - void Stop(); - bool IsRunning() { return Sound.IsRunning(); } - bool IsCallbackEntered() const { return Sound.IsCallbackEntered(); } - bool SetServerAddr ( QString strNAddr ); + bool Connect ( QString strServerAddress, QString strServerName ); + bool Disconnect(); + + bool SoundIsRunning() const { return Sound.IsCallbackEntered(); } // For OnTimerCheckAudioDeviceOk only + bool IsConnected() { return Channel.IsConnected(); } double GetLevelForMeterdBLeft() { return SignalLevelMeter.GetLevelForMeterdBLeftOrMono(); } double GetLevelForMeterdBRight() { return SignalLevelMeter.GetLevelForMeterdBRight(); } bool GetAndResetbJitterBufferOKFlag(); - bool IsConnected() { return Channel.IsConnected(); } - EGUIDesign GetGUIDesign() const { return eGUIDesign; } void SetGUIDesign ( const EGUIDesign eNGD ) { eGUIDesign = eNGD; } @@ -427,8 +424,9 @@ protected slots: void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); + void Connecting ( QString strServerName ); void Disconnected(); - void SoundDeviceChanged ( QString strError ); + void SoundDeviceChanged(); void ControllerInFaderLevel ( int iChannelIdx, int iValue ); void ControllerInPanValue ( int iChannelIdx, int iValue ); void ControllerInFaderIsSolo ( int iChannelIdx, bool bIsSolo ); diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 99b9fa6433..811e83b427 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -27,7 +27,6 @@ /* Implementation *************************************************************/ CClientDlg::CClientDlg ( CClient* pNCliP, CClientSettings* pNSetP, - const QString& strConnOnStartupAddress, const QString& strMIDISetup, const bool bNewShowComplRegConnList, const bool bShowAnalyzerConsole, @@ -272,14 +271,6 @@ CClientDlg::CClientDlg ( CClient* pNCliP, TimerCheckAudioDeviceOk.setSingleShot ( true ); // only check once after connection TimerDetectFeedback.setSingleShot ( true ); - // Connect on startup ------------------------------------------------------ - if ( !strConnOnStartupAddress.isEmpty() ) - { - // initiate connection (always show the address in the mixer board - // (no alias)) - Connect ( strConnOnStartupAddress, strConnOnStartupAddress ); - } - // File menu -------------------------------------------------------------- QMenu* pFileMenu = new QMenu ( tr ( "&File" ), this ); @@ -473,7 +464,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP, // other QObject::connect ( pClient, &CClient::ConClientListMesReceived, this, &CClientDlg::OnConClientListMesReceived ); - QObject::connect ( pClient, &CClient::Disconnected, this, &CClientDlg::OnDisconnected ); + QObject::connect ( pClient, &CClient::Connecting, this, &CClientDlg::OnConnect ); + + QObject::connect ( pClient, &CClient::Disconnected, this, &CClientDlg::OnDisconnect ); QObject::connect ( pClient, &CClient::ChatTextReceived, this, &CClientDlg::OnChatTextReceived ); @@ -608,11 +601,7 @@ void CClientDlg::closeEvent ( QCloseEvent* Event ) ConnectDlg.close(); AnalyzerConsole.close(); - // if connected, terminate connection - if ( pClient->IsRunning() ) - { - pClient->Stop(); - } + pClient->Disconnect(); // make sure all current fader settings are applied to the settings struct MainMixerBoard->StoreAllFaderSettings(); @@ -730,15 +719,12 @@ void CClientDlg::OnConnectDlgAccepted() } } - // first check if we are already connected, if this is the case we have to - // disconnect the old server first - if ( pClient->IsRunning() ) + // initiate connection + if ( pClient->Connect ( strSelectedAddress, strMixerBoardLabel ) ) { - Disconnect(); + OnConnect ( strMixerBoardLabel ); } - - // initiate connection - Connect ( strSelectedAddress, strMixerBoardLabel ); + // TODO: investigate and add error handling on failed Connect() call. // reset flag bConnectDlgWasShown = false; @@ -748,10 +734,10 @@ void CClientDlg::OnConnectDlgAccepted() void CClientDlg::OnConnectDisconBut() { // the connect/disconnect button implements a toggle functionality - if ( pClient->IsRunning() ) + if ( pClient->Disconnect() ) { - Disconnect(); - SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign() ); + // Client was Connected, now disconnected + // TODO: Refactor this with !pClient->Disconnect() } else { @@ -841,7 +827,7 @@ void CClientDlg::OnChatTextReceived ( QString strChatText ) // always when a new message arrives since this is annoying. ShowChatWindow ( ( strChatText.indexOf ( WELCOME_MESSAGE_PREFIX ) == 0 ) ); - UpdateDisplay(); + UpdateSettingsAndChatButtons(); } void CClientDlg::OnLicenceRequired ( ELicenceType eLicenceType ) @@ -859,7 +845,7 @@ void CClientDlg::OnLicenceRequired ( ELicenceType eLicenceType ) // disconnect from that server. if ( !LicenceDlg.exec() ) { - Disconnect(); + pClient->Disconnect(); } // unmute the client output stream if local mute button is not pressed @@ -996,7 +982,7 @@ void CClientDlg::ShowChatWindow ( const bool bForceRaise ) ChatDlg.activateWindow(); } - UpdateDisplay(); + UpdateSettingsAndChatButtons(); } void CClientDlg::ShowAnalyzerConsole() @@ -1146,7 +1132,7 @@ void CClientDlg::OnTimerCheckAudioDeviceOk() // timeout to check if a valid device is selected and if we do not have // fundamental settings errors (in which case the GUI would only show that // it is trying to connect the server which does not help to solve the problem (#129)) - if ( !pClient->IsCallbackEntered() ) + if ( !pClient->SoundIsRunning() ) { QMessageBox::warning ( this, APP_NAME, @@ -1157,20 +1143,8 @@ void CClientDlg::OnTimerCheckAudioDeviceOk() void CClientDlg::OnTimerDetectFeedback() { bDetectFeedback = false; } -void CClientDlg::OnSoundDeviceChanged ( QString strError ) +void CClientDlg::OnSoundDeviceChanged() { - if ( !strError.isEmpty() ) - { - // the sound device setup has a problem, disconnect any active connection - if ( pClient->IsRunning() ) - { - Disconnect(); - } - - // show the error message of the device setup - QMessageBox::critical ( this, APP_NAME, strError, tr ( "Ok" ), nullptr ); - } - // if the check audio device timer is running, it must be restarted on a device change if ( TimerCheckAudioDeviceOk.isActive() ) { @@ -1193,65 +1167,36 @@ void CClientDlg::OnCLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int ConnectDlg.SetPingTimeAndNumClientsResult ( InetAddr, iPingTime, iNumClients ); } -void CClientDlg::Connect ( const QString& strSelectedAddress, const QString& strMixerBoardLabel ) +void CClientDlg::OnConnect ( QString strServerName ) { - // set address and check if address is valid - if ( pClient->SetServerAddr ( strSelectedAddress ) ) - { - // try to start client, if error occurred, do not go in - // running state but show error message - try - { - if ( !pClient->IsRunning() ) - { - pClient->Start(); - } - } - catch ( const CGenErr& generr ) - { - // show error message and return the function - QMessageBox::critical ( this, APP_NAME, generr.GetErrorText(), "Close", nullptr ); - return; - } + // hide label connect to server + lblConnectToServer->hide(); + lbrInputLevelL->setEnabled ( true ); + lbrInputLevelR->setEnabled ( true ); - // hide label connect to server - lblConnectToServer->hide(); - lbrInputLevelL->setEnabled ( true ); - lbrInputLevelR->setEnabled ( true ); + // change connect button text to "disconnect" + butConnect->setText ( tr ( "&Disconnect" ) ); - // change connect button text to "disconnect" - butConnect->setText ( tr ( "&Disconnect" ) ); + // set server name in audio mixer group box title + MainMixerBoard->SetServerName ( strServerName ); - // set server name in audio mixer group box title - MainMixerBoard->SetServerName ( strMixerBoardLabel ); + // start timer for level meter bar and ping time measurement + TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS ); + TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS ); + TimerPing.start ( PING_UPDATE_TIME_MS ); + TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer - // start timer for level meter bar and ping time measurement - TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS ); - TimerBuffersLED.start ( BUFFER_LED_UPDATE_TIME_MS ); - TimerPing.start ( PING_UPDATE_TIME_MS ); - TimerCheckAudioDeviceOk.start ( CHECK_AUDIO_DEV_OK_TIME_MS ); // is single shot timer - - // audio feedback detection - if ( pSettings->bEnableFeedbackDetection ) - { - TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer - bDetectFeedback = true; - } + // audio feedback detection + if ( pSettings->bEnableFeedbackDetection ) + { + TimerDetectFeedback.start ( DETECT_FEEDBACK_TIME_MS ); // single shot timer + bDetectFeedback = true; } } -void CClientDlg::Disconnect() +void CClientDlg::OnDisconnect() { - // only stop client if currently running, in case we received - // the stopped message, the client is already stopped but the - // connect/disconnect button and other GUI controls must be - // updated - if ( pClient->IsRunning() ) - { - pClient->Stop(); - } - // change connect button text to "connect" butConnect->setText ( tr ( "C&onnect" ) ); @@ -1275,11 +1220,7 @@ void CClientDlg::Disconnect() TimerDetectFeedback.stop(); bDetectFeedback = false; - //### TODO: BEGIN ###// - // is this still required??? - // immediately update status bar - OnTimerStatus(); - //### TODO: END ###// + UpdateSettingsAndChatButtons(); // reset LEDs ledBuffers->Reset(); @@ -1293,9 +1234,11 @@ void CClientDlg::Disconnect() // clear mixer board (remove all faders) MainMixerBoard->HideAll(); + + SetMixerBoardDeco ( RS_UNDEFINED, pClient->GetGUIDesign() ); } -void CClientDlg::UpdateDisplay() +void CClientDlg::UpdateSettingsAndChatButtons() { // update settings/chat buttons (do not fire signals since it is an update) if ( chbSettings->isChecked() && !ClientSettingsDlg.isVisible() ) diff --git a/src/clientdlg.h b/src/clientdlg.h index 9737bcd2ca..12c65f7289 100644 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -76,7 +76,6 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase public: CClientDlg ( CClient* pNCliP, CClientSettings* pNSetP, - const QString& strConnOnStartupAddress, const QString& strMIDISetup, const bool bNewShowComplRegConnList, const bool bShowAnalyzerConsole, @@ -93,10 +92,8 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase void ShowChatWindow ( const bool bForceRaise = true ); void ShowAnalyzerConsole(); void UpdateAudioFaderSlider(); - void UpdateRevSelection(); - void Connect ( const QString& strSelectedAddress, const QString& strMixerBoardLabel ); - void Disconnect(); void ManageDragNDrop ( QDropEvent* Event, const bool bCheckAccept ); + void UpdateRevSelection(); void SetPingTime ( const int iPingTime, const int iOverallDelayMs, const CMultiColorLED::ELightColor eOverallDelayLEDColor ); CClient* pClient; @@ -119,7 +116,7 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase virtual void closeEvent ( QCloseEvent* Event ); virtual void dragEnterEvent ( QDragEnterEvent* Event ) { ManageDragNDrop ( Event, true ); } virtual void dropEvent ( QDropEvent* Event ) { ManageDragNDrop ( Event, false ); } - void UpdateDisplay(); + void UpdateSettingsAndChatButtons(); CClientSettingsDlg ClientSettingsDlg; CChatDlg ChatDlg; @@ -127,13 +124,15 @@ class CClientDlg : public CBaseDlg, private Ui_CClientDlgBase CAnalyzerConsole AnalyzerConsole; public slots: + void OnConnect ( QString strServerName ); + void OnDisconnect(); void OnConnectDisconBut(); void OnTimerSigMet(); void OnTimerBuffersLED(); void OnTimerCheckAudioDeviceOk(); void OnTimerDetectFeedback(); - void OnTimerStatus() { UpdateDisplay(); } + void OnTimerStatus() { UpdateSettingsAndChatButtons(); } void OnTimerPing(); void OnPingTimeResult ( int iPingTime ); @@ -191,7 +190,7 @@ public slots: void OnConClientListMesReceived ( CVector vecChanInfo ); void OnChatTextReceived ( QString strChatText ); void OnLicenceRequired ( ELicenceType eLicenceType ); - void OnSoundDeviceChanged ( QString strError ); + void OnSoundDeviceChanged(); void OnChangeChanGain ( int iId, float fGain, bool bIsMyOwnFader ) { pClient->SetRemoteChanGain ( iId, fGain, bIsMyOwnFader ); } @@ -232,7 +231,6 @@ public slots: } void OnConnectDlgAccepted(); - void OnDisconnected() { Disconnect(); } void OnGUIDesignChanged(); void OnMeterStyleChanged(); void OnRecorderStateReceived ( ERecorderState eRecorderState ); diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 58d51701a7..2a5b5522e9 100644 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -1066,22 +1066,24 @@ void CClientSettingsDlg::OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton void CClientSettingsDlg::UpdateUploadRate() { // update upstream rate information label - lblUpstreamValue->setText ( QString().setNum ( pClient->GetUploadRateKbps() ) ); - lblUpstreamUnit->setText ( "kbps" ); + if ( pClient->IsConnected() ) + { + lblUpstreamValue->setText ( QString().setNum ( pClient->GetUploadRateKbps() ) ); + lblUpstreamUnit->setText ( "kbps" ); + } + else + { + lblUpstreamValue->setText ( "---" ); + lblUpstreamUnit->setText ( "" ); + } } void CClientSettingsDlg::UpdateDisplay() { - // update slider controls (settings might have been changed) + // update slider controls (settings might have been changed) and upstream rate information label UpdateJitterBufferFrame(); UpdateSoundCardFrame(); - - if ( !pClient->IsRunning() ) - { - // clear text labels with client parameters - lblUpstreamValue->setText ( "---" ); - lblUpstreamUnit->setText ( "" ); - } + UpdateUploadRate(); } void CClientSettingsDlg::UpdateDirectoryComboBox() diff --git a/src/main.cpp b/src/main.cpp index 42d17a8dea..5dc16ed57e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -919,14 +919,7 @@ int main ( int argc, char** argv ) { // Client: // actual client object - CClient Client ( iPortNumber, - iQosNumber, - strConnOnStartupAddress, - strMIDISetup, - bNoAutoJackConnect, - strClientName, - bEnableIPv6, - bMuteMeInPersonalMix ); + CClient Client ( iPortNumber, iQosNumber, strMIDISetup, bNoAutoJackConnect, strClientName, bEnableIPv6, bMuteMeInPersonalMix ); // load settings from init-file (command line options override) CClientSettings Settings ( &Client, strIniFileName ); @@ -950,19 +943,18 @@ int main ( int argc, char** argv ) } // GUI object - CClientDlg ClientDlg ( &Client, - &Settings, - strConnOnStartupAddress, - strMIDISetup, - bShowComplRegConnList, - bShowAnalyzerConsole, - bMuteStream, - bEnableIPv6, - nullptr ); + CClientDlg + ClientDlg ( &Client, &Settings, strMIDISetup, bShowComplRegConnList, bShowAnalyzerConsole, bMuteStream, bEnableIPv6, nullptr ); // show dialog ClientDlg.show(); + // Connect on startup + if ( !strConnOnStartupAddress.isEmpty() ) + { + Client.Connect ( strConnOnStartupAddress, strConnOnStartupAddress ); + } + pApp->exec(); } else @@ -971,6 +963,12 @@ int main ( int argc, char** argv ) // only start application without using the GUI qInfo() << qUtf8Printable ( GetVersionAndNameStr ( false ) ); + // Connect on startup + if ( !strConnOnStartupAddress.isEmpty() ) + { + Client.Connect ( strConnOnStartupAddress, strConnOnStartupAddress ); + } + pApp->exec(); } }