server list entry work (colors), some code cleanup

This commit is contained in:
Volker Fischer 2011-04-18 20:42:37 +00:00
parent b39576d8d6
commit a49ef5c6bc
9 changed files with 114 additions and 39 deletions

View File

@ -438,7 +438,7 @@ QString CAudioMixerBoard::GenFaderText ( CChannelShortInfo& ChanInfo )
const CHostAddress TempAddr =
CHostAddress ( QHostAddress ( ChanInfo.iIpAddr ), 0 );
return TempAddr.GetIpAddressStringNoLastByte();
return TempAddr.toString ( CHostAddress::SM_IP_NO_LAST_BYTE );
}
else
{

View File

@ -42,7 +42,8 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
ListViewServers->setColumnWidth ( 0, 170 );
ListViewServers->setColumnWidth ( 1, 130 );
ListViewServers->setColumnWidth ( 2, 55 );
ListViewServers->setColumnWidth ( 3, 80 );
ListViewServers->setColumnWidth ( 3, 65 );
ListViewServers->setColumnWidth ( 4, 150 );
ListViewServers->clear();
@ -130,30 +131,48 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
pNewListViewItem->setText ( 2,
QString().setNum ( vecServerInfo[iIdx].iNumClients ) );
// store host address, note that for the very first entry which is
// the ping time shall be shown in bold font
QFont CurPingTimeFont = pNewListViewItem->font( 3 );
CurPingTimeFont.setBold ( true );
pNewListViewItem->setFont ( 3, CurPingTimeFont );
// 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;
if ( iIdx > 0 )
{
pNewListViewItem->setData ( 0, Qt::UserRole,
vecServerInfo[iIdx].HostAddr.toString() );
CurHostAddress = vecServerInfo[iIdx].HostAddr;
}
else
{
// substitude the receive host address for central server
pNewListViewItem->setData ( 0, Qt::UserRole, InetAddr.toString() );
CurHostAddress = InetAddr;
}
// 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.
if ( vecServerInfo[iIdx].HostAddr.iPort == LLCON_DEFAULT_PORT_NUMBER )
{
// only show IP number, no port number
pNewListViewItem->setText ( 4, CurHostAddress.
toString ( CHostAddress::SM_IP_NO_LAST_BYTE ) );
}
else
{
// show IP number and port
pNewListViewItem->setText ( 4, CurHostAddress.
toString ( CHostAddress::SM_IP_NO_LAST_BYTE_PORT ) );
}
// TEST
pNewListViewItem->setText ( 2,
pNewListViewItem->data ( 0, Qt::UserRole ).toString() );
// store host address
pNewListViewItem->setData ( 0, Qt::UserRole,
CurHostAddress.toString() );
}
// start the ping timer since the server list is filled now
TimerPing.start ( PING_UPDATE_TIME_MS );
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
}
void CConnectDlg::OnTimerPing()
@ -179,7 +198,8 @@ void CConnectDlg::OnTimerPing()
}
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime )
const int iPingTime,
const int iPingTimeLEDColor )
{
// apply the received ping time to the correct server list entry
const int iServerListLen = ListViewServers->topLevelItemCount();
@ -192,19 +212,31 @@ void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) )
{
// a ping time was received, set item to visible
ListViewServers->topLevelItem ( iIdx )->setHidden ( false );
// update the color of the ping time font
switch ( iPingTimeLEDColor )
{
case MUL_COL_LED_GREEN:
ListViewServers->
topLevelItem ( iIdx )->setTextColor ( 3, Qt::darkGreen );
break;
// TEST
QFont test = ListViewServers->topLevelItem ( iIdx )->font( 3 );
test.setBold ( true );
ListViewServers->topLevelItem ( iIdx )->setFont ( 3, test );
case MUL_COL_LED_YELLOW:
ListViewServers->
topLevelItem ( iIdx )->setTextColor ( 3, Qt::darkYellow );
break;
ListViewServers->topLevelItem ( iIdx )->setTextColor ( 3, Qt::red );
case MUL_COL_LED_RED:
ListViewServers->
topLevelItem ( iIdx )->setTextColor ( 3, Qt::red );
break;
}
// update ping text
ListViewServers->topLevelItem ( iIdx )->
setText ( 3, QString().setNum ( iPingTime ) + " ms" );
// a ping time was received, set item to visible
ListViewServers->topLevelItem ( iIdx )->setHidden ( false );
}
}
}

View File

@ -59,7 +59,9 @@ public:
void SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo );
void SetPingTimeResult ( CHostAddress& InetAddr, const int iPingTime );
void SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor );
protected:
virtual void showEvent ( QShowEvent* );

View File

@ -47,6 +47,11 @@
<string>Ping Time</string>
</property>
</column>
<column>
<property name="text" >
<string>Address</string>
</property>
</column>
</widget>
</item>
<item>

View File

@ -134,6 +134,10 @@
// defines the time interval at which the ping time is updated in the GUI
#define PING_UPDATE_TIME_MS 500 // ms
// defines the time interval at which the ping time is updated for the server
// list
#define PING_UPDATE_TIME_SERVER_LIST_MS 2000 // ms
// time-out until a registered server is deleted from the server list if no
// new registering was made in minutes
#define SERVLIST_TIME_OUT_MINUTES 60 // minutes

View File

@ -769,12 +769,28 @@ void CLlconClientDlg::OnPingTimeResult ( int iPingTime )
void CLlconClientDlg::OnCLPingTimeResult ( CHostAddress InetAddr,
int iPingTime )
{
// color definition: <= 25 ms green, <= 50 ms yellow, otherwise red
int iPingTimeLEDColor;
if ( iPingTime <= 25 )
{
iPingTimeLEDColor = MUL_COL_LED_GREEN;
}
else
{
if ( iPingTime <= 50 )
{
iPingTimeLEDColor = MUL_COL_LED_YELLOW;
}
else
{
iPingTimeLEDColor = MUL_COL_LED_RED;
}
}
// TODO evaluate the background color for the ping time result in the
// table in this function (see function above, there also the LED color
// is calculated so we do the other here, too)
ConnectDlg.SetPingTimeResult ( InetAddr, iPingTime );
// update connection dialog server list
ConnectDlg.SetPingTimeResult ( InetAddr,
iPingTime,
iPingTimeLEDColor );
}
void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )

View File

@ -41,7 +41,7 @@
</property>
<column>
<property name="text" >
<string>Client IP : Port</string>
<string>Client IP:Port</string>
</property>
</column>
<column>

View File

@ -831,8 +831,8 @@ void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID
if ( ChanName.isEmpty() )
{
// convert IP address to text and show it
ChanName =
vecChannels[iCurChanID].GetAddress().GetIpAddressStringNoLastByte();
ChanName = vecChannels[iCurChanID].GetAddress().
toString ( CHostAddress::SM_IP_NO_LAST_BYTE );
}
// add time and name of the client at the beginning of the message text and
@ -1114,8 +1114,8 @@ void CServer::WriteHTMLChannelList()
{
// convert IP address to text and show it, remove last
// digits
strCurChanName =
vecChannels[i].GetAddress().GetIpAddressStringNoLastByte();
strCurChanName = vecChannels[i].GetAddress().
toString ( CHostAddress::SM_IP_NO_LAST_BYTE );
}
streamFileOut << " <li>" << strCurChanName << "</li>" << endl;

View File

@ -393,6 +393,13 @@ protected:
class CHostAddress
{
public:
enum EStringMode
{
SM_IP_PORT,
SM_IP_NO_LAST_BYTE,
SM_IP_NO_LAST_BYTE_PORT
};
CHostAddress() :
InetAddr ( static_cast<quint32> ( 0 ) ),
iPort ( 0 ) {}
@ -421,16 +428,25 @@ public:
( CompAddr.iPort == iPort ) );
}
QString GetIpAddressStringNoLastByte() const
QString toString ( const EStringMode eStringMode = SM_IP_PORT ) const
{
// remove the last byte of the IP address
return InetAddr.toString().section ( ".", 0, 2 ) + ".x";
}
QString strReturn = InetAddr.toString();
QString toString() const
{
// return in the format [IP number]:[port]
return InetAddr.toString() + ":" + QString().setNum ( iPort );
if ( ( eStringMode == SM_IP_NO_LAST_BYTE ) ||
( eStringMode == SM_IP_NO_LAST_BYTE_PORT ) )
{
// replace last byte by an "x"
strReturn = strReturn.section ( ".", 0, 2 ) + ".x";
}
if ( ( eStringMode == SM_IP_PORT ) ||
( eStringMode == SM_IP_NO_LAST_BYTE_PORT ) )
{
// add port number after a semicolon
strReturn += ":" + QString().setNum ( iPort );
}
return strReturn;
}
QHostAddress InetAddr;