different column sizes since the label has changed

This commit is contained in:
Volker Fischer 2012-01-27 16:14:29 +00:00
parent 3a83c5cad0
commit 4dabebbd4f

View File

@ -1,448 +1,448 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * 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 * 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 * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * 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 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * 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., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#include "connectdlg.h" #include "connectdlg.h"
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList, CConnectDlg::CConnectDlg ( const bool bNewShowCompleteRegList,
QWidget* parent, QWidget* parent,
Qt::WindowFlags f ) Qt::WindowFlags f )
: QDialog ( parent, f ), : QDialog ( parent, f ),
strCentralServerAddress ( "" ), strCentralServerAddress ( "" ),
strSelectedAddress ( "" ), strSelectedAddress ( "" ),
strSelectedServerName ( "" ), strSelectedServerName ( "" ),
bShowCompleteRegList ( bNewShowCompleteRegList ), bShowCompleteRegList ( bNewShowCompleteRegList ),
bServerListReceived ( false ), bServerListReceived ( false ),
bStateOK ( false ), bStateOK ( false ),
bServerListItemWasChosen ( false ) bServerListItemWasChosen ( false )
{ {
setupUi ( this ); setupUi ( this );
// Add help text to controls ----------------------------------------------- // Add help text to controls -----------------------------------------------
// server list // server list
lvwServers->setWhatsThis ( tr ( "<b>Server List:</b> The server list shows " lvwServers->setWhatsThis ( tr ( "<b>Server List:</b> The server list shows "
"a list of available servers which are registered at the central " "a list of available servers which are registered at the central "
"server. Select a server from the list and press the connect button to " "server. Select a server from the list and press the connect button to "
"connect to this server. Alternatively, double click a server from " "connect to this server. Alternatively, double click a server from "
"the list to connect to it.<br>" "the list to connect to it.<br>"
"Note that it may take some time to retrieve the server list from the " "Note that it may take some time to retrieve the server list from the "
"central server. If no valid central server address is specified in " "central server. If no valid central server address is specified in "
"the settings, no server list will be available." ) ); "the settings, no server list will be available." ) );
lvwServers->setAccessibleName ( tr ( "Server list view" ) ); lvwServers->setAccessibleName ( tr ( "Server list view" ) );
// server address // server address
QString strServAddrH = tr ( "<b>Server Address:</b> The IP address or URL " QString strServAddrH = tr ( "<b>Server Address:</b> The IP address or URL "
"of the server running the llcon server software must be set here. An " "of the server running the llcon server software must be set here. An "
"optional port number can be added after the IP address or URL using " "optional port number can be added after the IP address or URL using "
"a comma as a separator, e.g, <i>" ) + DEFAULT_SERVER_ADDRESS + ":" + "a comma as a separator, e.g, <i>" ) + DEFAULT_SERVER_ADDRESS + ":" +
QString().setNum ( LLCON_DEFAULT_PORT_NUMBER ) + tr ( "</i>. A list of " QString().setNum ( LLCON_DEFAULT_PORT_NUMBER ) + tr ( "</i>. A list of "
"the most recent used server IP addresses or URLs is available for " "the most recent used server IP addresses or URLs is available for "
"selection." ); "selection." );
lblServerAddr->setWhatsThis ( strServAddrH ); lblServerAddr->setWhatsThis ( strServAddrH );
cbxServerAddr->setWhatsThis ( strServAddrH ); cbxServerAddr->setWhatsThis ( strServAddrH );
cbxServerAddr->setAccessibleName ( tr ( "Server address edit box" ) ); cbxServerAddr->setAccessibleName ( tr ( "Server address edit box" ) );
cbxServerAddr->setAccessibleDescription ( tr ( "Holds the current server " cbxServerAddr->setAccessibleDescription ( tr ( "Holds the current server "
"IP address or URL. It also stores old URLs in the combo box list." ) ); "IP address or URL. It also stores old URLs in the combo box list." ) );
// init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries) // init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries)
cbxServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS ); cbxServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
cbxServerAddr->setInsertPolicy ( QComboBox::NoInsert ); cbxServerAddr->setInsertPolicy ( QComboBox::NoInsert );
// set up list view for connected clients (note that the last column size // 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) // must not be specified since this column takes all the remaining space)
lvwServers->setColumnWidth ( 0, 170 ); lvwServers->setColumnWidth ( 0, 165 );
lvwServers->setColumnWidth ( 1, 65 ); lvwServers->setColumnWidth ( 1, 65 );
lvwServers->setColumnWidth ( 2, 55 ); lvwServers->setColumnWidth ( 2, 60 );
lvwServers->clear(); lvwServers->clear();
// add invisible column which is used for sorting the list // add invisible column which is used for sorting the list
lvwServers->setColumnCount ( 5 ); lvwServers->setColumnCount ( 5 );
lvwServers->hideColumn ( 4 ); lvwServers->hideColumn ( 4 );
// make sure the connect button has the focus // make sure the connect button has the focus
butConnect->setFocus(); butConnect->setFocus();
// Connections ------------------------------------------------------------- // Connections -------------------------------------------------------------
// list view // list view
QObject::connect ( lvwServers, QObject::connect ( lvwServers,
SIGNAL ( itemSelectionChanged() ), SIGNAL ( itemSelectionChanged() ),
this, SLOT ( OnServerListItemSelectionChanged() ) ); this, SLOT ( OnServerListItemSelectionChanged() ) );
QObject::connect ( lvwServers, QObject::connect ( lvwServers,
SIGNAL ( itemDoubleClicked ( QTreeWidgetItem*, int ) ), SIGNAL ( itemDoubleClicked ( QTreeWidgetItem*, int ) ),
this, SLOT ( OnServerListItemDoubleClicked ( QTreeWidgetItem*, int ) ) ); this, SLOT ( OnServerListItemDoubleClicked ( QTreeWidgetItem*, int ) ) );
QObject::connect ( lvwServers, // to get default return key behaviour working QObject::connect ( lvwServers, // to get default return key behaviour working
SIGNAL ( activated ( QModelIndex ) ), SIGNAL ( activated ( QModelIndex ) ),
this, SLOT ( OnConnectClicked() ) ); this, SLOT ( OnConnectClicked() ) );
// combo boxes // combo boxes
QObject::connect ( cbxServerAddr, SIGNAL ( editTextChanged ( const QString& ) ), QObject::connect ( cbxServerAddr, SIGNAL ( editTextChanged ( const QString& ) ),
this, SLOT ( OnServerAddrEditTextChanged ( const QString& ) ) ); this, SLOT ( OnServerAddrEditTextChanged ( const QString& ) ) );
// buttons // buttons
QObject::connect ( butCancel, SIGNAL ( clicked() ), QObject::connect ( butCancel, SIGNAL ( clicked() ),
this, SLOT ( close() ) ); this, SLOT ( close() ) );
QObject::connect ( butConnect, SIGNAL ( clicked() ), QObject::connect ( butConnect, SIGNAL ( clicked() ),
this, SLOT ( OnConnectClicked() ) ); this, SLOT ( OnConnectClicked() ) );
// timers // timers
QObject::connect ( &TimerPing, SIGNAL ( timeout() ), QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPing() ) ); this, SLOT ( OnTimerPing() ) );
QObject::connect ( &TimerReRequestServList, SIGNAL ( timeout() ), QObject::connect ( &TimerReRequestServList, SIGNAL ( timeout() ),
this, SLOT ( OnTimerReRequestServList() ) ); this, SLOT ( OnTimerReRequestServList() ) );
} }
void CConnectDlg::Init ( const QString strNewCentralServerAddr, void CConnectDlg::Init ( const QString strNewCentralServerAddr,
const CVector<QString>& vstrIPAddresses ) const CVector<QString>& vstrIPAddresses )
{ {
// take central server address string // take central server address string
strCentralServerAddress = strNewCentralServerAddr; strCentralServerAddress = strNewCentralServerAddr;
// load stored IP addresses in combo box // load stored IP addresses in combo box
cbxServerAddr->clear(); cbxServerAddr->clear();
for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ ) for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ )
{ {
if ( !vstrIPAddresses[iLEIdx].isEmpty() ) if ( !vstrIPAddresses[iLEIdx].isEmpty() )
{ {
cbxServerAddr->addItem ( vstrIPAddresses[iLEIdx] ); cbxServerAddr->addItem ( vstrIPAddresses[iLEIdx] );
} }
} }
} }
void CConnectDlg::showEvent ( QShowEvent* ) void CConnectDlg::showEvent ( QShowEvent* )
{ {
// reset flags (on opening the connect dialg, we always want to request a // reset flags (on opening the connect dialg, we always want to request a
// new updated server list per definition) // new updated server list per definition)
bServerListReceived = false; bServerListReceived = false;
bStateOK = false; bStateOK = false;
bServerListItemWasChosen = false; bServerListItemWasChosen = false;
// clear current address and name // clear current address and name
strSelectedAddress = ""; strSelectedAddress = "";
strSelectedServerName = ""; strSelectedServerName = "";
// clear server list view // clear server list view
lvwServers->clear(); lvwServers->clear();
// get the IP address of the central server (using the ParseNetworAddress // get the IP address of the central server (using the ParseNetworAddress
// function) when the connect dialog is opened, this seems to be the correct // function) when the connect dialog is opened, this seems to be the correct
// time to do it // time to do it
if ( LlconNetwUtil().ParseNetworkAddress ( strCentralServerAddress, if ( LlconNetwUtil().ParseNetworkAddress ( strCentralServerAddress,
CentralServerAddress ) ) CentralServerAddress ) )
{ {
// send the request for the server list // send the request for the server list
emit ReqServerListQuery ( CentralServerAddress ); emit ReqServerListQuery ( CentralServerAddress );
// start timer, if this message did not get any respond to retransmit // start timer, if this message did not get any respond to retransmit
// the server list request message // the server list request message
TimerReRequestServList.start ( SERV_LIST_REQ_UPDATE_TIME_MS ); TimerReRequestServList.start ( SERV_LIST_REQ_UPDATE_TIME_MS );
} }
} }
void CConnectDlg::hideEvent ( QHideEvent* ) void CConnectDlg::hideEvent ( QHideEvent* )
{ {
// get the IP address to be used according to the following definitions: // 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 focus and a line is selected, use this line
// - if the list has no focus, use the current combo box text // - if the list has no focus, use the current combo box text
QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems(); QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems();
if ( CurSelListItemList.count() > 0 ) if ( CurSelListItemList.count() > 0 )
{ {
// get host address from selected list view item as a string // get host address from selected list view item as a string
strSelectedAddress = strSelectedAddress =
CurSelListItemList[0]->data ( 0, Qt::UserRole ).toString(); CurSelListItemList[0]->data ( 0, Qt::UserRole ).toString();
// store selected server name // store selected server name
strSelectedServerName = CurSelListItemList[0]->text ( 0 ); strSelectedServerName = CurSelListItemList[0]->text ( 0 );
// set flag that a server list item was chosen to connect // set flag that a server list item was chosen to connect
bServerListItemWasChosen = true; bServerListItemWasChosen = true;
} }
else else
{ {
strSelectedAddress = cbxServerAddr->currentText(); strSelectedAddress = cbxServerAddr->currentText();
} }
// if window is closed, stop timers // if window is closed, stop timers
TimerPing.stop(); TimerPing.stop();
TimerReRequestServList.stop(); TimerReRequestServList.stop();
} }
void CConnectDlg::OnTimerReRequestServList() void CConnectDlg::OnTimerReRequestServList()
{ {
// if the server list is not yet received, retransmit the request for the // if the server list is not yet received, retransmit the request for the
// server list // server list
if ( !bServerListReceived ) if ( !bServerListReceived )
{ {
emit ReqServerListQuery ( CentralServerAddress ); emit ReqServerListQuery ( CentralServerAddress );
} }
} }
void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo ) const CVector<CServerInfo>& vecServerInfo )
{ {
// set flag and disable timer for resend server list request // set flag and disable timer for resend server list request
bServerListReceived = true; bServerListReceived = true;
TimerReRequestServList.stop(); TimerReRequestServList.stop();
// first clear list // first clear list
lvwServers->clear(); lvwServers->clear();
// add list item for each server in the server list // add list item for each server in the server list
const int iServerInfoLen = vecServerInfo.Size(); const int iServerInfoLen = vecServerInfo.Size();
for ( int iIdx = 0; iIdx < iServerInfoLen; iIdx++ ) for ( int iIdx = 0; iIdx < iServerInfoLen; iIdx++ )
{ {
// get the host address, note that for the very first entry which is // get the host address, note that for the very first entry which is
// the central server, we have to use the receive host address // the central server, we have to use the receive host address
// instead // instead
CHostAddress CurHostAddress; CHostAddress CurHostAddress;
if ( iIdx > 0 ) if ( iIdx > 0 )
{ {
CurHostAddress = vecServerInfo[iIdx].HostAddr; CurHostAddress = vecServerInfo[iIdx].HostAddr;
} }
else else
{ {
// substitude the receive host address for central server // substitude the receive host address for central server
CurHostAddress = InetAddr; CurHostAddress = InetAddr;
} }
// create new list view item // create new list view item
QTreeWidgetItem* pNewListViewItem = new QTreeWidgetItem ( lvwServers ); QTreeWidgetItem* pNewListViewItem = new QTreeWidgetItem ( lvwServers );
// make the entry invisible (will be set to visible on successful ping // make the entry invisible (will be set to visible on successful ping
// result) if the complete list of registered servers shall not be shown // result) if the complete list of registered servers shall not be shown
if ( !bShowCompleteRegList ) if ( !bShowCompleteRegList )
{ {
pNewListViewItem->setHidden ( true ); pNewListViewItem->setHidden ( true );
} }
// server name (if empty, show host address instead) // server name (if empty, show host address instead)
if ( !vecServerInfo[iIdx].strName.isEmpty() ) if ( !vecServerInfo[iIdx].strName.isEmpty() )
{ {
pNewListViewItem->setText ( 0, vecServerInfo[iIdx].strName ); pNewListViewItem->setText ( 0, vecServerInfo[iIdx].strName );
} }
else else
{ {
// IP address and port (use IP number without last byte) // IP address and port (use IP number without last byte)
// Definition: If the port number is the default port number, we do // Definition: If the port number is the default port number, we do
// not show it. // not show it.
if ( vecServerInfo[iIdx].HostAddr.iPort == LLCON_DEFAULT_PORT_NUMBER ) if ( vecServerInfo[iIdx].HostAddr.iPort == LLCON_DEFAULT_PORT_NUMBER )
{ {
// only show IP number, no port number // only show IP number, no port number
pNewListViewItem->setText ( 0, CurHostAddress. pNewListViewItem->setText ( 0, CurHostAddress.
toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) ); toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );
} }
else else
{ {
// show IP number and port // show IP number and port
pNewListViewItem->setText ( 0, CurHostAddress. pNewListViewItem->setText ( 0, CurHostAddress.
toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) ); toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) );
} }
} }
// the ping time shall be shown in bold font // the ping time shall be shown in bold font
QFont CurPingTimeFont = pNewListViewItem->font( 3 ); QFont CurPingTimeFont = pNewListViewItem->font( 3 );
CurPingTimeFont.setBold ( true ); CurPingTimeFont.setBold ( true );
pNewListViewItem->setFont ( 1, CurPingTimeFont ); pNewListViewItem->setFont ( 1, CurPingTimeFont );
// server location (city and country) // server location (city and country)
QString strLocation = vecServerInfo[iIdx].strCity; QString strLocation = vecServerInfo[iIdx].strCity;
if ( ( !strLocation.isEmpty() ) && if ( ( !strLocation.isEmpty() ) &&
( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry ) ) ( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry ) )
{ {
strLocation += ", "; strLocation += ", ";
} }
if ( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry ) if ( vecServerInfo[iIdx].eCountry != QLocale::AnyCountry )
{ {
strLocation += strLocation +=
QLocale::countryToString ( vecServerInfo[iIdx].eCountry ); QLocale::countryToString ( vecServerInfo[iIdx].eCountry );
} }
pNewListViewItem->setText ( 3, strLocation ); pNewListViewItem->setText ( 3, strLocation );
// init the minimum ping time with a large number (note that this number // init the minimum ping time with a large number (note that this number
// must fit in an integer type) // must fit in an integer type)
pNewListViewItem->setText ( 4, "99999999" ); pNewListViewItem->setText ( 4, "99999999" );
// store host address // store host address
pNewListViewItem->setData ( 0, Qt::UserRole, pNewListViewItem->setData ( 0, Qt::UserRole,
CurHostAddress.toString() ); CurHostAddress.toString() );
} }
// immediately issue the ping measurements and start the ping timer since // immediately issue the ping measurements and start the ping timer since
// the server list is filled now // the server list is filled now
OnTimerPing(); OnTimerPing();
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS ); TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
} }
void CConnectDlg::OnServerListItemSelectionChanged() void CConnectDlg::OnServerListItemSelectionChanged()
{ {
// get current selected item (we are only interested in the first selcted // get current selected item (we are only interested in the first selcted
// item) // item)
QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems(); QList<QTreeWidgetItem*> CurSelListItemList = lvwServers->selectedItems();
// if an item is clicked/selected, copy the server name to the combo box // if an item is clicked/selected, copy the server name to the combo box
if ( CurSelListItemList.count() > 0 ) if ( CurSelListItemList.count() > 0 )
{ {
// make sure no signals are send when we change the text // make sure no signals are send when we change the text
cbxServerAddr->blockSignals ( true ); cbxServerAddr->blockSignals ( true );
{ {
cbxServerAddr->setEditText ( CurSelListItemList[0]->text ( 0 ) ); cbxServerAddr->setEditText ( CurSelListItemList[0]->text ( 0 ) );
} }
cbxServerAddr->blockSignals ( false ); cbxServerAddr->blockSignals ( false );
} }
} }
void CConnectDlg::OnServerListItemDoubleClicked ( QTreeWidgetItem* Item, void CConnectDlg::OnServerListItemDoubleClicked ( QTreeWidgetItem* Item,
int ) int )
{ {
// if a server list item was double clicked, it is the same as if the // if a server list item was double clicked, it is the same as if the
// connect button was clicked // connect button was clicked
if ( Item != 0 ) if ( Item != 0 )
{ {
OnConnectClicked(); OnConnectClicked();
} }
} }
void CConnectDlg::OnServerAddrEditTextChanged ( const QString& ) void CConnectDlg::OnServerAddrEditTextChanged ( const QString& )
{ {
// in the server address combo box, a text was changed, remove selection // in the server address combo box, a text was changed, remove selection
// in the server list (if any) // in the server list (if any)
lvwServers->clearSelection(); lvwServers->clearSelection();
} }
void CConnectDlg::OnConnectClicked() void CConnectDlg::OnConnectClicked()
{ {
// set state OK flag // set state OK flag
bStateOK = true; bStateOK = true;
// close dialog // close dialog
close(); close();
} }
void CConnectDlg::OnTimerPing() void CConnectDlg::OnTimerPing()
{ {
// send ping messages to the servers in the list // send ping messages to the servers in the list
const int iServerListLen = lvwServers->topLevelItemCount(); const int iServerListLen = lvwServers->topLevelItemCount();
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
{ {
CHostAddress CurServerAddress; CHostAddress CurServerAddress;
// try to parse host address string which is stored as user data // try to parse host address string which is stored as user data
// in the server list item GUI control element // in the server list item GUI control element
if ( LlconNetwUtil().ParseNetworkAddress ( if ( LlconNetwUtil().ParseNetworkAddress (
lvwServers->topLevelItem ( iIdx )-> lvwServers->topLevelItem ( iIdx )->
data ( 0, Qt::UserRole ).toString(), data ( 0, Qt::UserRole ).toString(),
CurServerAddress ) ) CurServerAddress ) )
{ {
// if address is valid, send ping // if address is valid, send ping
emit CreateCLServerListPingMes ( CurServerAddress ); emit CreateCLServerListPingMes ( CurServerAddress );
} }
} }
} }
void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr, void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& InetAddr,
const int iPingTime, const int iPingTime,
const int iPingTimeLEDColor, const int iPingTimeLEDColor,
const int iNumClients ) const int iNumClients )
{ {
// apply the received ping time to the correct server list entry // apply the received ping time to the correct server list entry
const int iServerListLen = lvwServers->topLevelItemCount(); const int iServerListLen = lvwServers->topLevelItemCount();
for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ )
{ {
// compare the received address with the user data string of the // compare the received address with the user data string of the
// host address by a string compare // host address by a string compare
if ( !lvwServers->topLevelItem ( iIdx )-> if ( !lvwServers->topLevelItem ( iIdx )->
data ( 0, Qt::UserRole ).toString(). data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) ) compare ( InetAddr.toString() ) )
{ {
// update the color of the ping time font // update the color of the ping time font
switch ( iPingTimeLEDColor ) switch ( iPingTimeLEDColor )
{ {
case MUL_COL_LED_GREEN: case MUL_COL_LED_GREEN:
lvwServers-> lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkGreen ); topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkGreen );
break; break;
case MUL_COL_LED_YELLOW: case MUL_COL_LED_YELLOW:
lvwServers-> lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkYellow ); topLevelItem ( iIdx )->setTextColor ( 1, Qt::darkYellow );
break; break;
case MUL_COL_LED_RED: case MUL_COL_LED_RED:
lvwServers-> lvwServers->
topLevelItem ( iIdx )->setTextColor ( 1, Qt::red ); topLevelItem ( iIdx )->setTextColor ( 1, Qt::red );
break; break;
} }
// update ping text, take special care if ping time exceeds a // update ping text, take special care if ping time exceeds a
// certain value // certain value
if ( iPingTime > 500 ) if ( iPingTime > 500 )
{ {
lvwServers->topLevelItem ( iIdx )->setText ( 1, ">500 ms" ); lvwServers->topLevelItem ( iIdx )->setText ( 1, ">500 ms" );
} }
else else
{ {
lvwServers->topLevelItem ( iIdx )-> lvwServers->topLevelItem ( iIdx )->
setText ( 1, QString().setNum ( iPingTime ) + " ms" ); setText ( 1, QString().setNum ( iPingTime ) + " ms" );
} }
// update number of clients text // update number of clients text
lvwServers->topLevelItem ( iIdx )-> lvwServers->topLevelItem ( iIdx )->
setText ( 2, QString().setNum ( iNumClients ) ); setText ( 2, QString().setNum ( iNumClients ) );
// a ping time was received, set item to visible // a ping time was received, set item to visible
lvwServers->topLevelItem ( iIdx )->setHidden ( false ); lvwServers->topLevelItem ( iIdx )->setHidden ( false );
// update minimum ping time column (invisible, used for sorting) if // update minimum ping time column (invisible, used for sorting) if
// the new value is smaller than the old value // the new value is smaller than the old value
if ( lvwServers->topLevelItem ( iIdx )->text ( 4 ).toInt() > iPingTime ) if ( lvwServers->topLevelItem ( iIdx )->text ( 4 ).toInt() > iPingTime )
{ {
// we pad to a total of 8 characters with zeros to make sure the // we pad to a total of 8 characters with zeros to make sure the
// sorting is done correctly // sorting is done correctly
lvwServers->topLevelItem ( iIdx )-> lvwServers->topLevelItem ( iIdx )->
setText ( 4, QString ( "%1" ).arg ( setText ( 4, QString ( "%1" ).arg (
iPingTime, 8, 10, QLatin1Char( '0' ) ) ); iPingTime, 8, 10, QLatin1Char( '0' ) ) );
// Update the sorting (lowest number on top). // Update the sorting (lowest number on top).
// Note that the sorting must be the last action for the current // Note that the sorting must be the last action for the current
// item since the topLevelItem ( iIdx ) is then no longer valid. // item since the topLevelItem ( iIdx ) is then no longer valid.
lvwServers->sortByColumn ( 4, Qt::AscendingOrder ); lvwServers->sortByColumn ( 4, Qt::AscendingOrder );
} }
} }
} }
} }