1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #ifdef SUIT_ENABLE_PYTHON
25 #undef SUIT_ENABLE_PYTHON
28 #else //#if defined WIN32
30 #ifndef SUIT_ENABLE_PYTHON
31 // NOTE: DO NOT DELETE THIS DEFINITION ON LINUX
32 // or make sure Python is initialized in main() in any case
33 // Otherwise, application based on light SALOME and using Python
34 // are unlikely to work properly.
35 #define SUIT_ENABLE_PYTHON
39 #endif //#if defined WIN32
41 #include "SUITApp_Application.h"
43 #include <SUIT_Session.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <Style_Salome.h>
47 #include <QtxSplash.h>
49 #include <SUIT_LicenseDlg.h>
55 #include <QStringList>
63 static QString salomeVersion()
65 QString path( ::getenv( "GUI_ROOT_DIR" ) );
66 if ( !path.isEmpty() )
67 path += QDir::separator();
69 path += QString( "bin/salome/VERSION" );
72 if ( !vf.open( QFile::ReadOnly ) )
75 QString line = vf.readLine( 1024 );
81 while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
82 line.remove( line.length() - 1, 1 );
85 int idx = line.lastIndexOf( ":" );
87 ver = line.mid( idx + 1 ).trimmed();
92 static void MessageOutput( QtMsgType type, const char* msg )
98 printf( "Debug: %s\n", msg );
103 printf( "Warning: %s\n", msg );
108 printf( "Fatal: %s\n", msg );
117 static const char* pixmap_not_found_xpm[] = {
139 class SUITApp_Session: public SUIT_Session
142 SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
143 virtual ~SUITApp_Session() {}
145 virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
147 SUIT_ResourceMgr* resMgr = 0;
150 resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
151 resMgr->setCurrentFormat( "ini" );
155 resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
156 resMgr->setVersion( salomeVersion() );
157 resMgr->setCurrentFormat( "xml" );
162 static QPixmap defaultPixmap( pixmap_not_found_xpm );
163 resMgr->setDefaultPixmap( defaultPixmap );
164 resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
173 int main( int argc, char* argv[] )
175 #ifdef SUIT_ENABLE_PYTHON
176 // First of all initialize Python, as in complex multi-component applications
177 // someone else might initialize it some way unsuitable for light SALOME!
178 Py_SetProgramName( argv[0] );
179 Py_Initialize(); // Initialize the interpreter
180 PySys_SetArgv( argc, argv );
181 PyEval_InitThreads(); // Create (and acquire) the interpreter lock
182 PyEval_ReleaseLock(); // Let the others use Python API until we need it again
185 //qInstallMsgHandler( MessageOutput );
188 bool noExceptHandling = false;
189 bool iniFormat = false;
190 bool noSplash = false;
191 bool useLicense = false;
192 for ( int i = 1; i < argc /*&& !noExceptHandling*/; i++ )
194 if ( !strcmp( argv[i], "--noexcepthandling" ) )
195 noExceptHandling = true;
196 else if ( !strcmp( argv[i], "--format=ini") )
198 else if ( !strcmp( argv[i], "--nosplash") )
200 else if ( !strcmp( argv[i], "--uselicense" ) )
203 argList.append( QString( argv[i] ) );
206 SUITApp_Application app( argc, argv );
217 HANDLE hProcess = GetCurrentProcess();
218 OpenProcessToken(hProcess,TOKEN_QUERY,&aToken);
219 if( GetUserProfileDirectory( aToken, aStr, &aLen ) )
223 if ( ::getenv( "HOME" ) )
224 env = ::getenv( "HOME" );
227 QFile file( env + "/ReadLicense.log" ); // Read the text from a file
228 if( !file.exists() ) {
229 SUIT_LicenseDlg aLicense;
230 if ( aLicense.exec() != QDialog::Accepted )
235 if ( !argList.isEmpty() )
237 SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
238 QtxSplash* splash = 0;
239 SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
244 resMgr->loadLanguage( false );
246 splash = QtxSplash::splash( QPixmap() );
247 splash->readSettings( resMgr );
248 if ( splash->pixmap().isNull() ) {
253 QString appName = QObject::tr( "APP_NAME" ).trimmed();
254 QString appVersion = QObject::tr( "APP_VERSION" ).trimmed();
255 if ( appVersion == "APP_VERSION" )
257 if ( appName == "APP_NAME" || appName.toLower() == "salome" )
258 appVersion = salomeVersion();
262 splash->setOption( "%A", appName );
263 splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
264 splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
265 splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
267 QApplication::instance()->processEvents();
272 SUIT_Application* theApp = aSession->startApplication( argList.first() );
275 Style_Salome::initialize( theApp->resourceMgr() );
276 if ( theApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) )
277 Style_Salome::apply();
279 if ( !noExceptHandling )
280 app.setHandler( aSession->handler() );
283 splash->finish( theApp->desktop() );