Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[modules/gui.git] / src / SUIT / SUIT_Session.cxx
index 9dcef329a14af5edd78440d78d3189b6f9b0b372..a9db903d08ce360045b6bf2b393e34c502130fda 100755 (executable)
 
 SUIT_Session* SUIT_Session::mySession = 0;
 
+/*! Constructor.*/
+
 SUIT_Session::SUIT_Session()
 : QObject(),
 myResMgr( 0 ),
 myHandler( 0 ),
-myActiveApp( 0 )
+myActiveApp( 0 ),
+myExitStatus( FROM_GUI )
 {
   SUIT_ASSERT( !mySession )
 
@@ -32,6 +35,7 @@ myActiveApp( 0 )
   myAppList.setAutoDelete( true );
 }
 
+/*!destructor. Clear applications list and set mySession to zero.*/
 SUIT_Session::~SUIT_Session()
 {
   myAppList.clear();
@@ -39,6 +43,7 @@ SUIT_Session::~SUIT_Session()
   mySession = 0;
 }
 
+/*! \retval return mySession */
 SUIT_Session* SUIT_Session::session()
 {
   return mySession;
@@ -66,7 +71,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
     return 0;
   }
 
-  myAppLibs.insert( appName, libHandle );
+  if (!myAppLibs.contains(appName) || !myAppLibs[appName]) // jfa 22.06.2005
+    myAppLibs.insert( appName, libHandle );
 
   APP_CREATE_FUNC crtInst = 0;
 
@@ -90,7 +96,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
     myResMgr->loadLanguage();
   }
 
-  SUIT_Application* anApp = crtInst( args, argv );
+  //jfa 22.06.2005:SUIT_Application* anApp = crtInst( args, argv );
+  SUIT_Application* anApp = crtInst();
   if ( !anApp )
   {
     SUIT_MessageBox::warn1(0, tr( "Error" ), tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) );
@@ -191,29 +198,45 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp )
     myActiveApp = 0;
 
   if ( myAppList.isEmpty() )
-    qApp->quit();
+  {
+    printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus );
+    qApp->exit( myExitStatus );
+  }
 }
 
 /*!
   Destroys session by closing all applications.
 */
-void SUIT_Session::closeSession()
+void SUIT_Session::closeSession( int mode )
 {
   while ( !myAppList.isEmpty() )
   {
     SUIT_Application* app = myAppList.getFirst();
-    if ( !app->isPossibleToClose() )
+    if ( mode == ASK && !app->isPossibleToClose() )
       return;
+    else if ( mode == SAVE )
+    {
+      SUIT_Study* study = app->activeStudy();
+      if ( study->isModified() && study->isSaved() )
+       study->saveDocument();
+    }
+    else if ( mode == DONT_SAVE )
+    {
+      myExitStatus = FROM_CORBA_SESSION;
+      //....
+    }
 
     app->closeApplication();
   }
 }
 
+/*! \retval return myHandler*/
 SUIT_ExceptionHandler* SUIT_Session::handler() const
 {
   return myHandler;
 }
 
+/*! \retval return last error string.*/
 QString SUIT_Session::lastError() const
 {
   QString str;
@@ -229,6 +252,9 @@ QString SUIT_Session::lastError() const
   return str;
 }
 
+/*! Load library to session.
+ * \retval Loaded library.
+ */
 SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name )
 {
   QString libFile = SUIT_Tools::library( name );
@@ -245,6 +271,7 @@ SUIT_Session::AppLib SUIT_Session::loadLibrary( const QString& name )
   return lib;
 }
 
+/*! \retval Return file name by application name.*/
 QString SUIT_Session::applicationName( const QString& str ) const
 {
 #ifdef WIN32