Salome HOME
studyActivated() virtual method has been added
[modules/gui.git] / src / SUIT / SUIT_Session.h
1 #ifndef SUIT_SESSION_H
2 #define SUIT_SESSION_H
3
4 #include "SUIT.h"
5
6 #include "SUIT_Application.h"
7 #include "SUIT_ResourceMgr.h"
8
9 #include <qobject.h>
10 #include <qptrlist.h>
11 #include <qptrvector.h>
12 #include <qstringlist.h>
13
14 #ifdef WIN32
15 #define LIB_HANDLE HINSTANCE
16 #else
17 #define LIB_HANDLE void*
18 #endif
19
20 class SUIT_ResourceMgr;
21 class SUIT_ExceptionHandler;
22
23 /*!
24   The class Sesssion manages launching of Applications. Application must be returned
25   by static function "createApplication" in external library. The Library must be loaded with 
26   loadLibrary method and after that application can be started.
27 */
28
29 #ifdef WNT
30 #pragma warning( disable:4251 )
31 #endif
32
33 class SUIT_EXPORT SUIT_Session: public QObject
34 {
35   Q_OBJECT
36
37 public:
38   typedef LIB_HANDLE AppLib;
39
40   enum { ASK = 0, SAVE, DONT_SAVE } CloseMode;
41   enum { FROM_GUI = 0, FROM_CORBA_SESSION } ExitStatus;
42
43 public:
44   SUIT_Session();
45   virtual ~SUIT_Session();
46
47   static SUIT_Session*         session();
48
49   SUIT_Application*            startApplication( const QString&, int = 0, char** = 0 );
50
51   QPtrList<SUIT_Application>   applications() const;
52   SUIT_Application*            activeApplication() const;
53
54   SUIT_ResourceMgr*            resourceMgr() const;
55
56   void                         closeSession( int mode = ASK );
57
58   SUIT_ExceptionHandler*       handler() const;
59
60 signals:
61   void                         applicationClosed( SUIT_Application* );
62
63 protected:
64   virtual SUIT_ResourceMgr*    createResourceMgr( const QString& ) const;
65
66 private slots:
67   void                         onApplicationClosed( SUIT_Application* );
68   void                         onApplicationActivated( SUIT_Application* ); 
69
70 private:
71   typedef QPtrList<SUIT_Application>         AppList;
72   typedef QMap<QString, AppLib>              AppLibMap;
73   typedef QPtrListIterator<SUIT_Application> AppListIterator;
74
75 private:
76   QString                      lastError() const;
77   AppLib                       loadLibrary( const QString& );
78   QString                      applicationName( const QString& ) const;
79
80 private:
81   SUIT_ResourceMgr*            myResMgr;
82   AppList                      myAppList;
83   AppLibMap                    myAppLibs;
84   SUIT_Application*            myActiveApp;
85
86   SUIT_ExceptionHandler*       myHandler;
87   static SUIT_Session*         mySession;
88
89   int                          myExitStatus;
90 };
91
92 #endif