Salome HOME
SIMAN removal
[modules/gui.git] / src / Qtx / QtxResourceMgr.cxx
index 31cb87fc44b2125a0401937ac455b017d56a10bf..68511cf35c7703a6cada46f0a6917b91bba74f4f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  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
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 
 #include <stdlib.h>
 
 
 #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
 /*!
   \class QtxResourceMgr::Resources
   \internal
@@ -1386,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
   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()
 */
   \sa workingMode(), value(), hasValue(), hasSection(), setValue()
 */
-void QtxResourceMgr::setWorkingMode( WorkingMode mode )
+QtxResourceMgr::WorkingMode QtxResourceMgr::setWorkingMode( WorkingMode mode )
 {
 {
+  WorkingMode m = myWorkingMode;
   myWorkingMode = mode;
   myWorkingMode = mode;
+  return m;
 }
 
 /*!
 }
 
 /*!
@@ -2523,10 +2549,11 @@ QString QtxResourceMgr::sectionsToken() const
 */
 QPixmap QtxResourceMgr::defaultPixmap() 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;
 }
 
 /*!
 }
 
 /*!
@@ -2670,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 );
   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 ( !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 )
   }
 
   for ( QStringList::ConstIterator iter = prefixList.begin(); iter != prefixList.end(); ++iter )
@@ -2724,7 +2752,7 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList&
       {
         if ( !myTranslator[prefix].contains( trans ) )
           myTranslator[prefix].append( trans );
       {
         if ( !myTranslator[prefix].contains( trans ) )
           myTranslator[prefix].append( trans );
-        QApplication::instance()->installTranslator( trans );
+        if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
       }
     }
   }
       }
     }
   }
@@ -2756,7 +2784,7 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name
     {
       if ( !myTranslator[prefix].contains( trans ) )
         myTranslator[prefix].append( trans );
     {
       if ( !myTranslator[prefix].contains( trans ) )
         myTranslator[prefix].append( trans );
-      QApplication::instance()->installTranslator( trans );
+      if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
     }
   }
 }
     }
   }
 }
@@ -2772,7 +2800,7 @@ void QtxResourceMgr::removeTranslators( const QString& prefix )
 
   for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
   {
 
   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;
   }
 
     delete *it;
   }
 
@@ -2791,8 +2819,10 @@ void QtxResourceMgr::raiseTranslators( const QString& prefix )
 
   for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
   {
 
   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 );
+    }
   }
 }
 
   }
 }
 
@@ -2863,7 +2893,6 @@ QString QtxResourceMgr::userFileName( const QString& appName, const bool /*for_l
 {
   QString fileName;
   QString pathName = QDir::homePath();
 {
   QString fileName;
   QString pathName = QDir::homePath();
-
   QString cfgAppName = QApplication::applicationName();
   if ( !cfgAppName.isEmpty() )
     pathName = Qtx::addSlash( Qtx::addSlash( pathName ) + QString( ".config" ) ) + cfgAppName;
   QString cfgAppName = QApplication::applicationName();
   if ( !cfgAppName.isEmpty() )
     pathName = Qtx::addSlash( Qtx::addSlash( pathName ) + QString( ".config" ) ) + cfgAppName;