support for the new GUI controls in the server, net yet finished (still buggy)

This commit is contained in:
Volker Fischer 2011-04-30 13:01:26 +00:00
parent ead06da44d
commit c08fe59a68
9 changed files with 166 additions and 33 deletions

View file

@ -50,6 +50,10 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent )
vecpListViewItems[i]->setHidden ( true ); vecpListViewItems[i]->setHidden ( true );
} }
// update central server name line edit
LineEditCentralServerAddress->setText (
pServer->GetServerListCentralServerAddress() );
// update server name line edit // update server name line edit
LineEditServerName->setText ( pServer->GetServerName() ); LineEditServerName->setText ( pServer->GetServerName() );
@ -81,6 +85,16 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent )
ComboBoxLocationCountry->findData ( ComboBoxLocationCountry->findData (
static_cast<int> ( pServer->GetServerCountry() ) ) ); static_cast<int> ( pServer->GetServerCountry() ) ) );
// update register server check box
if ( pServer->GetServerListEnabled() )
{
cbRegisterServer->setCheckState ( Qt::Checked );
}
else
{
cbRegisterServer->setCheckState ( Qt::Unchecked );
}
// Main menu bar ----------------------------------------------------------- // Main menu bar -----------------------------------------------------------
pMenu = new QMenuBar ( this ); pMenu = new QMenuBar ( this );
@ -91,6 +105,25 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent )
// Connections ------------------------------------------------------------- // Connections -------------------------------------------------------------
// check boxes
QObject::connect ( cbRegisterServer, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnRegisterServerStateChanged ( int ) ) );
// line edits
QObject::connect ( LineEditCentralServerAddress,
SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnLineEditCentralServerAddressTextChanged ( const QString& ) ) );
QObject::connect ( LineEditServerName, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnLineEditServerNameTextChanged ( const QString& ) ) );
QObject::connect ( LineEditLocationCity, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnLineEditLocationCityTextChanged ( const QString& ) ) );
// combo boxes
QObject::connect ( ComboBoxLocationCountry, SIGNAL ( activated ( int ) ),
this, SLOT ( OnComboBoxLocationCountryActivated ( int ) ) );
// timers // timers
QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) ); QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) );
@ -100,6 +133,52 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent )
Timer.start ( GUI_CONTRL_UPDATE_TIME ); Timer.start ( GUI_CONTRL_UPDATE_TIME );
} }
void CLlconServerDlg::OnRegisterServerStateChanged ( int value )
{
const bool bEnabled = ( value == Qt::Checked );
// if register server is not enabled, we disable all the configuration
// controls for the server list
LabelCentralServerAddress->setEnabled ( bEnabled );
cbDefaultCentralServer->setEnabled ( bEnabled );
LineEditCentralServerAddress->setEnabled ( bEnabled );
GroupBoxServerInfo->setEnabled ( bEnabled );
// apply new setting to the server and update it
pServer->SetServerListEnabled ( bEnabled );
pServer->UpdateServerList();
}
void CLlconServerDlg::OnLineEditCentralServerAddressTextChanged ( const QString& strNewAddr )
{
// apply new setting to the server and update it
pServer->SetServerListCentralServerAddress ( strNewAddr );
pServer->UpdateServerList();
}
void CLlconServerDlg::OnLineEditServerNameTextChanged ( const QString& strNewName )
{
// apply new setting to the server and update it
pServer->SetServerName ( strNewName );
pServer->UpdateServerList();
}
void CLlconServerDlg::OnLineEditLocationCityTextChanged ( const QString& strNewCity )
{
// apply new setting to the server and update it
pServer->SetServerCity ( strNewCity );
pServer->UpdateServerList();
}
void CLlconServerDlg::OnComboBoxLocationCountryActivated ( int iCntryListItem )
{
// apply new setting to the server and update it
pServer->SetServerCountry ( static_cast<QLocale::Country> (
ComboBoxLocationCountry->itemData ( iCntryListItem ).toInt() ) );
pServer->UpdateServerList();
}
void CLlconServerDlg::OnTimer() void CLlconServerDlg::OnTimer()
{ {
CVector<CHostAddress> vecHostAddresses; CVector<CHostAddress> vecHostAddresses;

View file

@ -70,5 +70,10 @@ protected:
void UpdateSliderNetBuf(); void UpdateSliderNetBuf();
public slots: public slots:
void OnRegisterServerStateChanged ( int value );
void OnLineEditCentralServerAddressTextChanged ( const QString& strNewAddr );
void OnLineEditServerNameTextChanged ( const QString& strNewName );
void OnLineEditLocationCityTextChanged ( const QString& strNewCity );
void OnComboBoxLocationCountryActivated ( int iCntryListItem );
void OnTimer(); void OnTimer();
}; };

View file

@ -52,7 +52,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="CheckBoxRegisterServer" > <widget class="QCheckBox" name="cbRegisterServer" >
<property name="text" > <property name="text" >
<string>Register Server</string> <string>Register Server</string>
</property> </property>
@ -68,7 +68,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="CheckBoxDefaultCentralServer" > <widget class="QCheckBox" name="cbDefaultCentralServer" >
<property name="text" > <property name="text" >
<string>Default</string> <string>Default</string>
</property> </property>
@ -80,7 +80,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QGroupBox" name="groupBox" > <widget class="QGroupBox" name="GroupBoxServerInfo" >
<property name="title" > <property name="title" >
<string>Server Info</string> <string>Server Info</string>
</property> </property>

View file

@ -353,6 +353,10 @@ int main ( int argc, char** argv )
CSettings Settings ( &Server ); CSettings Settings ( &Server );
Settings.Load ( strIniFileName ); Settings.Load ( strIniFileName );
// update server list AFTER restoring the settings from the
// settings file
Server.UpdateServerList();
// GUI object for the server // GUI object for the server
CLlconServerDlg ServerDlg ( &Server, 0 ); CLlconServerDlg ServerDlg ( &Server, 0 );
@ -369,6 +373,9 @@ int main ( int argc, char** argv )
} }
else else
{ {
// update serverlist
Server.UpdateServerList();
// only start application without using the GUI // only start application without using the GUI
tsConsole << CAboutDlg::GetVersionAndNameStr ( false ) << endl; tsConsole << CAboutDlg::GetVersionAndNameStr ( false ) << endl;

View file

@ -383,11 +383,6 @@ CServer::CServer ( const QString& strLoggingFileName,
QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) ); QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) );
QObject::connect ( &vecChannels[10], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh10 ( int ) ) ); QObject::connect ( &vecChannels[10], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh10 ( int ) ) );
QObject::connect ( &vecChannels[11], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh11 ( int ) ) ); QObject::connect ( &vecChannels[11], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh11 ( int ) ) );
// set enable of the server list, must be done after the connections, we use
// the information about the enable status of the serverlist object itself
ServerListManager.SetEnabled ( ServerListManager.GetEnabled() );
} }
void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage ) void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )

View file

@ -126,6 +126,21 @@ public:
CVector<int>& veciJitBufNumFrames, CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact ); CVector<int>& veciNetwFrameSizeFact );
// Server list management --------------------------------------------------
void UpdateServerList() { ServerListManager.Update(); }
void SetServerListEnabled ( const bool bState )
{ ServerListManager.SetEnabled ( bState ); }
bool GetServerListEnabled() { return ServerListManager.GetEnabled(); }
void SetServerListCentralServerAddress ( const QString& sNCentServAddr )
{ ServerListManager.SetCentralServerAddress ( sNCentServAddr ); }
QString GetServerListCentralServerAddress()
{ return ServerListManager.GetCentralServerAddress(); }
void SetServerName ( const QString& strNewName ) void SetServerName ( const QString& strNewName )
{ ServerListManager.SetServerName ( strNewName ); } { ServerListManager.SetServerName ( strNewName ); }

View file

@ -29,27 +29,10 @@
CServerListManager::CServerListManager ( const QString& sNCentServAddr, CServerListManager::CServerListManager ( const QString& sNCentServAddr,
const QString& strServerInfo, const QString& strServerInfo,
CProtocol* pNConLProt ) CProtocol* pNConLProt )
: strCentralServerAddress ( sNCentServAddr ), : pConnLessProtocol ( pNConLProt )
pConnLessProtocol ( pNConLProt )
{ {
// per definition: If the central server address is empty, the server list // set the central server address
// is disabled. SetCentralServerAddress ( sNCentServAddr );
// per definition: If we are in server mode and the central server address
// is the localhost address, we are in central server mode. For the central
// server, the server list is always enabled.
if ( !strCentralServerAddress.isEmpty() )
{
bIsCentralServer =
( !strCentralServerAddress.toLower().compare ( "localhost" ) ||
!strCentralServerAddress.compare ( "127.0.0.1" ) );
bEnabled = true;
}
else
{
bIsCentralServer = false;
bEnabled = true;
}
// per definition, the very first entry is this server and this entry will // per definition, the very first entry is this server and this entry will
// never be deleted // never be deleted
@ -105,11 +88,35 @@ CServerListManager::CServerListManager ( const QString& sNCentServAddr,
this, SLOT ( OnTimerRegistering() ) ); this, SLOT ( OnTimerRegistering() ) );
} }
void CServerListManager::SetEnabled ( const bool bState ) void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr )
{ {
QMutexLocker locker ( &Mutex ); QMutexLocker locker ( &Mutex );
bEnabled = bState; strCentralServerAddress = sNCentServAddr;
// per definition: If the central server address is empty, the server list
// is disabled.
// per definition: If we are in server mode and the central server address
// is the localhost address, we are in central server mode. For the central
// server, the server list is always enabled.
if ( !strCentralServerAddress.isEmpty() )
{
bIsCentralServer =
( !strCentralServerAddress.toLower().compare ( "localhost" ) ||
!strCentralServerAddress.compare ( "127.0.0.1" ) );
bEnabled = true;
}
else
{
bIsCentralServer = false;
bEnabled = true;
}
}
void CServerListManager::Update()
{
QMutexLocker locker ( &Mutex );
if ( bEnabled ) if ( bEnabled )
{ {

View file

@ -125,9 +125,16 @@ public:
const QString& strServerInfo, const QString& strServerInfo,
CProtocol* pNConLProt ); CProtocol* pNConLProt );
void SetEnabled ( const bool bState ); // the update has to be called if any change to the server list
// properties was done
void Update();
void SetEnabled ( const bool bState ) { bEnabled = bState; }
bool GetEnabled() const { return bEnabled; } bool GetEnabled() const { return bEnabled; }
void SetCentralServerAddress ( const QString sNCentServAddr );
QString GetCentralServerAddress() { return strCentralServerAddress; }
bool GetIsCentralServer() const { return bIsCentralServer; } bool GetIsCentralServer() const { return bIsCentralServer; }
void RegisterServer ( const CHostAddress& InetAddr, void RegisterServer ( const CHostAddress& InetAddr,

View file

@ -193,11 +193,21 @@ void CSettings::ReadIniFile ( const QString& sFileName )
{ {
// server: // server:
// central server address
pServer->SetServerListCentralServerAddress (
GetIniSetting ( IniXMLDocument, "server", "centralservaddr" ) );
// server list enabled flag
if ( GetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", bValue ) )
{
pServer->SetServerListEnabled ( bValue );
}
// name // name
pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) ); pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
// city // city
pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "name" ) ); pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "city" ) );
// country // country
if ( GetNumericIniSet ( IniXMLDocument, "server", "country", if ( GetNumericIniSet ( IniXMLDocument, "server", "country",
@ -295,6 +305,14 @@ void CSettings::WriteIniFile ( const QString& sFileName )
{ {
// server: // server:
// central server address
PutIniSetting ( IniXMLDocument, "server", "centralservaddr",
pServer->GetServerListCentralServerAddress() );
// server list enabled flag
SetFlagIniSet ( IniXMLDocument, "server", "servlistenabled",
pServer->GetServerListEnabled() );
// name // name
PutIniSetting ( IniXMLDocument, "server", "name", PutIniSetting ( IniXMLDocument, "server", "name",
pServer->GetServerName() ); pServer->GetServerName() );