Salome HOME
7b16ea1832427b96cc319122b9d9245592865da4
[modules/gui.git] / src / SUIT / SUIT_Session.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef SUIT_SESSION_H
20 #define SUIT_SESSION_H
21
22 #include "SUIT.h"
23
24 #include "SUIT_Application.h"
25 #include "SUIT_ResourceMgr.h"
26
27 #include <qmutex.h>
28 #include <qobject.h>
29 #include <qptrlist.h>
30 #include <qptrvector.h>
31 #include <qstringlist.h>
32
33 #ifdef WIN32
34 #define LIB_HANDLE HINSTANCE
35 #else
36 #define LIB_HANDLE void*
37 #endif
38
39 class SUIT_ResourceMgr;
40 class SUIT_ExceptionHandler;
41
42 #ifdef WNT
43 #pragma warning( disable:4251 )
44 #endif
45 /*!
46   The class Sesssion manages launching of Applications. Application must be returned \n
47   by static function "createApplication" in external library. The Library must be loaded with \n
48   loadLibrary method and after that application can be started.
49 */
50 class SUIT_EXPORT SUIT_Session: public QObject
51 {
52   Q_OBJECT
53
54 public:
55   typedef LIB_HANDLE AppLib;
56
57   enum { ASK = 0, SAVE, DONT_SAVE } CloseMode;
58   enum { NORMAL = 0, FORCED } ExitStatus;
59
60 public:
61   SUIT_Session();
62   virtual ~SUIT_Session();
63
64   static SUIT_Session*         session();
65
66   SUIT_Application*            startApplication( const QString&, int = 0, char** = 0 );
67
68   QPtrList<SUIT_Application>   applications() const;
69   SUIT_Application*            activeApplication() const;
70
71   SUIT_ResourceMgr*            resourceMgr() const;
72
73   void                         closeSession( int mode = ASK, int flags = 0 );
74   int                          exitFlags() const;
75
76   SUIT_ExceptionHandler*       handler() const;
77
78   // To lock GUI user actions during python command execution (PAL12651)
79   static bool                  IsPythonExecuted();
80   static void                  SetPythonExecuted(bool isPythonExecuted);
81
82 signals:
83   void                         applicationClosed( SUIT_Application* );
84
85 protected:
86   virtual SUIT_ResourceMgr*    createResourceMgr( const QString& ) const;
87
88 private slots:
89   void                         onApplicationClosed( SUIT_Application* );
90   void                         onApplicationActivated( SUIT_Application* ); 
91
92 private:
93   typedef QPtrList<SUIT_Application>         AppList;
94   typedef QMap<QString, AppLib>              AppLibMap;
95   typedef QPtrListIterator<SUIT_Application> AppListIterator;
96
97 private:
98   QString                      lastError() const;
99   AppLib                       loadLibrary( const QString&, QString& );
100   QString                      applicationName( const QString& ) const;
101
102 private:
103   SUIT_ResourceMgr*            myResMgr;
104   AppList                      myAppList;
105   AppLibMap                    myAppLibs;
106   SUIT_Application*            myActiveApp;
107
108   SUIT_ExceptionHandler*       myHandler;
109   static SUIT_Session*         mySession;
110
111   int                          myExitStatus;
112   int                          myExitFlags;
113 };
114
115 #endif