*/
bool QtxResourceMgr::IniFormat::save( const QString& fname, const QMap<QString, Section>& secMap )
{
+ if ( !Qtx::mkDir( QFileInfo( fname ).absolutePath() ) )
+ return false;
+
QFile file( fname );
if ( !file.open( QFile::WriteOnly ) )
return false;
#ifndef QT_NO_DOM
+ if ( !Qtx::mkDir( QFileInfo( fname ).absolutePath() ) )
+ return false;
+
QFile file( fname );
if ( !file.open( QFile::WriteOnly ) )
return false;
the configuration file from the previous versions of the application).
\param appName application name
- \param for_load boolean flag indicating that file is opened for loading or saving (not used)
+ \param for_load boolean flag indicating that file is opened for loading or saving (not used in default implementation)
\return user configuration file name
\sa globalFileName()
*/
QString fileName;
QString pathName = QDir::homePath();
+ QString cfgAppName = QApplication::applicationName();
+ if ( !cfgAppName.isEmpty() )
+ pathName = Qtx::addSlash( Qtx::addSlash( pathName ) + QString( ".config" ) ) + cfgAppName;
+
#ifdef WIN32
fileName = QString( "%1.%2" ).arg( appName ).arg( currentFormat() );
#else
*/
QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const
{
- QDir d( QFileInfo( fname ).dir() );
- d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
- QStringList l = d.entryList();
QString appr_file;
- int id0 = userFileId( fname ), id, appr=-1;
- if( id0<0 )
+
+ // calculate default file id from user file name
+ long id0 = userFileId( fname );
+ if ( id0 < 0 ) // can't calculate file id from user file name, no further processing
return appr_file;
- for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ )
- {
- id = userFileId( *anIt );
- if( id<0 )
- continue;
+ long id, appr = -1;
+
+ // get all files from the same dir where use file is (should be) situated
+ QDir d( QFileInfo( fname ).dir() );
+ if ( d.exists() ) {
+ d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
+ QStringList l = d.entryList();
+ for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ )
+ {
+ id = userFileId( *anIt );
+ if ( id < 0 )
+ continue;
+ if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) )
+ {
+ appr = id;
+ appr_file = d.absoluteFilePath( *anIt );
+ }
+ }
+ }
+
+ // backward compatibility: check also user's home directory (if it differs from above one)
+ QDir home = QDir::home();
+ if ( home.exists() && d.canonicalPath() != home.canonicalPath() ) {
+ home.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
+ QStringList l = home.entryList();
- if( appr < 0 || abs( id-id0 ) < abs( appr-id0 ) )
+ for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ )
{
- appr = id;
- appr_file = d.absoluteFilePath( *anIt );
+ id = userFileId( *anIt );
+ if ( id < 0 )
+ continue;
+ if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) )
+ {
+ appr = id;
+ appr_file = home.absoluteFilePath( *anIt );
+ }
}
}
+
return appr_file;
}
/*!
Calculates integer extended version number by user file name for comparing
*/
-int SUIT_ResourceMgr::userFileId( const QString& ) const
+long SUIT_ResourceMgr::userFileId( const QString& ) const
{
return -1;
}
protected:
virtual QString userFileName( const QString&, const bool = true ) const;
virtual QString findAppropriateUserFile( const QString& ) const;
- virtual int userFileId( const QString& ) const;
+ virtual long userFileId( const QString& ) const;
private:
QString myVersion;
return GUI_VERSION_STR;
}
+static QString getAppName( const QString& libName )
+{
+ QString appName = QFileInfo( libName ).baseName();
+ if ( appName.startsWith( "lib" ) ) appName = appName.mid( 3 );
+ return appName;
+}
+
// static void MessageOutput( QtMsgType type, const char* msg )
// {
// switch ( type )
bool iniFormat = false;
bool noSplash = false;
bool useLicense = false;
- for ( int i = 1; i < argc /*&& !noExceptHandling*/; i++ )
+ for ( int i = 1; i < argc; i++ )
{
if ( !strcmp( argv[i], "--noexcepthandling" ) )
noExceptHandling = true;
iniFormat = true;
else if ( !strcmp( argv[i], "--nosplash") )
noSplash = true;
- else if ( !strcmp( argv[i], "--uselicense" ) )
+ else if ( !strcmp( argv[i], "--uselicense" ) )
useLicense = true;
- else
+ else
argList.append( QString( argv[i] ) );
}
QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
SUITApp_Application app( argc, argv );
+ QString cfgAppName = getAppName( argList.isEmpty() ? QString() : argList.first() );
+ // hard-coding for LightApp :( no other way to this for the moment
+ if ( cfgAppName == "LightApp" ) {
+ app.setOrganizationName( "salome" );
+ app.setApplicationName( "salome" );
+ app.setApplicationVersion( salomeVersion() );
+ }
int result = -1;
return SUIT_ResourceMgr::userFileName( myExtAppName, for_load );
}
- virtual int userFileId( const QString& _fname ) const
+ virtual long userFileId( const QString& _fname ) const
{
- int id = -1;
+ long id = -1;
if ( !myExtAppName.isEmpty() ) {
QRegExp exp( QString( "\\.%1rc\\.([a-zA-Z0-9.]+)$" ).arg( myExtAppName ) );
QRegExp vers_exp( "^([0-9]+)([A-Za-z]?)([0-9]*)$" );