Store file name in settings class on creation and do not require it for each load and save call
This commit is contained in:
parent
5811f3d10e
commit
aa0fd533e6
3 changed files with 26 additions and 25 deletions
12
src/main.cpp
12
src/main.cpp
|
@ -344,8 +344,8 @@ int main ( int argc, char** argv )
|
||||||
CClient Client ( iPortNumber );
|
CClient Client ( iPortNumber );
|
||||||
|
|
||||||
// load settings from init-file
|
// load settings from init-file
|
||||||
CSettings Settings ( &Client );
|
CSettings Settings ( &Client, strIniFileName );
|
||||||
Settings.Load ( strIniFileName );
|
Settings.Load();
|
||||||
|
|
||||||
// GUI object
|
// GUI object
|
||||||
CLlconClientDlg ClientDlg (
|
CLlconClientDlg ClientDlg (
|
||||||
|
@ -364,7 +364,7 @@ int main ( int argc, char** argv )
|
||||||
app.exec();
|
app.exec();
|
||||||
|
|
||||||
// save settings to init-file
|
// save settings to init-file
|
||||||
Settings.Save ( strIniFileName );
|
Settings.Save();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -387,8 +387,8 @@ int main ( int argc, char** argv )
|
||||||
Server.SetUseDefaultCentralServerAddress ( true );
|
Server.SetUseDefaultCentralServerAddress ( true );
|
||||||
|
|
||||||
// load settings from init-file
|
// load settings from init-file
|
||||||
CSettings Settings ( &Server );
|
CSettings Settings ( &Server, strIniFileName );
|
||||||
Settings.Load ( strIniFileName );
|
Settings.Load();
|
||||||
|
|
||||||
// update server list AFTER restoring the settings from the
|
// update server list AFTER restoring the settings from the
|
||||||
// settings file
|
// settings file
|
||||||
|
@ -410,7 +410,7 @@ int main ( int argc, char** argv )
|
||||||
app.exec();
|
app.exec();
|
||||||
|
|
||||||
// save settings to init-file
|
// save settings to init-file
|
||||||
Settings.Save ( strIniFileName );
|
Settings.Save();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
/* Implementation *************************************************************/
|
||||||
void CSettings::ReadIniFile ( const QString& sFileName )
|
void CSettings::Load()
|
||||||
{
|
{
|
||||||
int iValue;
|
int iValue;
|
||||||
bool bValue;
|
bool bValue;
|
||||||
|
@ -34,7 +34,7 @@ void CSettings::ReadIniFile ( const QString& sFileName )
|
||||||
|
|
||||||
// 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 ( strFileName );
|
||||||
if ( file.open ( QIODevice::ReadOnly ) )
|
if ( file.open ( QIODevice::ReadOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream in ( &file );
|
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
|
// create XML document for storing initialization parameters
|
||||||
QDomDocument IniXMLDocument;
|
QDomDocument IniXMLDocument;
|
||||||
|
@ -366,7 +366,7 @@ void CSettings::WriteIniFile ( const QString& sFileName )
|
||||||
|
|
||||||
// prepare file name for storing initialization data in XML file and store
|
// prepare file name for storing initialization data in XML file and store
|
||||||
// XML data in file
|
// XML data in file
|
||||||
QFile file ( GetIniFileNameWithPath ( sFileName ) );
|
QFile file ( strFileName );
|
||||||
if ( file.open ( QIODevice::WriteOnly ) )
|
if ( file.open ( QIODevice::WriteOnly ) )
|
||||||
{
|
{
|
||||||
QTextStream out ( &file );
|
QTextStream out ( &file );
|
||||||
|
@ -378,12 +378,12 @@ void CSettings::WriteIniFile ( const QString& sFileName )
|
||||||
|
|
||||||
|
|
||||||
// Help functions **************************************************************
|
// 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
|
// return the file name with complete path, take care if given file name is
|
||||||
// empty
|
// empty
|
||||||
QString sCurFileName = sFileName;
|
strFileName = sNFiName;
|
||||||
if ( sCurFileName.isEmpty() )
|
if ( strFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
// we use the Qt default setting file paths for the different OSs by
|
// we use the Qt default setting file paths for the different OSs by
|
||||||
// utilizing the QSettings class
|
// utilizing the QSettings class
|
||||||
|
@ -403,15 +403,13 @@ QString CSettings::GetIniFileNameWithPath ( const QString& sFileName )
|
||||||
// append the actual file name
|
// append the actual file name
|
||||||
if ( bIsClient )
|
if ( bIsClient )
|
||||||
{
|
{
|
||||||
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
|
strFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sCurFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
|
strFileName = sConfigDir + "/" + DEFAULT_INI_FILE_NAME_SERVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sCurFileName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile,
|
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile,
|
||||||
|
|
|
@ -39,17 +39,19 @@
|
||||||
class CSettings
|
class CSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CSettings ( CClient* pNCliP ) : pClient ( pNCliP ), bIsClient ( true ) {}
|
CSettings ( CClient* pNCliP, const QString& sNFiName ) :
|
||||||
CSettings ( CServer* pNSerP ) : pServer ( pNSerP ), bIsClient ( false ) {}
|
pClient ( pNCliP ), bIsClient ( true )
|
||||||
|
{ SetFileName ( sNFiName ); }
|
||||||
|
|
||||||
void Load ( const QString& sFileName = "" ) { ReadIniFile ( sFileName ); }
|
CSettings ( CServer* pNSerP, const QString& sNFiName ) :
|
||||||
void Save ( const QString& sFileName = "" ) { WriteIniFile ( sFileName ); }
|
pServer ( pNSerP ), bIsClient ( false )
|
||||||
|
{ SetFileName ( sNFiName ); }
|
||||||
|
|
||||||
|
void Load();
|
||||||
|
void Save();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadIniFile ( const QString& sFileName );
|
void SetFileName ( const QString& sNFiName );
|
||||||
void WriteIniFile ( const QString& sFileName );
|
|
||||||
|
|
||||||
QString GetIniFileNameWithPath ( const QString& sFileName );
|
|
||||||
|
|
||||||
// init file access function for read/write
|
// init file access function for read/write
|
||||||
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
void SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
|
||||||
|
@ -73,6 +75,7 @@ protected:
|
||||||
CServer* pServer; // for server
|
CServer* pServer; // for server
|
||||||
|
|
||||||
bool bIsClient;
|
bool bIsClient;
|
||||||
|
QString strFileName;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )
|
#endif // !defined ( SETTINGS_H__3B0BA660_DGEG56G456G9876D31912__INCLUDED_ )
|
||||||
|
|
Loading…
Reference in a new issue