1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 //#ifndef DISABLE_PYCONSOLE
25 //#define DISABLE_PYCONSOLE
27 //#else //#if defined WIN32
28 //#ifdef DISABLE_PYCONSOLE
29 // NOTE: DO NOT DELETE THIS DEFINITION ON LINUX
30 // or make sure Python is initialized in main() in any case
31 // Otherwise, application based on light SALOME and using Python
32 // are unlikely to work properly.
33 //#undef DISABLE_PYCONSOLE
37 #ifndef DISABLE_PYCONSOLE
38 #include "SUITApp_init_python.hxx"
41 //#endif //#if defined WIN32
43 #include "GUI_version.h"
44 #include "SUITApp_Application.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_LicenseDlg.h"
47 #include "SUIT_ResourceMgr.h"
48 #include "SUIT_Session.h"
49 #include "Style_Salome.h"
50 #include "QtxSplash.h"
56 #include <QStringList>
64 static QString salomeVersion()
66 return GUI_VERSION_STR;
69 static QString getAppName( const QString& libName )
71 QString appName = QFileInfo( libName ).baseName();
72 if ( appName.startsWith( "lib" ) ) appName = appName.mid( 3 );
76 // static void MessageOutput( QtMsgType type, const char* msg )
82 // printf( "Debug: %s\n", msg );
87 // printf( "Warning: %s\n", msg );
92 // printf( "Fatal: %s\n", msg );
101 static const char* pixmap_not_found_xpm[] = {
123 class SUITApp_Session: public SUIT_Session
126 SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
127 virtual ~SUITApp_Session() {}
129 virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
131 SUIT_ResourceMgr* resMgr = 0;
134 resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
135 resMgr->setCurrentFormat( "ini" );
139 resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
140 resMgr->setVersion( salomeVersion() );
141 resMgr->setCurrentFormat( "xml" );
146 static QPixmap defaultPixmap( pixmap_not_found_xpm );
147 resMgr->setDefaultPixmap( defaultPixmap );
148 resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
157 int main( int argc, char* argv[] )
159 //#ifndef DISABLE_PYCONSOLE
160 // // First of all initialize Python, as in complex multi-component applications
161 // // someone else might initialize it some way unsuitable for light SALOME!
162 // Py_SetProgramName( argv[0] );
163 // Py_Initialize(); // Initialize the interpreter
164 // PySys_SetArgv( argc, argv );
165 // PyEval_InitThreads(); // Create (and acquire) the interpreter lock
166 // PyEval_ReleaseLock(); // Let the others use Python API until we need it again
169 //qInstallMsgHandler( MessageOutput );
172 bool noExceptHandling = false;
173 bool iniFormat = false;
174 bool noSplash = false;
175 bool useLicense = false;
176 for ( int i = 1; i < argc; i++ )
178 if ( !strcmp( argv[i], "--noexcepthandling" ) )
179 noExceptHandling = true;
180 else if ( !strcmp( argv[i], "--format=ini") )
182 else if ( !strcmp( argv[i], "--nosplash") )
184 else if ( !strcmp( argv[i], "--uselicense" ) )
187 argList.append( QString( argv[i] ) );
190 // add $QTDIR/plugins to the pluins search path for image plugins
191 QString qtdir( ::getenv( "QTDIR" ) );
192 if ( !qtdir.isEmpty() )
193 QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
195 //Set a "native" graphic system in case if application runs on the remote host
196 QString remote(::getenv("REMOTEHOST"));
197 QString client(::getenv("SSH_CLIENT"));
198 if(remote.length() > 0 || client.length() > 0 ) {
199 QApplication::setGraphicsSystem(QLatin1String("native"));
202 SUITApp_Application app( argc, argv );
203 QString cfgAppName = getAppName( argList.isEmpty() ? QString() : argList.first() );
204 // hard-coding for LightApp :( no other way to this for the moment
205 if ( cfgAppName == "LightApp" ) {
206 app.setOrganizationName( "salome" );
207 app.setApplicationName( "salome" );
208 app.setApplicationVersion( salomeVersion() );
220 HANDLE hProcess = GetCurrentProcess();
221 OpenProcessToken(hProcess,TOKEN_QUERY,&aToken);
222 if( GetUserProfileDirectory( aToken, aStr, &aLen ) )
226 if ( ::getenv( "HOME" ) )
227 env = ::getenv( "HOME" );
230 QFile file( env + "/ReadLicense.log" ); // Read the text from a file
231 if( !file.exists() ) {
232 SUIT_LicenseDlg aLicense;
233 if ( aLicense.exec() != QDialog::Accepted )
238 if ( !argList.isEmpty() )
240 SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
241 QtxSplash* splash = 0;
242 SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
247 resMgr->loadLanguage();
249 splash = QtxSplash::splash( QPixmap() );
250 splash->readSettings( resMgr );
251 if ( splash->pixmap().isNull() ) {
256 QString appName = QObject::tr( "APP_NAME" ).trimmed();
257 QString appVersion = QObject::tr( "APP_VERSION" ).trimmed();
258 if ( appVersion == "APP_VERSION" )
260 if ( appName == "APP_NAME" || appName.toLower() == "salome" )
261 appVersion = salomeVersion();
265 splash->setOption( "%A", appName );
266 splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
267 splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) );
268 splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) );
270 QApplication::instance()->processEvents();
275 #ifndef DISABLE_PYCONSOLE
276 //...Initialize python
278 char* _argv[] = {(char*)""};
279 SUIT_PYTHON::init_python(_argc,_argv);
281 PyEval_RestoreThread( SUIT_PYTHON::_gtstate );
283 if ( !SUIT_PYTHON::salome_shared_modules_module ) // import only once
284 SUIT_PYTHON::salome_shared_modules_module = PyImport_ImportModule( (char*)"salome_shared_modules" );
285 if ( !SUIT_PYTHON::salome_shared_modules_module )
288 PyEval_ReleaseThread( SUIT_PYTHON::_gtstate );
292 SUIT_Application* theApp = aSession->startApplication( argList.first() );
295 Style_Salome::initialize( theApp->resourceMgr() );
296 if ( theApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) )
297 Style_Salome::apply();
299 if ( !noExceptHandling )
300 app.setHandler( aSession->handler() );
303 splash->finish( theApp->desktop() );