Skip to content

Commit e5ce26c

Browse files
authored
Merge pull request #3416 from softins/display-server-versions
Display server versions in Connect dialog
2 parents 828db7e + f5fc9b1 commit e5ce26c

File tree

4 files changed

+107
-59
lines changed

4 files changed

+107
-59
lines changed

src/clientdlg.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,11 @@ void CClientDlg::OnVersionAndOSReceived ( COSUtil::EOpSystemType, QString strVer
813813
#endif
814814
}
815815

816-
void CClientDlg::OnCLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString strVersion )
816+
void CClientDlg::OnCLVersionAndOSReceived ( CHostAddress InetAddr, COSUtil::EOpSystemType, QString strVersion )
817817
{
818+
// display version in connect dialog
819+
ConnectDlg.SetServerVersionResult ( InetAddr, strVersion );
820+
818821
// update check
819822
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 6, 0 ) ) && !defined( DISABLE_VERSION_CHECK )
820823
int mySuffixIndex;

src/connectdlg.cpp

Lines changed: 81 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,16 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
112112
// must not be specified since this column takes all the remaining space)
113113
#ifdef ANDROID
114114
// for Android we need larger numbers because of the default font size
115-
lvwServers->setColumnWidth ( 0, 200 );
116-
lvwServers->setColumnWidth ( 1, 130 );
117-
lvwServers->setColumnWidth ( 2, 100 );
115+
lvwServers->setColumnWidth ( LVC_NAME, 200 );
116+
lvwServers->setColumnWidth ( LVC_PING, 130 );
117+
lvwServers->setColumnWidth ( LVC_CLIENTS, 100 );
118+
lvwServers->setColumnWidth ( LVC_VERSION, 110 );
118119
#else
119-
lvwServers->setColumnWidth ( 0, 180 );
120-
lvwServers->setColumnWidth ( 1, 75 );
121-
lvwServers->setColumnWidth ( 2, 70 );
122-
lvwServers->setColumnWidth ( 3, 220 );
120+
lvwServers->setColumnWidth ( LVC_NAME, 180 );
121+
lvwServers->setColumnWidth ( LVC_PING, 75 );
122+
lvwServers->setColumnWidth ( LVC_CLIENTS, 70 );
123+
lvwServers->setColumnWidth ( LVC_LOCATION, 220 );
124+
lvwServers->setColumnWidth ( LVC_VERSION, 65 );
123125
#endif
124126
lvwServers->clear();
125127

@@ -132,11 +134,14 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
132134
// 1: ping time
133135
// 2: number of musicians (including additional strings like " (full)")
134136
// 3: location
135-
// 4: minimum ping time (invisible)
136-
// 5: maximum number of clients (invisible)
137-
lvwServers->setColumnCount ( 6 );
138-
lvwServers->hideColumn ( 4 );
139-
lvwServers->hideColumn ( 5 );
137+
// 4: server version
138+
// 5: minimum ping time (invisible)
139+
// 6: maximum number of clients (invisible)
140+
// (see EConnectListViewColumns in connectdlg.h, which must match the above)
141+
142+
lvwServers->setColumnCount ( LVC_COLUMNS );
143+
lvwServers->hideColumn ( LVC_PING_MIN_HIDDEN );
144+
lvwServers->hideColumn ( LVC_CLIENTS_MAX_HIDDEN );
140145

141146
// per default the root shall not be decorated (to save space)
142147
lvwServers->setRootIsDecorated ( false );
@@ -148,7 +153,7 @@ CConnectDlg::CConnectDlg ( CClientSettings* pNSetP, const bool bNewShowCompleteR
148153
if ( bShowCompleteRegList )
149154
{
150155
lvwServers->setSortingEnabled ( true );
151-
lvwServers->sortItems ( 0, Qt::AscendingOrder );
156+
lvwServers->sortItems ( LVC_NAME, Qt::AscendingOrder );
152157
}
153158

154159
// set a placeholder text to explain how to filter occupied servers (#397)
@@ -372,7 +377,7 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
372377
// server name (if empty, show host address instead)
373378
if ( !vecServerInfo[iIdx].strName.isEmpty() )
374379
{
375-
pNewListViewItem->setText ( 0, vecServerInfo[iIdx].strName );
380+
pNewListViewItem->setText ( LVC_NAME, vecServerInfo[iIdx].strName );
376381
}
377382
else
378383
{
@@ -382,30 +387,30 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
382387
if ( vecServerInfo[iIdx].HostAddr.iPort == DEFAULT_PORT_NUMBER )
383388
{
384389
// only show IP number, no port number
385-
pNewListViewItem->setText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );
390+
pNewListViewItem->setText ( LVC_NAME, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );
386391
}
387392
else
388393
{
389394
// show IP number and port
390-
pNewListViewItem->setText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) );
395+
pNewListViewItem->setText ( LVC_NAME, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) );
391396
}
392397
}
393398

394399
// in case of all servers shown, add the registration number at the beginning
395400
if ( bShowCompleteRegList )
396401
{
397-
pNewListViewItem->setText ( 0, QString ( "%1: " ).arg ( 1 + iIdx, 3 ) + pNewListViewItem->text ( 0 ) );
402+
pNewListViewItem->setText ( LVC_NAME, QString ( "%1: " ).arg ( 1 + iIdx, 3 ) + pNewListViewItem->text ( LVC_NAME ) );
398403
}
399404

400405
// show server name in bold font if it is a permanent server
401-
QFont CurServerNameFont = pNewListViewItem->font ( 0 );
406+
QFont CurServerNameFont = pNewListViewItem->font ( LVC_NAME );
402407
CurServerNameFont.setBold ( vecServerInfo[iIdx].bPermanentOnline );
403-
pNewListViewItem->setFont ( 0, CurServerNameFont );
408+
pNewListViewItem->setFont ( LVC_NAME, CurServerNameFont );
404409

405410
// the ping time shall be shown in bold font
406-
QFont CurPingTimeFont = pNewListViewItem->font ( 1 );
411+
QFont CurPingTimeFont = pNewListViewItem->font ( LVC_PING );
407412
CurPingTimeFont.setBold ( true );
408-
pNewListViewItem->setFont ( 1, CurPingTimeFont );
413+
pNewListViewItem->setFont ( LVC_PING, CurPingTimeFont );
409414

410415
// server location (city and country)
411416
QString strLocation = vecServerInfo[iIdx].strCity;
@@ -438,17 +443,17 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
438443
strLocation += strCountryToString;
439444
}
440445

441-
pNewListViewItem->setText ( 3, strLocation );
446+
pNewListViewItem->setText ( LVC_LOCATION, strLocation );
442447

443448
// init the minimum ping time with a large number (note that this number
444449
// must fit in an integer type)
445-
pNewListViewItem->setText ( 4, "99999999" );
450+
pNewListViewItem->setText ( LVC_PING_MIN_HIDDEN, "99999999" );
446451

447452
// store the maximum number of clients
448-
pNewListViewItem->setText ( 5, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) );
453+
pNewListViewItem->setText ( LVC_CLIENTS_MAX_HIDDEN, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) );
449454

450455
// store host address
451-
pNewListViewItem->setData ( 0, Qt::UserRole, CurHostAddress.toString() );
456+
pNewListViewItem->setData ( LVC_NAME, Qt::UserRole, CurHostAddress.toString() );
452457

453458
// per default expand the list item (if not "show all servers")
454459
if ( bShowAllMusicians )
@@ -499,7 +504,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect
499504
if ( !CountryFlagPixmap.isNull() )
500505
{
501506
// set correct picture
502-
pNewChildListViewItem->setIcon ( 0, QIcon ( CountryFlagPixmap ) );
507+
pNewChildListViewItem->setIcon ( LVC_NAME, QIcon ( CountryFlagPixmap ) );
503508

504509
bCountryFlagIsUsed = true;
505510
}
@@ -514,7 +519,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect
514519
if ( !( CInstPictures::IsNotUsedInstrument ( vecChanInfo[i].iInstrument ) || strCurResourceRef.isEmpty() ) )
515520
{
516521
// set correct picture
517-
pNewChildListViewItem->setIcon ( 0, QIcon ( QPixmap ( strCurResourceRef ) ) );
522+
pNewChildListViewItem->setIcon ( LVC_NAME, QIcon ( QPixmap ( strCurResourceRef ) ) );
518523
}
519524
}
520525

@@ -525,7 +530,7 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect
525530
}
526531

527532
// apply the client text to the list view item
528-
pNewChildListViewItem->setText ( 0, sClientText );
533+
pNewChildListViewItem->setText ( LVC_NAME, sClientText );
529534

530535
// add the new child to the corresponding server item
531536
pCurListViewItem->addChild ( pNewChildListViewItem );
@@ -643,29 +648,29 @@ void CConnectDlg::UpdateListFilter()
643648
else
644649
{
645650
// search server name
646-
if ( pCurListViewItem->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
651+
if ( pCurListViewItem->text ( LVC_NAME ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
647652
{
648653
bFilterFound = true;
649654
}
650655

651656
// search location
652-
if ( pCurListViewItem->text ( 3 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
657+
if ( pCurListViewItem->text ( LVC_LOCATION ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
653658
{
654659
bFilterFound = true;
655660
}
656661

657662
// search children
658663
for ( int iCCnt = 0; iCCnt < pCurListViewItem->childCount(); iCCnt++ )
659664
{
660-
if ( pCurListViewItem->child ( iCCnt )->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
665+
if ( pCurListViewItem->child ( iCCnt )->text ( LVC_NAME ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
661666
{
662667
bFilterFound = true;
663668
}
664669
}
665670
}
666671

667672
// only update Hide state if ping time was received
668-
if ( !pCurListViewItem->text ( 1 ).isEmpty() || bShowCompleteRegList )
673+
if ( !pCurListViewItem->text ( LVC_PING ).isEmpty() || bShowCompleteRegList )
669674
{
670675
// only update hide and expand status if the hide state has to be changed to
671676
// preserve if user clicked on expand icon manually
@@ -690,7 +695,7 @@ void CConnectDlg::UpdateListFilter()
690695
QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx );
691696

692697
// if ping time is empty, hide item (if not already hidden)
693-
if ( pCurListViewItem->text ( 1 ).isEmpty() && !bShowCompleteRegList )
698+
if ( pCurListViewItem->text ( LVC_PING ).isEmpty() && !bShowCompleteRegList )
694699
{
695700
pCurListViewItem->setHidden ( true );
696701
}
@@ -723,10 +728,10 @@ void CConnectDlg::OnConnectClicked()
723728
QTreeWidgetItem* pCurSelTopListItem = GetParentListViewItem ( CurSelListItemList[0] );
724729

725730
// get host address from selected list view item as a string
726-
strSelectedAddress = pCurSelTopListItem->data ( 0, Qt::UserRole ).toString();
731+
strSelectedAddress = pCurSelTopListItem->data ( LVC_NAME, Qt::UserRole ).toString();
727732

728733
// store selected server name
729-
strSelectedServerName = pCurSelTopListItem->text ( 0 );
734+
strSelectedServerName = pCurSelTopListItem->text ( LVC_NAME );
730735

731736
// set flag that a server list item was chosen to connect
732737
bServerListItemWasChosen = true;
@@ -772,26 +777,29 @@ void CConnectDlg::OnTimerPing()
772777

773778
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
774779
{
780+
QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx );
781+
782+
// we need to ask for the server version only if we have not received it
783+
const bool bNeedVersion = pCurListViewItem->text ( LVC_VERSION ).isEmpty();
784+
775785
CHostAddress haServerAddress;
776786

777787
// try to parse host address string which is stored as user data
778788
// in the server list item GUI control element
779-
if ( NetworkUtil().ParseNetworkAddress ( lvwServers->topLevelItem ( iIdx )->data ( 0, Qt::UserRole ).toString(),
780-
haServerAddress,
781-
bEnableIPv6 ) )
789+
if ( NetworkUtil().ParseNetworkAddress ( pCurListViewItem->data ( LVC_NAME, Qt::UserRole ).toString(), haServerAddress, bEnableIPv6 ) )
782790
{
783791
// if address is valid, send ping message using a new thread
784792
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
785-
QFuture<void> f = QtConcurrent::run ( &CConnectDlg::EmitCLServerListPingMes, this, haServerAddress );
793+
QFuture<void> f = QtConcurrent::run ( &CConnectDlg::EmitCLServerListPingMes, this, haServerAddress, bNeedVersion );
786794
Q_UNUSED ( f );
787795
#else
788-
QtConcurrent::run ( this, &CConnectDlg::EmitCLServerListPingMes, haServerAddress );
796+
QtConcurrent::run ( this, &CConnectDlg::EmitCLServerListPingMes, haServerAddress, bNeedVersion );
789797
#endif
790798
}
791799
}
792800
}
793801

794-
void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress )
802+
void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress, const bool bNeedVersion )
795803
{
796804
// The ping time messages for all servers should not be sent all in a very
797805
// short time since it showed that this leads to errors in the ping time
@@ -800,6 +808,12 @@ void CConnectDlg::EmitCLServerListPingMes ( const CHostAddress& haServerAddress
800808
// block the GUI).
801809
QThread::msleep ( 11 );
802810

811+
// first request the server version if we have not already received it
812+
if ( bNeedVersion )
813+
{
814+
emit CreateCLServerListReqVerAndOSMes ( haServerAddress );
815+
}
816+
803817
emit CreateCLServerListPingMes ( haServerAddress );
804818
}
805819

@@ -811,12 +825,12 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
811825
if ( pCurListViewItem )
812826
{
813827
// check if this is the first time a ping time is set
814-
const bool bIsFirstPing = pCurListViewItem->text ( 1 ).isEmpty();
828+
const bool bIsFirstPing = pCurListViewItem->text ( LVC_PING ).isEmpty();
815829
bool bDoSorting = false;
816830

817831
// update minimum ping time column (invisible, used for sorting) if
818832
// the new value is smaller than the old value
819-
int iMinPingTime = pCurListViewItem->text ( 4 ).toInt();
833+
int iMinPingTime = pCurListViewItem->text ( LVC_PING_MIN_HIDDEN ).toInt();
820834

821835
if ( iMinPingTime > iPingTime )
822836
{
@@ -825,7 +839,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
825839

826840
// we pad to a total of 8 characters with zeros to make sure the
827841
// sorting is done correctly
828-
pCurListViewItem->setText ( 4, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) );
842+
pCurListViewItem->setText ( LVC_PING_MIN_HIDDEN, QString ( "%1" ).arg ( iPingTime, 8, 10, QLatin1Char ( '0' ) ) );
829843

830844
// update the sorting (lowest number on top)
831845
bDoSorting = true;
@@ -843,46 +857,46 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
843857
// Color definition: <= 25 ms green, <= 50 ms yellow, otherwise red
844858
if ( iMinPingTime <= 25 )
845859
{
846-
pCurListViewItem->setForeground ( 1, Qt::darkGreen );
860+
pCurListViewItem->setForeground ( LVC_PING, Qt::darkGreen );
847861
}
848862
else
849863
{
850864
if ( iMinPingTime <= 50 )
851865
{
852-
pCurListViewItem->setForeground ( 1, Qt::darkYellow );
866+
pCurListViewItem->setForeground ( LVC_PING, Qt::darkYellow );
853867
}
854868
else
855869
{
856-
pCurListViewItem->setForeground ( 1, Qt::red );
870+
pCurListViewItem->setForeground ( LVC_PING, Qt::red );
857871
}
858872
}
859873

860874
// update ping text, take special care if ping time exceeds a
861875
// certain value
862876
if ( iMinPingTime > 500 )
863877
{
864-
pCurListViewItem->setText ( 1, ">500 ms" );
878+
pCurListViewItem->setText ( LVC_PING, ">500 ms" );
865879
}
866880
else
867881
{
868882
// prepend spaces so that we can sort correctly (fieldWidth of
869883
// 4 is sufficient since the maximum width is ">500") (#201)
870-
pCurListViewItem->setText ( 1, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) );
884+
pCurListViewItem->setText ( LVC_PING, QString ( "%1 ms" ).arg ( iMinPingTime, 4, 10, QLatin1Char ( ' ' ) ) );
871885
}
872886

873887
// update number of clients text
874-
if ( pCurListViewItem->text ( 5 ).toInt() == 0 )
888+
if ( pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ).toInt() == 0 )
875889
{
876890
// special case: reduced server list
877-
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) );
891+
pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) );
878892
}
879-
else if ( iNumClients >= pCurListViewItem->text ( 5 ).toInt() )
893+
else if ( iNumClients >= pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ).toInt() )
880894
{
881-
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + " (full)" );
895+
pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) + " (full)" );
882896
}
883897
else
884898
{
885-
pCurListViewItem->setText ( 2, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( 5 ) );
899+
pCurListViewItem->setText ( LVC_CLIENTS, QString().setNum ( iNumClients ) + "/" + pCurListViewItem->text ( LVC_CLIENTS_MAX_HIDDEN ) );
886900
}
887901

888902
// check if the number of child list items matches the number of
@@ -907,7 +921,7 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
907921
if ( bDoSorting && !bShowCompleteRegList &&
908922
( TimerInitialSort.isActive() || !lvwServers->underMouse() ) ) // do not sort if "show all servers"
909923
{
910-
lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
924+
lvwServers->sortByColumn ( LVC_PING_MIN_HIDDEN, Qt::AscendingOrder );
911925
}
912926
}
913927

@@ -934,6 +948,17 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
934948
UpdateListFilter();
935949
}
936950

951+
void CConnectDlg::SetServerVersionResult ( const CHostAddress& InetAddr, const QString& strVersion )
952+
{
953+
// apply the received server version to the correct server list entry
954+
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
955+
956+
if ( pCurListViewItem )
957+
{
958+
pCurListViewItem->setText ( LVC_VERSION, strVersion );
959+
}
960+
}
961+
937962
QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr )
938963
{
939964
const int iServerListLen = lvwServers->topLevelItemCount();
@@ -942,7 +967,7 @@ QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr )
942967
{
943968
// compare the received address with the user data string of the
944969
// host address by a string compare
945-
if ( !lvwServers->topLevelItem ( iIdx )->data ( 0, Qt::UserRole ).toString().compare ( InetAddr.toString() ) )
970+
if ( !lvwServers->topLevelItem ( iIdx )->data ( LVC_NAME, Qt::UserRole ).toString().compare ( InetAddr.toString() ) )
946971
{
947972
return lvwServers->topLevelItem ( iIdx );
948973
}

0 commit comments

Comments
 (0)