Skip to content

Commit 62a9c38

Browse files
jp8pljones
authored andcommitted
Add custom directory servers to Connect Dialog
This replaces "Custom" with the client's known custom directory servers.
1 parent e0cac75 commit 62a9c38

5 files changed

Lines changed: 72 additions & 24 deletions

File tree

src/connectdlg.cpp

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,10 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
6868
cbxServerAddr->setAccessibleDescription ( tr ( "Holds the current server "
6969
"IP address or URL. It also stores old URLs in the combo box list." ) );
7070

71-
// directory server address type combo box
72-
cbxCentServAddrType->clear();
73-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_DEFAULT ) );
74-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE2 ) );
75-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE3 ) );
76-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_ROCK ) );
77-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_JAZZ ) );
78-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_CLASSICAL_FOLK ) );
79-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_CHORAL ) );
80-
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_CUSTOM ) );
81-
82-
cbxCentServAddrType->setWhatsThis ( "<b>" + tr ( "Server List Selection" ) + ":</b> " + tr ( "Selects the server list to be shown." ) );
83-
cbxCentServAddrType->setAccessibleName ( tr ( "Server list selection combo box" ) );
71+
UpdateDirectoryServerComboBox();
72+
73+
cbxDirectoryServer->setWhatsThis ( "<b>" + tr ( "Server List Selection" ) + ":</b> " + tr ( "Selects the server list to be shown." ) );
74+
cbxDirectoryServer->setAccessibleName ( tr ( "Server list selection combo box" ) );
8475

8576
// filter
8677
edtFilter->setWhatsThis ( "<b>" + tr ( "Filter" ) + ":</b> " +
@@ -165,10 +156,10 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
165156
// combo boxes
166157
QObject::connect ( cbxServerAddr, &QComboBox::editTextChanged, this, &CConnectDlg::OnServerAddrEditTextChanged );
167158

168-
QObject::connect ( cbxCentServAddrType,
159+
QObject::connect ( cbxDirectoryServer,
169160
static_cast<void ( QComboBox::* ) ( int )> ( &QComboBox::activated ),
170161
this,
171-
&CConnectDlg::OnCentServAddrTypeChanged );
162+
&CConnectDlg::OnDirectoryServerChanged );
172163

173164
// check boxes
174165
QObject::connect ( chbExpandAll, &QCheckBox::stateChanged, this, &CConnectDlg::OnExpandAllStateChanged );
@@ -219,16 +210,19 @@ void CConnectDlg::RequestServerList()
219210
lvwServers->clear();
220211

221212
// update list combo box (disable events to avoid a signal)
222-
cbxCentServAddrType->blockSignals ( true );
223-
cbxCentServAddrType->setCurrentIndex ( static_cast<int> ( pSettings->eCentralServerAddressType ) );
224-
cbxCentServAddrType->blockSignals ( false );
213+
cbxDirectoryServer->blockSignals ( true );
214+
// iCustomDirectoryIndex is non-zero only if eCentralServerAddressType == AT_CUSTOM, and represents
215+
// the offset into cbxDirectoryServer after the last non-custom directory server
216+
cbxDirectoryServer->setCurrentIndex ( static_cast<int> ( pSettings->eCentralServerAddressType ) + pSettings->iCustomDirectoryIndex );
217+
cbxDirectoryServer->blockSignals ( false );
225218

226219
// Get the IP address of the directory server (using the ParseNetworAddress
227220
// function) when the connect dialog is opened, this seems to be the correct
228221
// time to do it. Note that in case of custom directory server address we
229-
// use the first entry in the vector per definition.
222+
// use iCustomDirectoryIndex as an index into the vector.
230223
if ( NetworkUtil().ParseNetworkAddress (
231-
NetworkUtil::GetCentralServerAddress ( pSettings->eCentralServerAddressType, pSettings->vstrCentralServerAddress[0] ),
224+
NetworkUtil::GetCentralServerAddress ( pSettings->eCentralServerAddressType,
225+
pSettings->vstrCentralServerAddress[pSettings->iCustomDirectoryIndex] ),
232226
CentralServerAddress ) )
233227
{
234228
// send the request for the server list
@@ -248,9 +242,20 @@ void CConnectDlg::hideEvent ( QHideEvent* )
248242
TimerReRequestServList.stop();
249243
}
250244

251-
void CConnectDlg::OnCentServAddrTypeChanged ( int iTypeIdx )
245+
void CConnectDlg::OnDirectoryServerChanged ( int iTypeIdx )
252246
{
253247
// store the new directory server address type and request new list
248+
// if iTypeIdx == AT_CUSTOM, then iCustomDirectoryIndex is the index into the vector holding the user's custom central servers
249+
// if iTypeIdx != AT_CUSTOM, then iCustomDirectoryIndex MUST be 0;
250+
if ( iTypeIdx >= AT_CUSTOM )
251+
{
252+
pSettings->iCustomDirectoryIndex = iTypeIdx - AT_CUSTOM;
253+
iTypeIdx = AT_CUSTOM;
254+
}
255+
else
256+
{
257+
pSettings->iCustomDirectoryIndex = 0;
258+
}
254259
pSettings->eCentralServerAddressType = static_cast<ECSAddType> ( iTypeIdx );
255260
RequestServerList();
256261
}
@@ -524,9 +529,14 @@ void CConnectDlg::OnServerAddrEditTextChanged ( const QString& )
524529

525530
void CConnectDlg::OnCustomCentralServerAddrChanged()
526531
{
527-
// only update list if the custom server list is selected
532+
UpdateDirectoryServerComboBox();
533+
// only update list if a custom server list is selected
528534
if ( pSettings->eCentralServerAddressType == AT_CUSTOM )
529535
{
536+
// TODO: detect if the currently select custom directory still exists in the now potentially re-ordered vector,
537+
// if so, then change to its new index. Issue #1899
538+
pSettings->eCentralServerAddressType = static_cast<ECSAddType> ( AT_DEFAULT );
539+
pSettings->iCustomDirectoryIndex = 0;
530540
RequestServerList();
531541
}
532542
}
@@ -887,3 +897,24 @@ void CConnectDlg::DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem )
887897
delete pCurChildItem;
888898
}
889899
}
900+
901+
void CConnectDlg::UpdateDirectoryServerComboBox()
902+
{
903+
// directory server address type combo box
904+
cbxDirectoryServer->clear();
905+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_DEFAULT ) );
906+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE2 ) );
907+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE3 ) );
908+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_ROCK ) );
909+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_JAZZ ) );
910+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_CLASSICAL_FOLK ) );
911+
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_CHORAL ) );
912+
913+
for ( int i = 0; i < MAX_NUM_SERVER_ADDR_ITEMS; i++ )
914+
{
915+
if ( pSettings->vstrCentralServerAddress[i] != "" )
916+
{
917+
cbxDirectoryServer->addItem ( pSettings->vstrCentralServerAddress[i] );
918+
}
919+
}
920+
}

src/connectdlg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
7474
void ShowAllMusicians ( const bool bState );
7575
void RequestServerList();
7676
void EmitCLServerListPingMes ( const CHostAddress& CurServerAddress );
77+
void UpdateDirectoryServerComboBox();
7778

7879
CClientSettings* pSettings;
7980

@@ -93,7 +94,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
9394
public slots:
9495
void OnServerListItemDoubleClicked ( QTreeWidgetItem* Item, int );
9596
void OnServerAddrEditTextChanged ( const QString& );
96-
void OnCentServAddrTypeChanged ( int iTypeIdx );
97+
void OnDirectoryServerChanged ( int iTypeIdx );
9798
void OnFilterTextEdited ( const QString& ) { UpdateListFilter(); }
9899
void OnExpandAllStateChanged ( int value ) { ShowAllMusicians ( value == Qt::Checked ); }
99100
void OnCustomCentralServerAddrChanged();

src/connectdlgbase.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</widget>
3838
</item>
3939
<item>
40-
<widget class="QComboBox" name="cbxCentServAddrType"/>
40+
<widget class="QComboBox" name="cbxDirectoryServer"/>
4141
</item>
4242
<item>
4343
<widget class="QLabel" name="lblFilter">

src/settings.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,18 @@ vstrCentralServerAddress[0] = GetIniSetting ( IniXMLDocument, "client", "central
445445
eCentralServerAddressType = AT_DEFAULT;
446446
}
447447

448+
// custom directory server index
449+
if ( ( eCentralServerAddressType == AT_CUSTOM ) &&
450+
GetNumericIniSet ( IniXMLDocument, "client", "customdirectoryindex", 0, MAX_NUM_SERVER_ADDR_ITEMS, iValue ) )
451+
{
452+
iCustomDirectoryIndex = iValue;
453+
}
454+
else
455+
{
456+
// if directory is not set to custom, or if no custom directory index is found in the settings .ini file, then initialize to zero
457+
iCustomDirectoryIndex = 0;
458+
}
459+
448460
// clang-format off
449461
// TODO compatibility to old version (<3.4.7)
450462
if ( GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) )
@@ -649,6 +661,9 @@ void CClientSettings::WriteSettingsToXML ( QDomDocument& IniXMLDocument )
649661
// directory server address type
650662
SetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", static_cast<int> ( eCentralServerAddressType ) );
651663

664+
// custom directory server index
665+
SetNumericIniSet ( IniXMLDocument, "client", "customdirectoryindex", iCustomDirectoryIndex );
666+
652667
// window position of the main window
653668
PutIniSetting ( IniXMLDocument, "client", "winposmain_base64", ToBase64 ( vecWindowPosMain ) );
654669

src/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class CClientSettings : public CSettings
157157
int iNumMixerPanelRows;
158158
CVector<QString> vstrCentralServerAddress;
159159
ECSAddType eCentralServerAddressType;
160+
int iCustomDirectoryIndex; // index of selected custom central server
160161
bool bEnableFeedbackDetection;
161162

162163
// window position/state settings

0 commit comments

Comments
 (0)