1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
21 #undef SUIT_ENABLE_PYTHON
23 //#include "SUITconfig.h"
26 #include "SUITApp_Application.h"
28 #include <SUIT_Session.h>
29 #include <SUIT_Desktop.h>
30 #include <SUIT_ResourceMgr.h>
32 #include <QtxSplash.h>
34 #ifdef SUIT_ENABLE_PYTHON
41 #include <qstringlist.h>
46 QString salomeVersion()
48 QString path( ::getenv( "GUI_ROOT_DIR" ) );
49 if ( !path.isEmpty() )
50 path += QDir::separator();
52 path += QString( "bin/salome/VERSION" );
55 if ( !vf.open( IO_ReadOnly ) )
59 vf.readLine( line, 1024 );
65 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
66 line.remove( line.length() - 1, 1 );
69 int idx = line.findRev( ":" );
71 ver = line.mid( idx + 1 ).stripWhiteSpace();
78 static const char* pixmap_not_found_xpm[] = {
100 class SUITApp_Session: public SUIT_Session
103 SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
104 virtual ~SUITApp_Session() {}
106 virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
108 SUIT_ResourceMgr* resMgr = 0;
111 resMgr = new SUIT_ResourceMgr( appName );
112 resMgr->setCurrentFormat( "ini" );
116 resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
117 resMgr->setVersion( salomeVersion() );
118 resMgr->setCurrentFormat( "xml" );
123 static QPixmap defaultPixmap( pixmap_not_found_xpm );
124 resMgr->setDefaultPixmap( defaultPixmap );
125 resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
134 int main( int args, char* argv[] )
136 #ifdef SUIT_ENABLE_PYTHON
138 PySys_SetArgv( args, argv );
142 bool noExceptHandling = false;
143 bool iniFormat = false;
144 bool noSplash = false;
145 for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ )
147 if ( !strcmp( argv[i], "--noexcepthandling" ) )
148 noExceptHandling = true;
149 else if ( !strcmp( argv[i], "--format=ini") )
151 else if ( !strcmp( argv[i], "--nosplash") )
154 argList.append( QString( argv[i] ) );
157 SUITApp_Application app( args, argv );
160 if ( !argList.isEmpty() )
162 SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
163 QtxSplash* splash = 0;
165 SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
167 resMgr->loadLanguage();
168 QString splashIcon, splashInfo, splashTextColors;
169 resMgr->value( "splash", "image", splashIcon );
170 resMgr->value( "splash", "info", splashInfo, false );
171 resMgr->value( "splash", "text_colors", splashTextColors );
172 QString appName = QObject::tr( "APP_NAME" ).stripWhiteSpace();
173 QString appVersion = QObject::tr( "APP_VERSION" ).stripWhiteSpace();
174 if ( appVersion == "APP_VERSION" ) {
175 if ( appName == "APP_NAME" || appName.lower() == "salome" )
176 appVersion = salomeVersion();
180 QPixmap px( splashIcon );
181 if ( !px.isNull() ) {
182 splash = QtxSplash::splash( px );
183 if ( !splashTextColors.isEmpty() ) {
184 QStringList colors = QStringList::split( "|", splashTextColors );
186 if ( colors.count() > 0 ) c1 = QColor( colors[0] );
187 if ( colors.count() > 1 ) c2 = QColor( colors[1] );
188 splash->setTextColors( c1, c2 );
191 splash->setTextColors( Qt::white, Qt::black );
194 splash->setHideOnClick( true );
196 QFont f = splash->font();
198 splash->setFont( f );
199 if ( !splashInfo.isEmpty() ) {
200 splashInfo.replace( QRegExp( "%A" ), appName );
201 splashInfo.replace( QRegExp( "%V" ), QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
202 splashInfo.replace( QRegExp( "%L" ), QObject::tr( "ABOUT_LICENSE" ) );
203 splashInfo.replace( QRegExp( "%C" ), QObject::tr( "ABOUT_COPYRIGHT" ) );
204 splashInfo.replace( QRegExp( "\\\\n" ), "\n" );
205 splash->message( splashInfo );
208 qApp->processEvents();
212 SUIT_Application* theApp = aSession->startApplication( argList.first() );
215 if ( !noExceptHandling )
216 app.setHandler( aSession->handler() );
218 // if ( !app.mainWidget() )
219 // app.setMainWidget( theApp->desktop() );
221 splash->finish( theApp->desktop() );