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,144 +45,167 @@ void CSettings::ReadIniFile ( const QString& sFileName )
// Actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
if ( bIsClient )
{
QString sDefaultIP = "";
// client:
// use default only for first entry
if ( iIPAddrIdx == 0 )
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
sDefaultIP = DEFAULT_SERVER_ADDRESS;
QString sDefaultIP = "";
// use default only for first entry
if ( iIPAddrIdx == 0 )
{
sDefaultIP = DEFAULT_SERVER_ADDRESS;
}
pClient->vstrIPAddress[iIPAddrIdx] =
GetIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP );
}
pClient->vstrIPAddress[iIPAddrIdx] =
GetIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP );
}
// name
pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" );
// name
pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" );
// audio fader
if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad",
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) )
{
pClient->SetAudioInFader ( iValue );
}
// audio fader
if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad",
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) )
{
pClient->SetAudioInFader ( iValue );
}
// reverberation level
if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev",
0, AUD_REVERB_MAX, iValue ) )
{
pClient->SetReverbLevel ( iValue );
}
// reverberation level
if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev",
0, AUD_REVERB_MAX, iValue ) )
{
pClient->SetReverbLevel ( iValue );
}
// reverberation channel assignment
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) )
{
pClient->SetReverbOnLeftChan ( bValue );
}
// reverberation channel assignment
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) )
{
pClient->SetReverbOnLeftChan ( bValue );
}
// 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
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{
pClient->SetSndCrdDev ( iValue );
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that
// no device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
}
// 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
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{
pClient->SetSndCrdDev ( iValue );
// sound card channel mapping settings: make sure these settings are
// set AFTER the sound card device is set, otherwise the settings are
// overwritten by the defaults
//
// sound card left input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdLeftInputChannel ( iValue );
}
// sound card right input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdRightInputChannel ( iValue );
}
// sound card left output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdLeftOutputChannel ( iValue );
}
// sound card right output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdRightOutputChannel ( iValue );
}
// sound card preferred buffer size index
if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) )
{
// additional check required since only a subset of factors are
// defined
if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) ||
( iValue == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iValue == FRAME_SIZE_FACTOR_SAFE ) )
{
pClient->SetSndCrdPrefFrameSizeFactor ( iValue );
}
}
// automatic network jitter buffer size setting
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
{
pClient->SetDoAutoSockBufSize ( bValue );
}
// network jitter buffer size
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
{
pClient->SetSockBufNumFrames ( iValue );
}
// flag whether the chat window shall be opened on a new chat message
if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) )
{
pClient->SetOpenChatOnNewMessage ( bValue );
}
// GUI design
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign",
0, 1 /* GD_ORIGINAL */, iValue ) )
{
pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
}
// flag whether using high quality audio or not
if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) )
{
pClient->SetCELTHighQuality ( bValue );
}
// flag whether stereo mode is used
if ( GetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", bValue ) )
{
pClient->SetUseStereo ( bValue );
}
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
// device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
}
// server:
// sound card channel mapping settings: make sure these settings are
// set AFTER the sound card device is set, otherwise the settings are
// overwritten by the defaults
//
// sound card left input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdLeftInputChannel ( iValue );
}
// name
pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
// sound card right input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdRightInputChannel ( iValue );
}
// city
pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
// sound card left output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdLeftOutputChannel ( iValue );
}
// sound card right output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
{
pClient->SetSndCrdRightOutputChannel ( iValue );
}
// sound card preferred buffer size index
if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) )
{
// additional check required since only a subset of factors are
// defined
if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) ||
( iValue == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iValue == FRAME_SIZE_FACTOR_SAFE ) )
// country
if ( GetNumericIniSet ( IniXMLDocument, "server", "country",
0, static_cast<int> ( QLocale::LastCountry ), iValue ) )
{
pClient->SetSndCrdPrefFrameSizeFactor ( iValue );
pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) );
}
}
// automatic network jitter buffer size setting
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
{
pClient->SetDoAutoSockBufSize ( bValue );
}
// network jitter buffer size
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
{
pClient->SetSockBufNumFrames ( iValue );
}
// flag whether the chat window shall be opened on a new chat message
if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) )
{
pClient->SetOpenChatOnNewMessage ( bValue );
}
// GUI design
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign",
0, 1 /* GD_ORIGINAL */, iValue ) )
{
pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
}
// flag whether using high quality audio or not
if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) )
{
pClient->SetCELTHighQuality ( bValue );
}
// flag whether stereo mode is used
if ( GetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", bValue ) )
{
pClient->SetUseStereo ( bValue );
}
}
void CSettings::WriteIniFile ( const QString& sFileName )
@ -192,77 +215,98 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// Actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
if ( bIsClient )
{
PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ),
pClient->vstrIPAddress[iIPAddrIdx] );
// client:
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ),
pClient->vstrIPAddress[iIPAddrIdx] );
}
// name
PutIniSetting ( IniXMLDocument, "client", "name",
pClient->strName );
// audio fader
SetNumericIniSet ( IniXMLDocument, "client", "audfad",
pClient->GetAudioInFader() );
// reverberation level
SetNumericIniSet ( IniXMLDocument, "client", "revlev",
pClient->GetReverbLevel() );
// reverberation channel assignment
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
pClient->IsReverbOnLeftChan() );
// sound card selection
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
pClient->GetSndCrdDev() );
// sound card left input channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
pClient->GetSndCrdLeftInputChannel() );
// sound card right input channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
pClient->GetSndCrdRightInputChannel() );
// sound card left output channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
pClient->GetSndCrdLeftOutputChannel() );
// sound card right output channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
pClient->GetSndCrdRightOutputChannel() );
// sound card preferred buffer size index
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
pClient->GetSndCrdPrefFrameSizeFactor() );
// automatic network jitter buffer size setting
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
pClient->GetDoAutoSockBufSize() );
// network jitter buffer size
SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
pClient->GetSockBufNumFrames() );
// flag whether the chat window shall be opened on a new chat message
SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
pClient->GetOpenChatOnNewMessage() );
// GUI design
SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
static_cast<int> ( pClient->GetGUIDesign() ) );
// flag whether using high quality audio or not
SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio",
pClient->GetCELTHighQuality() );
// flag whether stereo mode is used
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
pClient->GetUseStereo() );
}
else
{
// server:
// name
PutIniSetting ( IniXMLDocument, "client", "name",
pClient->strName );
// name
PutIniSetting ( IniXMLDocument, "server", "name",
pServer->GetServerName() );
// audio fader
SetNumericIniSet ( IniXMLDocument, "client", "audfad",
pClient->GetAudioInFader() );
// city
PutIniSetting ( IniXMLDocument, "server", "city",
pServer->GetServerCity() );
// reverberation level
SetNumericIniSet ( IniXMLDocument, "client", "revlev",
pClient->GetReverbLevel() );
// reverberation channel assignment
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
pClient->IsReverbOnLeftChan() );
// sound card selection
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
pClient->GetSndCrdDev() );
// sound card left input channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
pClient->GetSndCrdLeftInputChannel() );
// sound card right input channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
pClient->GetSndCrdRightInputChannel() );
// sound card left output channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
pClient->GetSndCrdLeftOutputChannel() );
// sound card right output channel mapping
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
pClient->GetSndCrdRightOutputChannel() );
// sound card preferred buffer size index
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
pClient->GetSndCrdPrefFrameSizeFactor() );
// automatic network jitter buffer size setting
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
pClient->GetDoAutoSockBufSize() );
// network jitter buffer size
SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
pClient->GetSockBufNumFrames() );
// flag whether the chat window shall be opened on a new chat message
SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
pClient->GetOpenChatOnNewMessage() );
// GUI design
SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
static_cast<int> ( pClient->GetGUIDesign() ) );
// flag whether using high quality audio or not
SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio",
pClient->GetCELTHighQuality() );
// flag whether stereo mode is used
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
pClient->GetUseStereo() );
// 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,7 +343,14 @@ QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
}
// append the actual file name
sCurFileName = sConfigDir + "/" + DEFAULT_INI_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_ )