From 514bd25fee8bc848b3b068ef95e5b50795e9af06 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 14 Apr 2020 16:51:44 +0200 Subject: [PATCH] added support for filter the server list --- ChangeLog | 2 + src/connectdlg.cpp | 85 +++++++++++++++++++++++++++++++++++--- src/connectdlg.h | 3 ++ src/connectdlgbase.ui | 17 ++++++++ src/res/homepage/manual.md | 10 ++--- 5 files changed, 106 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1f7ce2ad..76d3aeff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ * added support for 64 samples OPUS packets in the client (if a sound card buffer size larger or equal than 128 samples is chosen, the legacy 128 samples OPUS packets are used) + * added a filter for the server list to, e.g., filter a specific country or search for a musician + * refresh server list if the Central Server address type is changed * the unit of the mixer faders is now dB using the range -50 dB to 0 dB diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index e4ed50e5..bbf9da3c 100755 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -35,7 +35,8 @@ CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList, strSelectedServerName ( "" ), bShowCompleteRegList ( bNewShowCompleteRegList ), bServerListReceived ( false ), - bServerListItemWasChosen ( false ) + bServerListItemWasChosen ( false ), + bListFilterWasActive ( false ) { setupUi ( this ); @@ -142,6 +143,10 @@ CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList, SIGNAL ( activated ( QModelIndex ) ), this, SLOT ( OnConnectClicked() ) ); + // line edit + QObject::connect ( edtFilter, SIGNAL ( textEdited ( const QString& ) ), + this, SLOT ( OnFilterTextEdited ( const QString& ) ) ); + // combo boxes QObject::connect ( cbxServerAddr, SIGNAL ( editTextChanged ( const QString& ) ), this, SLOT ( OnServerAddrEditTextChanged ( const QString& ) ) ); @@ -188,6 +193,7 @@ void CConnectDlg::RequestServerList() // reset flags bServerListReceived = false; bServerListItemWasChosen = false; + bListFilterWasActive = false; // clear current address and name strSelectedAddress = ""; @@ -196,6 +202,9 @@ void CConnectDlg::RequestServerList() // clear server list view lvwServers->clear(); + // clear filter edit box + edtFilter->setText ( "" ); + // get the IP address of the central server (using the ParseNetworAddress // function) when the connect dialog is opened, this seems to be the correct // time to do it @@ -485,6 +494,66 @@ void CConnectDlg::OnServerAddrEditTextChanged ( const QString& ) lvwServers->clearSelection(); } +void CConnectDlg::UpdateListFilter() +{ + const QString sFilterText = edtFilter->text(); + + if ( !sFilterText.isEmpty() ) + { + bListFilterWasActive = true; + const int iServerListLen = lvwServers->topLevelItemCount(); + + for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) + { + bool bFilterFound = false; + + // search server name + if ( lvwServers->topLevelItem ( iIdx )->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + { + bFilterFound = true; + } + + // search location + if ( lvwServers->topLevelItem ( iIdx )->text ( 3 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + { + bFilterFound = true; + } + + // search childs + for ( int iCCnt = 0; iCCnt < lvwServers->topLevelItem ( iIdx )->childCount(); iCCnt++ ) + { + if ( lvwServers->topLevelItem ( iIdx )->child ( iCCnt )->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + { + bFilterFound = true; + } + } + + // only update Hide state if ping time was received + if ( !lvwServers->topLevelItem ( iIdx )->text ( 1 ).isEmpty() ) + { + lvwServers->topLevelItem ( iIdx )->setHidden ( !bFilterFound ); + } + } + } + else + { + // if the filter was active but is now disabled, we have to update all list + // view items for the "ping received" hide state + if ( bListFilterWasActive ) + { + const int iServerListLen = lvwServers->topLevelItemCount(); + + for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) + { + // if ping time is empty, hide item + lvwServers->topLevelItem ( iIdx )->setHidden ( lvwServers->topLevelItem ( iIdx )->text ( 1 ).isEmpty() ); + } + + bListFilterWasActive = false; + } + } +} + void CConnectDlg::OnConnectClicked() { // get the IP address to be used according to the following definitions: @@ -561,6 +630,9 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& if ( pCurListViewItem ) { + // check if this is the first time a ping time is set + const bool bIsFirstPing = pCurListViewItem->text ( 1 ).isEmpty(); + // update the color of the ping time font switch ( ePingTimeLEDColor ) { @@ -604,11 +676,8 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& // update number of clients value (hidden) pCurListViewItem->setText ( 6, QString().setNum ( iNumClients ) ); - // a ping time was received, set item to visible (note that we have - // to check if the item is hidden, otherwise we get a lot of CPU - // usage by calling "setHidden(false)" even if the item was already - // visible) - if ( pCurListViewItem->isHidden() ) + // this is the first time a ping time was received, set item to visible + if ( bIsFirstPing ) { pCurListViewItem->setHidden ( false ); } @@ -649,6 +718,10 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& { lvwServers->setRootIsDecorated ( false ); } + + // we may have changed the Hidden state for some items, if a filter was active, we now + // have to update it to void lines appear which do not satisfy the filter criteria + UpdateListFilter(); } QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr ) diff --git a/src/connectdlg.h b/src/connectdlg.h index 8ed6b677..c6cd86a7 100755 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -83,6 +83,7 @@ protected: QTreeWidgetItem* FindListViewItem ( const CHostAddress& InetAddr ); QTreeWidgetItem* GetParentListViewItem ( QTreeWidgetItem* pItem ); void DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem ); + void UpdateListFilter(); QTimer TimerPing; QTimer TimerReRequestServList; @@ -93,11 +94,13 @@ protected: bool bShowCompleteRegList; bool bServerListReceived; bool bServerListItemWasChosen; + bool bListFilterWasActive; public slots: void OnServerListItemSelectionChanged(); void OnServerListItemDoubleClicked ( QTreeWidgetItem* Item, int ); void OnServerAddrEditTextChanged ( const QString& ); + void OnFilterTextEdited ( const QString& ) { UpdateListFilter(); } void OnConnectClicked(); void OnTimerPing(); void OnTimerReRequestServList(); diff --git a/src/connectdlgbase.ui b/src/connectdlgbase.ui index 9f2b4621..50f7ecc2 100755 --- a/src/connectdlgbase.ui +++ b/src/connectdlgbase.ui @@ -24,6 +24,23 @@ true + + + + 0 + + + + + Filter + + + + + + + + diff --git a/src/res/homepage/manual.md b/src/res/homepage/manual.md index 95e8931b..3ef7275b 100644 --- a/src/res/homepage/manual.md +++ b/src/res/homepage/manual.md @@ -174,11 +174,11 @@ timing jitter. If the Auto check is enabled, the jitter buffer size faders are d ![Audio channels](audiochannels.png) -Select the number of audio channels to be used. There are three modes available. The mono and stereo modes use one -and two audio channels respectively. In the mono-in/stereo-out mode the audio signal which is sent to the server is -mono but the return signal is stereo. This is useful for the case that the sound card puts the instrument on one -input channel and the microphone on the other channel. In that case the two input signals can be mixed to one mono -channel but the server mix can be heard in stereo. +Select the number of audio channels to be used for communication between client and server. There are three modes +available. The mono and stereo modes use one and two audio channels respectively. In the mono-in/stereo-out mode +the audio signal which is sent to the server is mono but the return signal is stereo. This is useful for the case +that the sound card puts the instrument on one input channel and the microphone on the other channel. In that case +the two input signals can be mixed to one mono channel but the server mix can be heard in stereo. Enabling the stereo streaming mode will increase the stream data rate. Make sure that the current upload rate does not exceed the available bandwidth of your internet connection.