From 2780a48f3c7241bd4a5dfd73252b6039e3c522d1 Mon Sep 17 00:00:00 2001 From: AdamGLIN Date: Wed, 3 Apr 2024 15:43:04 +0200 Subject: [PATCH] first commit to resolve the issue #3233 I added a horizontal box layout which include the box and the delete button. I wrote a fonction to implement the delete button. It works well when we change the focus with the mouse to add a new directory but I can't make the enter key work : it delete the input and nothing happend. I tried to add the QLineEdit::returnPressed signal but it changed nothing. I struggle to understand the former use of the QComboBox::activated signal since I commented it and nothing seems to have changed. TODO : Allowing to add directory via enter key. Improve spacers in the ui. --- src/clientsettingsdlg.cpp | 57 ++++++++++++++++++++++++++---------- src/clientsettingsdlg.h | 1 + src/clientsettingsdlgbase.ui | 28 ++++++++++++++++++ 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index d31ca03b7e..74dd265b45 100644 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -360,14 +360,17 @@ 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" ) ); + butDeleteCustomDirectories->setAccessibleName ( tr ( "Delete custom directory button" ) ); + butDeleteCustomDirectories->setWhatsThis ( "" + tr ( "Delete Custom Directory" ) + ": " + + tr ( "Click the button to clear the currently selected custom directory " + "and delete it from the list of stored custom directories." ) ); + // current connection status parameter QString strConnStats = "" + tr ( "Audio Upstream Rate" ) + ": " + tr ( "Depends on the current audio packet size and " @@ -691,12 +694,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet this, &CClientSettingsDlg::OnMeterStyleActivated ); + QObject::connect ( butDeleteCustomDirectories, &QPushButton::clicked, this, &CClientSettingsDlg::OnDeleteCustomDirectoriesClicked ); + QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); - QObject::connect ( cbxCustomDirectories, - static_cast ( &QComboBox::activated ), - this, - &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); + // QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::returnPressed, this, &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); + + // QObject::connect ( cbxCustomDirectories, + // static_cast ( &QComboBox::activated ), + // this, + // &CClientSettingsDlg::OnCustomDirectoriesEditingFinished ); QObject::connect ( cbxLanguage, &CLanguageComboBox::LanguageChanged, this, &CClientSettingsDlg::OnLanguageChanged ); @@ -1009,17 +1016,37 @@ void CClientSettingsDlg::OnEnableOPUS64StateChanged ( int value ) void CClientSettingsDlg::OnFeedbackDetectionChanged ( int value ) { pSettings->bEnableFeedbackDetection = value == Qt::Checked; } -void CClientSettingsDlg::OnCustomDirectoriesEditingFinished() +void CClientSettingsDlg::OnDeleteCustomDirectoriesClicked() { - if ( cbxCustomDirectories->currentText().isEmpty() && cbxCustomDirectories->currentData().isValid() ) + if ( cbxCustomDirectories->currentText().isEmpty() ) + { + return; + } + + // move later items down one + for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS - 1; iLEIdx++ ) { - // 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()] = ""; + while ( pSettings->vstrDirectoryAddress[iLEIdx].compare ( NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) + { + for ( int jLEIdx = iLEIdx + 1; jLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; jLEIdx++ ) + { + pSettings->vstrDirectoryAddress[jLEIdx - 1] = pSettings->vstrDirectoryAddress[jLEIdx]; + } + } } - else if ( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare ( - NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) + // empty last entry + pSettings->vstrDirectoryAddress[MAX_NUM_SERVER_ADDR_ITEMS - 1] = QString(); + + // redisplay to pick up updated list + UpdateDisplay(); + UpdateDirectoryComboBox(); + emit CustomDirectoriesChanged(); +} + +void CClientSettingsDlg::OnCustomDirectoriesEditingFinished() +{ + if ( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare ( + NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) { // if the user has selected another entry in the combo box list without changing anything, // there is no need to update any list diff --git a/src/clientsettingsdlg.h b/src/clientsettingsdlg.h index db6fa97798..ec7ade0135 100644 --- a/src/clientsettingsdlg.h +++ b/src/clientsettingsdlg.h @@ -84,6 +84,7 @@ public slots: void OnEnableOPUS64StateChanged ( int value ); void OnFeedbackDetectionChanged ( int value ); void OnCustomDirectoriesEditingFinished(); + void OnDeleteCustomDirectoriesClicked(); 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..a6f599badb 100644 --- a/src/clientsettingsdlgbase.ui +++ b/src/clientsettingsdlgbase.ui @@ -1038,6 +1038,8 @@ + + @@ -1045,6 +1047,32 @@ + + + + + 0 + 0 + + + + + 24 + 16777215 + + + + + true + + + + + + + + +