Skip to content

Commit f965518

Browse files
authored
Merge pull request #3260 from AdamGLIN/customDirectoriesButton
#3233 UI: Common method to delete server and custom directory entries
2 parents c60f955 + 5ec1b26 commit f965518

File tree

3 files changed

+67
-30
lines changed

3 files changed

+67
-30
lines changed

src/clientsettingsdlg.cpp

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
360360
// custom directories
361361
QString strCustomDirectories = "<b>" + tr ( "Custom Directories" ) + ":</b> " +
362362
tr ( "If you need to add additional directories to the Connect dialog Directory drop down, "
363-
"you can enter the addresses here.<br>"
364-
"To remove a value, select it, delete the text in the input box, "
365-
"then move focus out of the control." );
363+
"you can enter the addresses here.<br>" );
366364

367365
lblCustomDirectories->setWhatsThis ( strCustomDirectories );
368366
cbxCustomDirectories->setWhatsThis ( strCustomDirectories );
369367
cbxCustomDirectories->setAccessibleName ( tr ( "Custom Directories combo box" ) );
370368

369+
butDeleteCustomDirectory->setAccessibleName ( tr ( "Delete custom directory button" ) );
370+
butDeleteCustomDirectory->setWhatsThis ( "<b>" + tr ( "Delete Custom Directory" ) + ":</b> " +
371+
tr ( "Click the button to delete the currently selected custom directory." ) );
372+
371373
// current connection status parameter
372374
QString strConnStats = "<b>" + tr ( "Audio Upstream Rate" ) + ":</b> " +
373375
tr ( "Depends on the current audio packet size and "
@@ -691,12 +693,9 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
691693
this,
692694
&CClientSettingsDlg::OnMeterStyleActivated );
693695

694-
QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, &CClientSettingsDlg::OnCustomDirectoriesEditingFinished );
695-
696-
QObject::connect ( cbxCustomDirectories,
697-
static_cast<void ( QComboBox::* ) ( int )> ( &QComboBox::activated ),
698-
this,
699-
&CClientSettingsDlg::OnCustomDirectoriesEditingFinished );
696+
QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, [this] {
697+
CClientSettingsDlg::OnCustomDirectoriesChanged ( false );
698+
} );
700699

701700
QObject::connect ( cbxLanguage, &CLanguageComboBox::LanguageChanged, this, &CClientSettingsDlg::OnLanguageChanged );
702701

@@ -711,6 +710,8 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
711710
QObject::connect ( butDriverSetup, &QPushButton::clicked, this, &CClientSettingsDlg::OnDriverSetupClicked );
712711
#endif
713712

713+
QObject::connect ( butDeleteCustomDirectory, &QPushButton::clicked, this, [this] { CClientSettingsDlg::OnCustomDirectoriesChanged ( true ); } );
714+
714715
// misc
715716
// sliders
716717
QObject::connect ( sldAudioPan, &QSlider::valueChanged, this, &CClientSettingsDlg::OnAudioPanValueChanged );
@@ -1009,29 +1010,32 @@ void CClientSettingsDlg::OnEnableOPUS64StateChanged ( int value )
10091010

10101011
void CClientSettingsDlg::OnFeedbackDetectionChanged ( int value ) { pSettings->bEnableFeedbackDetection = value == Qt::Checked; }
10111012

1012-
void CClientSettingsDlg::OnCustomDirectoriesEditingFinished()
1013+
void CClientSettingsDlg::OnCustomDirectoriesChanged ( bool bDelete )
10131014
{
1014-
if ( cbxCustomDirectories->currentText().isEmpty() && cbxCustomDirectories->currentData().isValid() )
1015-
{
1016-
// if the user has selected an entry in the combo box list and deleted the text in the input field,
1017-
// and then focus moves off the control without selecting a new entry,
1018-
// we delete the corresponding entry in the vector
1019-
pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()] = "";
1020-
}
1021-
else if ( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare (
1022-
NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 )
1015+
if ( bDelete )
10231016
{
1024-
// if the user has selected another entry in the combo box list without changing anything,
1025-
// there is no need to update any list
1026-
return;
1017+
if ( !cbxCustomDirectories->currentData().isValid() )
1018+
{
1019+
// no selected directory to delete
1020+
return;
1021+
}
1022+
// delete the selected directory
1023+
pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()] = QString();
10271024
}
10281025
else
10291026
{
1027+
1028+
if ( cbxCustomDirectories->currentText().isEmpty() ||
1029+
( cbxCustomDirectories->currentData().isValid() && pSettings->vstrDirectoryAddress[cbxCustomDirectories->currentData().toInt()].compare (
1030+
NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) ) == 0 ) )
1031+
{
1032+
// no need to add a already added directory
1033+
return;
1034+
}
10301035
// store new address at the top of the list, if the list was already
10311036
// full, the last element is thrown out
10321037
pSettings->vstrDirectoryAddress.StringFiFoWithCompare ( NetworkUtil::FixAddress ( cbxCustomDirectories->currentText() ) );
10331038
}
1034-
10351039
// update combo box list and inform connect dialog about the new address
10361040
UpdateDirectoryComboBox();
10371041
emit CustomDirectoriesChanged();

src/clientsettingsdlg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public slots:
8383
void OnAutoJitBufStateChanged ( int value );
8484
void OnEnableOPUS64StateChanged ( int value );
8585
void OnFeedbackDetectionChanged ( int value );
86-
void OnCustomDirectoriesEditingFinished();
86+
void OnCustomDirectoriesChanged ( bool bDelete );
8787
void OnNewClientLevelEditingFinished() { pSettings->iNewClientFaderLevel = edtNewClientLevel->text().toInt(); }
8888
void OnInputBoostChanged();
8989
void OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button );

src/clientsettingsdlgbase.ui

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,43 @@
10391039
</widget>
10401040
</item>
10411041
<item>
1042-
<widget class="QComboBox" name="cbxCustomDirectories">
1043-
<property name="editable">
1044-
<bool>true</bool>
1045-
</property>
1046-
</widget>
1042+
<layout class="QHBoxLayout">
1043+
<item>
1044+
<widget class="QComboBox" name="cbxCustomDirectories">
1045+
<property name="editable">
1046+
<bool>true</bool>
1047+
</property>
1048+
</widget>
1049+
</item>
1050+
<item>
1051+
<widget class="QPushButton" name="butDeleteCustomDirectory">
1052+
<property name="sizePolicy">
1053+
<sizepolicy hsizetype="Maximum" vsizetype="Ignored">
1054+
<horstretch>0</horstretch>
1055+
<verstretch>0</verstretch>
1056+
</sizepolicy>
1057+
</property>
1058+
<property name="maximumSize">
1059+
<size>
1060+
<width>24</width>
1061+
<height>16777215</height>
1062+
</size>
1063+
</property>
1064+
<property name="font">
1065+
<font>
1066+
<weight>75</weight>
1067+
<bold>true</bold>
1068+
</font>
1069+
</property>
1070+
<property name="text">
1071+
<string notr="true">⌫</string>
1072+
</property>
1073+
<property name="autoDefault">
1074+
<bool>false</bool>
1075+
</property>
1076+
</widget>
1077+
</item>
1078+
</layout>
10471079
</item>
10481080
<item>
10491081
<spacer name="verticalSpacer_4">
@@ -1053,7 +1085,7 @@
10531085
<property name="sizeHint" stdset="0">
10541086
<size>
10551087
<width>20</width>
1056-
<height>13</height>
1088+
<height>40</height>
10571089
</size>
10581090
</property>
10591091
</spacer>
@@ -1367,6 +1399,7 @@
13671399
<tabstop>sldNetBufServer</tabstop>
13681400
<tabstop>chbSmallNetworkBuffers</tabstop>
13691401
<tabstop>cbxCustomDirectories</tabstop>
1402+
<tabstop>butDeleteCustomDirectory</tabstop>
13701403
<tabstop>edtNewClientLevel</tabstop>
13711404
<tabstop>cbxInputBoost</tabstop>
13721405
<tabstop>chbDetectFeedback</tabstop>

0 commit comments

Comments
 (0)