Skip to content

Commit

Permalink
Merge pull request #3260 from AdamGLIN/customDirectoriesButton
Browse files Browse the repository at this point in the history
#3233 UI: Common method to delete server and custom directory entries
  • Loading branch information
pljones committed Jun 14, 2024
2 parents c60f955 + 5ec1b26 commit f965518
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 30 deletions.
50 changes: 27 additions & 23 deletions src/clientsettingsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,16 @@ CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, CClientSettings* pNSet
// custom directories
QString strCustomDirectories = "<b>" + tr ( "Custom Directories" ) + ":</b> " +
tr ( "If you need to add additional directories to the Connect dialog Directory drop down, "
"you can enter the addresses here.<br>"
"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.<br>" );

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

butDeleteCustomDirectory->setAccessibleName ( tr ( "Delete custom directory button" ) );
butDeleteCustomDirectory->setWhatsThis ( "<b>" + tr ( "Delete Custom Directory" ) + ":</b> " +
tr ( "Click the button to delete the currently selected custom directory." ) );

// current connection status parameter
QString strConnStats = "<b>" + tr ( "Audio Upstream Rate" ) + ":</b> " +
tr ( "Depends on the current audio packet size and "
Expand Down Expand Up @@ -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<void ( QComboBox::* ) ( int )> ( &QComboBox::activated ),
this,
&CClientSettingsDlg::OnCustomDirectoriesEditingFinished );
QObject::connect ( cbxCustomDirectories->lineEdit(), &QLineEdit::editingFinished, this, [this] {
CClientSettingsDlg::OnCustomDirectoriesChanged ( false );
} );

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

Expand All @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/clientsettingsdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
45 changes: 39 additions & 6 deletions src/clientsettingsdlgbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1039,11 +1039,43 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxCustomDirectories">
<property name="editable">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout">
<item>
<widget class="QComboBox" name="cbxCustomDirectories">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="butDeleteCustomDirectory">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">⌫</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_4">
Expand All @@ -1053,7 +1085,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>13</height>
<height>40</height>
</size>
</property>
</spacer>
Expand Down Expand Up @@ -1367,6 +1399,7 @@
<tabstop>sldNetBufServer</tabstop>
<tabstop>chbSmallNetworkBuffers</tabstop>
<tabstop>cbxCustomDirectories</tabstop>
<tabstop>butDeleteCustomDirectory</tabstop>
<tabstop>edtNewClientLevel</tabstop>
<tabstop>cbxInputBoost</tabstop>
<tabstop>chbDetectFeedback</tabstop>
Expand Down

0 comments on commit f965518

Please sign in to comment.