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 );
|
||||
}
|
||||
|
||||
|
||||
// TEST
|
||||
Sleep(300);
|
||||
|
||||
|
||||
// copy data from one stereo buffer in two separate buffers
|
||||
iInCnt = 0;
|
||||
for ( i = 0; i < iSndCrdBlockSizeSam; i++ )
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
// version and application name (always use this version)
|
||||
#undef VERSION
|
||||
#define VERSION "1.0.1cvs"
|
||||
#define VERSION "2.0.0cvs"
|
||||
#define APP_NAME "llcon"
|
||||
|
||||
// file name for logging file
|
||||
|
|
|
@ -84,16 +84,6 @@ protected:
|
|||
QMenu* pSettingsMenu;
|
||||
QMenuBar* pMenu;
|
||||
|
||||
/*
|
||||
QAction* pActGeneralSettings;
|
||||
QAction* pActExit;
|
||||
QAction* pActAbout;
|
||||
QMenu* pSettingsMenu;
|
||||
QMenu* pHelpMenu;
|
||||
QMenuBar* pMainMenuBar;
|
||||
*/
|
||||
|
||||
|
||||
CClientSettingsDlg ClientSettingsDlg;
|
||||
|
||||
public slots:
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -120,7 +120,11 @@ cerr << "logging ";
|
|||
|
||||
// load settings from init-file
|
||||
CSettings Settings ( &Client );
|
||||
Settings.Load ( strIniFileName );
|
||||
|
||||
|
||||
// TODO use QString
|
||||
|
||||
Settings.Load ( strIniFileName.c_str() );
|
||||
|
||||
// GUI object
|
||||
CLlconClientDlg ClientDlg ( &Client, 0 );
|
||||
|
@ -134,7 +138,10 @@ cerr << "logging ";
|
|||
app.exec();
|
||||
|
||||
// save settings to init-file
|
||||
Settings.Save ( strIniFileName );
|
||||
|
||||
// TODO use QString
|
||||
|
||||
Settings.Save ( strIniFileName.c_str() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
446
src/settings.cpp
446
src/settings.cpp
|
@ -1,8 +1,8 @@
|
|||
/******************************************************************************\
|
||||
* Copyright (c) 2004-2006
|
||||
* Copyright (c) 2004-2007
|
||||
*
|
||||
* Author(s):
|
||||
* Volker Fischer, Robert Kesterson
|
||||
* Volker Fischer
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
|
@ -26,155 +26,164 @@
|
|||
|
||||
|
||||
/* Implementation *************************************************************/
|
||||
void CSettings::Load ( std::string sFileName )
|
||||
{
|
||||
/* load settings from init-file */
|
||||
ReadIniFile ( sFileName );
|
||||
}
|
||||
|
||||
void CSettings::Save ( std::string sFileName )
|
||||
{
|
||||
/* write settings in init-file */
|
||||
WriteIniFile ( sFileName );
|
||||
}
|
||||
|
||||
|
||||
/* Read and write init-file ***************************************************/
|
||||
void CSettings::ReadIniFile ( std::string sFileName )
|
||||
void CSettings::ReadIniFile ( const QString& sFileName )
|
||||
{
|
||||
int iValue;
|
||||
bool bValue;
|
||||
INIFile ini;
|
||||
QDomDocument IniXMLDocument ( INIT_XML_ROOT_NAME );
|
||||
|
||||
// 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() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// use default file name
|
||||
ini = LoadIni ( LLCON_INIT_FILE_NAME );
|
||||
// if no file name is available, use default file name
|
||||
sCurFileName = 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
|
||||
pClient->strIPAddress = GetIniSetting ( ini, "Client", "ipaddress" ).c_str();
|
||||
pClient->strIPAddress = GetIniSetting ( IniXMLDocument, "Client", "ipaddress" );
|
||||
|
||||
// name
|
||||
pClient->strName = GetIniSetting ( ini, "Client", "name" ).c_str();
|
||||
pClient->strName = GetIniSetting ( IniXMLDocument, "Client", "name" );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// reverberation channel assignment
|
||||
if ( GetFlagIniSet ( ini, "Client", "reverblchan", bValue ) == TRUE )
|
||||
if ( GetFlagIniSet ( IniXMLDocument, "Client", "reverblchan", bValue ) )
|
||||
{
|
||||
pClient->SetReverbOnLeftChan ( bValue );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
// 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 );
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
PutIniSetting ( ini, "Client", "ipaddress", pClient->strIPAddress.toStdString().c_str() );
|
||||
PutIniSetting ( IniXMLDocument, "Client", "ipaddress", pClient->strIPAddress );
|
||||
|
||||
// name
|
||||
PutIniSetting ( ini, "Client", "name", pClient->strName.toStdString().c_str() );
|
||||
PutIniSetting ( IniXMLDocument, "Client", "name", pClient->strName );
|
||||
|
||||
// audio fader
|
||||
SetNumericIniSet ( ini, "Client", "audfad", pClient->GetAudioInFader() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "audfad", pClient->GetAudioInFader() );
|
||||
|
||||
// reverberation level
|
||||
SetNumericIniSet ( ini, "Client", "revlev", pClient->GetReverbLevel() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "revlev", pClient->GetReverbLevel() );
|
||||
|
||||
// reverberation channel assignment
|
||||
SetFlagIniSet ( ini, "Client", "reverblchan", pClient->IsReverbOnLeftChan() );
|
||||
SetFlagIniSet ( IniXMLDocument, "Client", "reverblchan", pClient->IsReverbOnLeftChan() );
|
||||
|
||||
// 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
|
||||
SetNumericIniSet ( ini, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "audoutbuf", pClient->GetSndInterface()->GetOutNumBuf() );
|
||||
|
||||
// network jitter buffer size
|
||||
SetNumericIniSet ( ini, "Client", "jitbuf", pClient->GetSockBufSize() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "jitbuf", pClient->GetSockBufSize() );
|
||||
|
||||
// network buffer size factor in
|
||||
SetNumericIniSet ( ini, "Client", "netwbusifactin", pClient->GetNetwBufSizeFactIn() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactin", pClient->GetNetwBufSizeFactIn() );
|
||||
|
||||
// network buffer size factor out
|
||||
SetNumericIniSet ( ini, "Client", "netwbusifactout", pClient->GetNetwBufSizeFactOut() );
|
||||
SetNumericIniSet ( IniXMLDocument, "Client", "netwbusifactout", pClient->GetNetwBufSizeFactOut() );
|
||||
|
||||
|
||||
// save settings in init-file
|
||||
if ( !sFileName.empty() )
|
||||
// prepare file name for storing initialization data in XML file
|
||||
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
|
||||
|
||||
// store XML data in file
|
||||
QFile file ( sCurFileName );
|
||||
if ( file.open ( QIODevice::WriteOnly ) )
|
||||
{
|
||||
// use default file name
|
||||
SaveIni ( ini, LLCON_INIT_FILE_NAME );
|
||||
QTextStream out ( &file );
|
||||
out << IniXMLDocument.toString();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSettings::GetNumericIniSet ( INIFile& theINI, string strSection,
|
||||
string strKey, int iRangeStart,
|
||||
int iRangeStop, int& iValue )
|
||||
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||
const QString& strKey, const int iValue )
|
||||
{
|
||||
/* Init return value */
|
||||
bool bReturn = FALSE;
|
||||
// convert input parameter which is an integer to string and store
|
||||
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
|
||||
}
|
||||
|
||||
const string strGetIni =
|
||||
GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() );
|
||||
|
||||
/* Check if it is a valid parameter */
|
||||
if ( !strGetIni.empty () )
|
||||
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||
const QString& strKey, const int iRangeStart,
|
||||
const int iRangeStop, int& iValue )
|
||||
{
|
||||
iValue = atoi( strGetIni.c_str () );
|
||||
// init return value
|
||||
bool bReturn = false;
|
||||
|
||||
/* Check range */
|
||||
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
|
||||
|
||||
// check if it is a valid parameter
|
||||
if ( !strGetIni.isEmpty() )
|
||||
{
|
||||
// convert string from init file to integer
|
||||
iValue = strGetIni.toInt();
|
||||
|
||||
// check range
|
||||
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
|
||||
{
|
||||
bReturn = TRUE;
|
||||
|
@ -184,275 +193,90 @@ bool CSettings::GetNumericIniSet ( INIFile& theINI, string strSection,
|
|||
return bReturn;
|
||||
}
|
||||
|
||||
void CSettings::SetNumericIniSet ( INIFile& theINI, string strSection,
|
||||
string strKey, int iValue )
|
||||
void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||
const QString& strKey, const bool bValue )
|
||||
{
|
||||
char cString[256];
|
||||
|
||||
sprintf ( cString, "%d", iValue );
|
||||
PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), cString );
|
||||
}
|
||||
|
||||
bool CSettings::GetFlagIniSet ( INIFile& theINI, string strSection,
|
||||
string strKey, bool& bValue )
|
||||
// we encode true -> "1" and false -> "0"
|
||||
if ( bValue == true )
|
||||
{
|
||||
/* Init return value */
|
||||
bool bReturn = FALSE;
|
||||
|
||||
const string strGetIni =
|
||||
GetIniSetting ( theINI, strSection.c_str(), strKey.c_str() );
|
||||
|
||||
if ( !strGetIni.empty() )
|
||||
{
|
||||
if ( atoi ( strGetIni.c_str() ) )
|
||||
{
|
||||
bValue = TRUE;
|
||||
PutIniSetting ( xmlFile, strSection, strKey, "1" );
|
||||
}
|
||||
else
|
||||
{
|
||||
bValue = FALSE;
|
||||
PutIniSetting ( xmlFile, strSection, strKey, "0" );
|
||||
}
|
||||
}
|
||||
|
||||
bReturn = TRUE;
|
||||
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
|
||||
const QString& strKey, bool& bValue )
|
||||
{
|
||||
// init return value
|
||||
bool bReturn = false;
|
||||
|
||||
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
|
||||
|
||||
if ( !strGetIni.isEmpty() )
|
||||
{
|
||||
if ( strGetIni.toInt() )
|
||||
{
|
||||
bValue = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bValue = false;
|
||||
}
|
||||
|
||||
bReturn = true;
|
||||
}
|
||||
|
||||
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" );
|
||||
}
|
||||
else
|
||||
// get key
|
||||
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
|
||||
if ( !xmlKey.isNull() )
|
||||
{
|
||||
PutIniSetting ( theINI, strSection.c_str(), strKey.c_str(), "0" );
|
||||
// get value
|
||||
sResult = xmlKey.text();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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 sResult;
|
||||
}
|
||||
|
||||
return result;
|
||||
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 );
|
||||
}
|
||||
|
||||
void CSettings::PutIniSetting ( CSettings::INIFile &theINI, const char *section,
|
||||
const char *key, const char *value )
|
||||
// check if key is already there, if not then create it
|
||||
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
|
||||
if ( xmlKey.isNull() )
|
||||
{
|
||||
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 (
|
||||
std::pair<std::string, std::string> ( std::string ( key ), std::string ( value ) ) );
|
||||
xmlKey = xmlFile.createElement ( sKey );
|
||||
xmlSection.appendChild ( xmlKey );
|
||||
}
|
||||
|
||||
theINI.insert (
|
||||
std::pair<std::string, INISection> ( std::string ( section ), newsection ) );
|
||||
// add actual data to the key
|
||||
QDomText currentValue = xmlFile.createTextNode ( sValue );
|
||||
xmlKey.appendChild ( currentValue );
|
||||
}
|
||||
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 (
|
||||
std::pair<std::string, std::string> ( std::string ( key ), std::string ( value ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSettings::INIFile CSettings::LoadIni ( const char* filename )
|
||||
{
|
||||
INIFile theINI;
|
||||
char *value, *temp;
|
||||
std::string section;
|
||||
char buffer[MAX_INI_LINE];
|
||||
std::fstream file ( filename, std::ios::in );
|
||||
|
||||
while ( file.good() )
|
||||
{
|
||||
memset ( buffer, 0, sizeof ( buffer ) );
|
||||
file.getline ( buffer, sizeof ( buffer ) );
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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):
|
||||
* Volker Fischer, Robert Kesterson
|
||||
* Volker Fischer
|
||||
*
|
||||
******************************************************************************
|
||||
*
|
||||
|
@ -25,9 +25,9 @@
|
|||
#if !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )
|
||||
#define SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <qdom.h>
|
||||
#include <qfile.h>
|
||||
#include <qtextstream.h>
|
||||
#include "global.h"
|
||||
#include "client.h"
|
||||
|
||||
|
@ -36,9 +36,8 @@
|
|||
// name of the init-file
|
||||
#define LLCON_INIT_FILE_NAME "llcon.ini"
|
||||
|
||||
/* change this if you expect to have huge lines in your INI files. Note that
|
||||
this is the max size of a single line, NOT the max number of lines */
|
||||
#define MAX_INI_LINE 500
|
||||
// XML document root name
|
||||
#define INIT_XML_ROOT_NAME "Llcon Init File"
|
||||
|
||||
|
||||
/* Classes ********************************************************************/
|
||||
|
@ -47,39 +46,29 @@ class CSettings
|
|||
public:
|
||||
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ) {}
|
||||
|
||||
void Load ( std::string sFileName = "" );
|
||||
void Save ( std::string sFileName = "" );
|
||||
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
|
||||
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
|
||||
|
||||
protected:
|
||||
void ReadIniFile ( std::string sFileName );
|
||||
void WriteIniFile ( std::string sFileName );
|
||||
void ReadIniFile ( const QString& sFileName );
|
||||
void WriteIniFile ( const QString& sFileName );
|
||||
|
||||
// function declarations for stlini code written by Robert Kesterson
|
||||
struct StlIniCompareStringNoCase
|
||||
{
|
||||
bool operator() ( const std::string& x, const std::string& y ) const;
|
||||
};
|
||||
// init file access function for read/write
|
||||
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||
const QString& strKey, const int iValue = 0 );
|
||||
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
|
||||
typedef std::map<string, std::string, StlIniCompareStringNoCase > INISection;
|
||||
typedef std::map<string, INISection , StlIniCompareStringNoCase > INIFile;
|
||||
|
||||
std::string GetIniSetting( INIFile& theINI, const char* pszSection,
|
||||
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 );
|
||||
// actual working function for init-file access
|
||||
QString GetIniSetting( const QDomDocument& xmlFile, const QString& sSection,
|
||||
const QString& sKey, const QString& sDefaultVal = "" );
|
||||
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;
|
||||
|
|
|
@ -300,7 +300,6 @@ CAboutDlg::CAboutDlg ( QWidget* parent ) : QDialog ( parent )
|
|||
"<li>audio reverberation code: by Perry R. Cook and Gary P. Scavone, "
|
||||
"1995 - 2004 (taken from \"The Synthesis ToolKit in C++ (STK)\")</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 "
|
||||
"Kurpiers</li>"
|
||||
"</ul>"
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
/>
|
||||
<Tool
|
||||
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"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
|
|
Loading…
Reference in a new issue