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