Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / Session / SALOME_Session_QThread.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SALOME_Session_QThread.cxx
4 // Created   : mar jun 19 15:18:31 CEST 2001
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2001
8 // $Header$
9 //=============================================================================
10
11 #include <qapplication.h>
12 #include <qlabel.h>
13
14 #include "utilities.h"
15 #include "SALOME_Session_QThread.hxx"
16 #include "SALOME_NamingService.hxx"
17 #include "SALOMEGUI_Application.h"
18 #include "QAD.h"
19 #include "QAD_MessageBox.h"
20 #include "QAD_Application.h"
21 #include "QAD_Settings.h"
22 #include "QAD_Config.h"
23 #include "QAD_Tools.h"
24 // only to use findFile method : perhaps put it in QAD_Tools ???
25 #include "QAD_ResourceMgr.h"
26 #include <qlabel.h>
27
28
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31
32 //=============================================================================
33 /*! SALOME_Session_QThread
34  *  constructor
35  */
36 //=============================================================================
37
38 SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread()
39 {
40   _qappl = 0 ;
41   _mw = 0 ;
42   _argc = argc ;
43   _argv = argv ;
44   _NS = 0 ;
45 } ;
46
47 //=============================================================================
48 /*! run
49  *  Creates one QApplication for the all the session life.
50  *  Executes the Qt main window of the GUI on a separate thread
51  */
52 //=============================================================================
53
54 void SALOME_Session_QThread::run()
55 {
56   if (_qappl == 0)
57     {
58       _qappl = new QApplication(_argc, _argv );
59       INFOS("creation QApplication");
60     }
61
62   QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
63   _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" );
64   INFOS("creation SALOMEGUI_Application");
65   
66   if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) )
67     {
68       QAD_MessageBox::error1 ( 0,
69                                QObject::tr("ERR_ERROR"), 
70                                QObject::tr("ERR_APP_INITFAILED"),
71                                QObject::tr("BUT_OK") );
72     }
73   else
74     {
75       
76       QFileInfo prgInfo(_argv[0]);
77       QDir prgDir(prgInfo.dirPath(true));
78       QAD_CONFIG->setPrgDir(prgDir);        // CWD is program directory
79       QAD_CONFIG->createConfigFile(false);  // Create config file ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none
80       QAD_CONFIG->readConfigFile();         // Read config file
81
82       _qappl->setPalette( QAD_Application::getPalette() ); 
83
84       /* Run 'SALOMEGUI' application */
85       QAD_Application::run();
86
87       // T2.12 - catch exceptions thrown on attempts to modified a locked study
88       while (1) {
89         try {
90           MESSAGE("run(): starting the main event loop")
91           _ret = _qappl->exec();
92           break;
93         }
94         catch(SALOMEDS::StudyBuilder::LockProtection&) {
95           MESSAGE("run(): An attempt to modify a locked study has not been handled by QAD_Operation")
96           QApplication::restoreOverrideCursor();
97           QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
98                                QObject::tr("WRN_WARNING"), 
99                                QObject::tr("WRN_STUDY_LOCKED"),
100                                QObject::tr("BUT_OK") );
101         }
102         catch(...) {
103           MESSAGE("run(): An exception has been caught")
104           QApplication::restoreOverrideCursor();
105           QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(),
106                                QObject::tr("ERR_ERROR"), 
107                                QObject::tr("ERR_APP_EXCEPTION"),
108                                QObject::tr("BUT_OK") );
109         }
110       }
111
112       QString confMsg = "Settings create $HOME/." + QObject::tr("MEN_APPNAME") + "/" + QObject::tr("MEN_APPNAME") + ".conf";
113       MESSAGE (confMsg )
114       QAD_CONFIG->createConfigFile(true);
115     }
116 } ;
117
118 //=============================================================================
119 /*! setNamingService
120  *  gives the naming service interface 
121  */
122 //=============================================================================
123 void SALOME_Session_QThread::setNamingService(SALOME_NamingService *ns)
124 {
125   _NS = ns;
126 }