replaced current init-file code with XML init-file code (using native QT XML support)
This commit is contained in:
parent
784383b6d5
commit
e53ded5b14
8 changed files with 175 additions and 361 deletions
|
@ -208,6 +208,11 @@ void CClient::run()
|
||||||
PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN );
|
PostWinMessage ( MS_SOUND_IN, MUL_COL_LED_GREEN );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TEST
|
||||||
|
Sleep(300);
|
||||||
|
|
||||||
|
|
||||||
// copy data from one stereo buffer in two separate buffers
|
// copy data from one stereo buffer in two separate buffers
|
||||||
iInCnt = 0;
|
iInCnt = 0;
|
||||||
for ( i = 0; i < iSndCrdBlockSizeSam; i++ )
|
for ( i = 0; i < iSndCrdBlockSizeSam; i++ )
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
|
|
||||||
// version and application name (always use this version)
|
// version and application name (always use this version)
|
||||||
#undef VERSION
|
#undef VERSION
|
||||||
#define VERSION "1.0.1cvs"
|
#define VERSION "2.0.0cvs"
|
||||||
#define APP_NAME "llcon"
|
#define APP_NAME "llcon"
|
||||||
|
|
||||||
// file name for logging file
|
// file name for logging file
|
||||||
|
|
|
@ -84,16 +84,6 @@ protected:
|
||||||
QMenu* pSettingsMenu;
|
QMenu* pSettingsMenu;
|
||||||
QMenuBar* pMenu;
|
QMenuBar* pMenu;
|
||||||
|
|
||||||
/*
|
|
||||||
QAction* pActGeneralSettings;
|
|
||||||
QAction* pActExit;
|
|
||||||
QAction* pActAbout;
|
|
||||||
QMenu* pSettingsMenu;
|
|
||||||
QMenu* pHelpMenu;
|
|
||||||
QMenuBar* pMainMenuBar;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
CClientSettingsDlg ClientSettingsDlg;
|
CClientSettingsDlg ClientSettingsDlg;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -120,7 +120,11 @@ cerr << "logging ";
|
||||||
|
|
||||||
// load settings from init-file
|
// load settings from init-file
|
||||||
CSettings Settings ( &Client );
|
CSettings Settings ( &Client );
|
||||||
Settings.Load ( strIniFileName );
|
|
||||||
|
|
||||||
|
// TODO use QString
|
||||||
|
|
||||||
|
Settings.Load ( strIniFileName.c_str() );
|
||||||
|
|
||||||
// GUI object
|
// GUI object
|
||||||
CLlconClientDlg ClientDlg ( &Client, 0 );
|
CLlconClientDlg ClientDlg ( &Client, 0 );
|
||||||
|
@ -134,7 +138,10 @@ cerr << "logging ";
|
||||||
app.exec();
|
app.exec();
|
||||||
|
|
||||||
// save settings to init-file
|
// save settings to init-file
|
||||||
Settings.Save ( strIniFileName );
|
|
||||||
|
// TODO use QString
|
||||||
|
|
||||||
|
Settings.Save ( strIniFileName.c_str() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
442
src/settings.cpp
442
src/settings.cpp
|
@ -1,8 +1,8 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Copyright (c) 2004-2006
|
* Copyright (c) 2004-2007
|
||||||
*
|
*
|
||||||
* Author(s):
|
* Author(s):
|
||||||
* Volker Fischer, Robert Kesterson
|
* Volker Fischer
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -26,155 +26,164 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
void CSettings::Load ( std::string sFileName )
|
void CSettings::ReadIniFile ( const QString& sFileName )
|
||||||
{
|
{
|
||||||
/* load settings from init-file */
|
int iValue;
|
||||||
ReadIniFile ( sFileName );
|
bool bValue;
|
||||||
}
|
QDomDocument IniXMLDocument ( INIT_XML_ROOT_NAME );
|
||||||
|
|
||||||
void CSettings::Save ( std::string sFileName )
|
|
||||||
{
|
|
||||||
/* write settings in init-file */
|
|
||||||
WriteIniFile ( sFileName );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Read and write init-file ***************************************************/
|
|
||||||
void CSettings::ReadIniFile ( std::string sFileName )
|
|
||||||
{
|
|
||||||
int iValue;
|
|
||||||
bool bValue;
|
|
||||||
INIFile ini;
|
|
||||||
|
|
||||||
// load data from init-file
|
// load data from init-file
|
||||||
if ( !sFileName.empty() )
|
// prepare file name for loading initialization data from XML file
|
||||||
|
QString sCurFileName = sFileName;
|
||||||
|
if ( sCurFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
ini = LoadIni ( sFileName.c_str() );
|
// if no file name is available, use default file name
|
||||||
}
|
sCurFileName = LLCON_INIT_FILE_NAME;
|
||||||
else
|
|
||||||
{
|
|
||||||
// use default file name
|
|
||||||
ini = LoadIni ( LLCON_INIT_FILE_NAME );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// read data from file if possible
|
||||||
|
QFile file ( sCurFileName );
|
||||||
|
if ( file.open ( QIODevice::ReadOnly ) )
|
||||||
|
{
|
||||||
|
IniXMLDocument.setContent ( &file );
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// actual settings data ---------------------------------------------------
|
||||||
// IP address
|
// IP address
|
||||||
pClient->strIPAddress = GetIniSetting ( ini, "Client", "ipaddress" ).c_str();
|
pClient->strIPAddress = GetIniSetting ( IniXMLDocument, "Client", "ipaddress" );
|
||||||
|
|
||||||
// name
|
// name
|
||||||
pClient->strName = GetIniSetting ( ini, "Client", "name" ).c_str();
|
pClient->strName = GetIniSetting ( IniXMLDocument, "Client", "name" );
|
||||||
|
|
||||||
// audio fader
|
// audio fader
|
||||||
if ( GetNumericIniSet ( ini, "Client", "audfad", 0, AUD_FADER_IN_MAX, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "audfad", 0, AUD_FADER_IN_MAX, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetAudioInFader ( iValue );
|
pClient->SetAudioInFader ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverberation level
|
// reverberation level
|
||||||
if ( GetNumericIniSet(ini, "Client", "revlev", 0, AUD_REVERB_MAX, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "revlev", 0, AUD_REVERB_MAX, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetReverbLevel ( iValue );
|
pClient->SetReverbLevel ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverberation channel assignment
|
// reverberation channel assignment
|
||||||
if ( GetFlagIniSet ( ini, "Client", "reverblchan", bValue ) == TRUE )
|
if ( GetFlagIniSet ( IniXMLDocument, "Client", "reverblchan", bValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetReverbOnLeftChan ( bValue );
|
pClient->SetReverbOnLeftChan ( bValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// sound card in number of buffers
|
// sound card in number of buffers
|
||||||
if ( GetNumericIniSet ( ini, "Client", "audinbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "audinbuf", 0, AUD_SLIDER_LENGTH, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->GetSndInterface()->SetInNumBuf( iValue );
|
pClient->GetSndInterface()->SetInNumBuf( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// sound card out number of buffers
|
// sound card out number of buffers
|
||||||
if ( GetNumericIniSet ( ini, "Client", "audoutbuf", 0, AUD_SLIDER_LENGTH, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "audoutbuf", 0, AUD_SLIDER_LENGTH, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->GetSndInterface()->SetOutNumBuf ( iValue );
|
pClient->GetSndInterface()->SetOutNumBuf ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network jitter buffer size
|
// network jitter buffer size
|
||||||
if ( GetNumericIniSet ( ini, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "jitbuf", 0, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetSockBufSize ( iValue );
|
pClient->SetSockBufSize ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network buffer size factor in
|
// network buffer size factor in
|
||||||
if ( GetNumericIniSet ( ini, "Client", "netwbusifactin", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactin", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetNetwBufSizeFactIn ( iValue );
|
pClient->SetNetwBufSizeFactIn ( iValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// network buffer size factor out
|
// network buffer size factor out
|
||||||
if ( GetNumericIniSet ( ini, "Client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) == TRUE )
|
if ( GetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactout", 1, MAX_NET_BLOCK_SIZE_FACTOR, iValue ) )
|
||||||
{
|
{
|
||||||
pClient->SetNetwBufSizeFactOut ( iValue );
|
pClient->SetNetwBufSizeFactOut ( iValue );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::WriteIniFile ( std::string sFileName )
|
void CSettings::WriteIniFile ( const QString& sFileName )
|
||||||
{
|
{
|
||||||
INIFile ini;
|
// create XML document for storing initialization parameters
|
||||||
|
QDomDocument IniXMLDocument ( INIT_XML_ROOT_NAME );
|
||||||
|
|
||||||
|
|
||||||
|
// actual settings data ---------------------------------------------------
|
||||||
// IP address
|
// IP address
|
||||||
PutIniSetting ( ini, "Client", "ipaddress", pClient->strIPAddress.toStdString().c_str() );
|
PutIniSetting ( IniXMLDocument, "Client", "ipaddress", pClient->strIPAddress );
|
||||||
|
|
||||||
// name
|
// name
|
||||||
PutIniSetting ( ini, "Client", "name", pClient->strName.toStdString().c_str() );
|
PutIniSetting ( IniXMLDocument, "Client", "name", pClient->strName );
|
||||||
|
|
||||||
// audio fader
|
// audio fader
|
||||||
SetNumericIniSet ( ini, "Client", "audfad", pClient->GetAudioInFader() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "audfad", pClient->GetAudioInFader() );
|
||||||
|
|
||||||
// reverberation level
|
// reverberation level
|
||||||
SetNumericIniSet ( ini, "Client", "revlev", pClient->GetReverbLevel() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "revlev", pClient->GetReverbLevel() );
|
||||||
|
|
||||||
// reverberation channel assignment
|
// reverberation channel assignment
|
||||||
SetFlagIniSet ( ini, "Client", "reverblchan", pClient->IsReverbOnLeftChan() );
|
SetFlagIniSet ( IniXMLDocument, "Client", "reverblchan", pClient->IsReverbOnLeftChan() );
|
||||||
|
|
||||||
// sound card in number of buffers
|
// sound card in number of buffers
|
||||||
SetNumericIniSet ( ini, "Client", "audinbuf", pClient->GetSndInterface()->GetInNumBuf() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "audinbuf", pClient->GetSndInterface()->GetInNumBuf() );
|
||||||
|
|
||||||
// sound card out number of buffers
|
// sound card out number of buffers
|
||||||
SetNumericIniSet ( ini, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() );
|
||||||
|
|
||||||
// network jitter buffer size
|
// network jitter buffer size
|
||||||
SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetSockBufSize() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "jitbuf", pClient->GetSockBufSize() );
|
||||||
|
|
||||||
// network buffer size factor in
|
// network buffer size factor in
|
||||||
SetNumericIniSet ( ini, "Client", "netwbusifactin", pClient->GetNetwBufSizeFactIn() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactin", pClient->GetNetwBufSizeFactIn() );
|
||||||
|
|
||||||
// network buffer size factor out
|
// network buffer size factor out
|
||||||
SetNumericIniSet ( ini, "Client", "netwbusifactout", pClient->GetNetwBufSizeFactOut() );
|
SetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactout", pClient->GetNetwBufSizeFactOut() );
|
||||||
|
|
||||||
|
|
||||||
// save settings in init-file
|
// prepare file name for storing initialization data in XML file
|
||||||
if ( !sFileName.empty() )
|
QString sCurFileName = sFileName;
|
||||||
|
if ( sCurFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
SaveIni ( ini, sFileName.c_str() );
|
// if no file name is available, use default file name
|
||||||
}
|
sCurFileName = LLCON_INIT_FILE_NAME;
|
||||||
else
|
|
||||||
{
|
|
||||||
// use default file name
|
|
||||||
SaveIni ( ini, LLCON_INIT_FILE_NAME );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// store XML data in file
|
||||||
|
QFile file ( sCurFileName );
|
||||||
|
if ( file.open ( QIODevice::WriteOnly ) )
|
||||||
|
{
|
||||||
|
QTextStream out ( &file );
|
||||||
|
out << IniXMLDocument.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::GetNumericIniSet ( INIFile& theINI, string strSection,
|
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||||
string strKey, int iRangeStart,
|
const QString& strKey, const int iValue )
|
||||||
int iRangeStop, int& iValue )
|
|
||||||
{
|
{
|
||||||
/* Init return value */
|
// convert input parameter which is an integer to string and store
|
||||||
bool bReturn = FALSE;
|
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
|
||||||
|
}
|
||||||
|
|
||||||
const string strGetIni =
|
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||||
GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() );
|
const QString& strKey, const int iRangeStart,
|
||||||
|
const int iRangeStop, int& iValue )
|
||||||
|
{
|
||||||
|
// init return value
|
||||||
|
bool bReturn = false;
|
||||||
|
|
||||||
/* Check if it is a valid parameter */
|
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
|
||||||
if ( !strGetIni.empty () )
|
|
||||||
|
// check if it is a valid parameter
|
||||||
|
if ( !strGetIni.isEmpty() )
|
||||||
{
|
{
|
||||||
iValue = atoi( strGetIni.c_str () );
|
// convert string from init file to integer
|
||||||
|
iValue = strGetIni.toInt();
|
||||||
|
|
||||||
/* Check range */
|
// check range
|
||||||
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
|
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
|
||||||
{
|
{
|
||||||
bReturn = TRUE;
|
bReturn = TRUE;
|
||||||
|
@ -184,275 +193,90 @@ bool CSettings::GetNumericIniSet ( INIFile& theINI, string strSection,
|
||||||
return bReturn;
|
return bReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetNumericIniSet ( INIFile& theINI, string strSection,
|
void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||||
string strKey, int iValue )
|
const QString& strKey, const bool bValue )
|
||||||
{
|
{
|
||||||
char cString[256];
|
// we encode true -> "1" and false -> "0"
|
||||||
|
if ( bValue == true )
|
||||||
sprintf ( cString, "%d", iValue );
|
{
|
||||||
PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), cString );
|
PutIniSetting ( xmlFile, strSection, strKey, "1" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PutIniSetting ( xmlFile, strSection, strKey, "0" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSettings::GetFlagIniSet ( INIFile& theINI, string strSection,
|
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||||
string strKey, bool& bValue )
|
const QString& strKey, bool& bValue )
|
||||||
{
|
{
|
||||||
/* Init return value */
|
// init return value
|
||||||
bool bReturn = FALSE;
|
bool bReturn = false;
|
||||||
|
|
||||||
const string strGetIni =
|
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
|
||||||
GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() );
|
|
||||||
|
|
||||||
if ( !strGetIni.empty() )
|
if ( !strGetIni.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( atoi ( strGetIni.c_str() ) )
|
if ( strGetIni.toInt() )
|
||||||
{
|
{
|
||||||
bValue = TRUE;
|
bValue = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bValue = FALSE;
|
bValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bReturn = TRUE;
|
bReturn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bReturn;
|
return bReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetFlagIniSet ( INIFile& theINI, string strSection, string strKey,
|
|
||||||
bool bValue )
|
// Init-file routines using XML ***********************************************
|
||||||
|
QString CSettings::GetIniSetting ( const QDomDocument& xmlFile, const QString& sSection,
|
||||||
|
const QString& sKey, const QString& sDefaultVal )
|
||||||
{
|
{
|
||||||
if ( bValue == TRUE )
|
// init return parameter with default value
|
||||||
|
QString sResult ( sDefaultVal );
|
||||||
|
|
||||||
|
// get section
|
||||||
|
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
|
||||||
|
if ( !xmlSection.isNull() )
|
||||||
{
|
{
|
||||||
PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), "1" );
|
// get key
|
||||||
}
|
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
|
||||||
else
|
if ( !xmlKey.isNull() )
|
||||||
{
|
|
||||||
PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), "0" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* INI File routines using the STL ********************************************/
|
|
||||||
/* The following code was taken from "INI File Tools (STLINI)" written by
|
|
||||||
Robert Kesterson in 1999. The original files are stlini.cpp and stlini.h.
|
|
||||||
The homepage is http://robertk.com/source
|
|
||||||
|
|
||||||
Copyright August 18, 1999 by Robert Kesterson */
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
/* These pragmas are to quiet VC++ about the expanded template identifiers
|
|
||||||
exceeding 255 chars. You won't be able to see those variables in a debug
|
|
||||||
session, but the code will run normally */
|
|
||||||
#pragma warning ( push )
|
|
||||||
#pragma warning ( disable : 4786 4503 )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string CSettings::GetIniSetting ( CSettings::INIFile& theINI, const char* section,
|
|
||||||
const char* key, const char* defaultval )
|
|
||||||
{
|
|
||||||
std::string result ( defaultval );
|
|
||||||
INIFile::iterator iSection = theINI.find ( std::string ( section ) );
|
|
||||||
|
|
||||||
if ( iSection != theINI.end() )
|
|
||||||
{
|
|
||||||
INISection::iterator apair = iSection->second.find ( std::string ( key ) );
|
|
||||||
|
|
||||||
if ( apair != iSection->second.end() )
|
|
||||||
{
|
|
||||||
result = apair->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSettings::PutIniSetting ( CSettings::INIFile &theINI, const char *section,
|
|
||||||
const char *key, const char *value )
|
|
||||||
{
|
|
||||||
INIFile::iterator iniSection;
|
|
||||||
INISection::iterator apair;
|
|
||||||
|
|
||||||
if ( ( iniSection = theINI.find ( std::string ( section ) ) ) == theINI.end() )
|
|
||||||
{
|
|
||||||
// no such section? Then add one
|
|
||||||
INISection newsection;
|
|
||||||
if (key)
|
|
||||||
{
|
{
|
||||||
newsection.insert (
|
// get value
|
||||||
std::pair<std::string, std::string> ( std::string ( key ), std::string ( value ) ) );
|
sResult = xmlKey.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
theINI.insert (
|
|
||||||
std::pair<std::string, INISection> ( std::string ( section ), newsection ) );
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( key )
|
|
||||||
{
|
|
||||||
/* Found section, make sure key isn't in there already,
|
|
||||||
if it is, just drop and re-add */
|
|
||||||
apair = iniSection->second.find ( string ( key ) );
|
|
||||||
if ( apair != iniSection->second.end() )
|
|
||||||
{
|
|
||||||
iniSection->second.erase(apair);
|
|
||||||
}
|
|
||||||
|
|
||||||
iniSection->second.insert (
|
return sResult;
|
||||||
std::pair<std::string, std::string> ( std::string ( key ), std::string ( value ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSettings::INIFile CSettings::LoadIni ( const char* filename )
|
void CSettings::PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
|
||||||
|
const QString& sKey, const QString& sValue )
|
||||||
{
|
{
|
||||||
INIFile theINI;
|
// check if section is already there, if not then create it
|
||||||
char *value, *temp;
|
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
|
||||||
std::string section;
|
if ( xmlSection.isNull() )
|
||||||
char buffer[MAX_INI_LINE];
|
|
||||||
std::fstream file ( filename, std::ios::in );
|
|
||||||
|
|
||||||
while ( file.good() )
|
|
||||||
{
|
{
|
||||||
memset ( buffer, 0, sizeof ( buffer ) );
|
// create new root element and add to document
|
||||||
file.getline ( buffer, sizeof ( buffer ) );
|
xmlSection = xmlFile.createElement ( sSection );
|
||||||
|
xmlFile.appendChild ( xmlSection );
|
||||||
if ( ( temp = strchr ( buffer, '\n' ) ) )
|
|
||||||
{
|
|
||||||
*temp = '\0'; // cut off at newline
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( temp = strchr ( buffer, '\r' ) ) )
|
|
||||||
{
|
|
||||||
*temp = '\0'; // cut off at linefeeds
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ( buffer[0] == '[' ) && ( temp = strrchr ( buffer, ']' ) ) )
|
|
||||||
{ // if line is like --> [section name]
|
|
||||||
*temp = '\0'; // chop off the trailing ']'
|
|
||||||
section = &buffer[1];
|
|
||||||
PutIniSetting ( theINI, &buffer[1] ); // start new section
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( buffer[0] && ( value = strchr ( buffer, '=' ) ) )
|
|
||||||
{
|
|
||||||
// assign whatever follows = sign to value, chop at "="
|
|
||||||
*value++ = '\0';
|
|
||||||
|
|
||||||
// and add both sides to INISection
|
|
||||||
PutIniSetting ( theINI, section.c_str(), buffer, value );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( buffer[0] )
|
|
||||||
{
|
|
||||||
// must be a comment or something
|
|
||||||
PutIniSetting ( theINI, section.c_str(), buffer, "" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return theINI;
|
// 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SaveIni ( CSettings::INIFile &theINI, const char* filename )
|
|
||||||
{
|
|
||||||
bool bFirstSection = TRUE; // init flag
|
|
||||||
|
|
||||||
std::fstream file ( filename, std::ios::out );
|
|
||||||
if ( !file.good() )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// just iterate the hashes and values and dump them to a file
|
|
||||||
INIFile::iterator section = theINI.begin();
|
|
||||||
while ( section != theINI.end() )
|
|
||||||
{
|
|
||||||
if ( section->first > "" )
|
|
||||||
{
|
|
||||||
if ( bFirstSection == TRUE )
|
|
||||||
{
|
|
||||||
// do not put a newline at the beginning of the first section
|
|
||||||
file << "[" << section->first << "]" << std::endl;
|
|
||||||
|
|
||||||
// reset flag
|
|
||||||
bFirstSection = FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file << std::endl << "[" << section->first << "]" << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
INISection::iterator pair = section->second.begin();
|
|
||||||
|
|
||||||
while ( pair != section->second.end() )
|
|
||||||
{
|
|
||||||
if ( pair->second > "" )
|
|
||||||
{
|
|
||||||
file << pair->first << "=" << pair->second << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
file << pair->first << "=" << std::endl;
|
|
||||||
}
|
|
||||||
pair++;
|
|
||||||
}
|
|
||||||
section++;
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return true or false depending on whether the first string is less than the
|
|
||||||
second */
|
|
||||||
bool CSettings::StlIniCompareStringNoCase::operator() ( const std::string& x,
|
|
||||||
const std::string& y ) const
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
return ( stricmp ( x.c_str(), y.c_str() ) < 0 ) ? true : false;
|
|
||||||
#else
|
|
||||||
#ifdef strcasecmp
|
|
||||||
return ( strcasecmp ( x.c_str(), y.c_str() ) < 0 ) ? true : false;
|
|
||||||
#else
|
|
||||||
unsigned nCount = 0;
|
|
||||||
int nResult = 0;
|
|
||||||
const char *p1 = x.c_str();
|
|
||||||
const char *p2 = y.c_str();
|
|
||||||
|
|
||||||
while ( *p1 && *p2 )
|
|
||||||
{
|
|
||||||
nResult = toupper ( *p1 ) - toupper ( *p2 );
|
|
||||||
if ( nResult != 0 )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
p1++;
|
|
||||||
p2++;
|
|
||||||
nCount++;
|
|
||||||
}
|
|
||||||
if ( nResult == 0 )
|
|
||||||
{
|
|
||||||
if ( *p1 && !*p2 )
|
|
||||||
{
|
|
||||||
nResult = -1;
|
|
||||||
}
|
|
||||||
if ( !*p1 && *p2 )
|
|
||||||
{
|
|
||||||
nResult = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( nResult < 0 )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#endif /* strcasecmp */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#pragma warning ( pop )
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/******************************************************************************\
|
/******************************************************************************\
|
||||||
* Copyright (c) 2004-2006
|
* Copyright (c) 2004-2007
|
||||||
*
|
*
|
||||||
* Author(s):
|
* Author(s):
|
||||||
* Volker Fischer, Robert Kesterson
|
* Volker Fischer
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -25,9 +25,9 @@
|
||||||
#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 <map>
|
#include <qdom.h>
|
||||||
#include <string>
|
#include <qfile.h>
|
||||||
#include <fstream>
|
#include <qtextstream.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
|
|
||||||
|
@ -36,9 +36,8 @@
|
||||||
// name of the init-file
|
// name of the init-file
|
||||||
#define LLCON_INIT_FILE_NAME "llcon.ini"
|
#define LLCON_INIT_FILE_NAME "llcon.ini"
|
||||||
|
|
||||||
/* change this if you expect to have huge lines in your INI files. Note that
|
// XML document root name
|
||||||
this is the max size of a single line, NOT the max number of lines */
|
#define INIT_XML_ROOT_NAME "Llcon Init File"
|
||||||
#define MAX_INI_LINE 500
|
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
@ -47,39 +46,29 @@ class CSettings
|
||||||
public:
|
public:
|
||||||
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ) {}
|
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ) {}
|
||||||
|
|
||||||
void Load ( std::string sFileName = "" );
|
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
|
||||||
void Save ( std::string sFileName = "" );
|
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadIniFile ( std::string sFileName );
|
void ReadIniFile ( const QString& sFileName );
|
||||||
void WriteIniFile ( std::string sFileName );
|
void WriteIniFile ( const QString& sFileName );
|
||||||
|
|
||||||
// function declarations for stlini code written by Robert Kesterson
|
// init file access function for read/write
|
||||||
struct StlIniCompareStringNoCase
|
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||||
{
|
const QString& strKey, const int iValue = 0 );
|
||||||
bool operator() ( const std::string& x, const std::string& y ) const;
|
bool GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||||
};
|
const QString& strKey, const int iRangeStart,
|
||||||
|
const int iRangeStop, int& iValue );
|
||||||
|
void SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||||
|
const QString& strKey, const bool bValue = false );
|
||||||
|
bool GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||||
|
const QString& strKey, bool& bValue );
|
||||||
|
|
||||||
// these typedefs just make the code a bit more readable
|
// actual working function for init-file access
|
||||||
typedef std::map<string, std::string, StlIniCompareStringNoCase > INISection;
|
QString GetIniSetting( const QDomDocument& xmlFile, const QString& sSection,
|
||||||
typedef std::map<string, INISection , StlIniCompareStringNoCase > INIFile;
|
const QString& sKey, const QString& sDefaultVal = "" );
|
||||||
|
void PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
|
||||||
std::string GetIniSetting( INIFile& theINI, const char* pszSection,
|
const QString& sKey, const QString& sValue = "" );
|
||||||
const char* pszKey, const char* pszDefaultVal = "" );
|
|
||||||
void PutIniSetting ( INIFile &theINI, const char *pszSection,
|
|
||||||
const char* pszKey = NULL, const char* pszValue = "" );
|
|
||||||
void SaveIni ( INIFile& theINI, const char* pszFilename );
|
|
||||||
INIFile LoadIni ( const char* pszFilename );
|
|
||||||
|
|
||||||
|
|
||||||
void SetNumericIniSet ( INIFile& theINI, std::string strSection, std::string strKey,
|
|
||||||
int iValue );
|
|
||||||
bool GetNumericIniSet ( INIFile& theINI, string strSection, std::string strKey,
|
|
||||||
int iRangeStart, int iRangeStop, int& iValue );
|
|
||||||
void SetFlagIniSet ( INIFile& theINI, std::string strSection, std::string strKey,
|
|
||||||
bool bValue );
|
|
||||||
bool GetFlagIniSet ( INIFile& theINI, std::string strSection, std::string strKey,
|
|
||||||
bool& bValue );
|
|
||||||
|
|
||||||
// pointer to the client object needed for the various settings
|
// pointer to the client object needed for the various settings
|
||||||
CClient* pClient;
|
CClient* pClient;
|
||||||
|
|
|
@ -300,7 +300,6 @@ CAboutDlg::CAboutDlg ( QWidget* parent ) : QDialog ( parent )
|
||||||
"<li>audio reverberation code: by Perry R. Cook and Gary P. Scavone, "
|
"<li>audio reverberation code: by Perry R. Cook and Gary P. Scavone, "
|
||||||
"1995 - 2004 (taken from \"The Synthesis ToolKit in C++ (STK)\")</li>"
|
"1995 - 2004 (taken from \"The Synthesis ToolKit in C++ (STK)\")</li>"
|
||||||
"<li>IMA-ADPCM: by Erik de Castro Lopo</li>"
|
"<li>IMA-ADPCM: by Erik de Castro Lopo</li>"
|
||||||
"<li>INI File Tools (STLINI): Robert Kesterson in 1999</li>"
|
|
||||||
"<li>Parts from Dream DRM Receiver by Volker Fischer and Alexander "
|
"<li>Parts from Dream DRM Receiver by Volker Fischer and Alexander "
|
||||||
"Kurpiers</li>"
|
"Kurpiers</li>"
|
||||||
"</ul>"
|
"</ul>"
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
/>
|
/>
|
||||||
<Tool
|
<Tool
|
||||||
Name="VCLinkerTool"
|
Name="VCLinkerTool"
|
||||||
AdditionalDependencies="$(QTDIR)\lib\qtmain.lib $(QTDIR)\lib\QtCore4.lib $(QTDIR)\lib\QtGui4.lib $(QTDIR)\lib\QtNetwork4.lib winmm.lib"
|
AdditionalDependencies="$(QTDIR)\lib\qtmain.lib $(QTDIR)\lib\QtCore4.lib $(QTDIR)\lib\QtGui4.lib $(QTDIR)\lib\QtNetwork4.lib $(QTDIR)\lib\QtXml4.lib winmm.lib"
|
||||||
OutputFile=".\Debug/llcon.exe"
|
OutputFile=".\Debug/llcon.exe"
|
||||||
LinkIncremental="2"
|
LinkIncremental="2"
|
||||||
SuppressStartupBanner="true"
|
SuppressStartupBanner="true"
|
||||||
|
|
Loading…
Reference in a new issue