From c08fe59a68f95e97691ccea5e4b15ea255e97ac4 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 30 Apr 2011 13:01:26 +0000 Subject: [PATCH] support for the new GUI controls in the server, net yet finished (still buggy) --- src/llconserverdlg.cpp | 81 ++++++++++++++++++++++++++++++++++++++- src/llconserverdlg.h | 5 +++ src/llconserverdlgbase.ui | 6 +-- src/main.cpp | 7 ++++ src/server.cpp | 5 --- src/server.h | 15 ++++++++ src/serverlist.cpp | 51 +++++++++++++----------- src/serverlist.h | 9 ++++- src/settings.cpp | 20 +++++++++- 9 files changed, 166 insertions(+), 33 deletions(-) diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index 7e9a02b3..9fb004c8 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -49,7 +49,11 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) vecpListViewItems[i] = new CServerListViewItem ( ListViewClients ); vecpListViewItems[i]->setHidden ( true ); } - + + // update central server name line edit + LineEditCentralServerAddress->setText ( + pServer->GetServerListCentralServerAddress() ); + // update server name line edit LineEditServerName->setText ( pServer->GetServerName() ); @@ -81,6 +85,16 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) ComboBoxLocationCountry->findData ( static_cast ( pServer->GetServerCountry() ) ) ); + // update register server check box + if ( pServer->GetServerListEnabled() ) + { + cbRegisterServer->setCheckState ( Qt::Checked ); + } + else + { + cbRegisterServer->setCheckState ( Qt::Unchecked ); + } + // Main menu bar ----------------------------------------------------------- pMenu = new QMenuBar ( this ); @@ -91,6 +105,25 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) // 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 QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) ); @@ -100,6 +133,52 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP, QWidget* parent ) 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 ( + ComboBoxLocationCountry->itemData ( iCntryListItem ).toInt() ) ); + + pServer->UpdateServerList(); +} + void CLlconServerDlg::OnTimer() { CVector vecHostAddresses; diff --git a/src/llconserverdlg.h b/src/llconserverdlg.h index 97db957f..4f1f0cbd 100755 --- a/src/llconserverdlg.h +++ b/src/llconserverdlg.h @@ -70,5 +70,10 @@ protected: void UpdateSliderNetBuf(); 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(); }; diff --git a/src/llconserverdlgbase.ui b/src/llconserverdlgbase.ui index a42b7a84..8c9f8742 100755 --- a/src/llconserverdlgbase.ui +++ b/src/llconserverdlgbase.ui @@ -52,7 +52,7 @@ - + Register Server @@ -68,7 +68,7 @@ - + Default @@ -80,7 +80,7 @@ - + Server Info diff --git a/src/main.cpp b/src/main.cpp index 7bff976c..e5e6daaf 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -353,6 +353,10 @@ int main ( int argc, char** argv ) CSettings Settings ( &Server ); Settings.Load ( strIniFileName ); + // update server list AFTER restoring the settings from the + // settings file + Server.UpdateServerList(); + // GUI object for the server CLlconServerDlg ServerDlg ( &Server, 0 ); @@ -369,6 +373,9 @@ int main ( int argc, char** argv ) } else { + // update serverlist + Server.UpdateServerList(); + // only start application without using the GUI tsConsole << CAboutDlg::GetVersionAndNameStr ( false ) << endl; diff --git a/src/server.cpp b/src/server.cpp index 3defa8bd..647833b2 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -383,11 +383,6 @@ CServer::CServer ( const QString& strLoggingFileName, 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[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 vecMessage ) diff --git a/src/server.h b/src/server.h index 0f81df50..67681671 100755 --- a/src/server.h +++ b/src/server.h @@ -126,6 +126,21 @@ public: CVector& veciJitBufNumFrames, CVector& 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 ) { ServerListManager.SetServerName ( strNewName ); } diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 0f02d31b..4c4d1a91 100755 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -29,27 +29,10 @@ CServerListManager::CServerListManager ( const QString& sNCentServAddr, const QString& strServerInfo, CProtocol* pNConLProt ) - : strCentralServerAddress ( sNCentServAddr ), - pConnLessProtocol ( pNConLProt ) + : pConnLessProtocol ( pNConLProt ) { - // 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; - } + // set the central server address + SetCentralServerAddress ( sNCentServAddr ); // per definition, the very first entry is this server and this entry will // never be deleted @@ -105,11 +88,35 @@ CServerListManager::CServerListManager ( const QString& sNCentServAddr, this, SLOT ( OnTimerRegistering() ) ); } -void CServerListManager::SetEnabled ( const bool bState ) +void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr ) { 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 ) { diff --git a/src/serverlist.h b/src/serverlist.h index 3ebf049a..6c12afea 100755 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -125,9 +125,16 @@ public: const QString& strServerInfo, 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; } + void SetCentralServerAddress ( const QString sNCentServAddr ); + QString GetCentralServerAddress() { return strCentralServerAddress; } + bool GetIsCentralServer() const { return bIsCentralServer; } void RegisterServer ( const CHostAddress& InetAddr, diff --git a/src/settings.cpp b/src/settings.cpp index dfec9489..7ab6b719 100755 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -193,11 +193,21 @@ void CSettings::ReadIniFile ( const QString& sFileName ) { // server: + // central server address + pServer->SetServerListCentralServerAddress ( + GetIniSetting ( IniXMLDocument, "server", "centralservaddr" ) ); + + // server list enabled flag + if ( GetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", bValue ) ) + { + pServer->SetServerListEnabled ( bValue ); + } + // name pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) ); // city - pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "name" ) ); + pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "city" ) ); // country if ( GetNumericIniSet ( IniXMLDocument, "server", "country", @@ -295,6 +305,14 @@ void CSettings::WriteIniFile ( const QString& sFileName ) { // server: + // central server address + PutIniSetting ( IniXMLDocument, "server", "centralservaddr", + pServer->GetServerListCentralServerAddress() ); + + // server list enabled flag + SetFlagIniSet ( IniXMLDocument, "server", "servlistenabled", + pServer->GetServerListEnabled() ); + // name PutIniSetting ( IniXMLDocument, "server", "name", pServer->GetServerName() );