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

@ -1,287 +1,288 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#if !defined ( GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_ ) #if !defined ( GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_ )
#define GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_ #define GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_
#include <qstring.h> #include <qstring.h>
#include <qevent.h> #include <qevent.h>
#include <qdebug.h> #include <qdebug.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <string> #include <string>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
/* Definitions ****************************************************************/ /* Definitions ****************************************************************/
// define this macro to get debug output // define this macro to get debug output
//#define _DEBUG_ //#define _DEBUG_
#undef _DEBUG_ #undef _DEBUG_
// version and application name (always use this version) // version and application name (always use this version)
#undef VERSION #undef VERSION
#define VERSION "3.1.3cvs" #define VERSION "3.1.3cvs"
#define APP_NAME "llcon" #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 "llcon.ini"
#define DEFAULT_INI_FILE_NAME_SERVER "llconserver.ini"
// file name for logging file
#define DEFAULT_LOG_FILE_NAME "llconsrvlog.txt" // file name for logging file
#define DEFAULT_LOG_FILE_NAME "llconsrvlog.txt"
// default server address
#define DEFAULT_SERVER_ADDRESS "llcon.dyndns.org" // default server address
#define DEFAULT_SERVER_ADDRESS "llcon.dyndns.org"
// download URL
#define LLCON_DOWNLOAD_URL "http://sourceforge.net/projects/llcon/files" // download URL
#define LLCON_DOWNLOAD_URL "http://sourceforge.net/projects/llcon/files"
// defined port number for client and server
#define LLCON_DEFAULT_PORT_NUMBER 22124 // defined port number for client and server
#define LLCON_DEFAULT_PORT_NUMBER 22124
// system sample rate (the sound card and audio coder works on this sample rate)
#define SYSTEM_SAMPLE_RATE_HZ 48000 // Hz // system sample rate (the sound card and audio coder works on this sample rate)
#define SYSTEM_SAMPLE_RATE_HZ 48000 // Hz
// System block size, this is the block size on which the audio coder works.
// All other block sizes must be a multiple of this size // System block size, this is the block size on which the audio coder works.
#define SYSTEM_FRAME_SIZE_SAMPLES 128 // All other block sizes must be a multiple of this size
#define SYSTEM_FRAME_SIZE_SAMPLES 128
#define SYSTEM_BLOCK_DURATION_MS_FLOAT \
( static_cast<double> ( SYSTEM_FRAME_SIZE_SAMPLES ) / \ #define SYSTEM_BLOCK_DURATION_MS_FLOAT \
SYSTEM_SAMPLE_RATE_HZ * 1000 ) ( static_cast<double> ( SYSTEM_FRAME_SIZE_SAMPLES ) / \
SYSTEM_SAMPLE_RATE_HZ * 1000 )
// define the allowed audio frame size factors (since the
// "SYSTEM_FRAME_SIZE_SAMPLES" is quite small, it may be that on some // define the allowed audio frame size factors (since the
// computers a larger value is required) // "SYSTEM_FRAME_SIZE_SAMPLES" is quite small, it may be that on some
#define FRAME_SIZE_FACTOR_PREFERRED 1 // 128 (for frame size 128) // computers a larger value is required)
#define FRAME_SIZE_FACTOR_DEFAULT 2 // 256 (for frame size 128) #define FRAME_SIZE_FACTOR_PREFERRED 1 // 128 (for frame size 128)
#define FRAME_SIZE_FACTOR_SAFE 4 // 512 (for frame size 128) #define FRAME_SIZE_FACTOR_DEFAULT 2 // 256 (for frame size 128)
#define FRAME_SIZE_FACTOR_SAFE 4 // 512 (for frame size 128)
// low complexity CELT encoder (if defined)
#define USE_LOW_COMPLEXITY_CELT_ENC // low complexity CELT encoder (if defined)
#define USE_LOW_COMPLEXITY_CELT_ENC
// define the maximum mono audio buffer size at a sample rate
// of 48 kHz, this is important for defining the maximum number // define the maximum mono audio buffer size at a sample rate
// of bytes to be expected from the network interface // of 48 kHz, this is important for defining the maximum number
#define MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ 4096 // of bytes to be expected from the network interface
#define MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ 4096
// Maximum block size for network input buffer. Consider a maximum sample rate
// of 48 kHz and two audio channels and two bytes per sample. // Maximum block size for network input buffer. Consider a maximum sample rate
#define MAX_SIZE_BYTES_NETW_BUF ( MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ * 4 ) // of 48 kHz and two audio channels and two bytes per sample.
#define MAX_SIZE_BYTES_NETW_BUF ( MAX_MONO_AUD_BUFF_SIZE_AT_48KHZ * 4 )
// minimum/maximum network buffer size (which can be chosen by slider)
#define MIN_NET_BUF_SIZE_NUM_BL 1 // number of blocks // minimum/maximum network buffer size (which can be chosen by slider)
#define MAX_NET_BUF_SIZE_NUM_BL 20 // number of blocks #define MIN_NET_BUF_SIZE_NUM_BL 1 // number of blocks
#define MAX_NET_BUF_SIZE_NUM_BL 20 // number of blocks
// default network buffer size
#define DEF_NET_BUF_SIZE_NUM_BL 10 // number of blocks // default network buffer size
#define DEF_NET_BUF_SIZE_NUM_BL 10 // number of blocks
// maximum number of recognized sound cards installed in the system,
// definition for "no device" // maximum number of recognized sound cards installed in the system,
#define MAX_NUMBER_SOUND_CARDS 10 // definition for "no device"
#define INVALID_SNC_CARD_DEVICE -1 #define MAX_NUMBER_SOUND_CARDS 10
#define INVALID_SNC_CARD_DEVICE -1
// define the maximum number of audio channel for input/output we can store
// channel infos for (and therefore this is the maximum number of entries in // define the maximum number of audio channel for input/output we can store
// the channel selection combo box regardless of the actual available number // channel infos for (and therefore this is the maximum number of entries in
// of channels by the audio device) // the channel selection combo box regardless of the actual available number
#define MAX_NUM_IN_OUT_CHANNELS 32 // of channels by the audio device)
#define MAX_NUM_IN_OUT_CHANNELS 32
// maximum number of elemts in the server address combo box
#define MAX_NUM_SERVER_ADDR_ITEMS 6 // maximum number of elemts in the server address combo box
#define MAX_NUM_SERVER_ADDR_ITEMS 6
// defines for LED input level meter
#define NUM_STEPS_INP_LEV_METER 8 // defines for LED input level meter
#define RED_BOUND_INP_LEV_METER 7 #define NUM_STEPS_INP_LEV_METER 8
#define YELLOW_BOUND_INP_LEV_METER 5 #define RED_BOUND_INP_LEV_METER 7
#define YELLOW_BOUND_INP_LEV_METER 5
// maximum number of internet connections (channels)
// if you want to change this paramter, there has to be done code modifications // maximum number of internet connections (channels)
// on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places // if you want to change this paramter, there has to be done code modifications
// (just search for the tag in the entire code) // on other places, too! The code tag "MAX_NUM_CHANNELS_TAG" shows these places
#define MAX_NUM_CHANNELS 12 // max number channels for server // (just search for the tag in the entire code)
#define MAX_NUM_CHANNELS 12 // max number channels for server
// actual number of used channels in the server
// this parameter can safely be changed from 1 to MAX_NUM_CHANNELS // actual number of used channels in the server
// without any other changes in the code // this parameter can safely be changed from 1 to MAX_NUM_CHANNELS
#define USED_NUM_CHANNELS 6 // used number channels for server // without any other changes in the code
#define USED_NUM_CHANNELS 6 // used number channels for server
// maximum number of servers registered in the server list
#define MAX_NUM_SERVERS_IN_SERVER_LIST 100 // maximum number of servers registered in the server list
#define MAX_NUM_SERVERS_IN_SERVER_LIST 100
// defines the time interval at which the ping time is updated in the GUI
#define PING_UPDATE_TIME_MS 500 // ms // defines the time interval at which the ping time is updated in the GUI
#define PING_UPDATE_TIME_MS 500 // ms
// defines the time interval at which the ping time is updated for the server
// list // defines the time interval at which the ping time is updated for the server
#define PING_UPDATE_TIME_SERVER_LIST_MS 2000 // ms // list
#define PING_UPDATE_TIME_SERVER_LIST_MS 2000 // ms
// time-out until a registered server is deleted from the server list if no
// new registering was made in minutes // time-out until a registered server is deleted from the server list if no
#define SERVLIST_TIME_OUT_MINUTES 60 // minutes // new registering was made in minutes
#define SERVLIST_TIME_OUT_MINUTES 60 // minutes
// poll time for server list (to check if entries are time-out)
#define SERVLIST_POLL_TIME_MINUTES 1 // minute // poll time for server list (to check if entries are time-out)
#define SERVLIST_POLL_TIME_MINUTES 1 // minute
// time until a slave server registers in the server list
#define SERVLIST_REGIST_INTERV_MINUTES 30 // minutes // time until a slave server registers in the server list
#define SERVLIST_REGIST_INTERV_MINUTES 30 // minutes
// length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE_SECONDS 30 // seconds // length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE_SECONDS 30 // seconds
// Maximum length of fader tag and text message strings (Since for chat messages
// some HTML code is added, we also have to define a second length which includes // Maximum length of fader tag and text message strings (Since for chat messages
// this additionl HTML code. Right now the length of the HTML code is approx. 66 // some HTML code is added, we also have to define a second length which includes
// character. Here, we add some headroom to this number) // this additionl HTML code. Right now the length of the HTML code is approx. 66
#define MAX_LEN_FADER_TAG 16 // character. Here, we add some headroom to this number)
#define MAX_LEN_CHAT_TEXT 1600 #define MAX_LEN_FADER_TAG 16
#define MAX_LEN_CHAT_TEXT_PLUS_HTML 1800 #define MAX_LEN_CHAT_TEXT 1600
#define MAX_LEN_SERVER_NAME 20 #define MAX_LEN_CHAT_TEXT_PLUS_HTML 1800
#define MAX_LEN_SERVER_TOPIC 32 #define MAX_LEN_SERVER_NAME 20
#define MAX_LEN_SERVER_CITY 20 #define MAX_LEN_SERVER_TOPIC 32
#define MAX_LEN_SERVER_CITY 20
// common tool tip bottom line text
#define TOOLTIP_COM_END_TEXT tr ( \ // common tool tip bottom line text
"<br><div align=right><font size=-1><i>" \ #define TOOLTIP_COM_END_TEXT tr ( \
"For more information use the ""What's " \ "<br><div align=right><font size=-1><i>" \
"This"" help (? menu, right mouse button or Shift+F1)" \ "For more information use the ""What's " \
"</i></font></div>" ) "This"" help (? menu, right mouse button or Shift+F1)" \
"</i></font></div>" )
#define _MAXSHORT 32767
#define _MAXBYTE 255 // binary: 11111111 #define _MAXSHORT 32767
#define _MINSHORT ( -32768 ) #define _MAXBYTE 255 // binary: 11111111
#define _MINSHORT ( -32768 )
#if HAVE_STDINT_H
# include <stdint.h> #if HAVE_STDINT_H
#elif HAVE_INTTYPES_H # include <stdint.h>
# include <inttypes.h> #elif HAVE_INTTYPES_H
#elif defined ( _WIN32 ) # include <inttypes.h>
typedef __int64 int64_t; #elif defined ( _WIN32 )
typedef __int32 int32_t; typedef __int64 int64_t;
typedef __int16 int16_t; typedef __int32 int32_t;
typedef unsigned __int64 uint64_t; typedef __int16 int16_t;
typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t;
typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t;
#else typedef unsigned __int8 uint8_t;
typedef long long int64_t; #else
typedef int int32_t; typedef long long int64_t;
typedef short int16_t; typedef int int32_t;
typedef unsigned long long uint64_t; typedef short int16_t;
typedef unsigned int uint32_t; typedef unsigned long long uint64_t;
typedef unsigned short uint16_t; typedef unsigned int uint32_t;
typedef unsigned char uint8_t; typedef unsigned short uint16_t;
#endif typedef unsigned char uint8_t;
#endif
/* Definitions for window message system ------------------------------------ */
typedef unsigned int _MESSAGE_IDENT; /* Definitions for window message system ------------------------------------ */
#define MS_RESET_ALL 0 // MS: Message typedef unsigned int _MESSAGE_IDENT;
#define MS_SOUND_IN 1 #define MS_RESET_ALL 0 // MS: Message
#define MS_SOUND_OUT 2 #define MS_SOUND_IN 1
#define MS_JIT_BUF_PUT 3 #define MS_SOUND_OUT 2
#define MS_JIT_BUF_GET 4 #define MS_JIT_BUF_PUT 3
#define MS_PACKET_RECEIVED 5 #define MS_JIT_BUF_GET 4
#define MS_ERROR_IN_THREAD 6 #define MS_PACKET_RECEIVED 5
#define MS_SET_JIT_BUF_SIZE 7 #define MS_ERROR_IN_THREAD 6
#define MS_SET_JIT_BUF_SIZE 7
#define MUL_COL_LED_RED 0
#define MUL_COL_LED_YELLOW 1 #define MUL_COL_LED_RED 0
#define MUL_COL_LED_GREEN 2 #define MUL_COL_LED_YELLOW 1
#define MUL_COL_LED_GREEN 2
/* Classes ********************************************************************/
class CGenErr /* Classes ********************************************************************/
{ class CGenErr
public: {
CGenErr ( QString strNewErrorMsg, QString strNewErrorType = "" ) : public:
strErrorMsg ( strNewErrorMsg ), strErrorType ( strNewErrorType ) {} CGenErr ( QString strNewErrorMsg, QString strNewErrorType = "" ) :
strErrorMsg ( strNewErrorMsg ), strErrorType ( strNewErrorType ) {}
QString GetErrorText()
{ QString GetErrorText()
// return formatted error text {
if ( strErrorType.isEmpty() ) // return formatted error text
{ if ( strErrorType.isEmpty() )
return strErrorMsg; {
} return strErrorMsg;
else }
{ else
return strErrorType + ": " + strErrorMsg; {
} return strErrorType + ": " + strErrorMsg;
} }
}
protected:
QString strErrorMsg; protected:
QString strErrorType; QString strErrorMsg;
}; QString strErrorType;
};
class CLlconEvent : public QEvent
{ class CLlconEvent : public QEvent
public: {
CLlconEvent ( int iNewMeTy, int iNewSt, int iNewChN = 0 ) : public:
QEvent ( QEvent::Type ( QEvent::User + 11 ) ), iMessType ( iNewMeTy ), iStatus ( iNewSt ), CLlconEvent ( int iNewMeTy, int iNewSt, int iNewChN = 0 ) :
iChanNum ( iNewChN ) {} QEvent ( QEvent::Type ( QEvent::User + 11 ) ), iMessType ( iNewMeTy ), iStatus ( iNewSt ),
iChanNum ( iNewChN ) {}
int iMessType;
int iStatus; int iMessType;
int iChanNum; int iStatus;
}; int iChanNum;
};
/* Prototypes for global functions ********************************************/
// command line parsing, TODO do not declare functions globally but in a class /* Prototypes for global functions ********************************************/
QString UsageArguments ( char** argv ); // command line parsing, TODO do not declare functions globally but in a class
QString UsageArguments ( char** argv );
bool GetFlagArgument ( char** argv,
int& i, bool GetFlagArgument ( char** argv,
QString strShortOpt, int& i,
QString strLongOpt ); QString strShortOpt,
QString strLongOpt );
bool GetStringArgument ( QTextStream& tsConsole,
int argc, bool GetStringArgument ( QTextStream& tsConsole,
char** argv, int argc,
int& i, char** argv,
QString strShortOpt, int& i,
QString strLongOpt, QString strShortOpt,
QString& strArg ); QString strLongOpt,
QString& strArg );
bool GetNumericArgument ( QTextStream& tsConsole,
int argc, bool GetNumericArgument ( QTextStream& tsConsole,
char** argv, int argc,
int& i, char** argv,
QString strShortOpt, int& i,
QString strLongOpt, QString strShortOpt,
double rRangeStart, QString strLongOpt,
double rRangeStop, double rRangeStart,
double& rValue); double rRangeStop,
double& rValue);
// posting a window message
void PostWinMessage ( const _MESSAGE_IDENT MessID, // posting a window message
const int iMessageParam = 0, void PostWinMessage ( const _MESSAGE_IDENT MessID,
const int iChanNum = 0 ); const int iMessageParam = 0,
const int iChanNum = 0 );
#endif /* !defined ( GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_ ) */
#endif /* !defined ( GLOBAL_H__3B123453_4344_BB2B_23E7A0D31912__INCLUDED_ ) */

View File

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

View File

@ -126,6 +126,22 @@ public:
CVector<int>& veciJitBufNumFrames, CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact ); 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: protected:
// access functions for actual channels // access functions for actual channels
bool IsConnected ( const int iChanNum ) bool IsConnected ( const int iChanNum )

View File

@ -127,6 +127,7 @@ public:
void SetEnabled ( const bool bState ); void SetEnabled ( const bool bState );
bool GetEnabled() const { return bEnabled; } bool GetEnabled() const { return bEnabled; }
bool GetIsCentralServer() const { return bIsCentralServer; } bool GetIsCentralServer() const { return bIsCentralServer; }
void RegisterServer ( const CHostAddress& InetAddr, void RegisterServer ( const CHostAddress& InetAddr,
@ -134,6 +135,25 @@ public:
void QueryServerList ( const CHostAddress& InetAddr ); 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: protected:
QTimer TimerPollList; QTimer TimerPollList;
QTimer TimerRegistering; QTimer TimerRegistering;

View File

@ -1,424 +1,477 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#include "settings.h" #include "settings.h"
/* Implementation *************************************************************/ /* Implementation *************************************************************/
void CSettings::ReadIniFile ( const QString& sFileName ) void CSettings::ReadIniFile ( const QString& sFileName )
{ {
int iValue; int iValue;
bool bValue; bool bValue;
QDomDocument IniXMLDocument; QDomDocument IniXMLDocument;
// prepare file name for loading initialization data from XML file and read // prepare file name for loading initialization data from XML file and read
// data from file if possible // data from file if possible
QFile file ( GetIniFileNameWithPath ( sFileName ) ); QFile file ( GetIniFileNameWithPath ( sFileName ) );
if ( file.open ( QIODevice::ReadOnly ) ) if ( file.open ( QIODevice::ReadOnly ) )
{ {
QTextStream in ( &file ); QTextStream in ( &file );
IniXMLDocument.setContent ( in.readAll(), false ); IniXMLDocument.setContent ( in.readAll(), false );
file.close(); file.close();
} }
// Actual settings data --------------------------------------------------- // Actual settings data ---------------------------------------------------
// IP addresses if ( bIsClient )
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ ) {
{ // client:
QString sDefaultIP = "";
// IP addresses
// use default only for first entry for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
if ( iIPAddrIdx == 0 ) {
{ QString sDefaultIP = "";
sDefaultIP = DEFAULT_SERVER_ADDRESS;
} // use default only for first entry
if ( iIPAddrIdx == 0 )
pClient->vstrIPAddress[iIPAddrIdx] = {
GetIniSetting ( IniXMLDocument, "client", sDefaultIP = DEFAULT_SERVER_ADDRESS;
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP ); }
}
pClient->vstrIPAddress[iIPAddrIdx] =
// name GetIniSetting ( IniXMLDocument, "client",
pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" ); QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP );
}
// audio fader
if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad", // name
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) ) pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" );
{
pClient->SetAudioInFader ( iValue ); // audio fader
} if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad",
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) )
// reverberation level {
if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev", pClient->SetAudioInFader ( iValue );
0, AUD_REVERB_MAX, iValue ) ) }
{
pClient->SetReverbLevel ( iValue ); // reverberation level
} if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev",
0, AUD_REVERB_MAX, iValue ) )
// reverberation channel assignment {
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) ) pClient->SetReverbLevel ( iValue );
{ }
pClient->SetReverbOnLeftChan ( bValue );
} // reverberation channel assignment
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) )
// sound card selection {
// special case with this setting: the sound card initialization depends on this setting pClient->SetReverbOnLeftChan ( bValue );
// 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", // sound card selection
1, MAX_NUMBER_SOUND_CARDS, iValue ) ) // special case with this setting: the sound card initialization depends
{ // on this setting call, therefore, if no setting file parameter could
pClient->SetSndCrdDev ( iValue ); // be retrieved, the sound card is initialized with a default setting
} // defined here
else if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
{ 1, MAX_NUMBER_SOUND_CARDS, iValue ) )
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no {
// device selection was done previously pClient->SetSndCrdDev ( iValue );
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE ); }
} else
{
// sound card channel mapping settings: make sure these settings are // use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that
// set AFTER the sound card device is set, otherwise the settings are // no device selection was done previously
// overwritten by the defaults pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
// }
// sound card left input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch", // sound card channel mapping settings: make sure these settings are
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) // set AFTER the sound card device is set, otherwise the settings are
{ // overwritten by the defaults
pClient->SetSndCrdLeftInputChannel ( iValue ); //
} // sound card left input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
// sound card right input channel mapping 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch", {
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) pClient->SetSndCrdLeftInputChannel ( iValue );
{ }
pClient->SetSndCrdRightInputChannel ( iValue );
} // sound card right input channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
// sound card left output channel mapping 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch", {
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) pClient->SetSndCrdRightInputChannel ( iValue );
{ }
pClient->SetSndCrdLeftOutputChannel ( iValue );
} // sound card left output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
// sound card right output channel mapping 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch", {
0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) ) pClient->SetSndCrdLeftOutputChannel ( iValue );
{ }
pClient->SetSndCrdRightOutputChannel ( iValue );
} // sound card right output channel mapping
if ( GetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
// sound card preferred buffer size index 0, MAX_NUM_IN_OUT_CHANNELS - 1, iValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", {
FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) ) pClient->SetSndCrdRightOutputChannel ( iValue );
{ }
// additional check required since only a subset of factors are
// defined // sound card preferred buffer size index
if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) || if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
( iValue == FRAME_SIZE_FACTOR_DEFAULT ) || FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) )
( iValue == FRAME_SIZE_FACTOR_SAFE ) ) {
{ // additional check required since only a subset of factors are
pClient->SetSndCrdPrefFrameSizeFactor ( iValue ); // defined
} if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) ||
} ( iValue == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iValue == FRAME_SIZE_FACTOR_SAFE ) )
// automatic network jitter buffer size setting {
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) ) pClient->SetSndCrdPrefFrameSizeFactor ( iValue );
{ }
pClient->SetDoAutoSockBufSize ( bValue ); }
}
// automatic network jitter buffer size setting
// network jitter buffer size if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf", {
MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) ) pClient->SetDoAutoSockBufSize ( bValue );
{ }
pClient->SetSockBufNumFrames ( iValue );
} // network jitter buffer size
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
// flag whether the chat window shall be opened on a new chat message MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) ) {
{ pClient->SetSockBufNumFrames ( iValue );
pClient->SetOpenChatOnNewMessage ( bValue ); }
}
// flag whether the chat window shall be opened on a new chat message
// GUI design if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) )
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign", {
0, 1 /* GD_ORIGINAL */, iValue ) ) pClient->SetOpenChatOnNewMessage ( bValue );
{ }
pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
} // GUI design
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign",
// flag whether using high quality audio or not 0, 1 /* GD_ORIGINAL */, iValue ) )
if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) ) {
{ pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
pClient->SetCELTHighQuality ( bValue ); }
}
// flag whether using high quality audio or not
// flag whether stereo mode is used if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) )
if ( GetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", bValue ) ) {
{ pClient->SetCELTHighQuality ( bValue );
pClient->SetUseStereo ( bValue ); }
}
} // flag whether stereo mode is used
if ( GetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", bValue ) )
void CSettings::WriteIniFile ( const QString& sFileName ) {
{ pClient->SetUseStereo ( bValue );
// create XML document for storing initialization parameters }
QDomDocument IniXMLDocument; }
else
{
// Actual settings data --------------------------------------------------- // server:
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ ) // name
{ pServer->SetServerName ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), // city
pClient->vstrIPAddress[iIPAddrIdx] ); pServer->SetServerCity ( GetIniSetting ( IniXMLDocument, "server", "name" ) );
}
// country
// name if ( GetNumericIniSet ( IniXMLDocument, "server", "country",
PutIniSetting ( IniXMLDocument, "client", "name", 0, static_cast<int> ( QLocale::LastCountry ), iValue ) )
pClient->strName ); {
pServer->SetServerCountry ( static_cast<QLocale::Country> ( iValue ) );
// audio fader }
SetNumericIniSet ( IniXMLDocument, "client", "audfad", }
pClient->GetAudioInFader() ); }
// reverberation level void CSettings::WriteIniFile ( const QString& sFileName )
SetNumericIniSet ( IniXMLDocument, "client", "revlev", {
pClient->GetReverbLevel() ); // create XML document for storing initialization parameters
QDomDocument IniXMLDocument;
// reverberation channel assignment
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
pClient->IsReverbOnLeftChan() ); // Actual settings data ---------------------------------------------------
if ( bIsClient )
// sound card selection {
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx", // client:
pClient->GetSndCrdDev() );
// IP addresses
// sound card left input channel mapping for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch", {
pClient->GetSndCrdLeftInputChannel() ); PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ),
// sound card right input channel mapping pClient->vstrIPAddress[iIPAddrIdx] );
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch", }
pClient->GetSndCrdRightInputChannel() );
// name
// sound card left output channel mapping PutIniSetting ( IniXMLDocument, "client", "name",
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch", pClient->strName );
pClient->GetSndCrdLeftOutputChannel() );
// audio fader
// sound card right output channel mapping SetNumericIniSet ( IniXMLDocument, "client", "audfad",
SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch", pClient->GetAudioInFader() );
pClient->GetSndCrdRightOutputChannel() );
// reverberation level
// sound card preferred buffer size index SetNumericIniSet ( IniXMLDocument, "client", "revlev",
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx", pClient->GetReverbLevel() );
pClient->GetSndCrdPrefFrameSizeFactor() );
// reverberation channel assignment
// automatic network jitter buffer size setting SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", pClient->IsReverbOnLeftChan() );
pClient->GetDoAutoSockBufSize() );
// sound card selection
// network jitter buffer size SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
SetNumericIniSet ( IniXMLDocument, "client", "jitbuf", pClient->GetSndCrdDev() );
pClient->GetSockBufNumFrames() );
// sound card left input channel mapping
// flag whether the chat window shall be opened on a new chat message SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinlch",
SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", pClient->GetSndCrdLeftInputChannel() );
pClient->GetOpenChatOnNewMessage() );
// sound card right input channel mapping
// GUI design SetNumericIniSet ( IniXMLDocument, "client", "sndcrdinrch",
SetNumericIniSet ( IniXMLDocument, "client", "guidesign", pClient->GetSndCrdRightInputChannel() );
static_cast<int> ( pClient->GetGUIDesign() ) );
// sound card left output channel mapping
// flag whether using high quality audio or not SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutlch",
SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", pClient->GetSndCrdLeftOutputChannel() );
pClient->GetCELTHighQuality() );
// sound card right output channel mapping
// flag whether stereo mode is used SetNumericIniSet ( IniXMLDocument, "client", "sndcrdoutrch",
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio", pClient->GetSndCrdRightOutputChannel() );
pClient->GetUseStereo() );
// sound card preferred buffer size index
// prepare file name for storing initialization data in XML file and store SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
// XML data in file pClient->GetSndCrdPrefFrameSizeFactor() );
QFile file ( GetIniFileNameWithPath ( sFileName ) );
if ( file.open ( QIODevice::WriteOnly ) ) // automatic network jitter buffer size setting
{ SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
QTextStream out ( &file ); pClient->GetDoAutoSockBufSize() );
out << IniXMLDocument.toString();
} // network jitter buffer size
} SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
pClient->GetSockBufNumFrames() );
QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
{ // flag whether the chat window shall be opened on a new chat message
// return the file name with complete path, take care if given file name is SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
// empty pClient->GetOpenChatOnNewMessage() );
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() ) // GUI design
{ SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
// we use the Qt default setting file paths for the different OSs by static_cast<int> ( pClient->GetGUIDesign() ) );
// utilizing the QSettings class
const QSettings TempSettingsObject ( // flag whether using high quality audio or not
QSettings::IniFormat, QSettings::UserScope, APP_NAME, APP_NAME ); SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio",
pClient->GetCELTHighQuality() );
const QString sConfigDir =
QFileInfo ( TempSettingsObject.fileName() ).absolutePath(); // flag whether stereo mode is used
SetFlagIniSet ( IniXMLDocument, "client", "stereoaudio",
// make sure the directory exists pClient->GetUseStereo() );
if ( !QFile::exists ( sConfigDir ) ) }
{ else
QDir TempDirectoryObject; {
TempDirectoryObject.mkpath ( sConfigDir ); // server:
}
// name
// append the actual file name PutIniSetting ( IniXMLDocument, "server", "name",
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME; pServer->GetServerName() );
}
// city
return sCurFileName; PutIniSetting ( IniXMLDocument, "server", "city",
} pServer->GetServerCity() );
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection, // country
const QString& strKey, const int iValue ) SetNumericIniSet ( IniXMLDocument, "server", "country",
{ static_cast<int> ( pServer->GetServerCountry() ) );
// convert input parameter which is an integer to string and store }
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
} // prepare file name for storing initialization data in XML file and store
// XML data in file
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection, QFile file ( GetIniFileNameWithPath ( sFileName ) );
const QString& strKey, const int iRangeStart, if ( file.open ( QIODevice::WriteOnly ) )
const int iRangeStop, int& iValue ) {
{ QTextStream out ( &file );
// init return value out << IniXMLDocument.toString();
bool bReturn = false; }
}
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
// check if it is a valid parameter // Help functions **************************************************************
if ( !strGetIni.isEmpty() ) QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
{ {
// convert string from init file to integer // return the file name with complete path, take care if given file name is
iValue = strGetIni.toInt(); // empty
QString sCurFileName = sFileName;
// check range if ( sCurFileName.isEmpty() )
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) ) {
{ // we use the Qt default setting file paths for the different OSs by
bReturn = true; // utilizing the QSettings class
} const QSettings TempSettingsObject (
} QSettings::IniFormat, QSettings::UserScope, APP_NAME, APP_NAME );
return bReturn; const QString sConfigDir =
} QFileInfo ( TempSettingsObject.fileName() ).absolutePath();
void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection, // make sure the directory exists
const QString& strKey, const bool bValue ) if ( !QFile::exists ( sConfigDir ) )
{ {
// we encode true -> "1" and false -> "0" QDir TempDirectoryObject;
if ( bValue == true ) TempDirectoryObject.mkpath ( sConfigDir );
{ }
PutIniSetting ( xmlFile, strSection, strKey, "1" );
} // append the actual file name
else if ( bIsClient )
{ {
PutIniSetting ( xmlFile, strSection, strKey, "0" ); sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
} }
} else
{
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection, sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
const QString& strKey, bool& bValue ) }
{ }
// init return value
bool bReturn = false; return sCurFileName;
}
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
if ( !strGetIni.isEmpty() ) const QString& strKey, const int iValue )
{ {
if ( strGetIni.toInt() ) // convert input parameter which is an integer to string and store
{ PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
bValue = true; }
}
else bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
{ const QString& strKey, const int iRangeStart,
bValue = false; const int iRangeStop, int& iValue )
} {
// init return value
bReturn = true; bool bReturn = false;
}
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
return bReturn;
} // check if it is a valid parameter
if ( !strGetIni.isEmpty() )
{
// Init-file routines using XML *********************************************** // convert string from init file to integer
QString CSettings::GetIniSetting ( const QDomDocument& xmlFile, const QString& sSection, iValue = strGetIni.toInt();
const QString& sKey, const QString& sDefaultVal )
{ // check range
// init return parameter with default value if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
QString sResult ( sDefaultVal ); {
bReturn = true;
// get section }
QDomElement xmlSection = xmlFile.firstChildElement ( sSection ); }
if ( !xmlSection.isNull() )
{ return bReturn;
// get key }
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( !xmlKey.isNull() ) void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
{ const QString& strKey, const bool bValue )
// get value {
sResult = xmlKey.text(); // we encode true -> "1" and false -> "0"
} if ( bValue == true )
} {
PutIniSetting ( xmlFile, strSection, strKey, "1" );
return sResult; }
} else
{
void CSettings::PutIniSetting ( QDomDocument& xmlFile, const QString& sSection, PutIniSetting ( xmlFile, strSection, strKey, "0" );
const QString& sKey, const QString& sValue ) }
{ }
// check if section is already there, if not then create it
QDomElement xmlSection = xmlFile.firstChildElement ( sSection ); bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
if ( xmlSection.isNull() ) const QString& strKey, bool& bValue )
{ {
// create new root element and add to document // init return value
xmlSection = xmlFile.createElement ( sSection ); bool bReturn = false;
xmlFile.appendChild ( xmlSection );
} const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
// check if key is already there, if not then create it if ( !strGetIni.isEmpty() )
QDomElement xmlKey = xmlSection.firstChildElement ( sKey ); {
if ( xmlKey.isNull() ) if ( strGetIni.toInt() )
{ {
xmlKey = xmlFile.createElement ( sKey ); bValue = true;
xmlSection.appendChild ( xmlKey ); }
} else
{
// add actual data to the key bValue = false;
QDomText currentValue = xmlFile.createTextNode ( sValue ); }
xmlKey.appendChild ( currentValue );
} bReturn = true;
}
return bReturn;
}
// Init-file routines using XML ***********************************************
QString CSettings::GetIniSetting ( const QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sDefaultVal )
{
// init return parameter with default value
QString sResult ( sDefaultVal );
// get section
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( !xmlSection.isNull() )
{
// get key
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( !xmlKey.isNull() )
{
// get value
sResult = xmlKey.text();
}
}
return sResult;
}
void CSettings::PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sValue )
{
// check if section is already there, if not then create it
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( xmlSection.isNull() )
{
// create new root element and add to document
xmlSection = xmlFile.createElement ( sSection );
xmlFile.appendChild ( xmlSection );
}
// check if key is already there, if not then create it
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( xmlKey.isNull() )
{
xmlKey = xmlFile.createElement ( sKey );
xmlSection.appendChild ( xmlKey );
}
// add actual data to the key
QDomText currentValue = xmlFile.createTextNode ( sValue );
xmlKey.appendChild ( currentValue );
}

View File

@ -1,73 +1,78 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2007 * Copyright (c) 2004-2007
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#if !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ ) #if !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )
#define SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ #define SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_
#include <qdom.h> #include <qdom.h>
#include <qfile.h> #include <qfile.h>
#include <qsettings.h> #include <qsettings.h>
#include <qdir.h> #include <qdir.h>
#include <qtextstream.h> #include <qtextstream.h>
#include "global.h" #include "global.h"
#include "client.h" #include "client.h"
#include "server.h"
/* Classes ********************************************************************/
class CSettings /* Classes ********************************************************************/
{ class CSettings
public: {
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ) {} public:
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ), bIsClient ( true ) {}
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); } CSettings ( CServer* pNSerP ) : pServer ( pNSerP ), bIsClient ( false ) {}
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
protected: void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
void ReadIniFile ( const QString& sFileName );
void WriteIniFile ( const QString& sFileName ); protected:
void ReadIniFile ( const QString& sFileName );
QString GetIniFileNameWithPath ( const QString& sFileName ); void WriteIniFile ( const QString& sFileName );
// init file access function for read/write QString GetIniFileNameWithPath ( const QString& sFileName );
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iValue = 0 ); // init file access function for read/write
bool GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection, void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iRangeStart, const QString& strKey, const int iValue = 0 );
const int iRangeStop, int& iValue ); bool GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
void SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection, const QString& strKey, const int iRangeStart,
const QString& strKey, const bool bValue = false ); const int iRangeStop, int& iValue );
bool GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection, void SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, bool& bValue ); const QString& strKey, const bool bValue = false );
bool GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
// actual working function for init-file access const QString& strKey, bool& bValue );
QString GetIniSetting( const QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sDefaultVal = "" ); // actual working function for init-file access
void PutIniSetting ( QDomDocument& xmlFile, const QString& sSection, QString GetIniSetting( const QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sValue = "" ); const QString& sKey, const QString& sDefaultVal = "" );
void PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
// pointer to the client object needed for the various settings const QString& sKey, const QString& sValue = "" );
CClient* pClient;
}; // pointer to the client/server object which stores the various settings
CClient* pClient; // for client
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ ) CServer* pServer; // for server
bool bIsClient;
};
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )