Store file name in settings class on creation and do not require it for each load and save call

This commit is contained in:
Volker Fischer 2011-05-21 16:53:01 +00:00
parent 5811f3d10e
commit aa0fd533e6
3 changed files with 26 additions and 25 deletions

View file

@ -344,8 +344,8 @@ int main ( int argc, char** argv )
CClient Client ( iPortNumber );
// load settings from init-file
CSettings Settings ( &Client );
Settings.Load ( strIniFileName );
CSettings Settings ( &Client, strIniFileName );
Settings.Load();
// GUI object
CLlconClientDlg ClientDlg (
@ -364,7 +364,7 @@ int main ( int argc, char** argv )
app.exec();
// save settings to init-file
Settings.Save ( strIniFileName );
Settings.Save();
}
else
{
@ -387,8 +387,8 @@ int main ( int argc, char** argv )
Server.SetUseDefaultCentralServerAddress ( true );
// load settings from init-file
CSettings Settings ( &Server );
Settings.Load ( strIniFileName );
CSettings Settings ( &Server, strIniFileName );
Settings.Load();
// update server list AFTER restoring the settings from the
// settings file
@ -410,7 +410,7 @@ int main ( int argc, char** argv )
app.exec();
// save settings to init-file
Settings.Save ( strIniFileName );
Settings.Save();
}
else
{

View file

@ -26,7 +26,7 @@
/* Implementation *************************************************************/
void CSettings::ReadIniFile ( const QString& sFileName )
void CSettings::Load()
{
int iValue;
bool bValue;
@ -34,7 +34,7 @@ void CSettings::ReadIniFile ( const QString& sFileName )
// prepare file name for loading initialization data from XML file and read
// data from file if possible
QFile file ( GetIniFileNameWithPath ( sFileName ) );
QFile file ( strFileName );
if ( file.open ( QIODevice::ReadOnly ) )
{
QTextStream in ( &file );
@ -240,7 +240,7 @@ void CSettings::ReadIniFile ( const QString& sFileName )
}
}
void CSettings::WriteIniFile ( const QString& sFileName )
void CSettings::Save()
{
// create XML document for storing initialization parameters
QDomDocument IniXMLDocument;
@ -366,7 +366,7 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// prepare file name for storing initialization data in XML file and store
// XML data in file
QFile file ( GetIniFileNameWithPath ( sFileName ) );
QFile file ( strFileName );
if ( file.open ( QIODevice::WriteOnly ) )
{
QTextStream out ( &file );
@ -378,12 +378,12 @@ void CSettings::WriteIniFile ( const QString& sFileName )
// Help functions **************************************************************
QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
void CSettings::SetFileName ( const QString& sNFiName )
{
// return the file name with complete path, take care if given file name is
// empty
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
strFileName = sNFiName;
if ( strFileName.isEmpty() )
{
// we use the Qt default setting file paths for the different OSs by
// utilizing the QSettings class
@ -403,15 +403,13 @@ QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
// append the actual file name
if ( bIsClient )
{
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
strFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
}
else
{
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
strFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
}
}
return sCurFileName;
}
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile,

View file

@ -39,17 +39,19 @@
class CSettings
{
public:
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ), bIsClient ( true ) {}
CSettings ( CServer* pNSerP ) : pServer ( pNSerP ), bIsClient ( false ) {}
CSettings ( CClient* pNCliP, const QString& sNFiName ) :
pClient ( pNCliP ), bIsClient ( true )
{ SetFileName ( sNFiName ); }
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
CSettings ( CServer* pNSerP, const QString& sNFiName ) :
pServer ( pNSerP ), bIsClient ( false )
{ SetFileName ( sNFiName ); }
void Load();
void Save();
protected:
void ReadIniFile ( const QString& sFileName );
void WriteIniFile ( const QString& sFileName );
QString GetIniFileNameWithPath ( const QString& sFileName );
void SetFileName ( const QString& sNFiName );
// init file access function for read/write
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
@ -73,6 +75,7 @@ protected:
CServer* pServer; // for server
bool bIsClient;
QString strFileName;
};
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )