From: nds Date: Mon, 19 Sep 2005 06:47:57 +0000 (+0000) Subject: Set parameter for load resource .xml or .ini file in LightApp. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a39f67eb48f9476124816736721e6e5498886701;p=modules%2Fgui.git Set parameter for load resource .xml or .ini file in LightApp. --- diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index 1735250d9..9c7c34fb8 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -7,6 +7,7 @@ #include #include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" #include "SUITApp_Application.h" #ifdef SUIT_ENABLE_PYTHON @@ -14,6 +15,88 @@ #endif #include +#include +#include +#include + +QString salomeVersion() +{ + QString path( ::getenv( "GUI_ROOT_DIR" ) ); + if ( !path.isEmpty() ) + path += QDir::separator(); + path += QString( "bin/salome/VERSION" ); + + QFile vf( path ); + if ( !vf.open( IO_ReadOnly ) ) + return QString::null; + + QString line; + vf.readLine( line, 1024 ); + vf.close(); + + if ( line.isEmpty() ) + return QString::null; + + while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) + line.remove( line.length() - 1, 1 ); + + QString ver; + int idx = line.findRev( ":" ); + if ( idx != -1 ) + ver = line.mid( idx + 1 ).stripWhiteSpace(); + + return ver; +} + +/* XPM */ +static const char* pixmap_not_found_xpm[] = { +"16 16 3 1", +" c None", +". c #000000", +"+ c #A80000", +" ", +" ", +" . . ", +" .+. .+. ", +" .+++. .+++. ", +" .+++.+++. ", +" .+++++. ", +" .+++. ", +" .+++++. ", +" .+++.+++. ", +" .+++. .+++. ", +" .+. .+. ", +" . . ", +" ", +" ", +" "}; + +class SUITApp_Session: public SUIT_Session +{ +public: + SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {} + virtual ~SUITApp_Session() {} + +protected: + virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const + { + SUIT_ResourceMgr* resMgr; + if ( myIniFormat ) + resMgr = new SUIT_ResourceMgr( appName ); + else { + resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) ); + resMgr->setVersion( salomeVersion() ); + resMgr->setCurrentFormat( "xml" ); + resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) ); + static QPixmap defaultPixmap( pixmap_not_found_xpm ); + resMgr->setDefaultPixmap( defaultPixmap ); + } + return resMgr; + } +private: + bool myIniFormat; +}; + int main( int args, char* argv[] ) { @@ -24,21 +107,25 @@ int main( int args, char* argv[] ) QStringList argList; bool noExceptHandling = false; - for ( int i = 1; i < args && !noExceptHandling; i++ ) + bool iniFormat = false; + for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ ) { if ( !strcmp( argv[i], "/noexcepthandling" ) ) noExceptHandling = true; + else if ( !strcmp( argv[i], "--format=ini") ) + iniFormat = true; else argList.append( QString( argv[i] ) ); } + SUITApp_Application app( args, argv ); int result = -1; if ( !argList.isEmpty() ) { - SUIT_Session* aSession = new SUIT_Session(); - if ( aSession->startApplication( argList.first() ) ) + SUITApp_Session* aSession = new SUITApp_Session( iniFormat ); + if ( aSession->startApplication( argList.first() ) ) { if ( !noExceptHandling ) app.setHandler( aSession->handler() );