Salome HOME
Fix a bug: "locale" preferences option is ignored when using --resources command...
authorvsr <vsr@opencascade.com>
Mon, 2 Feb 2015 16:02:45 +0000 (19:02 +0300)
committervsr <vsr@opencascade.com>
Mon, 2 Feb 2015 16:02:45 +0000 (19:02 +0300)
src/SUIT/SUIT_ResourceMgr.cxx
src/SUIT/SUIT_Session.cxx
src/SUIT/SUIT_Session.h
src/SUITApp/SUITApp.cxx
src/Session/SALOME_Session_Server.cxx

index dd2d9024f1e497208006f7f08dc5e7530d7fcd43..4482036f474835e24acf76077cad68e85208f52b 100755 (executable)
@@ -21,6 +21,7 @@
 //
 
 #include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
 
 #include <QDir>
 #include <QFileInfo>
@@ -81,7 +82,8 @@ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_l
 {
   QString pathName;
 
-  QStringList arguments = QApplication::arguments();
+  QStringList arguments;
+  if ( SUIT_Session::session() ) arguments = SUIT_Session::session()->arguments();
   // Try config file, given in arguments
   for (int i = 1; i < arguments.count(); i++) {
     QRegExp rx ("--resources=(.+)");
index dc60507a9ebde8c63b59d93658010b74d11f3f20..7946bf4a8b678377c697239719c7a8ee5bf00b28 100755 (executable)
@@ -53,6 +53,22 @@ SUIT_Session::SUIT_Session()
   mySession = this;
 }
 
+SUIT_Session::SUIT_Session( int argc, char** argv )
+: QObject(),
+  myResMgr( 0 ),
+  myActiveApp( 0 ),
+  myHandler( 0 ),
+  myExitStatus( NORMAL ),
+  myExitFlags ( 0 )
+{
+  SUIT_ASSERT( !mySession )
+
+  mySession = this;
+
+  for ( int i = 0; i < argc; i++ )
+    myArguments << QString( argv[i] );
+}
+
 /*!destructor. Clear applications list and set mySession to zero.*/
 SUIT_Session::~SUIT_Session()
 {
@@ -69,6 +85,17 @@ SUIT_Session::~SUIT_Session()
   mySession = 0;
 }
 
+/*!
+  Get arguments of the current session
+ */
+QStringList SUIT_Session::arguments()
+{
+  QStringList r;
+  if ( !myArguments.isEmpty() ) r = myArguments;
+  else if ( QApplication::instance() ) r = QApplication::arguments();
+  return r;
+}
+
 /*! \retval return mySession */
 SUIT_Session* SUIT_Session::session()
 {
index f4040c550baff4d567ec48de5e03e89fc17fe506..252718b9a06b9da9466e369400f5a0c8640f80ba 100755 (executable)
@@ -29,6 +29,7 @@
 #include <QList>
 #include <QObject>
 #include <QString>
+#include <QStringList>
 
 #ifdef WIN32
 #include <windows.h>
@@ -63,10 +64,13 @@ public:
 
 public:
   SUIT_Session();
+  SUIT_Session( int, char** );
   virtual ~SUIT_Session();
 
   static SUIT_Session*         session();
 
+  QStringList                  arguments();
+
   SUIT_Application*            startApplication( const QString&, int = 0, char** = 0 );
 
   QList<SUIT_Application*>     applications() const;
@@ -101,6 +105,8 @@ private:
   QString                      applicationName( const QString& ) const;
 
 private:
+  QStringList                  myArguments;
+
   SUIT_ResourceMgr*            myResMgr;
   AppList                      myAppList;
   AppLibMap                    myAppLibs;
index 1f693f34b506aa56787ea30a2a9079245ca23e06..861f9df0a55366a43a7cd936abee47e1d8fed62d 100644 (file)
@@ -51,6 +51,7 @@
 
 #include <QDir>
 #include <QFile>
+#include <QLocale>
 #include <QRegExp>
 #include <QString>
 #include <QStringList>
@@ -100,7 +101,7 @@ static QString getAppName( const QString& libName )
 class SUITApp_Session: public SUIT_Session
 {
 public:
-  SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
+  SUITApp_Session( bool theIniFormat, int argc, char** argv ) : SUIT_Session( argc, argv ), myIniFormat ( theIniFormat ) {}
   virtual ~SUITApp_Session() {}
 
   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
@@ -162,6 +163,20 @@ int main( int argc, char* argv[] )
       argList.append( QString( argv[i] ) );
   }
 
+  // set "C" locale if requested via preferences
+  {
+    SUITApp_Session stmp( iniFormat, argc, argv );
+    QApplication::setApplicationName( "salome" );
+    SUIT_ResourceMgr* resMgr = stmp.createResourceMgr( "LightApp" );
+    bool isCloc = resMgr->booleanValue( "language", "locale", true );
+    if ( isCloc ) {
+      QLocale::setDefault( QLocale::c() );
+    }
+    else {
+      QLocale::setDefault( QLocale::system() );
+    }
+  }
+
   // add $QTDIR/plugins to the pluins search path for image plugins
   QString qtdir( ::getenv( "QTDIR" ) );
   if ( !qtdir.isEmpty() )
@@ -212,9 +227,9 @@ int main( int argc, char* argv[] )
 
   if ( !argList.isEmpty() )
   {
-    SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
+    SUITApp_Session aSession( iniFormat, argc, argv );
     QtxSplash* splash = 0;
-    SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
+    SUIT_ResourceMgr* resMgr = aSession.createResourceMgr( argList.first() );
     if ( !noSplash ) 
     {
       if ( resMgr )
@@ -254,7 +269,7 @@ int main( int argc, char* argv[] )
     SUIT_PYTHON::init_python(_argc,_argv);
 #endif
 
-    SUIT_Application* theApp = aSession->startApplication( argList.first() );
+    SUIT_Application* theApp = aSession.startApplication( argList.first() );
     if ( theApp )
     {
       Style_Salome::initialize( theApp->resourceMgr() );
@@ -262,14 +277,13 @@ int main( int argc, char* argv[] )
         Style_Salome::apply();
 
       if ( !noExceptHandling )
-        app.setHandler( aSession->handler() );
+        app.setHandler( aSession.handler() );
 
       if ( splash )
         splash->finish( theApp->desktop() );
 
       result = app.exec();
     }
-    delete aSession;
   }
 
   return result;
index 30d208e83284d286c81f5fa8762900a67db8a466..dee5c66895c7fe46a6f93f80a5545400c6a34d67 100755 (executable)
@@ -228,7 +228,7 @@ QString SALOME_ResourceMgr::myExtAppVersion = QString();
 class SALOME_Session : public SUIT_Session
 {
 public:
-  SALOME_Session() : SUIT_Session() {}
+  SALOME_Session( int argc, char** argv ) : SUIT_Session( argc, argv ) {}
   virtual ~SALOME_Session() {}
 
 public:
@@ -355,12 +355,13 @@ int main( int argc, char **argv )
   if ( !qtdir.isEmpty() )
     QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
 
+  // set "C" locale if requested via preferences
   {
-    SALOME_Session s;
+    SALOME_Session stmp( argc, argv );
     QApplication::setApplicationName( "salome" );
-    SUIT_ResourceMgr* resMgr = s.createResourceMgr( "SalomeApp" );
+    SUIT_ResourceMgr* resMgr = stmp.createResourceMgr( "SalomeApp" );
     bool isCloc = resMgr->booleanValue( "language", "locale", true );
-    if ( isCloc ) { 
+    if ( isCloc ) {
       QLocale::setDefault( QLocale::c() );
     }
     else {
@@ -556,7 +557,7 @@ int main( int argc, char **argv )
       }
 
       // SUIT_Session creation
-      aGUISession = new SALOME_Session();
+      aGUISession = new SALOME_Session( argc, argv );
 
       // Load SalomeApp dynamic library
       MESSAGE( "creation SUIT_Application" );