From dd84f523512abc26fbd5ad99430ddf432482b4fb Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 2 Feb 2015 19:02:45 +0300 Subject: [PATCH] Fix a bug: "locale" preferences option is ignored when using --resources command line option --- src/SUIT/SUIT_ResourceMgr.cxx | 4 +++- src/SUIT/SUIT_Session.cxx | 27 +++++++++++++++++++++++++++ src/SUIT/SUIT_Session.h | 6 ++++++ src/SUITApp/SUITApp.cxx | 26 ++++++++++++++++++++------ src/Session/SALOME_Session_Server.cxx | 11 ++++++----- 5 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index dd2d9024f..4482036f4 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -21,6 +21,7 @@ // #include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" #include #include @@ -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=(.+)"); diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index dc60507a9..7946bf4a8 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -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() { diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index f4040c550..252718b9a 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -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 applications() const; @@ -101,6 +105,8 @@ private: QString applicationName( const QString& ) const; private: + QStringList myArguments; + SUIT_ResourceMgr* myResMgr; AppList myAppList; AppLibMap myAppLibs; diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index 1f693f34b..861f9df0a 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -51,6 +51,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 30d208e83..dee5c6689 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -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" ); -- 2.39.2