-using namespace std;
-// File : QAD_ResourceMgr.cxx
-// Created : UI team, 22.10.00
-// Descr : ResourceMgr QAD-based application
-// Author : UI team
-// Project : SALOME
-// Module : SALOMEGUI
-// Copyright : Open CASCADE
+// SALOME SALOMEGUI : implementation of desktop and GUI kernel
+//
+// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//
+//
+//
+// File : QAD_ResourceMgr.cxx
+// Author : UI team
+// Module : SALOME
// $Header$
/*!
#include <qfileinfo.h>
#include <Standard.hxx>
+using namespace std;
/* configuration file */
static const char* CONFIG_FILE = "config";
static const char* RES_PIXMAPS = "icons";
static const char* RES_STRINGS = "strings";
static const char* RES_LANGUAGE = "language";
+static const char* RES_FILES = "resources";
static const char* SEPARATOR = ":";
*/
QString resDirs = collectDirs( prefix );
conf.insert( RES_DIR, new QString( resDirs ) );
- QString fileConfig = path( CONFIG_FILE, prefix, 0 ) ;
+ QString fileConfig = QString( prefix ) + QString( "." ) + QString( CONFIG_FILE );
+ fileConfig = path( fileConfig, prefix, 0 ) ;
//MESSAGE("QAD_ResourceMgr::loadresources : config : "<<fileConfig);
+ if ( fileConfig.isEmpty() )
+ fileConfig = path( CONFIG_FILE, prefix, 0 ) ;
if ( !fileConfig.isEmpty() ) {
QFile configFile( fileConfig );
if ( !configFile.exists() || !configFile.open( IO_ReadOnly ) ) {
bool bLoadString = false;
bool bLoadImages = false;
- QStringList dirList = QStringList::split( SEPARATOR, resDirs, false ); // skip empty entries
- for ( int i = dirList.count()-1; i >= 0; i-- ) {
- QString dir = dirList[ i ];
- QString fileString = QAD_Tools::addSlash( dir ) + stFile;
- QString fileImage = QAD_Tools::addSlash( dir ) + imagesFile;
+ QStringList resFiles = conf[ RES_FILES ] ? QStringList::split( SEPARATOR, *( conf[ RES_FILES ] ), false ) : QStringList();
+
+ // first load main module's resources
+ QString fileString = path( stFile, prefix, 0 );
+ QString fileImage = path( imagesFile, prefix, 0 );
+
+ if ( !fileString.isEmpty() && settings->load( fileString ) ) {
+ bLoadString = true;
+ }
+ if ( !fileImage.isEmpty() && settings->load( fileImage ) ) {
+ bLoadImages = true;
+ }
+
+ // then load additional module's resources if any are given
+ for ( int j = 0; j < resFiles.count(); j++ ) {
+ QString stFileAdd = resFiles[j] + "_msg_" + *( conf[ RES_LANGUAGE ] ) + ".qm" ;
+ QString imagesFileAdd = resFiles[j] + "_" + RES_PIXMAPS + ".qm";
+ if ( conf[ RES_STRINGS ] && !conf[ RES_STRINGS ]->isEmpty() )
+ stFileAdd = QAD_Tools::addSlash( *conf[ RES_STRINGS ] ) + stFileAdd;
+ if ( conf[ RES_PIXMAPS ] && !conf[ RES_PIXMAPS ]->isEmpty() )
+ imagesFileAdd = QAD_Tools::addSlash( *conf[ RES_PIXMAPS ] ) + imagesFileAdd;
- if ( settings->load( fileString ) ) {
- bLoadString = true;
- }
- if ( settings->load( fileImage ) ) {
- bLoadImages = true;
- }
+ QString fileStringAdd = path( stFileAdd, prefix, 0 );
+ QString fileImageAdd = path( imagesFileAdd, prefix, 0 );
+
+ if ( !fileStringAdd.isEmpty() )
+ settings->load( fileStringAdd );
+ if ( !fileImageAdd.isEmpty() )
+ settings->load( fileImageAdd );
}
-
+
if ( !bLoadString ) {
QString warnMsg;
warnMsg.sprintf( "String resources for module %s not found.\n"
Collects list of directories, separated by ';' where resources for module 'prefix'
can be situated
The order is following :
- - CSF_<prefix>Resources env.var directory ( or directory list )
- - CSF_ResourcesDefaults env.var directory ( or directory list )
+ - <prefix>_ROOT_DIR/share/salome/resources directory
+ - SALOME_<prefix>Resources env.var directory ( or directory list )
- ${HOME}/.salome/resources directory
- - ${SALOME_SITE_DIR}/share/salome/resources directory
- - ${SALOME_ROOT_DIR}/share/salome/resources directory
+ - ${SALOME_SITE_DIR}/share/${SALOME_SITE_NAME}/resources directory (for SALOME-based applications)
+ - ${KERNEL_ROOT_DIR}/share/salome/resources directory
*/
QString QAD_ResourceMgr::collectDirs( const QString& prefix ) const
{
QString dirList;
- QCString envVar( "CSF_" );
+ QCString envVar;
QString dir;
char* cenv;
- // Try CSF_<prefix>Resources env.var directory ( or directory list )
if ( !prefix.isEmpty() ) {
- envVar = QCString( "CSF_" ) + prefix.latin1() + QCString( "Resources" );
+ envVar = prefix.latin1() + QCString( "_ROOT_DIR" );
cenv = getenv( ( const char* ) envVar );
if ( cenv ) {
dir.sprintf( "%s", cenv );
- if ( !dir.isEmpty() )
+ if ( !dir.isEmpty() ) {
+ dir = QAD_Tools::addSlash(dir) ;
+ dir = dir + "share" ;
+ dir = QAD_Tools::addSlash(dir) ;
+ dir = dir + "salome" ;
+ dir = QAD_Tools::addSlash(dir) ;
+ dir = dir + "resources" ;
+ dir = QAD_Tools::addSlash(dir) ;
dirList.append( dirList.isEmpty() ? dir : ( QString( SEPARATOR ) + dir ) );
+ }
}
}
- // Try CSF_ResourcesDefaults env.var directory ( or directory list )
- cenv = getenv( "CSF_ResourcesDefaults" );
- if ( cenv ) {
- dir.sprintf( "%s", cenv );
- if ( !dir.isEmpty() )
- dirList.append( dirList.isEmpty() ? dir : ( QString( SEPARATOR ) + dir ) );
+
+ // Try SALOME_<prefix>Resources env.var directory ( or directory list )
+ if ( !prefix.isEmpty() ) {
+ envVar = QCString( "SALOME_" ) + prefix.latin1() + QCString( "Resources" );
+ cenv = getenv( ( const char* ) envVar );
+ if ( cenv ) {
+ dir.sprintf( "%s", cenv );
+ if ( !dir.isEmpty() )
+ dirList.append( dirList.isEmpty() ? dir : ( QString( SEPARATOR ) + dir ) );
+ }
}
// Try ${HOME}/.salome/resources directory
cenv = getenv( "HOME" );
dirList.append( dirList.isEmpty() ? dir : ( QString( SEPARATOR ) + dir ) );
}
}
- // Try ${SALOME_SITE_DIR}/share/salome/resources directory
+ // Try ${SALOME_SITE_DIR}/share/${SALOME_SITE_NAME}/resources directory
cenv = getenv( "SALOME_SITE_DIR" );
if ( cenv ) {
dir.sprintf( "%s", cenv );
dir = QAD_Tools::addSlash(dir) ;
dir = dir + "share" ;
dir = QAD_Tools::addSlash(dir) ;
- dir = dir + "salome" ;
+ cenv = getenv( "SALOME_SITE_NAME" );
+ if ( cenv )
+ dir = dir + cenv ;
+ else
+ dir = dir + "salome" ;
dir = QAD_Tools::addSlash(dir) ;
dir = dir + "resources" ;
dir = QAD_Tools::addSlash(dir) ;
dirList.append( dirList.isEmpty() ? dir : ( QString( SEPARATOR ) + dir ) );
}
}
- // Try ${SALOME_ROOT_DIR}/share/salome/resources directory
- cenv = getenv( "SALOME_ROOT_DIR" );
+ // Try ${KERNEL_ROOT_DIR}/share/salome/resources directory
+ cenv = getenv( "KERNEL_ROOT_DIR" );
if ( cenv ) {
dir.sprintf( "%s", cenv );
if ( !dir.isEmpty() ) {
*/
QString QAD_ResourceMgr::path( const QString& filename, const char* prefix, const char* key ) const
{
- QString filePath;
-
ResourceSettings* rs = myRes[ prefix ];
if ( rs ) {
StringDict& conf = rs->config();
for ( int i = 0; i < dirList.count(); i++ ) {
QString dir = dirList[ i ];
dir = QAD_Tools::addSlash( dir );
- if ( key ) {
- QString* where = conf[ key ];
- if ( where )
- dir = dir + QAD_Tools::addSlash( *where );
+ if ( key && conf[ key ] ) {
+ dir = dir + QString( *( conf[ key ] ) );
+ dir = QAD_Tools::addSlash( dir );
}
dir = dir + filename;
QFileInfo fileInfo( dir );
if ( fileInfo.isFile() && fileInfo.exists() ) {
- filePath = fileInfo.filePath();
- break;
+ return fileInfo.filePath();
}
}
}
}
//MESSAGE("QAD_ResourceMgr::path : <"<<filename.latin1()<<"> : "<<filePath.latin1()) ;
- return filePath;
+ return QString::null;
}
/*!