Salome HOME
*** empty log message ***
[modules/gui.git] / src / SUIT / SUIT_Session.cxx
index d2c547c1dbe4ecf1714e9a230560ac5e60b4c5fd..d47b8d3e33ff94fda620db1b0657932aa76a0ecd 100755 (executable)
@@ -22,7 +22,9 @@ SUIT_Session* SUIT_Session::mySession = 0;
 SUIT_Session::SUIT_Session()
 : QObject(),
 myResMgr( 0 ),
-myHandler( 0 )
+myHandler( 0 ),
+myActiveApp( 0 ),
+myExitStatus( FROM_GUI )
 {
   SUIT_ASSERT( !mySession )
 
@@ -65,7 +67,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;
 
@@ -89,7 +92,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" ) );
@@ -100,6 +104,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args,
 
   connect( anApp, SIGNAL( applicationClosed( SUIT_Application* ) ),
            this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
+  connect( anApp, SIGNAL( activated( SUIT_Application* ) ), 
+          this, SLOT( onApplicationActivated( SUIT_Application* ) ) );
 
   myAppList.append( anApp );
 
@@ -139,6 +145,7 @@ QPtrList<SUIT_Application> SUIT_Session::applications() const
 */
 SUIT_Application* SUIT_Session::activeApplication() const
 {
+  /*
   if ( myAppList.count() == 1 )
     return myAppList.getFirst();
 
@@ -162,6 +169,8 @@ SUIT_Application* SUIT_Session::activeApplication() const
     return 0;
 
   return study->application();
+  */
+  return myActiveApp;
 }
 
 /*!
@@ -181,22 +190,40 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp )
   emit applicationClosed( theApp );
 
   myAppList.remove( theApp );
+  if ( theApp == myActiveApp )
+    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 )
 {
-  for ( AppListIterator it( myAppList ); it.current(); ++it )
+  while ( !myAppList.isEmpty() )
   {
-    if ( !it.current()->isPossibleToClose() )
+    SUIT_Application* app = myAppList.getFirst();
+    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();
   }
-  qApp->quit();
 }
 
 SUIT_ExceptionHandler* SUIT_Session::handler() const
@@ -254,3 +281,11 @@ SUIT_ResourceMgr* SUIT_Session::createResourceMgr( const QString& appName ) cons
 {
   return new SUIT_ResourceMgr( appName );
 }
+
+/*!
+  Slot, called on activation of some application's desktop
+*/
+void SUIT_Session::onApplicationActivated( SUIT_Application* app ) 
+{
+  myActiveApp = app;
+}