From 5995164ba9718e1c261d5b3c31ab8d27c0fdedc9 Mon Sep 17 00:00:00 2001 From: AdamGLIN Date: Wed, 3 Apr 2024 15:43:04 +0200 Subject: [PATCH 1/2] Add "Delete Entry" button for Custom Directories In Advanced Settings, changes the method of deleting a custom directory to use a delete button, for consistency with the similar method in Connect. --- src/clientsettingsdlg.cpp | 50 +++++++++++++++++++----------------- src/clientsettingsdlg.h | 2 +- src/clientsettingsdlgbase.ui | 42 +++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 30 deletions(-) diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index d31ca03b7e..f4437603be 100644 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -360,14 +360,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet // custom directories QString strCustomDirectories = "" + tr ( "Custom Directories" ) + ": " + tr ( "If you need to add additional directories to the Connect dialog Directory drop down, " - "you can enter the addresses here.
" - "To remove a value, select it, delete the text in the input box, " - "then move focus out of the control." ); + "you can enter the addresses here.
" ); lblCustomDirectories->setWhatsThis ( strCustomDirectories ); cbxCustomDirectories->setWhatsThis ( strCustomDirectories ); cbxCustomDirectories->setAccessibleName ( tr ( "Custom Directories combo box" ) ); + butDeleteCustomDirectory->setAccessibleName ( tr ( "Delete custom directory button" ) ); + butDeleteCustomDirectory->setWhatsThis ( "" + tr ( "Delete Custom Directory" ) + ": " + + tr ( "Click the button to delete the currently selected custom directory." ) ); + // current connection status parameter QString strConnStats = "" + tr ( "Audio Upstream Rate" ) + ": " + tr ( "Depends on the current audio packet size and " @@ -691,12 +693,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet this, &CClientSettingsDlg::OnMeterStyleActivated ); - QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); - - QObject::connect ( cbxCustomDirectories, - static_cast ( &QComboBox::activated ), - this, - &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); + QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, [this] { + CClientSettingsDlg::OnCustomDirectoriesChanged ( false ); + } ); QObject::connect ( cbxLanguage, &CLanguageComboBox::LanguageChanged, this, &CClientSettingsDlg::OnLanguageChanged ); @@ -711,6 +710,8 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet QObject::connect ( butDriverSetup, &QPushButton::clicked, this, &CClientSettingsDlg::OnDriverSetupClicked ); #endif + QObject::connect ( butDeleteCustomDirectory, &QPushButton::clicked, this, [this] { CClientSettingsDlg::OnCustomDirectoriesChanged ( true ); } ); + // misc // sliders QObject::connect ( sldAudioPan, &QSlider::valueChanged, this, &CClientSettingsDlg::OnAudioPanValueChanged ); @@ -1009,29 +1010,32 @@ void CClientSettingsDlg::OnEnableOPUS64StateChanged ( int value ) void CClientSettingsDlg::OnFeedbackDetectionChanged ( int value ) { pSettings->bEnableFeedbackDetection = value == Qt::Checked; } -void CClientSettingsDlg::OnCustomDirectoriesEditingFinished() +void CClientSettingsDlg::OnCustomDirectoriesChanged ( bool bDelete ) { - if ( cbxCustomDirectories->currentText().isEmpty() && cbxCustomDirectories->currentData().isValid() ) - { - // if the user has selected an entry in the combo box list and deleted the text in the input field, - // and then focus moves off the control without selecting a new entry, - // we delete the corresponding entry in the vector - pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()] = ""; - } - else if ( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare ( - NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) + if ( bDelete ) { - // if the user has selected another entry in the combo box list without changing anything, - // there is no need to update any list - return; + if ( !cbxCustomDirectories->currentData().isValid() ) + { + // no selected directory to delete + return; + } + // delete the selected directory + pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()] = QString(); } else { + + if ( cbxCustomDirectories->currentText().isEmpty() || + ( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare ( + NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) ) + { + // no need to add a already added directory + return; + } // store new address at the top of the list, if the list was already // full, the last element is thrown out pSettings->vstrDirectoryAddress.StringFiFoWithCompare ( NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ); } - // update combo box list and inform connect dialog about the new address UpdateDirectoryComboBox(); emit CustomDirectoriesChanged(); diff --git a/src/clientsettingsdlg.h b/src/clientsettingsdlg.h index db6fa97798..4678aeb32f 100644 --- a/src/clientsettingsdlg.h +++ b/src/clientsettingsdlg.h @@ -83,7 +83,7 @@ public slots: void OnAutoJitBufStateChanged ( int value ); void OnEnableOPUS64StateChanged ( int value ); void OnFeedbackDetectionChanged ( int value ); - void OnCustomDirectoriesEditingFinished(); + void OnCustomDirectoriesChanged ( bool bDelete ); void OnNewClientLevelEditingFinished() { pSettings->iNewClientFaderLevel = edtNewClientLevel->text().toInt(); } void OnInputBoostChanged(); void OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button ); diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index 06273311e6..e88cb2d215 100644 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -1039,11 +1039,40 @@ - - - true - - + + + + + true + + + + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + 75 + true + + + + + + + + @@ -1053,7 +1082,7 @@ 20 - 13 + 40 @@ -1367,6 +1396,7 @@ sldNetBufServer chbSmallNetworkBuffers cbxCustomDirectories + butDeleteCustomDirectory edtNewClientLevel cbxInputBoost chbDetectFeedback From 5ec1b2688091906f3055b78c94e394725db79f64 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Tue, 11 Jun 2024 21:19:32 +0100 Subject: [PATCH 2/2] Prevent Enter from deleting current entry --- src/clientsettingsdlgbase.ui | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/clientsettingsdlgbase.ui b/src/clientsettingsdlgbase.ui index e88cb2d215..404ff39ecc 100644 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -1070,6 +1070,9 @@ + + false +