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