Skip to content

Commit

Permalink
Fetch and display version for each server
Browse files Browse the repository at this point in the history
  • Loading branch information
softins committed Oct 25, 2024
1 parent a8e5918 commit 0193705
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,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;
Expand Down
36 changes: 28 additions & 8 deletions src/connectdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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<void> f = QtConcurrent::run ( &CConnectDlg::EmitCLServerListPingMes, this, haServerAddress );
QFuture<void> 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
Expand All @@ -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 )
Expand Down Expand Up @@ -937,6 +946,17 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
UpdateListFilter();
}

void CConnectDlg::SetServerVersionResult ( const CHostAddress& InetAddr, const QString& strVersion )
{
// apply the received ping time 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();
Expand Down
3 changes: 2 additions & 1 deletion src/connectdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase
void SetConnClientsList ( const CHostAddress& InetAddr, const CVector<CChannelInfo>& 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; }
Expand All @@ -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;
Expand Down

0 comments on commit 0193705

Please sign in to comment.