From f5c30255872f522ea37e1e5afa1fcc5c18779974 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Fri, 25 Oct 2024 16:26:58 +0100 Subject: [PATCH 1/6] Add version column to server list in connectdlg Updated column indexes to match. Version column not yet populated. --- src/connectdlg.cpp | 67 ++++++++++++++++++++++--------------------- src/connectdlgbase.ui | 5 ++++ 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 055dae6de1..9bb5104fb0 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -114,12 +114,14 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR // for Android we need larger numbers because of the default font size lvwServers->setColumnWidth ( 0, 200 ); lvwServers->setColumnWidth ( 1, 130 ); - lvwServers->setColumnWidth ( 2, 100 ); + lvwServers->setColumnWidth ( 2, 130 ); + lvwServers->setColumnWidth ( 3, 100 ); #else lvwServers->setColumnWidth ( 0, 180 ); lvwServers->setColumnWidth ( 1, 75 ); - lvwServers->setColumnWidth ( 2, 70 ); - lvwServers->setColumnWidth ( 3, 220 ); + lvwServers->setColumnWidth ( 2, 75 ); + lvwServers->setColumnWidth ( 3, 70 ); + lvwServers->setColumnWidth ( 4, 220 ); #endif lvwServers->clear(); @@ -129,14 +131,15 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR // add invisible columns which are used for sorting the list and storing // the current/maximum number of clients // 0: server name - // 1: ping time - // 2: number of musicians (including additional strings like " (full)") - // 3: location - // 4: minimum ping time (invisible) - // 5: maximum number of clients (invisible) - lvwServers->setColumnCount ( 6 ); - lvwServers->hideColumn ( 4 ); + // 1: server version + // 2: ping time + // 3: number of musicians (including additional strings like " (full)") + // 4: location + // 5: minimum ping time (invisible) + // 6: maximum number of clients (invisible) + lvwServers->setColumnCount ( 7 ); lvwServers->hideColumn ( 5 ); + lvwServers->hideColumn ( 6 ); // per default the root shall not be decorated (to save space) lvwServers->setRootIsDecorated ( false ); @@ -403,9 +406,9 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetFont ( 0, CurServerNameFont ); // the ping time shall be shown in bold font - QFont CurPingTimeFont = pNewListViewItem->font ( 1 ); + QFont CurPingTimeFont = pNewListViewItem->font ( 2 ); CurPingTimeFont.setBold ( true ); - pNewListViewItem->setFont ( 1, CurPingTimeFont ); + pNewListViewItem->setFont ( 2, CurPingTimeFont ); // server location (city and country) QString strLocation = vecServerInfo[iIdx].strCity; @@ -438,14 +441,14 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetText ( 3, strLocation ); + pNewListViewItem->setText ( 4, strLocation ); // init the minimum ping time with a large number (note that this number // must fit in an integer type) - pNewListViewItem->setText ( 4, "99999999" ); + pNewListViewItem->setText ( 5, "99999999" ); // store the maximum number of clients - pNewListViewItem->setText ( 5, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) ); + pNewListViewItem->setText ( 6, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) ); // store host address pNewListViewItem->setData ( 0, Qt::UserRole, CurHostAddress.toString() ); @@ -649,7 +652,7 @@ void CConnectDlg::UpdateListFilter() } // search location - if ( pCurListViewItem->text ( 3 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + if ( pCurListViewItem->text ( 4 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) { bFilterFound = true; } @@ -665,7 +668,7 @@ void CConnectDlg::UpdateListFilter() } // only update Hide state if ping time was received - if ( !pCurListViewItem->text ( 1 ).isEmpty() || bShowCompleteRegList ) + if ( !pCurListViewItem->text ( 2 ).isEmpty() || bShowCompleteRegList ) { // only update hide and expand status if the hide state has to be changed to // preserve if user clicked on expand icon manually @@ -690,7 +693,7 @@ void CConnectDlg::UpdateListFilter() QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx ); // if ping time is empty, hide item (if not already hidden) - if ( pCurListViewItem->text ( 1 ).isEmpty() && !bShowCompleteRegList ) + if ( pCurListViewItem->text ( 2 ).isEmpty() && !bShowCompleteRegList ) { pCurListViewItem->setHidden ( true ); } @@ -811,12 +814,12 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, if ( pCurListViewItem ) { // check if this is the first time a ping time is set - const bool bIsFirstPing = pCurListViewItem->text ( 1 ).isEmpty(); + const bool bIsFirstPing = pCurListViewItem->text ( 2 ).isEmpty(); bool bDoSorting = false; // update minimum ping time column (invisible, used for sorting) if // the new value is smaller than the old value - int iMinPingTime = pCurListViewItem->text ( 4 ).toInt(); + int iMinPingTime = pCurListViewItem->text ( 5 ).toInt(); if ( iMinPingTime > iPingTime ) { @@ -825,7 +828,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // we pad to a total of 8 characters with zeros to make sure the // sorting is done correctly - pCurListViewItem->setText ( 4, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) ); + pCurListViewItem->setText ( 5, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) ); // update the sorting (lowest number on top) bDoSorting = true; @@ -843,17 +846,17 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // Color definition: <= 25 ms green, <= 50 ms yellow, otherwise red if ( iMinPingTime <= 25 ) { - pCurListViewItem->setForeground ( 1, Qt::darkGreen ); + pCurListViewItem->setForeground ( 2, Qt::darkGreen ); } else { if ( iMinPingTime <= 50 ) { - pCurListViewItem->setForeground ( 1, Qt::darkYellow ); + pCurListViewItem->setForeground ( 2, Qt::darkYellow ); } else { - pCurListViewItem->setForeground ( 1, Qt::red ); + pCurListViewItem->setForeground ( 2, Qt::red ); } } @@ -861,28 +864,28 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // certain value if ( iMinPingTime > 500 ) { - pCurListViewItem->setText ( 1, ">500 ms" ); + pCurListViewItem->setText ( 2, ">500 ms" ); } else { // prepend spaces so that we can sort correctly (fieldWidth of // 4 is sufficient since the maximum width is ">500") (#201) - pCurListViewItem->setText ( 1, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) ); + pCurListViewItem->setText ( 2, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) ); } // update number of clients text - if ( pCurListViewItem->text ( 5 ).toInt() == 0 ) + if ( pCurListViewItem->text ( 6 ).toInt() == 0 ) { // special case: reduced server list - pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) ); + pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) ); } - else if ( iNumClients >= pCurListViewItem->text ( 5 ).toInt() ) + else if ( iNumClients >= pCurListViewItem->text ( 6 ).toInt() ) { - pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + " (full)" ); + pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) + " (full)" ); } else { - pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 5 ) ); + pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 6 ) ); } // check if the number of child list items matches the number of @@ -907,7 +910,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, if ( bDoSorting && !bShowCompleteRegList && ( TimerInitialSort.isActive() || !lvwServers->underMouse() ) ) // do not sort if "show all servers" { - lvwServers->sortByColumn ( 4, Qt::AscendingOrder ); + lvwServers->sortByColumn ( 5, Qt::AscendingOrder ); } } diff --git a/src/connectdlgbase.ui b/src/connectdlgbase.ui index 279c76dc0b..852fcfaa1b 100644 --- a/src/connectdlgbase.ui +++ b/src/connectdlgbase.ui @@ -71,6 +71,11 @@ Server Name + + + Version + + Ping Time From bceba0ca3c0268e7e9054f8b42611c63afadc1d4 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Fri, 25 Oct 2024 17:39:33 +0100 Subject: [PATCH 2/6] Fetch and display version for each server --- src/clientdlg.cpp | 5 ++++- src/connectdlg.cpp | 36 ++++++++++++++++++++++++++++-------- src/connectdlg.h | 3 ++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 725628d719..cbfa04518d 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -813,8 +813,11 @@ void CClientDlg::OnVersionAndOSReceived ( COSUtil::EOpSystemType, QString strVer #endif } -void CClientDlg::OnCLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString strVersion ) +void CClientDlg::OnCLVersionAndOSReceived ( CHostAddress InetAddr, COSUtil::EOpSystemType, QString strVersion ) { + // display version in connect dialog + ConnectDlg.SetServerVersionResult ( InetAddr, strVersion ); + // update check #if ( QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 ) ) && !defined( DISABLE_VERSION_CHECK ) int mySuffixIndex; diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 9bb5104fb0..3093e05e94 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -113,12 +113,12 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR #ifdef ANDROID // for Android we need larger numbers because of the default font size lvwServers->setColumnWidth ( 0, 200 ); - lvwServers->setColumnWidth ( 1, 130 ); + lvwServers->setColumnWidth ( 1, 110 ); lvwServers->setColumnWidth ( 2, 130 ); lvwServers->setColumnWidth ( 3, 100 ); #else lvwServers->setColumnWidth ( 0, 180 ); - lvwServers->setColumnWidth ( 1, 75 ); + lvwServers->setColumnWidth ( 1, 65 ); lvwServers->setColumnWidth ( 2, 75 ); lvwServers->setColumnWidth ( 3, 70 ); lvwServers->setColumnWidth ( 4, 220 ); @@ -775,26 +775,29 @@ void CConnectDlg::OnTimerPing() for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) { + QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx ); + + // we need to ask for the server version only if we have not received it + const bool bNeedVersion = pCurListViewItem->text ( 1 ).isEmpty(); + CHostAddress haServerAddress; // try to parse host address string which is stored as user data // in the server list item GUI control element - if ( NetworkUtil().ParseNetworkAddress ( lvwServers->topLevelItem ( iIdx )->data ( 0, Qt::UserRole ).toString(), - haServerAddress, - bEnableIPv6 ) ) + if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( 0, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) ) { // if address is valid, send ping message using a new thread #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) - QFuture f = QtConcurrent::run ( &CConnectDlg::EmitCLServerListPingMes, this, haServerAddress ); + QFuture f = QtConcurrent::run ( &CConnectDlg::EmitCLServerListPingMes, this, haServerAddress, bNeedVersion ); Q_UNUSED ( f ); #else - QtConcurrent::run ( this, &CConnectDlg::EmitCLServerListPingMes, haServerAddress ); + QtConcurrent::run ( this, &CConnectDlg::EmitCLServerListPingMes, haServerAddress, bNeedVersion ); #endif } } } -void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress ) +void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress, const bool bNeedVersion ) { // The ping time messages for all servers should not be sent all in a very // short time since it showed that this leads to errors in the ping time @@ -804,6 +807,12 @@ void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress QThread::msleep ( 11 ); emit CreateCLServerListPingMes ( haServerAddress ); + + // also request the server version if we have not already received it + if ( bNeedVersion ) + { + emit CreateCLServerListReqVerAndOSMes ( haServerAddress ); + } } void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, const int iPingTime, const int iNumClients ) @@ -937,6 +946,17 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, UpdateListFilter(); } +void CConnectDlg::SetServerVersionResult ( const CHostAddress& InetAddr, const QString& strVersion ) +{ + // apply the received server version to the correct server list entry + QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr ); + + if ( pCurListViewItem ) + { + pCurListViewItem->setText ( 1, strVersion ); + } +} + QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr ) { const int iServerListLen = lvwServers->topLevelItemCount(); diff --git a/src/connectdlg.h b/src/connectdlg.h index 71c79ddb1f..2a9aa6a3e5 100644 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -59,6 +59,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase void SetConnClientsList ( const CHostAddress& InetAddr, const CVector& vecChanInfo ); void SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, const int iPingTime, const int iNumClients ); + void SetServerVersionResult ( const CHostAddress& InetAddr, const QString& strVersion ); bool GetServerListItemWasChosen() const { return bServerListItemWasChosen; } QString GetSelectedAddress() const { return strSelectedAddress; } @@ -74,7 +75,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase void UpdateListFilter(); void ShowAllMusicians ( const bool bState ); void RequestServerList(); - void EmitCLServerListPingMes ( const CHostAddress& haServerAddress ); + void EmitCLServerListPingMes ( const CHostAddress& haServerAddress, const bool bNeedVersion ); void UpdateDirectoryComboBox(); CClientSettings* pSettings; From 6d381643ff3c8992c5fb480c5dc108eed6e6c3fb Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Sat, 26 Oct 2024 00:18:09 +0100 Subject: [PATCH 3/6] Add use of enum values for column indexes --- src/connectdlg.cpp | 106 ++++++++++++++++++++++----------------------- src/connectdlg.h | 14 ++++++ 2 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 3093e05e94..51e18a57aa 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -112,16 +112,16 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR // must not be specified since this column takes all the remaining space) #ifdef ANDROID // for Android we need larger numbers because of the default font size - lvwServers->setColumnWidth ( 0, 200 ); - lvwServers->setColumnWidth ( 1, 110 ); - lvwServers->setColumnWidth ( 2, 130 ); - lvwServers->setColumnWidth ( 3, 100 ); + lvwServers->setColumnWidth ( LVC_NAME, 200 ); + lvwServers->setColumnWidth ( LVC_VERSION, 110 ); + lvwServers->setColumnWidth ( LVC_PING, 130 ); + lvwServers->setColumnWidth ( LVC_CLIENTS, 100 ); #else - lvwServers->setColumnWidth ( 0, 180 ); - lvwServers->setColumnWidth ( 1, 65 ); - lvwServers->setColumnWidth ( 2, 75 ); - lvwServers->setColumnWidth ( 3, 70 ); - lvwServers->setColumnWidth ( 4, 220 ); + lvwServers->setColumnWidth ( LVC_NAME, 180 ); + lvwServers->setColumnWidth ( LVC_VERSION, 65 ); + lvwServers->setColumnWidth ( LVC_PING, 75 ); + lvwServers->setColumnWidth ( LVC_CLIENTS, 70 ); + lvwServers->setColumnWidth ( LVC_LOCATION, 220 ); #endif lvwServers->clear(); @@ -137,9 +137,9 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR // 4: location // 5: minimum ping time (invisible) // 6: maximum number of clients (invisible) - lvwServers->setColumnCount ( 7 ); - lvwServers->hideColumn ( 5 ); - lvwServers->hideColumn ( 6 ); + lvwServers->setColumnCount ( LVC_COLUMNS ); + lvwServers->hideColumn ( LVC_PING_MIN_HIDDEN ); + lvwServers->hideColumn ( LVC_CLIENTS_MAX_HIDDEN ); // per default the root shall not be decorated (to save space) lvwServers->setRootIsDecorated ( false ); @@ -151,7 +151,7 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR if ( bShowCompleteRegList ) { lvwServers->setSortingEnabled ( true ); - lvwServers->sortItems ( 0, Qt::AscendingOrder ); + lvwServers->sortItems ( LVC_NAME, Qt::AscendingOrder ); } // set a placeholder text to explain how to filter occupied servers (#397) @@ -375,7 +375,7 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetText ( 0, vecServerInfo[iIdx].strName ); + pNewListViewItem->setText ( LVC_NAME, vecServerInfo[iIdx].strName ); } else { @@ -385,30 +385,30 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) ); + pNewListViewItem->setText ( LVC_NAME, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) ); } else { // show IP number and port - pNewListViewItem->setText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) ); + pNewListViewItem->setText ( LVC_NAME, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) ); } } // in case of all servers shown, add the registration number at the beginning if ( bShowCompleteRegList ) { - pNewListViewItem->setText ( 0, QString ( "%1: " ).arg ( 1 + iIdx, 3 ) + pNewListViewItem->text ( 0 ) ); + pNewListViewItem->setText ( LVC_NAME, QString ( "%1: " ).arg ( 1 + iIdx, 3 ) + pNewListViewItem->text ( LVC_NAME ) ); } // show server name in bold font if it is a permanent server - QFont CurServerNameFont = pNewListViewItem->font ( 0 ); + QFont CurServerNameFont = pNewListViewItem->font ( LVC_NAME ); CurServerNameFont.setBold ( vecServerInfo[iIdx].bPermanentOnline ); - pNewListViewItem->setFont ( 0, CurServerNameFont ); + pNewListViewItem->setFont ( LVC_NAME, CurServerNameFont ); // the ping time shall be shown in bold font - QFont CurPingTimeFont = pNewListViewItem->font ( 2 ); + QFont CurPingTimeFont = pNewListViewItem->font ( LVC_PING ); CurPingTimeFont.setBold ( true ); - pNewListViewItem->setFont ( 2, CurPingTimeFont ); + pNewListViewItem->setFont ( LVC_PING, CurPingTimeFont ); // server location (city and country) QString strLocation = vecServerInfo[iIdx].strCity; @@ -441,17 +441,17 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetText ( 4, strLocation ); + pNewListViewItem->setText ( LVC_LOCATION, strLocation ); // init the minimum ping time with a large number (note that this number // must fit in an integer type) - pNewListViewItem->setText ( 5, "99999999" ); + pNewListViewItem->setText ( LVC_PING_MIN_HIDDEN, "99999999" ); // store the maximum number of clients - pNewListViewItem->setText ( 6, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) ); + pNewListViewItem->setText ( LVC_CLIENTS_MAX_HIDDEN, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) ); // store host address - pNewListViewItem->setData ( 0, Qt::UserRole, CurHostAddress.toString() ); + pNewListViewItem->setData ( LVC_NAME, Qt::UserRole, CurHostAddress.toString() ); // per default expand the list item (if not "show all servers") if ( bShowAllMusicians ) @@ -502,7 +502,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect if ( !CountryFlagPixmap.isNull() ) { // set correct picture - pNewChildListViewItem->setIcon ( 0, QIcon ( CountryFlagPixmap ) ); + pNewChildListViewItem->setIcon ( LVC_NAME, QIcon ( CountryFlagPixmap ) ); bCountryFlagIsUsed = true; } @@ -517,7 +517,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect if ( !( CInstPictures::IsNotUsedInstrument ( vecChanInfo[i].iInstrument ) || strCurResourceRef.isEmpty() ) ) { // set correct picture - pNewChildListViewItem->setIcon ( 0, QIcon ( QPixmap ( strCurResourceRef ) ) ); + pNewChildListViewItem->setIcon ( LVC_NAME, QIcon ( QPixmap ( strCurResourceRef ) ) ); } } @@ -528,7 +528,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect } // apply the client text to the list view item - pNewChildListViewItem->setText ( 0, sClientText ); + pNewChildListViewItem->setText ( LVC_NAME, sClientText ); // add the new child to the corresponding server item pCurListViewItem->addChild ( pNewChildListViewItem ); @@ -646,13 +646,13 @@ void CConnectDlg::UpdateListFilter() else { // search server name - if ( pCurListViewItem->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + if ( pCurListViewItem->text ( LVC_NAME ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) { bFilterFound = true; } // search location - if ( pCurListViewItem->text ( 4 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + if ( pCurListViewItem->text ( LVC_LOCATION ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) { bFilterFound = true; } @@ -660,7 +660,7 @@ void CConnectDlg::UpdateListFilter() // search children for ( int iCCnt = 0; iCCnt < pCurListViewItem->childCount(); iCCnt++ ) { - if ( pCurListViewItem->child ( iCCnt )->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) + if ( pCurListViewItem->child ( iCCnt )->text ( LVC_NAME ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 ) { bFilterFound = true; } @@ -668,7 +668,7 @@ void CConnectDlg::UpdateListFilter() } // only update Hide state if ping time was received - if ( !pCurListViewItem->text ( 2 ).isEmpty() || bShowCompleteRegList ) + if ( !pCurListViewItem->text ( LVC_PING ).isEmpty() || bShowCompleteRegList ) { // only update hide and expand status if the hide state has to be changed to // preserve if user clicked on expand icon manually @@ -693,7 +693,7 @@ void CConnectDlg::UpdateListFilter() QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx ); // if ping time is empty, hide item (if not already hidden) - if ( pCurListViewItem->text ( 2 ).isEmpty() && !bShowCompleteRegList ) + if ( pCurListViewItem->text ( LVC_PING ).isEmpty() && !bShowCompleteRegList ) { pCurListViewItem->setHidden ( true ); } @@ -726,10 +726,10 @@ void CConnectDlg::OnConnectClicked() QTreeWidgetItem* pCurSelTopListItem = GetParentListViewItem ( CurSelListItemList[0] ); // get host address from selected list view item as a string - strSelectedAddress = pCurSelTopListItem->data ( 0, Qt::UserRole ).toString(); + strSelectedAddress = pCurSelTopListItem->data ( LVC_NAME, Qt::UserRole ).toString(); // store selected server name - strSelectedServerName = pCurSelTopListItem->text ( 0 ); + strSelectedServerName = pCurSelTopListItem->text ( LVC_NAME ); // set flag that a server list item was chosen to connect bServerListItemWasChosen = true; @@ -778,13 +778,13 @@ void CConnectDlg::OnTimerPing() QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx ); // we need to ask for the server version only if we have not received it - const bool bNeedVersion = pCurListViewItem->text ( 1 ).isEmpty(); + const bool bNeedVersion = pCurListViewItem->text ( LVC_VERSION ).isEmpty(); CHostAddress haServerAddress; // try to parse host address string which is stored as user data // in the server list item GUI control element - if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( 0, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) ) + if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) ) { // if address is valid, send ping message using a new thread #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) @@ -823,12 +823,12 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, if ( pCurListViewItem ) { // check if this is the first time a ping time is set - const bool bIsFirstPing = pCurListViewItem->text ( 2 ).isEmpty(); + const bool bIsFirstPing = pCurListViewItem->text ( LVC_PING ).isEmpty(); bool bDoSorting = false; // update minimum ping time column (invisible, used for sorting) if // the new value is smaller than the old value - int iMinPingTime = pCurListViewItem->text ( 5 ).toInt(); + int iMinPingTime = pCurListViewItem->text ( LVC_PING_MIN_HIDDEN ).toInt(); if ( iMinPingTime > iPingTime ) { @@ -837,7 +837,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // we pad to a total of 8 characters with zeros to make sure the // sorting is done correctly - pCurListViewItem->setText ( 5, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) ); + pCurListViewItem->setText ( LVC_PING_MIN_HIDDEN, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) ); // update the sorting (lowest number on top) bDoSorting = true; @@ -855,17 +855,17 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // Color definition: <= 25 ms green, <= 50 ms yellow, otherwise red if ( iMinPingTime <= 25 ) { - pCurListViewItem->setForeground ( 2, Qt::darkGreen ); + pCurListViewItem->setForeground ( LVC_PING, Qt::darkGreen ); } else { if ( iMinPingTime <= 50 ) { - pCurListViewItem->setForeground ( 2, Qt::darkYellow ); + pCurListViewItem->setForeground ( LVC_PING, Qt::darkYellow ); } else { - pCurListViewItem->setForeground ( 2, Qt::red ); + pCurListViewItem->setForeground ( LVC_PING, Qt::red ); } } @@ -873,28 +873,28 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // certain value if ( iMinPingTime > 500 ) { - pCurListViewItem->setText ( 2, ">500 ms" ); + pCurListViewItem->setText ( LVC_PING, ">500 ms" ); } else { // prepend spaces so that we can sort correctly (fieldWidth of // 4 is sufficient since the maximum width is ">500") (#201) - pCurListViewItem->setText ( 2, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) ); + pCurListViewItem->setText ( LVC_PING, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) ); } // update number of clients text - if ( pCurListViewItem->text ( 6 ).toInt() == 0 ) + if ( pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ).toInt() == 0 ) { // special case: reduced server list - pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) ); + pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) ); } - else if ( iNumClients >= pCurListViewItem->text ( 6 ).toInt() ) + else if ( iNumClients >= pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ).toInt() ) { - pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) + " (full)" ); + pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) + " (full)" ); } else { - pCurListViewItem->setText ( 3, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 6 ) ); + pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ) ); } // check if the number of child list items matches the number of @@ -919,7 +919,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, if ( bDoSorting && !bShowCompleteRegList && ( TimerInitialSort.isActive() || !lvwServers->underMouse() ) ) // do not sort if "show all servers" { - lvwServers->sortByColumn ( 5, Qt::AscendingOrder ); + lvwServers->sortByColumn ( LVC_PING_MIN_HIDDEN, Qt::AscendingOrder ); } } @@ -953,7 +953,7 @@ void CConnectDlg::SetServerVersionResult ( const CHostAddress& InetAddr, const Q if ( pCurListViewItem ) { - pCurListViewItem->setText ( 1, strVersion ); + pCurListViewItem->setText ( LVC_VERSION, strVersion ); } } @@ -965,7 +965,7 @@ QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr ) { // compare the received address with the user data string of the // host address by a string compare - if ( !lvwServers->topLevelItem ( iIdx )->data ( 0, Qt::UserRole ).toString().compare ( InetAddr.toString() ) ) + if ( !lvwServers->topLevelItem ( iIdx )->data ( LVC_NAME, Qt::UserRole ).toString().compare ( InetAddr.toString() ) ) { return lvwServers->topLevelItem ( iIdx ); } diff --git a/src/connectdlg.h b/src/connectdlg.h index 2a9aa6a3e5..339ae1e09f 100644 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -66,6 +66,20 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase QString GetSelectedServerName() const { return strSelectedServerName; } protected: + // NOTE: This enum must list the columns in the same order + // as their column headings in connectdlgbase.ui + enum EConnectListViewColumns + { + LVC_NAME, // server name + LVC_VERSION, // server version + LVC_PING, // ping time + LVC_CLIENTS, // number of connected clients (including additional strings like " (full)") + LVC_LOCATION, // location + LVC_PING_MIN_HIDDEN, // minimum ping time (invisible) + LVC_CLIENTS_MAX_HIDDEN, // maximum number of clients (invisible) + LVC_COLUMNS // total number of columns + }; + virtual void showEvent ( QShowEvent* ); virtual void hideEvent ( QHideEvent* ); From 2471ef726f277078d29f2674b6283cb91ed52cf6 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Sat, 26 Oct 2024 22:10:58 +0100 Subject: [PATCH 4/6] Move version column to after location --- src/connectdlg.cpp | 14 ++++++++------ src/connectdlg.h | 2 +- src/connectdlgbase.ui | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 51e18a57aa..ab646e817e 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -113,15 +113,15 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR #ifdef ANDROID // for Android we need larger numbers because of the default font size lvwServers->setColumnWidth ( LVC_NAME, 200 ); - lvwServers->setColumnWidth ( LVC_VERSION, 110 ); lvwServers->setColumnWidth ( LVC_PING, 130 ); lvwServers->setColumnWidth ( LVC_CLIENTS, 100 ); + lvwServers->setColumnWidth ( LVC_VERSION, 110 ); #else lvwServers->setColumnWidth ( LVC_NAME, 180 ); - lvwServers->setColumnWidth ( LVC_VERSION, 65 ); lvwServers->setColumnWidth ( LVC_PING, 75 ); lvwServers->setColumnWidth ( LVC_CLIENTS, 70 ); lvwServers->setColumnWidth ( LVC_LOCATION, 220 ); + lvwServers->setColumnWidth ( LVC_VERSION, 65 ); #endif lvwServers->clear(); @@ -131,12 +131,14 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR // add invisible columns which are used for sorting the list and storing // the current/maximum number of clients // 0: server name - // 1: server version - // 2: ping time - // 3: number of musicians (including additional strings like " (full)") - // 4: location + // 1: ping time + // 2: number of musicians (including additional strings like " (full)") + // 3: location + // 4: server version // 5: minimum ping time (invisible) // 6: maximum number of clients (invisible) + // (see EConnectListViewColumns in connectdlg.h, which must match the above) + lvwServers->setColumnCount ( LVC_COLUMNS ); lvwServers->hideColumn ( LVC_PING_MIN_HIDDEN ); lvwServers->hideColumn ( LVC_CLIENTS_MAX_HIDDEN ); diff --git a/src/connectdlg.h b/src/connectdlg.h index 339ae1e09f..9be91cf657 100644 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -71,10 +71,10 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase enum EConnectListViewColumns { LVC_NAME, // server name - LVC_VERSION, // server version LVC_PING, // ping time LVC_CLIENTS, // number of connected clients (including additional strings like " (full)") LVC_LOCATION, // location + LVC_VERSION, // server version LVC_PING_MIN_HIDDEN, // minimum ping time (invisible) LVC_CLIENTS_MAX_HIDDEN, // maximum number of clients (invisible) LVC_COLUMNS // total number of columns diff --git a/src/connectdlgbase.ui b/src/connectdlgbase.ui index 852fcfaa1b..273d6fa978 100644 --- a/src/connectdlgbase.ui +++ b/src/connectdlgbase.ui @@ -73,22 +73,22 @@ - Version + Ping Time - Ping Time + Musicians - Musicians + Location - Location + Version From 790b84ab5f01a7a118efeab1f0bfa54f227e92e3 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Tue, 29 Oct 2024 12:23:09 +0000 Subject: [PATCH 5/6] Request version before sending ping. This helps the first ping be a bit more accurate, as firewall/NAT sessions will already have been opened by the version request. --- src/connectdlg.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index ab646e817e..06c0dfccfc 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -808,13 +808,13 @@ void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress, // block the GUI). QThread::msleep ( 11 ); - emit CreateCLServerListPingMes ( haServerAddress ); - - // also request the server version if we have not already received it + // first request the server version if we have not already received it if ( bNeedVersion ) { emit CreateCLServerListReqVerAndOSMes ( haServerAddress ); } + + emit CreateCLServerListPingMes ( haServerAddress ); } void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, const int iPingTime, const int iNumClients ) From f5fc9b12027ddae0ea3a0b08e3a2646a39505371 Mon Sep 17 00:00:00 2001 From: Tony Mountifield Date: Mon, 4 Nov 2024 18:02:18 +0000 Subject: [PATCH 6/6] Increase default width of connect dialog --- src/connectdlgbase.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connectdlgbase.ui b/src/connectdlgbase.ui index 273d6fa978..f12cdbe39a 100644 --- a/src/connectdlgbase.ui +++ b/src/connectdlgbase.ui @@ -6,7 +6,7 @@ 0 0 - 521 + 648 493