Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEGUI / QAD_ResourceMgr.cxx
index bb52c0aeecb03f716bb0ea1299cdcd8f8a28932d..576c7475c1c094eab92d59636d7da4a33b64715e 100644 (file)
@@ -26,7 +26,6 @@
 //  Module : SALOME
 //  $Header$
 
-using namespace std;
 /*!
   \class QAD_ResourceMgr QAD_ResourceMgr.h
   \brief ResourceMgr QAD-based application.
@@ -46,6 +45,7 @@ using namespace std;
 #include <qfileinfo.h>
 
 #include <Standard.hxx>
+using namespace std;
 
 /* configuration file */
 static const char* CONFIG_FILE = "config";
@@ -56,6 +56,7 @@ static const char* RES_DOCS     = "docs";
 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    = ":";
 
@@ -125,8 +126,11 @@ bool QAD_ResourceMgr::loadResources( const char* prefix, QString &msg )
     */
     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 ) ) {
@@ -168,20 +172,37 @@ bool QAD_ResourceMgr::loadResources( const char* prefix, QString &msg )
     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"
@@ -240,16 +261,16 @@ QString QAD_ResourceMgr::resources( const char* prefix ) const
   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;
   
@@ -271,9 +292,9 @@ QString QAD_ResourceMgr::collectDirs( const QString& prefix ) const
     }
   }
 
-  // Try CSF_<prefix>Resources env.var directory ( or directory list )
+  // Try SALOME_<prefix>Resources env.var directory ( or directory list )
   if ( !prefix.isEmpty() ) {
-    envVar = QCString( "CSF_" ) + prefix.latin1() + QCString( "Resources" );
+    envVar = QCString( "SALOME_" ) + prefix.latin1() + QCString( "Resources" );
     cenv = getenv( ( const char* ) envVar );
     if ( cenv ) {
       dir.sprintf( "%s", cenv );
@@ -281,13 +302,6 @@ QString QAD_ResourceMgr::collectDirs( const QString& prefix ) const
        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 ${HOME}/.salome/resources directory
   cenv = getenv( "HOME" );
   if ( cenv ) {
@@ -301,7 +315,7 @@ QString QAD_ResourceMgr::collectDirs( const QString& prefix ) const
       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 );
@@ -309,29 +323,17 @@ QString QAD_ResourceMgr::collectDirs( const QString& prefix ) const
       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 ${SALOME_ROOT_DIR}/share/salome/resources directory
-  cenv = getenv( "SALOME_ROOT_DIR" );
-  if ( cenv ) {
-    dir.sprintf( "%s", cenv );
-    if ( !dir.isEmpty() ) {
-      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 ${KERNEL_ROOT_DIR}/share/salome/resources directory
   cenv = getenv( "KERNEL_ROOT_DIR" );
   if ( cenv ) {
@@ -395,8 +397,6 @@ QString QAD_ResourceMgr::findFile( const QString& filename, const char* prefix )
 */
 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();
@@ -407,22 +407,20 @@ QString QAD_ResourceMgr::path( const QString& filename, const char* prefix, cons
       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;
 }
 
 /*!