Salome HOME
Join modifications from branch BR_3_1_0deb
[modules/gui.git] / src / Session / SALOME_Session_Server.cxx
index b52c9b040d2a28d7cd15082dc7950df4a6ab52a3..ac7738582d033d4c2aeca4277a32af12747c6d50 100755 (executable)
@@ -34,7 +34,9 @@
 #include "InquireServersQThread.h" // splash
 
 #include <iostream>
+#ifndef WNT
 #include <unistd.h>
+#endif
 
 #include <qdir.h>
 #include <qfile.h>
@@ -57,6 +59,7 @@
 #include "SUIT_Session.h"
 #include "SUIT_Application.h"
 #include "SUIT_MessageBox.h"
+#include "SUIT_ResourceMgr.h"
 
 #include "SUIT_ExceptionHandler.h"
 
@@ -80,35 +83,6 @@ extern "C" int HandleSignals( QApplication *theQApplication );
  * - get session state
  */
 
-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;
-}
-
 PyObject* salome_shared_modules_module = 0;
 
 void MessageOutput( QtMsgType type, const char* msg )
@@ -150,6 +124,78 @@ static const char* pixmap_not_found_xpm[] = {
 "                ",
 "                "};
 
+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;
+}
+
+class SALOME_ResourceMgr : public SUIT_ResourceMgr
+{
+public:
+  SALOME_ResourceMgr( const QString& app, const QString& resVarTemplate ) : SUIT_ResourceMgr( app, resVarTemplate )
+  {
+    setCurrentFormat( "xml" );
+    setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
+    setDefaultPixmap( QPixmap( pixmap_not_found_xpm ) );
+  }
+  static void initResourceMgr()
+  {
+    if ( myExtAppName.isNull() || myExtAppVersion.isNull() ) {
+      SALOME_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) );
+      resMgr.loadLanguage( "SalomeApp", "en" );
+
+      myExtAppName = QObject::tr( "APP_NAME" ).stripWhiteSpace();
+      if ( myExtAppName == "APP_NAME" || myExtAppName.lower() == "salome" ) 
+        myExtAppName = "SalomeApp";
+      myExtAppVersion = QObject::tr( "APP_VERSION" );
+      if ( myExtAppVersion == "APP_VERSION" ) {
+        if ( myExtAppName != "SalomeApp" )
+          myExtAppVersion = "";
+       else myExtAppVersion = salomeVersion();
+      }
+    }
+  }
+  QString version() const { return myExtAppVersion; }
+
+protected:
+  QString userFileName( const QString& appName ) const
+  { 
+    if ( version().isNull()  ) return ""; 
+    return SUIT_ResourceMgr::userFileName( myExtAppName );
+  }
+
+public:
+  static QString myExtAppName;
+  static QString myExtAppVersion;
+};
+
+QString SALOME_ResourceMgr::myExtAppName    = QString::null;
+QString SALOME_ResourceMgr::myExtAppVersion = QString::null;
+
 class SALOME_Session : public SUIT_Session
 {
 public:
@@ -159,12 +205,8 @@ public:
 protected:
   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
   {
-    SUIT_ResourceMgr* 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 );
+    SALOME_ResourceMgr::initResourceMgr();
+    SALOME_ResourceMgr* resMgr = new SALOME_ResourceMgr( appName, QString( "%1Config" ) );
     return resMgr;
   }
 };
@@ -237,7 +279,6 @@ int main( int argc, char **argv )
   SUIT_Session* aGUISession = 0;
   SALOME_NamingService* _NS = 0;
   GetInterfaceThread* guiThread = 0;
-  SALOMETraceCollector* myThreadTrace = 0;
   Session_ServerLauncher* myServerLauncher = 0;
 
   try {
@@ -254,7 +295,6 @@ int main( int argc, char **argv )
     {
       INFOS( "salome_shared_modules_module == NULL" );
       PyErr_Print();
-      PyErr_Clear();
     }
     PyEval_ReleaseThread( KERNEL_PYTHON::_gtstate );
 
@@ -263,7 +303,6 @@ int main( int argc, char **argv )
     ASSERT( SINGLETON_<ORB_INIT>::IsAlreadyExisting() );
     int orbArgc = 1;
     orb = init( orbArgc, argv );
-    myThreadTrace = SALOMETraceCollector::instance( orb );
 
     // Install SALOME thread event handler
     SALOME_Event::GetSessionThread();
@@ -319,13 +358,12 @@ int main( int argc, char **argv )
     {
       // create temporary resource manager just to load splash icon
       SUIT_ResourceMgr resMgr( "SalomeApp", QString( "%1Config" ) );
-      resMgr.setVersion( salomeVersion() );
       resMgr.setCurrentFormat( "xml" );
-      resMgr.loadLanguage( "SalomeApp", "en" );
+      resMgr.loadLanguage( "LightApp", "en" );
 
       // create splash object: widget ( splash with progress bar ) and "pinging" thread
       InquireServersGUI splash;
-      splash.setPixmap( resMgr.loadPixmap( "SalomeApp", QObject::tr( "ABOUT" ) ) );
+      splash.setPixmap( resMgr.loadPixmap( "LightApp", QObject::tr( "ABOUT_SPLASH" ) ) );
       SUIT_Tools::centerWidget( &splash, _qappl.desktop() );
       
       _qappl.setMainWidget( &splash );
@@ -374,8 +412,9 @@ int main( int argc, char **argv )
       SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
       if ( aGUIApp )
       {
-       _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
-                                                    // aGUISession contains SalomeApp_ExceptionHandler
+       if ( !isFound( "noexcepthandler", argc, argv ) )
+         _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
+                                                      // aGUISession contains SalomeApp_ExceptionHandler
        // Run GUI loop
        MESSAGE( "run(): starting the main event loop" );
        result = _qappl.exec();
@@ -399,7 +438,9 @@ int main( int argc, char **argv )
   delete guiThread;
   delete myServerLauncher;
   delete _NS;
-  delete myThreadTrace;
+
+  LocalTraceBufferPool *bp1 = LocalTraceBufferPool::instance();
+  LocalTraceBufferPool::deleteInstance(bp1);
 
   return result;
 }