Salome HOME
497906700d51bd86b9e042b0d26df6b6d3415760
[modules/gui.git] / src / SUITApp / SUITApp.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #if defined WNT
20
21 #undef SUIT_ENABLE_PYTHON
22 //#else
23 //#include "SUITconfig.h"
24 #endif
25
26 #include "SUITApp_Application.h"
27
28 #include <SUIT_Session.h>
29 #include <SUIT_Desktop.h>
30 #include <SUIT_ResourceMgr.h>
31
32
33 #ifdef SUIT_ENABLE_PYTHON
34 #include <Python.h>
35 #endif
36
37 #include <qdir.h>
38 #include <qfile.h>
39 #include <qstring.h>
40 #include <qstringlist.h>
41
42 #include <stdlib.h>
43
44 QString salomeVersion()
45 {
46   QString path( ::getenv( "GUI_ROOT_DIR" ) );
47   if ( !path.isEmpty() )
48     path += QDir::separator();
49
50   path += QString( "bin/salome/VERSION" );
51
52   QFile vf( path );
53   if ( !vf.open( IO_ReadOnly ) )
54     return QString::null;
55
56   QString line;
57   vf.readLine( line, 1024 );
58   vf.close();
59
60   if ( line.isEmpty() )
61     return QString::null;
62
63   while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
64     line.remove( line.length() - 1, 1 );
65
66   QString ver;
67   int idx = line.findRev( ":" );
68   if ( idx != -1 )
69     ver = line.mid( idx + 1 ).stripWhiteSpace();
70
71   return ver;
72 }
73
74
75 /* XPM */
76 static const char* pixmap_not_found_xpm[] = {
77 "16 16 3 1",
78 "       c None",
79 ".      c #000000",
80 "+      c #A80000",
81 "                ",
82 "                ",
83 "    .     .     ",
84 "   .+.   .+.    ",
85 "  .+++. .+++.   ",
86 "   .+++.+++.    ",
87 "    .+++++.     ",
88 "     .+++.      ",
89 "    .+++++.     ",
90 "   .+++.+++.    ",
91 "  .+++. .+++.   ",
92 "   .+.   .+.    ",
93 "    .     .     ",
94 "                ",
95 "                ",
96 "                "};
97
98 class SUITApp_Session: public SUIT_Session
99 {
100 public:
101   SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
102   virtual ~SUITApp_Session() {}
103
104 protected:
105   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
106   {
107     SUIT_ResourceMgr* resMgr = 0;
108     if ( myIniFormat )
109     {
110       resMgr = new SUIT_ResourceMgr( appName );
111       resMgr->setCurrentFormat( "ini" );
112     }
113     else
114     {
115       resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
116       resMgr->setVersion( salomeVersion() );
117       resMgr->setCurrentFormat( "xml" );
118     }
119
120     if ( resMgr )
121     {
122       static QPixmap defaultPixmap( pixmap_not_found_xpm );
123       resMgr->setDefaultPixmap( defaultPixmap );
124       resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
125     }
126     return resMgr;
127   }
128
129 private:
130   bool  myIniFormat;
131 };
132
133 int main( int args, char* argv[] )
134 {
135 #ifdef SUIT_ENABLE_PYTHON
136   Py_Initialize();
137   PySys_SetArgv( args, argv );
138 #endif
139
140   QStringList argList;
141   bool noExceptHandling = false;
142   bool iniFormat = false;
143   for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ )
144   {
145     if ( !strcmp( argv[i], "/noexcepthandling" ) )
146       noExceptHandling = true;
147     else if ( !strcmp( argv[i], "--format=ini") )
148       iniFormat = true;
149     else
150       argList.append( QString( argv[i] ) );
151   }
152
153   SUITApp_Application app( args, argv );
154
155   int result = -1;
156   if ( !argList.isEmpty() )
157   {
158     SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
159     SUIT_Application* theApp = aSession->startApplication( argList.first() );
160     if ( theApp )
161     {
162       if ( !noExceptHandling )
163         app.setHandler( aSession->handler() );
164
165 //      if ( !app.mainWidget() )
166 //        app.setMainWidget( theApp->desktop() );
167
168       result = app.exec();
169     }
170     delete aSession;
171   }
172
173   return result;
174 }