]> SALOME platform Git repositories - modules/gui.git/blob - src/SUITApp/SUITApp.cxx
Salome HOME
Transaction management in operations modifed.
[modules/gui.git] / src / SUITApp / SUITApp.cxx
1 #if defined WNT
2
3 #undef SUIT_ENABLE_PYTHON
4 //#else
5 //#include "SUITconfig.h"
6 #endif
7
8 #include "SUITApp_Application.h"
9
10 #include "SUIT_Session.h"
11 #include "SUIT_ResourceMgr.h"
12
13
14 #ifdef SUIT_ENABLE_PYTHON
15 #include <Python.h>
16 #endif
17
18 #include <qdir.h>
19 #include <qfile.h>
20 #include <qstring.h>
21 #include <qstringlist.h>
22
23 #include <stdlib.h>
24
25 QString salomeVersion()
26 {
27   QString path( ::getenv( "GUI_ROOT_DIR" ) );
28   if ( !path.isEmpty() )
29     path += QDir::separator();
30
31   path += QString( "bin/salome/VERSION" );
32
33   QFile vf( path );
34   if ( !vf.open( IO_ReadOnly ) )
35     return QString::null;
36
37   QString line;
38   vf.readLine( line, 1024 );
39   vf.close();
40
41   if ( line.isEmpty() )
42     return QString::null;
43
44   while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
45     line.remove( line.length() - 1, 1 );
46
47   QString ver;
48   int idx = line.findRev( ":" );
49   if ( idx != -1 )
50     ver = line.mid( idx + 1 ).stripWhiteSpace();
51
52   return ver;
53 }
54
55
56 /* XPM */
57 static const char* pixmap_not_found_xpm[] = {
58 "16 16 3 1",
59 "       c None",
60 ".      c #000000",
61 "+      c #A80000",
62 "                ",
63 "                ",
64 "    .     .     ",
65 "   .+.   .+.    ",
66 "  .+++. .+++.   ",
67 "   .+++.+++.    ",
68 "    .+++++.     ",
69 "     .+++.      ",
70 "    .+++++.     ",
71 "   .+++.+++.    ",
72 "  .+++. .+++.   ",
73 "   .+.   .+.    ",
74 "    .     .     ",
75 "                ",
76 "                ",
77 "                "};
78
79 class SUITApp_Session: public SUIT_Session
80 {
81 public:
82   SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
83   virtual ~SUITApp_Session() {}
84
85 protected:
86   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
87   {
88     SUIT_ResourceMgr* resMgr = 0;
89     if ( myIniFormat )
90     {
91       resMgr = new SUIT_ResourceMgr( appName );
92       resMgr->setCurrentFormat( "ini" );
93     }
94     else
95     {
96       resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
97       resMgr->setVersion( salomeVersion() );
98       resMgr->setCurrentFormat( "xml" );
99     }
100
101     if ( resMgr )
102     {
103       static QPixmap defaultPixmap( pixmap_not_found_xpm );
104       resMgr->setDefaultPixmap( defaultPixmap );
105       resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
106     }
107     return resMgr;
108   }
109
110 private:
111   bool  myIniFormat;
112 };
113
114 int main( int args, char* argv[] )
115 {
116 #ifdef SUIT_ENABLE_PYTHON
117   Py_Initialize();
118   PySys_SetArgv( args, argv );
119 #endif
120
121   QStringList argList;
122   bool noExceptHandling = false;
123   bool iniFormat = false;
124   for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ )
125   {
126     if ( !strcmp( argv[i], "/noexcepthandling" ) )
127       noExceptHandling = true;
128     else if ( !strcmp( argv[i], "--format=ini") )
129       iniFormat = true;
130     else
131       argList.append( QString( argv[i] ) );
132   }
133
134   SUITApp_Application app( args, argv );
135
136   int result = -1;
137   if ( !argList.isEmpty() )
138   {
139     SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
140     if ( aSession->startApplication( argList.first() ) )
141     {
142       if ( !noExceptHandling )
143         app.setHandler( aSession->handler() );
144
145       result = app.exec();
146     }
147     delete aSession;
148   }
149
150   return result;
151 }