Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On connect dialog, in the directory list, remove 'Custom' and add all custom central servers #1894

Closed
75 changes: 53 additions & 22 deletions src/connectdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,10 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
cbxServerAddr->setAccessibleDescription ( tr ( "Holds the current server "
"IP address or URL. It also stores old URLs in the combo box list." ) );

// directory server address type combo box
cbxCentServAddrType->clear();
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_DEFAULT ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE2 ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE3 ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_ROCK ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_JAZZ ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_CLASSICAL_FOLK ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_CHORAL ) );
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_CUSTOM ) );

cbxCentServAddrType->setWhatsThis ( "<b>" + tr ( "Server List Selection" ) + ":</b> " + tr ( "Selects the server list to be shown." ) );
cbxCentServAddrType->setAccessibleName ( tr ( "Server list selection combo box" ) );
UpdateDirectoryServerComboBox();

cbxDirectoryServer->setWhatsThis ( "<b>" + tr ( "Server List Selection" ) + ":</b> " + tr ( "Selects the server list to be shown." ) );
cbxDirectoryServer->setAccessibleName ( tr ( "Server list selection combo box" ) );

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

QObject::connect ( cbxCentServAddrType,
QObject::connect ( cbxDirectoryServer,
static_cast<void ( QComboBox::* ) ( int )> ( &QComboBox::activated ),
this,
&CConnectDlg::OnCentServAddrTypeChanged );
&CConnectDlg::OnDirectoryServerChanged );

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

// update list combo box (disable events to avoid a signal)
pljones marked this conversation as resolved.
Show resolved Hide resolved
cbxCentServAddrType->blockSignals ( true );
cbxCentServAddrType->setCurrentIndex ( static_cast<int> ( pSettings->eCentralServerAddressType ) );
cbxCentServAddrType->blockSignals ( false );
cbxDirectoryServer->blockSignals ( true );
// iCustomDirectoryIndex is non-zero only if eCentralServerAddressType == AT_CUSTOM, and represents
// the offset into cbxDirectoryServer after the last non-custom directory server
cbxDirectoryServer->setCurrentIndex ( static_cast<int> ( pSettings->eCentralServerAddressType ) + pSettings->iCustomDirectoryIndex );
cbxDirectoryServer->blockSignals ( false );

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

void CConnectDlg::OnCentServAddrTypeChanged ( int iTypeIdx )
void CConnectDlg::OnDirectoryServerChanged ( int iTypeIdx )
{
// store the new directory server address type and request new list
// if iTypeIdx == AT_CUSTOM, then iCustomDirectoryIndex is the index into the vector holding the user's custom central servers
// if iTypeIdx != AT_CUSTOM, then iCustomDirectoryIndex MUST be 0;
if ( iTypeIdx >= AT_CUSTOM )
pljones marked this conversation as resolved.
Show resolved Hide resolved
{
pSettings->iCustomDirectoryIndex = iTypeIdx - AT_CUSTOM;
iTypeIdx = AT_CUSTOM;
}
else
{
pSettings->iCustomDirectoryIndex = 0;
}
pSettings->eCentralServerAddressType = static_cast<ECSAddType> ( iTypeIdx );
RequestServerList();
}
Expand Down Expand Up @@ -524,9 +529,14 @@ void CConnectDlg::OnServerAddrEditTextChanged ( const QString& )

void CConnectDlg::OnCustomCentralServerAddrChanged()
{
// only update list if the custom server list is selected
UpdateDirectoryServerComboBox();
// only update list if a custom server list is selected
jp8 marked this conversation as resolved.
Show resolved Hide resolved
if ( pSettings->eCentralServerAddressType == AT_CUSTOM )
{
// TODO: detect if the currently select custom directory still exists in the now potentially re-ordered vector,
// if so, then change to its new index. Issue #1899
pSettings->eCentralServerAddressType = static_cast<ECSAddType> ( AT_DEFAULT );
pSettings->iCustomDirectoryIndex = 0;
RequestServerList();
}
}
Expand Down Expand Up @@ -887,3 +897,24 @@ void CConnectDlg::DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem )
delete pCurChildItem;
}
}

void CConnectDlg::UpdateDirectoryServerComboBox()
{
jp8 marked this conversation as resolved.
Show resolved Hide resolved
// directory server address type combo box
cbxDirectoryServer->clear();
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_DEFAULT ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE2 ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_ANY_GENRE3 ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_ROCK ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_JAZZ ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_CLASSICAL_FOLK ) );
cbxDirectoryServer->addItem ( csCentServAddrTypeToString ( AT_GENRE_CHORAL ) );

for ( int i = 0; i < MAX_NUM_SERVER_ADDR_ITEMS; i++ )
{
if ( pSettings->vstrCentralServerAddress[i] != "" )
{
cbxDirectoryServer->addItem ( pSettings->vstrCentralServerAddress[i] );
}
}
}
3 changes: 2 additions & 1 deletion src/connectdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
void ShowAllMusicians ( const bool bState );
void RequestServerList();
void EmitCLServerListPingMes ( const CHostAddress& CurServerAddress );
void UpdateDirectoryServerComboBox();

CClientSettings* pSettings;

Expand All @@ -93,7 +94,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
public slots:
void OnServerListItemDoubleClicked ( QTreeWidgetItem* Item, int );
void OnServerAddrEditTextChanged ( const QString& );
void OnCentServAddrTypeChanged ( int iTypeIdx );
void OnDirectoryServerChanged ( int iTypeIdx );
void OnFilterTextEdited ( const QString& ) { UpdateListFilter(); }
void OnExpandAllStateChanged ( int value ) { ShowAllMusicians ( value == Qt::Checked ); }
void OnCustomCentralServerAddrChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/connectdlgbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxCentServAddrType"/>
<widget class="QComboBox" name="cbxDirectoryServer"/>
</item>
<item>
<widget class="QLabel" name="lblFilter">
Expand Down
15 changes: 15 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ vstrCentralServerAddress[0] = GetIniSetting ( IniXMLDocument, "client", "central
eCentralServerAddressType = AT_DEFAULT;
}

// custom directory server index
if ( ( eCentralServerAddressType == AT_CUSTOM ) &&
GetNumericIniSet ( IniXMLDocument, "client", "customdirectoryindex", 0, MAX_NUM_SERVER_ADDR_ITEMS, iValue ) )
{
iCustomDirectoryIndex = iValue;
}
else
{
// if directory is not set to custom, or if no custom directory index is found in the settings .ini file, then initialize to zero
iCustomDirectoryIndex = 0;
}

// clang-format off
// TODO compatibility to old version (<3.4.7)
if ( GetFlagIniSet ( IniXMLDocument, "client", "defcentservaddr", bValue ) )
Expand Down Expand Up @@ -649,6 +661,9 @@ void CClientSettings::WriteSettingsToXML ( QDomDocument& IniXMLDocument )
// directory server address type
SetNumericIniSet ( IniXMLDocument, "client", "centservaddrtype", static_cast<int> ( eCentralServerAddressType ) );

// custom directory server index
SetNumericIniSet ( IniXMLDocument, "client", "customdirectoryindex", iCustomDirectoryIndex );

// window position of the main window
PutIniSetting ( IniXMLDocument, "client", "winposmain_base64", ToBase64 ( vecWindowPosMain ) );

Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class CClientSettings : public CSettings
int iNumMixerPanelRows;
CVector<QString> vstrCentralServerAddress;
ECSAddType eCentralServerAddressType;
int iCustomDirectoryIndex; // index of selected custom central server
bool bEnableFeedbackDetection;

// window position/state settings
Expand Down