]> SALOME platform Git repositories - modules/gui.git/blob - src/SUITApp/SUITApp.cxx
Salome HOME
57098d0cc80cbc27b7c43862b7cd377d3e547350
[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 #include <QtxSplash.h>
33
34 #ifdef SUIT_ENABLE_PYTHON
35 #include <Python.h>
36 #endif
37
38 #include <qdir.h>
39 #include <qfile.h>
40 #include <qstring.h>
41 #include <qstringlist.h>
42 #include <qregexp.h>
43
44 #include <stdlib.h>
45
46 QString salomeVersion()
47 {
48   QString path( ::getenv( "GUI_ROOT_DIR" ) );
49   if ( !path.isEmpty() )
50     path += QDir::separator();
51
52   path += QString( "bin/salome/VERSION" );
53
54   QFile vf( path );
55   if ( !vf.open( IO_ReadOnly ) )
56     return QString::null;
57
58   QString line;
59   vf.readLine( line, 1024 );
60   vf.close();
61
62   if ( line.isEmpty() )
63     return QString::null;
64
65   while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
66     line.remove( line.length() - 1, 1 );
67
68   QString ver;
69   int idx = line.findRev( ":" );
70   if ( idx != -1 )
71     ver = line.mid( idx + 1 ).stripWhiteSpace();
72
73   return ver;
74 }
75
76
77 /* XPM */
78 static const char* pixmap_not_found_xpm[] = {
79 "16 16 3 1",
80 "       c None",
81 ".      c #000000",
82 "+      c #A80000",
83 "                ",
84 "                ",
85 "    .     .     ",
86 "   .+.   .+.    ",
87 "  .+++. .+++.   ",
88 "   .+++.+++.    ",
89 "    .+++++.     ",
90 "     .+++.      ",
91 "    .+++++.     ",
92 "   .+++.+++.    ",
93 "  .+++. .+++.   ",
94 "   .+.   .+.    ",
95 "    .     .     ",
96 "                ",
97 "                ",
98 "                "};
99
100 class SUITApp_Session: public SUIT_Session
101 {
102 public:
103   SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {}
104   virtual ~SUITApp_Session() {}
105
106   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
107   {
108     SUIT_ResourceMgr* resMgr = 0;
109     if ( myIniFormat )
110     {
111       resMgr = new SUIT_ResourceMgr( appName );
112       resMgr->setCurrentFormat( "ini" );
113     }
114     else
115     {
116       resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
117       resMgr->setVersion( salomeVersion() );
118       resMgr->setCurrentFormat( "xml" );
119     }
120
121     if ( resMgr )
122     {
123       static QPixmap defaultPixmap( pixmap_not_found_xpm );
124       resMgr->setDefaultPixmap( defaultPixmap );
125       resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) );
126     }
127     return resMgr;
128   }
129
130 private:
131   bool  myIniFormat;
132 };
133
134 int main( int args, char* argv[] )
135 {
136 #ifdef SUIT_ENABLE_PYTHON
137   Py_Initialize();
138   PySys_SetArgv( args, argv );
139 #endif
140
141   QStringList argList;
142   bool noExceptHandling = false;
143   bool iniFormat        = false;
144   bool noSplash         = false;
145   for ( int i = 1; i < args /*&& !noExceptHandling*/; i++ )
146   {
147     if ( !strcmp( argv[i], "--noexcepthandling" ) )
148       noExceptHandling = true;
149     else if ( !strcmp( argv[i], "--format=ini") )
150       iniFormat = true;
151     else if ( !strcmp( argv[i], "--nosplash") )
152       noSplash = true;
153     else
154       argList.append( QString( argv[i] ) );
155   }
156
157   SUITApp_Application app( args, argv );
158
159   int result = -1;
160   if ( !argList.isEmpty() )
161   {
162     SUITApp_Session* aSession = new SUITApp_Session( iniFormat );
163     QtxSplash* splash = 0;
164     if ( !noSplash ) {
165       SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() );
166       if ( resMgr ) {
167         resMgr->loadLanguage();
168         QString splashIcon, splashInfo, splashTextColors;
169         resMgr->value( "splash", "image",       splashIcon );
170         resMgr->value( "splash", "info",        splashInfo, false );
171         resMgr->value( "splash", "text_colors", splashTextColors );
172         QString appName    = QObject::tr( "APP_NAME" ).stripWhiteSpace();
173         QString appVersion = QObject::tr( "APP_VERSION" ).stripWhiteSpace();
174         if ( appVersion == "APP_VERSION" ) {
175           if ( appName == "APP_NAME" || appName.lower() == "salome" )
176             appVersion = salomeVersion();
177           else
178             appVersion = "";
179         }
180         QPixmap px( splashIcon );
181         if ( !px.isNull() ) {
182           splash = QtxSplash::splash( px );
183           if ( !splashTextColors.isEmpty() ) {
184             QStringList colors = QStringList::split( "|", splashTextColors );
185             QColor c1, c2;
186             if ( colors.count() > 0 ) c1 = QColor( colors[0] );
187             if ( colors.count() > 1 ) c2 = QColor( colors[1] );
188             splash->setTextColors( c1, c2 );
189           }
190           else {
191             splash->setTextColors( Qt::white, Qt::black );
192           }
193 #ifdef _DEBUG_
194           splash->setHideOnClick( true );
195 #endif
196           QFont f = splash->font();
197           f.setBold( true );
198           splash->setFont( f );
199           if ( !splashInfo.isEmpty() ) {
200             splashInfo.replace( QRegExp( "%A" ),  appName );
201             splashInfo.replace( QRegExp( "%V" ),  QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) );
202             splashInfo.replace( QRegExp( "%L" ),  QObject::tr( "ABOUT_LICENSE" ) );
203             splashInfo.replace( QRegExp( "%C" ),  QObject::tr( "ABOUT_COPYRIGHT" ) );
204             splashInfo.replace( QRegExp( "\\\\n" ), "\n" );
205             splash->message( splashInfo );
206           }
207           splash->show();
208           qApp->processEvents();
209         }
210       }
211     }
212     SUIT_Application* theApp = aSession->startApplication( argList.first() );
213     if ( theApp )
214     {
215       if ( !noExceptHandling )
216         app.setHandler( aSession->handler() );
217
218 //      if ( !app.mainWidget() )
219 //        app.setMainWidget( theApp->desktop() );
220       if ( splash )
221         splash->finish( theApp->desktop() );
222
223       result = app.exec();
224       if ( splash )
225         delete splash;
226     }
227     delete aSession;
228   }
229
230   return result;
231 }