2012-01-27 17:14:29 +01:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2012-01-27 17:14:29 +01:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
2020-06-08 22:58:11 +02:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2012-01-27 17:14:29 +01:00
|
|
|
*
|
|
|
|
\******************************************************************************/
|
|
|
|
|
|
|
|
#include "connectdlg.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
2020-05-16 17:35:38 +02:00
|
|
|
CConnectDlg::CConnectDlg ( CClient* pNCliP,
|
|
|
|
const bool bNewShowCompleteRegList,
|
|
|
|
QWidget* parent,
|
2012-01-27 17:14:29 +01:00
|
|
|
Qt::WindowFlags f )
|
|
|
|
: QDialog ( parent, f ),
|
2020-05-16 17:35:38 +02:00
|
|
|
pClient ( pNCliP ),
|
2012-01-27 17:14:29 +01:00
|
|
|
strCentralServerAddress ( "" ),
|
|
|
|
strSelectedAddress ( "" ),
|
|
|
|
strSelectedServerName ( "" ),
|
|
|
|
bShowCompleteRegList ( bNewShowCompleteRegList ),
|
|
|
|
bServerListReceived ( false ),
|
2020-04-14 16:51:44 +02:00
|
|
|
bServerListItemWasChosen ( false ),
|
2020-04-19 09:39:58 +02:00
|
|
|
bListFilterWasActive ( false ),
|
|
|
|
bShowAllMusicians ( true )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
setupUi ( this );
|
|
|
|
|
|
|
|
|
|
|
|
// Add help text to controls -----------------------------------------------
|
|
|
|
// server list
|
2020-05-07 08:51:16 +02:00
|
|
|
lvwServers->setWhatsThis ( "<b>" + tr ( "Server List" ) + ":</b> " + tr (
|
2020-06-04 17:40:11 +02:00
|
|
|
"The Connection Setup window shows a list of available servers. "
|
2020-06-04 17:35:14 +02:00
|
|
|
"Server operators can optionally list their servers by music genre. "
|
|
|
|
"Use the List dropdown to select a genre, click on the server you want "
|
|
|
|
"to join and press the Connect button to connect to it. Alternatively, "
|
|
|
|
"double click on on the server name. Permanent servers (those that have "
|
2020-06-05 13:10:59 +02:00
|
|
|
"been listed for longer than 48 hours) are shown in bold." ) );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
lvwServers->setAccessibleName ( tr ( "Server list view" ) );
|
|
|
|
|
|
|
|
// server address
|
2020-05-07 08:51:16 +02:00
|
|
|
QString strServAddrH = "<b>" + tr ( "Server Address" ) + ":</b> " + tr (
|
2020-06-04 17:35:14 +02:00
|
|
|
"If you know the IP address or URL of a server, you can connect to it "
|
|
|
|
"using the Server name/Address field. An optional port number can be added after the IP "
|
2020-05-12 10:16:19 +02:00
|
|
|
"address or URL using a colon as a separator, e.g, "
|
2015-10-18 21:07:43 +02:00
|
|
|
"example.org:" ) +
|
2020-06-04 17:35:14 +02:00
|
|
|
QString().setNum ( DEFAULT_PORT_NUMBER ) + tr ( ". The field will "
|
|
|
|
"also show a list of the most recently used server addresses.");
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
lblServerAddr->setWhatsThis ( strServAddrH );
|
|
|
|
cbxServerAddr->setWhatsThis ( strServAddrH );
|
|
|
|
|
|
|
|
cbxServerAddr->setAccessibleName ( tr ( "Server address edit box" ) );
|
|
|
|
cbxServerAddr->setAccessibleDescription ( tr ( "Holds the current server "
|
|
|
|
"IP address or URL. It also stores old URLs in the combo box list." ) );
|
|
|
|
|
2020-05-16 17:35:38 +02:00
|
|
|
// central server address type combo box
|
|
|
|
cbxCentServAddrType->clear();
|
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_DEFAULT ) );
|
2020-05-22 06:25:38 +02:00
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_ALL_GENRES ) );
|
2020-05-23 21:23:20 +02:00
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_ROCK ) );
|
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_JAZZ ) );
|
2020-05-22 09:48:58 +02:00
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_GENRE_CLASSICAL_FOLK ) );
|
2020-05-22 06:25:38 +02:00
|
|
|
cbxCentServAddrType->addItem ( csCentServAddrTypeToString ( AT_CUSTOM ) );
|
2020-05-16 17:35:38 +02:00
|
|
|
|
2020-05-22 08:36:25 +02:00
|
|
|
cbxCentServAddrType->setWhatsThis ( "<b>" + tr ( "Server List Selection" ) + ":</b> " + tr (
|
|
|
|
"Selects the server list to be shown." ) );
|
|
|
|
cbxCentServAddrType->setAccessibleName ( tr ( "Server list selection combo box" ) );
|
|
|
|
|
2020-04-14 17:41:21 +02:00
|
|
|
// filter
|
2020-05-07 08:51:16 +02:00
|
|
|
edtFilter->setWhatsThis ( "<b>" + tr ( "Filter" ) + ":</b> " + tr ( "The server "
|
2020-05-15 21:52:20 +02:00
|
|
|
"list is filtered by the given text. Note that the filter is case insensitive." ) );
|
2020-04-14 17:41:21 +02:00
|
|
|
edtFilter->setAccessibleName ( tr ( "Filter edit box" ) );
|
|
|
|
|
|
|
|
// show all mucisians
|
2020-05-07 08:51:16 +02:00
|
|
|
chbExpandAll->setWhatsThis ( "<b>" + tr ( "Show All Musicians" ) + ":</b> " + tr (
|
|
|
|
"If you check this check box, the musicians of all servers are shown. If you "
|
2020-04-14 17:41:21 +02:00
|
|
|
"uncheck the check box, all list view items are collapsed.") );
|
|
|
|
chbExpandAll->setAccessibleName ( tr ( "Show all musicians check box" ) );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
// init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries)
|
|
|
|
cbxServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
|
|
|
|
cbxServerAddr->setInsertPolicy ( QComboBox::NoInsert );
|
|
|
|
|
|
|
|
// set up list view for connected clients (note that the last column size
|
|
|
|
// must not be specified since this column takes all the remaining space)
|
2014-01-30 09:54:58 +01:00
|
|
|
#ifdef ANDROID
|
|
|
|
// for Android we need larger numbers because of the default font size
|
|
|
|
lvwServers->setColumnWidth ( 0, 200 );
|
|
|
|
lvwServers->setColumnWidth ( 1, 130 );
|
|
|
|
lvwServers->setColumnWidth ( 2, 100 );
|
|
|
|
#else
|
2015-12-09 17:34:21 +01:00
|
|
|
lvwServers->setColumnWidth ( 0, 180 );
|
2020-04-10 16:24:53 +02:00
|
|
|
lvwServers->setColumnWidth ( 1, 75 );
|
|
|
|
lvwServers->setColumnWidth ( 2, 70 );
|
2018-03-20 18:10:25 +01:00
|
|
|
lvwServers->setColumnWidth ( 3, 220 );
|
2014-01-30 09:54:58 +01:00
|
|
|
#endif
|
2012-01-27 17:14:29 +01:00
|
|
|
lvwServers->clear();
|
|
|
|
|
2018-03-20 18:10:25 +01:00
|
|
|
// make sure we do not get a too long horizontal scroll bar
|
|
|
|
lvwServers->header()->setStretchLastSection ( false );
|
|
|
|
|
2016-02-09 16:05:06 +01:00
|
|
|
// add invisible columns which are used for sorting the list and storing
|
2016-03-05 14:38:31 +01:00
|
|
|
// 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)
|
2020-05-25 21:00:02 +02:00
|
|
|
lvwServers->setColumnCount ( 6 );
|
2012-01-27 17:14:29 +01:00
|
|
|
lvwServers->hideColumn ( 4 );
|
2016-02-09 16:05:06 +01:00
|
|
|
lvwServers->hideColumn ( 5 );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
// per default the root shall not be decorated (to save space)
|
|
|
|
lvwServers->setRootIsDecorated ( false );
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// make sure the connect button has the focus
|
|
|
|
butConnect->setFocus();
|
|
|
|
|
2020-04-12 14:54:28 +02:00
|
|
|
// for "show all servers" mode make sort by click on header possible
|
|
|
|
if ( bShowCompleteRegList )
|
|
|
|
{
|
|
|
|
lvwServers->setSortingEnabled ( true );
|
2020-04-12 15:34:43 +02:00
|
|
|
lvwServers->sortItems ( 0, Qt::AscendingOrder );
|
2020-04-12 14:54:28 +02:00
|
|
|
}
|
|
|
|
|
2014-01-20 21:42:58 +01:00
|
|
|
#ifdef ANDROID
|
|
|
|
// for the android version maximize the window
|
|
|
|
setWindowState ( Qt::WindowMaximized );
|
|
|
|
#endif
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
// Connections -------------------------------------------------------------
|
|
|
|
// list view
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( lvwServers, &QTreeWidget::itemSelectionChanged,
|
|
|
|
this, &CConnectDlg::OnServerListItemSelectionChanged );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( lvwServers, &QTreeWidget::itemDoubleClicked,
|
|
|
|
this, &CConnectDlg::OnServerListItemDoubleClicked );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-06-06 22:15:33 +02:00
|
|
|
// to get default return key behaviour working
|
|
|
|
QObject::connect ( lvwServers, &QTreeWidget::activated,
|
|
|
|
this, &CConnectDlg::OnConnectClicked );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-04-14 16:51:44 +02:00
|
|
|
// line edit
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( edtFilter, &QLineEdit::textEdited,
|
|
|
|
this, &CConnectDlg::OnFilterTextEdited );
|
2020-04-14 16:51:44 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// combo boxes
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( cbxServerAddr, &QComboBox::editTextChanged,
|
|
|
|
this, &CConnectDlg::OnServerAddrEditTextChanged );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-06-07 09:01:52 +02:00
|
|
|
QObject::connect ( cbxCentServAddrType, static_cast<void (QComboBox::*) ( int )> ( &QComboBox::activated ),
|
|
|
|
this, &CConnectDlg::OnCentServAddrTypeChanged );
|
2020-05-16 17:35:38 +02:00
|
|
|
|
2020-04-14 17:23:53 +02:00
|
|
|
// check boxes
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( chbExpandAll, &QCheckBox::stateChanged,
|
|
|
|
this, &CConnectDlg::OnExpandAllStateChanged );
|
2020-04-14 17:23:53 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// buttons
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( butCancel, &QPushButton::clicked,
|
|
|
|
this, &CConnectDlg::close );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( butConnect, &QPushButton::clicked,
|
|
|
|
this, &CConnectDlg::OnConnectClicked );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
// timers
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( &TimerPing, &QTimer::timeout,
|
|
|
|
this, &CConnectDlg::OnTimerPing );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( &TimerReRequestServList, &QTimer::timeout,
|
|
|
|
this, &CConnectDlg::OnTimerReRequestServList );
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
|
2020-04-12 12:33:50 +02:00
|
|
|
void CConnectDlg::Init ( const CVector<QString>& vstrIPAddresses )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
// load stored IP addresses in combo box
|
|
|
|
cbxServerAddr->clear();
|
2015-10-18 21:07:43 +02:00
|
|
|
cbxServerAddr->clearEditText();
|
2013-05-03 21:11:01 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ )
|
|
|
|
{
|
|
|
|
if ( !vstrIPAddresses[iLEIdx].isEmpty() )
|
|
|
|
{
|
|
|
|
cbxServerAddr->addItem ( vstrIPAddresses[iLEIdx] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::showEvent ( QShowEvent* )
|
|
|
|
{
|
2020-04-12 12:33:50 +02:00
|
|
|
// on opening the connect dialg, we always want to request a
|
|
|
|
// new updated server list per definition
|
|
|
|
RequestServerList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::RequestServerList()
|
|
|
|
{
|
|
|
|
// reset flags
|
2012-01-27 17:14:29 +01:00
|
|
|
bServerListReceived = false;
|
|
|
|
bServerListItemWasChosen = false;
|
2020-04-14 16:51:44 +02:00
|
|
|
bListFilterWasActive = false;
|
2012-01-27 17:14:29 +01:00
|
|
|
|
|
|
|
// clear current address and name
|
|
|
|
strSelectedAddress = "";
|
|
|
|
strSelectedServerName = "";
|
|
|
|
|
|
|
|
// clear server list view
|
|
|
|
lvwServers->clear();
|
|
|
|
|
2020-04-14 16:51:44 +02:00
|
|
|
// clear filter edit box
|
|
|
|
edtFilter->setText ( "" );
|
|
|
|
|
2020-05-16 17:35:38 +02:00
|
|
|
// update list combo box (disable events to avoid a signal)
|
|
|
|
cbxCentServAddrType->blockSignals ( true );
|
|
|
|
cbxCentServAddrType->setCurrentIndex ( static_cast<int> ( pClient->GetCentralServerAddressType() ) );
|
|
|
|
cbxCentServAddrType->blockSignals ( false );
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// 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
|
2013-03-24 12:38:00 +01:00
|
|
|
if ( NetworkUtil().ParseNetworkAddress ( strCentralServerAddress,
|
|
|
|
CentralServerAddress ) )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
// send the request for the server list
|
|
|
|
emit ReqServerListQuery ( CentralServerAddress );
|
|
|
|
|
|
|
|
// start timer, if this message did not get any respond to retransmit
|
|
|
|
// the server list request message
|
|
|
|
TimerReRequestServList.start ( SERV_LIST_REQ_UPDATE_TIME_MS );
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 09:24:35 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
void CConnectDlg::hideEvent ( QHideEvent* )
|
|
|
|
{
|
|
|
|
// if window is closed, stop timers
|
|
|
|
TimerPing.stop();
|
|
|
|
TimerReRequestServList.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::OnTimerReRequestServList()
|
|
|
|
{
|
|
|
|
// if the server list is not yet received, retransmit the request for the
|
|
|
|
// server list
|
|
|
|
if ( !bServerListReceived )
|
|
|
|
{
|
2020-04-12 12:33:50 +02:00
|
|
|
// note that this is a connection less message which may get lost
|
|
|
|
// and therefore it makes sense to re-transmit it
|
2012-01-27 17:14:29 +01:00
|
|
|
emit ReqServerListQuery ( CentralServerAddress );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CServerInfo>& vecServerInfo )
|
|
|
|
{
|
|
|
|
// set flag and disable timer for resend server list request
|
|
|
|
bServerListReceived = true;
|
|
|
|
TimerReRequestServList.stop();
|
|
|
|
|
|
|
|
// first clear list
|
|
|
|
lvwServers->clear();
|
|
|
|
|
|
|
|
// add list item for each server in the server list
|
|
|
|
const int iServerInfoLen = vecServerInfo.Size();
|
|
|
|
|
|
|
|
for ( int iIdx = 0; iIdx < iServerInfoLen; iIdx++ )
|
|
|
|
{
|
|
|
|
// get the host address, note that for the very first entry which is
|
|
|
|
// the central server, we have to use the receive host address
|
|
|
|
// instead
|
|
|
|
CHostAddress CurHostAddress;
|
2020-04-01 21:16:44 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
if ( iIdx > 0 )
|
|
|
|
{
|
|
|
|
CurHostAddress = vecServerInfo[iIdx].HostAddr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// substitude the receive host address for central server
|
|
|
|
CurHostAddress = InetAddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create new list view item
|
|
|
|
QTreeWidgetItem* pNewListViewItem = new QTreeWidgetItem ( lvwServers );
|
|
|
|
|
|
|
|
// make the entry invisible (will be set to visible on successful ping
|
|
|
|
// result) if the complete list of registered servers shall not be shown
|
|
|
|
if ( !bShowCompleteRegList )
|
|
|
|
{
|
|
|
|
pNewListViewItem->setHidden ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
// server name (if empty, show host address instead)
|
|
|
|
if ( !vecServerInfo[iIdx].strName.isEmpty() )
|
|
|
|
{
|
|
|
|
pNewListViewItem->setText ( 0, vecServerInfo[iIdx].strName );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// IP address and port (use IP number without last byte)
|
|
|
|
// Definition: If the port number is the default port number, we do
|
|
|
|
// not show it.
|
2020-05-15 21:00:41 +02:00
|
|
|
if ( vecServerInfo[iIdx].HostAddr.iPort == DEFAULT_PORT_NUMBER )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
// only show IP number, no port number
|
2020-04-01 21:16:44 +02:00
|
|
|
pNewListViewItem->setText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// show IP number and port
|
2020-04-01 21:16:44 +02:00
|
|
|
pNewListViewItem->setText ( 0, CurHostAddress.toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) );
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 21:16:44 +02:00
|
|
|
// in case of all servers shown, add the registration number at the beginning
|
|
|
|
if ( bShowCompleteRegList )
|
|
|
|
{
|
2020-04-12 14:54:28 +02:00
|
|
|
pNewListViewItem->setText ( 0, QString ( "%1: " ).arg ( 1 + iIdx, 3 ) + pNewListViewItem->text ( 0 ) );
|
2020-04-01 21:16:44 +02:00
|
|
|
}
|
|
|
|
|
2016-02-15 18:35:49 +01:00
|
|
|
// show server name in bold font if it is a permanent server
|
|
|
|
QFont CurServerNameFont = pNewListViewItem->font ( 0 );
|
|
|
|
CurServerNameFont.setBold ( vecServerInfo[iIdx].bPermanentOnline );
|
|
|
|
pNewListViewItem->setFont ( 0, CurServerNameFont );
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// the ping time shall be shown in bold font
|
2016-02-15 18:35:49 +01:00
|
|
|
QFont CurPingTimeFont = pNewListViewItem->font ( 1 );
|
2012-01-27 17:14:29 +01:00
|
|
|
CurPingTimeFont.setBold ( true );
|
|
|
|
pNewListViewItem->setFont ( 1, CurPingTimeFont );
|
|
|
|
|
|
|
|
// server location (city and country)
|
|
|
|
QString strLocation = vecServerInfo[iIdx].strCity;
|
2020-04-01 21:16:44 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
if ( ( !strLocation.isEmpty() ) &&
|
|
|
|
( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry ) )
|
|
|
|
{
|
|
|
|
strLocation += ", ";
|
|
|
|
}
|
2020-04-12 14:54:28 +02:00
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
if ( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry )
|
|
|
|
{
|
2020-04-12 14:54:28 +02:00
|
|
|
QString strCountryToString = QLocale::countryToString ( vecServerInfo[iIdx].eCountry );
|
|
|
|
|
|
|
|
// Qt countryToString does not use spaces in between country name
|
|
|
|
// parts but they use upper case letters which we can detect and
|
|
|
|
// insert spaces as a post processing
|
2020-04-12 21:19:41 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
2020-04-12 14:54:28 +02:00
|
|
|
if ( !strCountryToString.contains ( " " ) )
|
|
|
|
{
|
|
|
|
QRegularExpressionMatchIterator reMatchIt = QRegularExpression ( "[A-Z][^A-Z]*" ).globalMatch ( strCountryToString );
|
|
|
|
QStringList slNames;
|
|
|
|
while ( reMatchIt.hasNext() )
|
|
|
|
{
|
|
|
|
slNames << reMatchIt.next().capturedTexts();
|
|
|
|
}
|
|
|
|
strCountryToString = slNames.join ( " " );
|
|
|
|
}
|
2020-04-12 21:19:41 +02:00
|
|
|
#endif
|
2020-04-12 14:54:28 +02:00
|
|
|
|
|
|
|
strLocation += strCountryToString;
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pNewListViewItem->setText ( 3, strLocation );
|
|
|
|
|
|
|
|
// init the minimum ping time with a large number (note that this number
|
|
|
|
// must fit in an integer type)
|
|
|
|
pNewListViewItem->setText ( 4, "99999999" );
|
|
|
|
|
2016-02-09 16:05:06 +01:00
|
|
|
// store the maximum number of clients
|
|
|
|
pNewListViewItem->setText ( 5, QString().setNum ( vecServerInfo[iIdx].iMaxNumClients ) );
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
// store host address
|
2020-04-01 21:16:44 +02:00
|
|
|
pNewListViewItem->setData ( 0, Qt::UserRole, CurHostAddress.toString() );
|
2020-04-06 23:06:28 +02:00
|
|
|
|
|
|
|
// per default expand the list item (if not "show all servers")
|
2020-04-19 09:39:58 +02:00
|
|
|
if ( bShowAllMusicians )
|
2020-04-06 23:06:28 +02:00
|
|
|
{
|
|
|
|
lvwServers->expandItem ( pNewListViewItem );
|
|
|
|
}
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// immediately issue the ping measurements and start the ping timer since
|
|
|
|
// the server list is filled now
|
|
|
|
OnTimerPing();
|
|
|
|
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
|
|
|
|
}
|
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CChannelInfo>& vecChanInfo )
|
|
|
|
{
|
|
|
|
// find the server with the correct address
|
|
|
|
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
|
|
|
|
|
|
|
|
if ( pCurListViewItem )
|
|
|
|
{
|
|
|
|
// first remove any existing childs
|
|
|
|
DeleteAllListViewItemChilds ( pCurListViewItem );
|
|
|
|
|
|
|
|
// get number of connected clients
|
|
|
|
const int iNumConnectedClients = vecChanInfo.Size();
|
|
|
|
|
|
|
|
for ( int i = 0; i < iNumConnectedClients; i++ )
|
|
|
|
{
|
|
|
|
// create new list view item
|
|
|
|
QTreeWidgetItem* pNewChildListViewItem =
|
|
|
|
new QTreeWidgetItem ( pCurListViewItem );
|
|
|
|
|
|
|
|
// child items shall use only one column
|
|
|
|
pNewChildListViewItem->setFirstColumnSpanned ( true );
|
|
|
|
|
|
|
|
// set the clients name
|
2020-06-05 14:22:44 +02:00
|
|
|
QString sClientText = vecChanInfo[i].strName;
|
2015-12-10 16:52:29 +01:00
|
|
|
|
|
|
|
// set the icon: country flag has priority over instrument
|
|
|
|
bool bCountryFlagIsUsed = false;
|
|
|
|
|
|
|
|
if ( vecChanInfo[i].eCountry != QLocale::AnyCountry )
|
|
|
|
{
|
|
|
|
// try to load the country flag icon
|
|
|
|
QPixmap CountryFlagPixmap (
|
2020-04-11 10:31:26 +02:00
|
|
|
CLocale::GetCountryFlagIconsResourceReference ( vecChanInfo[i].eCountry ) );
|
2015-12-10 16:52:29 +01:00
|
|
|
|
|
|
|
// first check if resource reference was valid
|
|
|
|
if ( !CountryFlagPixmap.isNull() )
|
|
|
|
{
|
|
|
|
// set correct picture
|
|
|
|
pNewChildListViewItem->setIcon ( 0, QIcon ( CountryFlagPixmap ) );
|
|
|
|
|
|
|
|
// add the instrument information as text
|
|
|
|
if ( !CInstPictures::IsNotUsedInstrument ( vecChanInfo[i].iInstrument ) )
|
|
|
|
{
|
|
|
|
sClientText.append ( " (" +
|
|
|
|
CInstPictures::GetName ( vecChanInfo[i].iInstrument ) + ")" );
|
|
|
|
}
|
|
|
|
|
|
|
|
bCountryFlagIsUsed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bCountryFlagIsUsed )
|
|
|
|
{
|
|
|
|
// get the resource reference string for this instrument
|
|
|
|
const QString strCurResourceRef =
|
|
|
|
CInstPictures::GetResourceReference ( vecChanInfo[i].iInstrument );
|
|
|
|
|
|
|
|
// first check if instrument picture is used or not and if it is valid
|
|
|
|
if ( !( CInstPictures::IsNotUsedInstrument ( vecChanInfo[i].iInstrument ) ||
|
|
|
|
strCurResourceRef.isEmpty() ) )
|
|
|
|
{
|
|
|
|
// set correct picture
|
|
|
|
pNewChildListViewItem->setIcon ( 0, QIcon ( QPixmap ( strCurResourceRef ) ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply the client text to the list view item
|
|
|
|
pNewChildListViewItem->setText ( 0, sClientText );
|
2015-12-09 16:50:30 +01:00
|
|
|
|
|
|
|
// add the new child to the corresponding server item
|
|
|
|
pCurListViewItem->addChild ( pNewChildListViewItem );
|
|
|
|
|
|
|
|
// at least one server has childs now, show decoration to be able
|
2015-12-09 18:11:16 +01:00
|
|
|
// to show the childs
|
2015-12-09 16:50:30 +01:00
|
|
|
lvwServers->setRootIsDecorated ( true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
void CConnectDlg::OnServerListItemSelectionChanged()
|
|
|
|
{
|
|
|
|
// get current selected item (we are only interested in the first selcted
|
|
|
|
// item)
|
|
|
|
QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems();
|
|
|
|
|
|
|
|
// if an item is clicked/selected, copy the server name to the combo box
|
|
|
|
if ( CurSelListItemList.count() > 0 )
|
|
|
|
{
|
|
|
|
// make sure no signals are send when we change the text
|
|
|
|
cbxServerAddr->blockSignals ( true );
|
|
|
|
{
|
2015-12-09 16:50:30 +01:00
|
|
|
cbxServerAddr->setEditText (
|
|
|
|
GetParentListViewItem ( CurSelListItemList[0] )->text ( 0 ) );
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
cbxServerAddr->blockSignals ( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::OnServerListItemDoubleClicked ( QTreeWidgetItem* Item,
|
|
|
|
int )
|
|
|
|
{
|
|
|
|
// if a server list item was double clicked, it is the same as if the
|
|
|
|
// connect button was clicked
|
2019-05-17 22:55:46 +02:00
|
|
|
if ( Item != nullptr )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
OnConnectClicked();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::OnServerAddrEditTextChanged ( const QString& )
|
|
|
|
{
|
|
|
|
// in the server address combo box, a text was changed, remove selection
|
|
|
|
// in the server list (if any)
|
|
|
|
lvwServers->clearSelection();
|
|
|
|
}
|
|
|
|
|
2020-04-19 09:39:58 +02:00
|
|
|
void CConnectDlg::ShowAllMusicians ( const bool bState )
|
2020-04-14 17:23:53 +02:00
|
|
|
{
|
2020-04-19 09:39:58 +02:00
|
|
|
bShowAllMusicians = bState;
|
|
|
|
|
2020-04-19 10:04:19 +02:00
|
|
|
// update list
|
2020-04-19 09:39:58 +02:00
|
|
|
if ( bState )
|
2020-04-14 17:23:53 +02:00
|
|
|
{
|
|
|
|
lvwServers->expandAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lvwServers->collapseAll();
|
|
|
|
}
|
2020-04-19 10:04:19 +02:00
|
|
|
|
|
|
|
// update check box if necessary
|
|
|
|
if ( ( chbExpandAll->checkState() == Qt::Checked && !bShowAllMusicians ) ||
|
|
|
|
( chbExpandAll->checkState() == Qt::Unchecked && bShowAllMusicians ) )
|
|
|
|
{
|
|
|
|
chbExpandAll->setCheckState ( bState ? Qt::Checked : Qt::Unchecked );
|
|
|
|
}
|
2020-04-14 17:23:53 +02:00
|
|
|
}
|
|
|
|
|
2020-04-14 16:51:44 +02:00
|
|
|
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++ )
|
|
|
|
{
|
2020-04-19 09:39:58 +02:00
|
|
|
QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx );
|
|
|
|
bool bFilterFound = false;
|
2020-04-14 16:51:44 +02:00
|
|
|
|
|
|
|
// search server name
|
2020-04-19 09:39:58 +02:00
|
|
|
if ( pCurListViewItem->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
|
2020-04-14 16:51:44 +02:00
|
|
|
{
|
|
|
|
bFilterFound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search location
|
2020-04-19 09:39:58 +02:00
|
|
|
if ( pCurListViewItem->text ( 3 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
|
2020-04-14 16:51:44 +02:00
|
|
|
{
|
|
|
|
bFilterFound = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// search childs
|
2020-04-19 09:39:58 +02:00
|
|
|
for ( int iCCnt = 0; iCCnt < pCurListViewItem->childCount(); iCCnt++ )
|
2020-04-14 16:51:44 +02:00
|
|
|
{
|
2020-04-19 09:39:58 +02:00
|
|
|
if ( pCurListViewItem->child ( iCCnt )->text ( 0 ).indexOf ( sFilterText, 0, Qt::CaseInsensitive ) >= 0 )
|
2020-04-14 16:51:44 +02:00
|
|
|
{
|
|
|
|
bFilterFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only update Hide state if ping time was received
|
2020-04-20 20:40:16 +02:00
|
|
|
if ( !pCurListViewItem->text ( 1 ).isEmpty() || bShowCompleteRegList )
|
2020-04-14 16:51:44 +02:00
|
|
|
{
|
2020-04-19 09:39:58 +02:00
|
|
|
// only update hide and expand status if the hide state has to be changed to
|
|
|
|
// preserve if user clicked on expand icon manually
|
|
|
|
if ( ( pCurListViewItem->isHidden() && bFilterFound ) ||
|
|
|
|
( !pCurListViewItem->isHidden() && !bFilterFound ) )
|
|
|
|
{
|
|
|
|
pCurListViewItem->setHidden ( !bFilterFound );
|
|
|
|
pCurListViewItem->setExpanded ( bShowAllMusicians );
|
|
|
|
}
|
2020-04-14 16:51:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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++ )
|
|
|
|
{
|
2020-04-19 09:39:58 +02:00
|
|
|
QTreeWidgetItem* pCurListViewItem = lvwServers->topLevelItem ( iIdx );
|
|
|
|
|
|
|
|
// if ping time is empty, hide item (if not already hidden)
|
2020-04-20 20:40:16 +02:00
|
|
|
if ( pCurListViewItem->text ( 1 ).isEmpty() && !bShowCompleteRegList )
|
2020-04-19 09:39:58 +02:00
|
|
|
{
|
|
|
|
pCurListViewItem->setHidden ( true );
|
|
|
|
}
|
2020-04-19 15:17:06 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// in case it was hidden, show it and take care of expand
|
|
|
|
if ( pCurListViewItem->isHidden() )
|
|
|
|
{
|
|
|
|
pCurListViewItem->setHidden ( false );
|
|
|
|
pCurListViewItem->setExpanded ( bShowAllMusicians );
|
|
|
|
}
|
|
|
|
}
|
2020-04-14 16:51:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bListFilterWasActive = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-27 17:14:29 +01:00
|
|
|
void CConnectDlg::OnConnectClicked()
|
|
|
|
{
|
2013-05-03 21:11:01 +02:00
|
|
|
// get the IP address to be used according to the following definitions:
|
|
|
|
// - if the list has focus and a line is selected, use this line
|
|
|
|
// - if the list has no focus, use the current combo box text
|
|
|
|
QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems();
|
|
|
|
|
|
|
|
if ( CurSelListItemList.count() > 0 )
|
|
|
|
{
|
2015-12-09 16:50:30 +01:00
|
|
|
// get the parent list view item
|
|
|
|
QTreeWidgetItem* pCurSelTopListItem =
|
|
|
|
GetParentListViewItem ( CurSelListItemList[0] );
|
|
|
|
|
2013-05-03 21:11:01 +02:00
|
|
|
// get host address from selected list view item as a string
|
|
|
|
strSelectedAddress =
|
2015-12-09 16:50:30 +01:00
|
|
|
pCurSelTopListItem->data ( 0, Qt::UserRole ).toString();
|
2013-05-03 21:11:01 +02:00
|
|
|
|
|
|
|
// store selected server name
|
2015-12-09 16:50:30 +01:00
|
|
|
strSelectedServerName = pCurSelTopListItem->text ( 0 );
|
2013-05-03 21:11:01 +02:00
|
|
|
|
|
|
|
// set flag that a server list item was chosen to connect
|
|
|
|
bServerListItemWasChosen = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strSelectedAddress = cbxServerAddr->currentText();
|
|
|
|
}
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2013-05-03 21:11:01 +02:00
|
|
|
// tell the parent window that the connection shall be initiated
|
|
|
|
done ( QDialog::Accepted );
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CConnectDlg::OnTimerPing()
|
|
|
|
{
|
|
|
|
// send ping messages to the servers in the list
|
|
|
|
const int iServerListLen = lvwServers->topLevelItemCount();
|
|
|
|
|
|
|
|
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
|
|
|
|
{
|
|
|
|
CHostAddress CurServerAddress;
|
|
|
|
|
|
|
|
// try to parse host address string which is stored as user data
|
|
|
|
// in the server list item GUI control element
|
2013-03-24 12:38:00 +01:00
|
|
|
if ( NetworkUtil().ParseNetworkAddress (
|
2012-01-27 17:14:29 +01:00
|
|
|
lvwServers->topLevelItem ( iIdx )->
|
|
|
|
data ( 0, Qt::UserRole ).toString(),
|
|
|
|
CurServerAddress ) )
|
|
|
|
{
|
2014-02-23 10:46:25 +01:00
|
|
|
// if address is valid, send ping or the version and OS request
|
|
|
|
#ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING
|
|
|
|
emit CreateCLServerListReqVerAndOSMes ( CurServerAddress );
|
|
|
|
#else
|
2012-01-27 17:14:29 +01:00
|
|
|
emit CreateCLServerListPingMes ( CurServerAddress );
|
2014-02-23 10:46:25 +01:00
|
|
|
#endif
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 22:22:53 +02:00
|
|
|
void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr,
|
|
|
|
const int iPingTime,
|
|
|
|
const int iNumClients )
|
2012-01-27 17:14:29 +01:00
|
|
|
{
|
|
|
|
// apply the received ping time to the correct server list entry
|
2015-12-09 16:50:30 +01:00
|
|
|
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
|
|
|
|
|
|
|
|
if ( pCurListViewItem )
|
|
|
|
{
|
2020-04-14 16:51:44 +02:00
|
|
|
// check if this is the first time a ping time is set
|
|
|
|
const bool bIsFirstPing = pCurListViewItem->text ( 1 ).isEmpty();
|
2020-04-16 22:22:53 +02:00
|
|
|
bool bDoSorting = false;
|
2020-04-14 16:51:44 +02:00
|
|
|
|
2020-04-16 22:22:53 +02:00
|
|
|
// 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();
|
|
|
|
|
|
|
|
if ( iMinPingTime > iPingTime )
|
2015-12-09 16:50:30 +01:00
|
|
|
{
|
2020-04-16 22:22:53 +02:00
|
|
|
// update the minimum ping time with the new lowest value
|
|
|
|
iMinPingTime = iPingTime;
|
2015-12-09 16:50:30 +01:00
|
|
|
|
2020-04-16 22:22:53 +02:00
|
|
|
// 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' ) ) );
|
2015-12-09 16:50:30 +01:00
|
|
|
|
2020-04-16 22:22:53 +02:00
|
|
|
// update the sorting (lowest number on top)
|
|
|
|
bDoSorting = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for debugging it is good to see the current ping time in the list
|
|
|
|
// and not the minimum ping time -> overwrite the value for debugging
|
|
|
|
if ( bShowCompleteRegList )
|
|
|
|
{
|
|
|
|
iMinPingTime = iPingTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only show minimum ping time in the list since this is the important
|
|
|
|
// value. Temporary bad ping measurements are of no interest.
|
|
|
|
// Color definition: <= 25 ms green, <= 50 ms yellow, otherwise red
|
|
|
|
if ( iMinPingTime <= 25 )
|
|
|
|
{
|
|
|
|
pCurListViewItem->setForeground ( 1, Qt::darkGreen );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( iMinPingTime <= 50 )
|
|
|
|
{
|
|
|
|
pCurListViewItem->setForeground ( 1, Qt::darkYellow );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCurListViewItem->setForeground ( 1, Qt::red );
|
|
|
|
}
|
2015-12-09 16:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// update ping text, take special care if ping time exceeds a
|
|
|
|
// certain value
|
2020-04-16 22:22:53 +02:00
|
|
|
if ( iMinPingTime > 500 )
|
2015-12-09 16:50:30 +01:00
|
|
|
{
|
|
|
|
pCurListViewItem->setText ( 1, ">500 ms" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCurListViewItem->
|
2020-04-16 22:22:53 +02:00
|
|
|
setText ( 1, QString().setNum ( iMinPingTime ) + " ms" );
|
2015-12-09 16:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// update number of clients text
|
2016-02-09 16:05:06 +01:00
|
|
|
if ( iNumClients >= pCurListViewItem->text ( 5 ).toInt() )
|
|
|
|
{
|
|
|
|
pCurListViewItem->
|
|
|
|
setText ( 2, QString().setNum ( iNumClients ) + " (full)" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pCurListViewItem->
|
|
|
|
setText ( 2, QString().setNum ( iNumClients ) );
|
|
|
|
}
|
2015-12-09 16:50:30 +01:00
|
|
|
|
2020-05-25 21:00:02 +02:00
|
|
|
// check if the number of child list items matches the number of
|
|
|
|
// connected clients, if not then request the client names
|
|
|
|
if ( iNumClients != pCurListViewItem->childCount() )
|
|
|
|
{
|
|
|
|
emit CreateCLServerListReqConnClientsListMes ( InetAddr );
|
|
|
|
}
|
2016-03-05 14:38:31 +01:00
|
|
|
|
2020-04-14 16:51:44 +02:00
|
|
|
// this is the first time a ping time was received, set item to visible
|
|
|
|
if ( bIsFirstPing )
|
2015-12-09 16:50:30 +01:00
|
|
|
{
|
|
|
|
pCurListViewItem->setHidden ( false );
|
|
|
|
}
|
|
|
|
|
2020-04-16 22:22:53 +02:00
|
|
|
// Update sorting. Note that the sorting must be the last action for the
|
|
|
|
// current item since the topLevelItem ( iIdx ) is then no longer valid.
|
|
|
|
if ( bDoSorting && !bShowCompleteRegList ) // do not sort if "show all servers"
|
2015-12-09 16:50:30 +01:00
|
|
|
{
|
2020-04-16 22:22:53 +02:00
|
|
|
lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
|
2015-12-09 16:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no server item has childs, do not show decoration
|
|
|
|
bool bAnyListItemHasChilds = false;
|
|
|
|
const int iServerListLen = lvwServers->topLevelItemCount();
|
|
|
|
|
|
|
|
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
|
|
|
|
{
|
|
|
|
// check if the current list item has childs
|
|
|
|
if ( lvwServers->topLevelItem ( iIdx )->childCount() > 0 )
|
|
|
|
{
|
|
|
|
bAnyListItemHasChilds = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bAnyListItemHasChilds )
|
|
|
|
{
|
|
|
|
lvwServers->setRootIsDecorated ( false );
|
|
|
|
}
|
2020-04-14 16:51:44 +02:00
|
|
|
|
|
|
|
// 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();
|
2015-12-09 16:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem* CConnectDlg::FindListViewItem ( const CHostAddress& InetAddr )
|
|
|
|
{
|
2012-01-27 17:14:29 +01:00
|
|
|
const int iServerListLen = lvwServers->topLevelItemCount();
|
|
|
|
|
|
|
|
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
|
|
|
|
{
|
|
|
|
// 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() ) )
|
|
|
|
{
|
2015-12-09 16:50:30 +01:00
|
|
|
return lvwServers->topLevelItem ( iIdx );
|
|
|
|
}
|
|
|
|
}
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2019-05-17 22:55:46 +02:00
|
|
|
return nullptr;
|
2015-12-09 16:50:30 +01:00
|
|
|
}
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
QTreeWidgetItem* CConnectDlg::GetParentListViewItem ( QTreeWidgetItem* pItem )
|
|
|
|
{
|
|
|
|
// check if the current item is already the top item, i.e. the parent
|
|
|
|
// query fails and returns null
|
|
|
|
if ( pItem->parent() )
|
|
|
|
{
|
|
|
|
// we only have maximum one level, i.e. if we call the parent function
|
|
|
|
// we are at the top item
|
|
|
|
return pItem->parent();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// this item is already the top item
|
|
|
|
return pItem;
|
|
|
|
}
|
|
|
|
}
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
void CConnectDlg::DeleteAllListViewItemChilds ( QTreeWidgetItem* pItem )
|
|
|
|
{
|
|
|
|
// loop over all childs
|
|
|
|
while ( pItem->childCount() > 0 )
|
|
|
|
{
|
|
|
|
// get the first child in the list
|
|
|
|
QTreeWidgetItem* pCurChildItem = pItem->child ( 0 );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
// remove it from the item (note that the object is not deleted)
|
|
|
|
pItem->removeChild ( pCurChildItem );
|
2012-01-27 17:14:29 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
// delete the object to avoid a memory leak
|
|
|
|
delete pCurChildItem;
|
2012-01-27 17:14:29 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-21 22:25:26 +01:00
|
|
|
|
2014-02-23 10:46:25 +01:00
|
|
|
#ifdef ENABLE_CLIENT_VERSION_AND_OS_DEBUGGING
|
2014-02-21 22:25:26 +01:00
|
|
|
void CConnectDlg::SetVersionAndOSType ( CHostAddress InetAddr,
|
|
|
|
COSUtil::EOpSystemType eOSType,
|
|
|
|
QString strVersion )
|
|
|
|
{
|
|
|
|
// apply the received version and OS type to the correct server list entry
|
2015-12-09 16:50:30 +01:00
|
|
|
QTreeWidgetItem* pCurListViewItem = FindListViewItem ( InetAddr );
|
2014-02-21 22:25:26 +01:00
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
if ( pCurListViewItem )
|
2014-02-21 22:25:26 +01:00
|
|
|
{
|
|
|
|
// TEST since this is just a debug info, we just reuse the ping column (note
|
|
|
|
// the we have to replace the ping message emit with the version and OS request
|
|
|
|
// so that this works, see above code)
|
2015-12-09 16:50:30 +01:00
|
|
|
pCurListViewItem->
|
2014-02-21 22:25:26 +01:00
|
|
|
setText ( 1, strVersion + "/" + COSUtil::GetOperatingSystemString ( eOSType ) );
|
|
|
|
|
|
|
|
// a version and OS type was received, set item to visible
|
2015-12-09 16:50:30 +01:00
|
|
|
if ( pCurListViewItem->isHidden() )
|
2014-02-21 22:25:26 +01:00
|
|
|
{
|
2015-12-09 16:50:30 +01:00
|
|
|
pCurListViewItem->setHidden ( false );
|
2014-02-21 22:25:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-23 10:46:25 +01:00
|
|
|
#endif
|