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 = const CHostAddress TempAddr =
CHostAddress ( QHostAddress ( ChanInfo.iIpAddr ), 0 ); CHostAddress ( QHostAddress ( ChanInfo.iIpAddr ), 0 );
return TempAddr.GetIpAddressStringNoLastByte(); return TempAddr.toString ( CHostAddress::SM_IP_NO_LAST_BYTE );
} }
else else
{ {

View File

@ -42,7 +42,8 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
ListViewServers->setColumnWidth ( 0, 170 ); ListViewServers->setColumnWidth ( 0, 170 );
ListViewServers->setColumnWidth ( 1, 130 ); ListViewServers->setColumnWidth ( 1, 130 );
ListViewServers->setColumnWidth ( 2, 55 ); ListViewServers->setColumnWidth ( 2, 55 );
ListViewServers->setColumnWidth ( 3, 80 ); ListViewServers->setColumnWidth ( 3, 65 );
ListViewServers->setColumnWidth ( 4, 150 );
ListViewServers->clear(); ListViewServers->clear();
@ -130,30 +131,48 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
pNewListViewItem->setText ( 2, pNewListViewItem->setText ( 2,
QString().setNum ( vecServerInfo[iIdx].iNumClients ) ); 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 // the central server, we have to use the receive host address
// instead // instead
CHostAddress CurHostAddress;
if ( iIdx > 0 ) if ( iIdx > 0 )
{ {
pNewListViewItem->setData ( 0, Qt::UserRole, CurHostAddress = vecServerInfo[iIdx].HostAddr;
vecServerInfo[iIdx].HostAddr.toString() );
} }
else else
{ {
// substitude the receive host address for central server // 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 // store host address
pNewListViewItem->setText ( 2, pNewListViewItem->setData ( 0, Qt::UserRole,
pNewListViewItem->data ( 0, Qt::UserRole ).toString() ); CurHostAddress.toString() );
} }
// start the ping timer since the server list is filled now // 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() void CConnectDlg::OnTimerPing()
@ -179,7 +198,8 @@ void CConnectDlg::OnTimerPing()
} }
void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr, 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 // apply the received ping time to the correct server list entry
const int iServerListLen = ListViewServers->topLevelItemCount(); const int iServerListLen = ListViewServers->topLevelItemCount();
@ -192,19 +212,31 @@ void CConnectDlg::SetPingTimeResult ( CHostAddress& InetAddr,
data ( 0, Qt::UserRole ).toString(). data ( 0, Qt::UserRole ).toString().
compare ( InetAddr.toString() ) ) compare ( InetAddr.toString() ) )
{ {
// a ping time was received, set item to visible // update the color of the ping time font
ListViewServers->topLevelItem ( iIdx )->setHidden ( false ); switch ( iPingTimeLEDColor )
{
case MUL_COL_LED_GREEN:
ListViewServers->
topLevelItem ( iIdx )->setTextColor ( 3, Qt::darkGreen );
break;
// TEST case MUL_COL_LED_YELLOW:
QFont test = ListViewServers->topLevelItem ( iIdx )->font( 3 ); ListViewServers->
test.setBold ( true ); topLevelItem ( iIdx )->setTextColor ( 3, Qt::darkYellow );
ListViewServers->topLevelItem ( iIdx )->setFont ( 3, test ); break;
ListViewServers->topLevelItem ( iIdx )->setTextColor ( 3, Qt::red ); case MUL_COL_LED_RED:
ListViewServers->
topLevelItem ( iIdx )->setTextColor ( 3, Qt::red );
break;
}
// update ping text // update ping text
ListViewServers->topLevelItem ( iIdx )-> ListViewServers->topLevelItem ( iIdx )->
setText ( 3, QString().setNum ( iPingTime ) + " ms" ); 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, void SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo ); const CVector<CServerInfo>& vecServerInfo );
void SetPingTimeResult ( CHostAddress& InetAddr, const int iPingTime ); void SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime,
const int iPingTimeLEDColor );
protected: protected:
virtual void showEvent ( QShowEvent* ); virtual void showEvent ( QShowEvent* );

View File

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

View File

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

View File

@ -769,12 +769,28 @@ void CLlconClientDlg::OnPingTimeResult ( int iPingTime )
void CLlconClientDlg::OnCLPingTimeResult ( CHostAddress InetAddr, void CLlconClientDlg::OnCLPingTimeResult ( CHostAddress InetAddr,
int iPingTime ) 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 // update connection dialog server list
// table in this function (see function above, there also the LED color ConnectDlg.SetPingTimeResult ( InetAddr,
// is calculated so we do the other here, too) iPingTime,
iPingTimeLEDColor );
ConnectDlg.SetPingTimeResult ( InetAddr, iPingTime );
} }
void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart ) void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )

View File

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

View File

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

View File

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