support for storing/recovering settings for the server in GUI mode

This commit is contained in:
Volker Fischer 2011-04-25 16:16:31 +00:00
parent 886251367b
commit 328dbd2b1c
6 changed files with 886 additions and 784 deletions

View file

@ -46,8 +46,9 @@
#define VERSION "3.1.3cvs"
#define APP_NAME "llcon"
// default name of the ini-file
// default names of the ini-file for client and server
#define DEFAULT_INI_FILE_NAME "llcon.ini"
#define DEFAULT_INI_FILE_NAME_SERVER "llconserver.ini"
// file name for logging file
#define DEFAULT_LOG_FILE_NAME "llconsrvlog.txt"

View file

@ -349,6 +349,10 @@ int main ( int argc, char** argv )
if ( bUseGUI )
{
// load settings from init-file
CSettings Settings ( &Server );
Settings.Load ( strIniFileName );
// GUI object for the server
CLlconServerDlg ServerDlg ( &Server, 0 );
@ -359,6 +363,9 @@ int main ( int argc, char** argv )
// show dialog
ServerDlg.show();
app.exec();
// save settings to init-file
Settings.Save ( strIniFileName );
}
else
{

View file

@ -126,6 +126,22 @@ public:
CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact );
void SetServerName ( const QString& strNewName )
{ ServerListManager.SetServerName ( strNewName ); }
QString GetServerName() { return ServerListManager.GetServerName(); }
void SetServerCity ( const QString& strNewCity )
{ ServerListManager.SetServerCity ( strNewCity ); }
QString GetServerCity() { return ServerListManager.GetServerCity(); }
void SetServerCountry ( const QLocale::Country eNewCountry )
{ ServerListManager.SetServerCountry ( eNewCountry ); }
QLocale::Country GetServerCountry()
{ return ServerListManager.GetServerCountry(); }
protected:
// access functions for actual channels
bool IsConnected ( const int iChanNum )

View file

@ -127,6 +127,7 @@ public:
void SetEnabled ( const bool bState );
bool GetEnabled() const { return bEnabled; }
bool GetIsCentralServer() const { return bIsCentralServer; }
void RegisterServer ( const CHostAddress& InetAddr,
@ -134,6 +135,25 @@ public:
void QueryServerList ( const CHostAddress& InetAddr );
// set server infos -> per definition the server info of this server is
// stored in the first entry of the list, we assume here that the first
// entry is correctly created in the constructor of the class
void SetServerName ( const QString& strNewName )
{ ServerList[0].strName = strNewName; }
QString GetServerName() { return ServerList[0].strName; }
void SetServerCity ( const QString& strNewCity )
{ ServerList[0].strCity = strNewCity; }
QString GetServerCity() { return ServerList[0].strCity; }
void SetServerCountry ( const QLocale::Country eNewCountry )
{ ServerList[0].eCountry = eNewCountry; }
QLocale::Country GetServerCountry() { return ServerList[0].eCountry; }
protected:
QTimer TimerPollList;
QTimer TimerRegistering;

View file

@ -45,6 +45,10 @@ void CSettings::ReadIniFile ( const QString& sFileName )
// Actual settings data ---------------------------------------------------
if ( bIsClient )
{
// client:
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
@ -85,9 +89,10 @@ void CSettings::ReadIniFile ( const QString& sFileName )
}
// sound card selection
// special case with this setting: the sound card initialization depends on this setting
// call, therefore, if no setting file parameter could be retrieved, the sound card is
// initialized with a default setting defined here
// special case with this setting: the sound card initialization depends
// on this setting call, therefore, if no setting file parameter could
// be retrieved, the sound card is initialized with a default setting
// defined here
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{
@ -95,8 +100,8 @@ void CSettings::ReadIniFile ( const QString& sFileName )
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
// device selection was done previously
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that
// no device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
}
@ -184,6 +189,24 @@ void CSettings::ReadIniFile ( const QString& sFileName )
pClient->SetUseStereo ( bValue );
}
}
else
{
// server:
// name
pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
// city
pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
// country
if ( GetNumericIniSet ( IniXMLDocument, "server", "country",
0, static_cast<int> ( QLocale::LastCountry ), iValue ) )
{
pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) );
}
}
}
void CSettings::WriteIniFile ( const QString& sFileName )
{
@ -192,6 +215,10 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// Actual settings data ---------------------------------------------------
if ( bIsClient )
{
// client:
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
@ -263,6 +290,23 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// flag whether stereo mode is used
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
pClient->GetUseStereo() );
}
else
{
// server:
// name
PutIniSetting ( IniXMLDocument, "server", "name",
pServer->GetServerName() );
// city
PutIniSetting ( IniXMLDocument, "server", "city",
pServer->GetServerCity() );
// country
SetNumericIniSet ( IniXMLDocument, "server", "country",
static_cast<int> ( pServer->GetServerCountry() ) );
}
// prepare file name for storing initialization data in XML file and store
// XML data in file
@ -274,6 +318,8 @@ void CSettings::WriteIniFile ( const QString& sFileName )
}
}
// Help functions **************************************************************
QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
{
// return the file name with complete path, take care if given file name is
@ -297,8 +343,15 @@ QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
}
// append the actual file name
if ( bIsClient )
{
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
}
else
{
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
}
}
return sCurFileName;
}

View file

@ -32,13 +32,15 @@
#include <qtextstream.h>
#include "global.h"
#include "client.h"
#include "server.h"
/* Classes ********************************************************************/
class CSettings
{
public:
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ) {}
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ), bIsClient ( true ) {}
CSettings ( CServer* pNSerP ) : pServer ( pNSerP ), bIsClient ( false ) {}
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
@ -66,8 +68,11 @@ protected:
void PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sValue = "" );
// pointer to the client object needed for the various settings
CClient* pClient;
// pointer to the client/server object which stores the various settings
CClient* pClient; // for client
CServer* pServer; // for server
bool bIsClient;
};
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )