Salome HOME
Update copyrights 2014.
[modules/gui.git] / src / SUIT / SUIT_Session.h
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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
23 #ifndef SUIT_SESSION_H
24 #define SUIT_SESSION_H
25
26 #include "SUIT.h"
27 #include "SUIT_Application.h"
28
29 #include <QList>
30 #include <QObject>
31 #include <QString>
32
33 #ifdef WIN32
34 #include <windows.h>
35 #endif
36
37 #ifdef WIN32
38 #define LIB_HANDLE HINSTANCE
39 #else
40 #define LIB_HANDLE void*
41 #endif
42
43 class SUIT_ResourceMgr;
44 class SUIT_ExceptionHandler;
45
46 #ifdef WIN32
47 #pragma warning( disable:4251 )
48 #endif
49 /*!
50   The class Sesssion manages launching of Applications. Application must be returned \n
51   by static function "createApplication" in external library. The Library must be loaded with \n
52   loadLibrary method and after that application can be started.
53 */
54 class SUIT_EXPORT SUIT_Session : public QObject
55 {
56   Q_OBJECT
57
58 public:
59   typedef LIB_HANDLE AppLib;
60
61   enum { ASK = 0, SAVE, DONT_SAVE } CloseMode;
62   enum { NORMAL = 0, FORCED } ExitStatus;
63
64 public:
65   SUIT_Session();
66   virtual ~SUIT_Session();
67
68   static SUIT_Session*         session();
69
70   SUIT_Application*            startApplication( const QString&, int = 0, char** = 0 );
71
72   QList<SUIT_Application*>     applications() const;
73   SUIT_Application*            activeApplication() const;
74
75   SUIT_ResourceMgr*            resourceMgr() const;
76
77   void                         closeSession( int mode = ASK, int flags = 0 );
78   int                          exitFlags() const;
79
80   SUIT_ExceptionHandler*       handler() const;
81
82   void                         insertApplication( SUIT_Application* );
83
84 signals:
85   void                         applicationClosed( SUIT_Application* );
86
87 protected:
88   virtual SUIT_ResourceMgr*    createResourceMgr( const QString& ) const;
89
90 private slots:
91   void                         onApplicationClosed( SUIT_Application* );
92   void                         onApplicationActivated( SUIT_Application* ); 
93
94 private:
95   typedef QList<SUIT_Application*> AppList;
96   typedef QMap<QString, AppLib>    AppLibMap;
97
98 private:
99   QString                      lastError() const;
100   AppLib                       loadLibrary( const QString&, QString& );
101   QString                      applicationName( const QString& ) const;
102
103 private:
104   SUIT_ResourceMgr*            myResMgr;
105   AppList                      myAppList;
106   AppLibMap                    myAppLibs;
107   SUIT_Application*            myActiveApp;
108
109   SUIT_ExceptionHandler*       myHandler;
110   static SUIT_Session*         mySession;
111
112   int                          myExitStatus;
113   int                          myExitFlags;
114 };
115
116 #endif