@@ -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
525530void 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+ }
0 commit comments