Salome HOME
SIMAN removal
[modules/gui.git] / src / Qtx / QtxResourceMgr.cxx
index 2e06646cee95d144ba4446c0d41f9e8c878d39d7..68511cf35c7703a6cada46f0a6917b91bba74f4f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include <stdlib.h>
 
+/* XPM for the default pixmap */
+static const char* pixmap_not_found_xpm[] = {
+"16 16 3 1",
+"       c None",
+".      c #000000",
+"+      c #A80000",
+"                ",
+"                ",
+"    .     .     ",
+"   .+.   .+.    ",
+"  .+++. .+++.   ",
+"   .+++.+++.    ",
+"    .+++++.     ",
+"     .+++.      ",
+"    .+++++.     ",
+"   .+++.+++.    ",
+"  .+++. .+++.   ",
+"   .+.   .+.    ",
+"    .     .     ",
+"                ",
+"                ",
+"                "};
+
 /*!
   \class QtxResourceMgr::Resources
   \internal
@@ -334,15 +357,22 @@ const QtxResourceMgr::Section QtxResourceMgr::Resources::section( const QString&
 QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& prefix, const QString& name ) const
 {
   QString path;
-  if ( hasValue( sect, prefix ) )
+  if ( !QFileInfo( name ).isRelative() )
+  {
+    path = name;
+  }
+  else
   {
-    path = value( sect, prefix, true );
-    if ( !path.isEmpty() )
+    if ( hasValue( sect, prefix ) )
     {
-      if ( QFileInfo( path ).isRelative() )
-        path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path;
-
-      path = Qtx::addSlash( path ) + name;
+      path = value( sect, prefix, true );
+      if ( !path.isEmpty() )
+      {
+       if ( QFileInfo( path ).isRelative() )
+         path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path;
+       
+       path = Qtx::addSlash( path ) + name;
+      }
     }
   }
   if( !path.isEmpty() )
@@ -1379,11 +1409,14 @@ QtxResourceMgr::WorkingMode QtxResourceMgr::workingMode() const
   Note, that setValue() method always put the value to the user settings file.
   
   \param mode new working mode
+  \return previous working mode
   \sa workingMode(), value(), hasValue(), hasSection(), setValue()
 */
-void QtxResourceMgr::setWorkingMode( WorkingMode mode )
+QtxResourceMgr::WorkingMode QtxResourceMgr::setWorkingMode( WorkingMode mode )
 {
+  WorkingMode m = myWorkingMode;
   myWorkingMode = mode;
+  return m;
 }
 
 /*!
@@ -2516,10 +2549,11 @@ QString QtxResourceMgr::sectionsToken() const
 */
 QPixmap QtxResourceMgr::defaultPixmap() const
 {
-  QPixmap res;
-  if ( myDefaultPix && !myDefaultPix->isNull() )
-    res = *myDefaultPix;
-  return res;
+  static QPixmap* defpx = 0;
+  if ( !defpx ) 
+    defpx = new QPixmap( pixmap_not_found_xpm );
+
+  return myDefaultPix ? *myDefaultPix : *defpx;
 }
 
 /*!
@@ -2663,15 +2697,16 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l )
   if ( pref.isEmpty() && lang != "en" ) {
     // load Qt resources
     QString qt_translations = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
-    QString qt_dir_trpath;
-    if ( ::getenv( "QTDIR" ) )
-      qt_dir_trpath = QString( ::getenv( "QTDIR" ) );
+    QString qt_dir_trpath = qgetenv( "QT_ROOT_DIR" );
+    if ( qt_dir_trpath.isEmpty() )
+      qt_dir_trpath = qgetenv( "QTDIR" );
     if ( !qt_dir_trpath.isEmpty() )
       qt_dir_trpath = QDir( qt_dir_trpath ).absoluteFilePath( "translations" );
 
     QTranslator* trans = new QtxTranslator( 0 );
-    if ( trans->load( QString("qt_%1").arg( lang ), qt_translations ) || trans->load( QString("qt_%1").arg( lang ), qt_dir_trpath ) )
-      QApplication::instance()->installTranslator( trans );
+    if ( trans->load( QString("qt_%1").arg( lang ), qt_translations ) || trans->load( QString("qt_%1").arg( lang ), qt_dir_trpath ) ) {
+      if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
+    }
   }
 
   for ( QStringList::ConstIterator iter = prefixList.begin(); iter != prefixList.end(); ++iter )
@@ -2717,7 +2752,7 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList&
       {
         if ( !myTranslator[prefix].contains( trans ) )
           myTranslator[prefix].append( trans );
-        QApplication::instance()->installTranslator( trans );
+        if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
       }
     }
   }
@@ -2749,7 +2784,7 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name
     {
       if ( !myTranslator[prefix].contains( trans ) )
         myTranslator[prefix].append( trans );
-      QApplication::instance()->installTranslator( trans );
+      if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
     }
   }
 }
@@ -2765,7 +2800,7 @@ void QtxResourceMgr::removeTranslators( const QString& prefix )
 
   for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
   {
-    QApplication::instance()->removeTranslator( *it );
+    if ( QApplication::instance() ) QApplication::instance()->removeTranslator( *it );
     delete *it;
   }
 
@@ -2784,8 +2819,10 @@ void QtxResourceMgr::raiseTranslators( const QString& prefix )
 
   for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
   {
-    QApplication::instance()->removeTranslator( *it );
-    QApplication::instance()->installTranslator( *it );
+    if ( QApplication::instance() ) {
+      QApplication::instance()->removeTranslator( *it );
+      QApplication::instance()->installTranslator( *it );
+    }
   }
 }
 
@@ -2856,7 +2893,6 @@ QString QtxResourceMgr::userFileName( const QString& appName, const bool /*for_l
 {
   QString fileName;
   QString pathName = QDir::homePath();
-
   QString cfgAppName = QApplication::applicationName();
   if ( !cfgAppName.isEmpty() )
     pathName = Qtx::addSlash( Qtx::addSlash( pathName ) + QString( ".config" ) ) + cfgAppName;