Salome HOME
Fixing a bug : Salome GUI style needs addLibraryPath() method to be called
[modules/gui.git] / src / Session / SALOME_Session_Server.cxx
index 6aeb7e868380648ec082bded0f6581338de0edc8..1d3af0a513c41506bf58ab43f4fbba5755c9c160 100755 (executable)
@@ -35,9 +35,9 @@
 #include <iostream>
 #include <unistd.h>
 
-#include <qthread.h> 
+#include <qdir.h>
+#include <qfile.h>
 #include <qapplication.h>
-#include <qlabel.h>
 #include <qwaitcondition.h>
 
 #include "Utils_SALOME_Exception.hxx"
@@ -80,13 +80,37 @@ extern "C" int HandleSignals(QApplication *theQApplication);
  *   - get session state
  */
 
-#ifdef _DEBUG_
-static int MYDEBUG = 0;
-#else
-static int MYDEBUG = 0;
-#endif
+QString salomeVersion()
+{
+  QString path( ::getenv( "GUI_ROOT_DIR" ) );
+  if ( !path.isEmpty() )
+    path += QDir::separator();
+  path += QString( "bin/salome/VERSION" );
+
+  QFile vf( path );
+  if ( !vf.open( IO_ReadOnly ) )
+    return QString::null;
+
+  QString line;
+  vf.readLine( line, 1024 );
+  vf.close();
+
+  if ( line.isEmpty() )
+    return QString::null;
+
+  while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) )
+    line.remove( line.length() - 1, 1 );
+
+  QString ver;
+  int idx = line.findRev( ":" );
+  if ( idx != -1 )
+    ver = line.mid( idx + 1 ).stripWhiteSpace();
+
+  return ver;
+}
 
 PyObject *salome_shared_modules_module = NULL;
+
 void MessageOutput( QtMsgType type, const char *msg )
 {
   switch ( type ) {
@@ -112,6 +136,7 @@ protected:
   virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const
   {
     SUIT_ResourceMgr* resMgr = new SUIT_ResourceMgr( appName, QString( "%1Config" ) );
+    resMgr->setVersion( salomeVersion() );
     resMgr->setCurrentFormat( "xml" );
     return resMgr;
   }
@@ -137,16 +162,31 @@ private:
   SUIT_ExceptionHandler*  myHandler;
 };
 
-
-
-
 int main(int argc, char **argv)
 {
   qInstallMsgHandler( MessageOutput );
 
   /*
-   * Python initialisation : only once
-   */
+  char* _argv_0[512];
+  strcpy( (char*)_argv_0, (char*)argv[0] );
+  */
+
+  // QApplication should be create before all other operations
+  // When uses QApplication::libraryPaths() (example, QFile::encodeName())
+  // qApp used for detection of the executable dir path.
+  SALOME_QApplication _qappl( argc, argv );
+  ASSERT( QObject::connect(&_qappl, SIGNAL( lastWindowClosed() ), &_qappl, SLOT( quit() ) ) );
+  QString path( ::getenv( "GUI_ROOT_DIR" ) );
+  if ( !path.isEmpty() )
+    path += QDir::separator();
+  path += QString( "bin/salome" );
+  _qappl.addLibraryPath( path );
+  _qappl.setStyle( "salome" );
+
+  /*
+    Python initialisation : only once
+  */
+
   int _argc = 1;
   char* _argv[] = {""};
   KERNEL_PYTHON::init_python(_argc,_argv);
@@ -206,15 +246,23 @@ int main(int argc, char **argv)
        // this thread wakes up, and lock mutex
 
        INFOS("Session activated, Launch IAPP...");
-
+       /*
        int qArgc = 1;
+       argv[0] = (char*)_argv_0;
        SALOME_QApplication* _qappl = new SALOME_QApplication( qArgc, argv );
+
+       QStringList lst = _qappl->libraryPaths();
+       for ( QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it )
+         printf( "=====> Library path: %s\n", (*it).latin1() );
+
+       _qappl->setStyle( "salome" );
+
+       ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
+       */
        
        INFOS("creation QApplication");
        _GUIMutex.unlock();
 
-       ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) );
-
        // 3.1 SUIT_Session creation    
        SUIT_Session* aGUISession = new SALOME_Session();
        INFOS("creation SUIT_Application");
@@ -228,17 +276,13 @@ int main(int argc, char **argv)
          {
            MESSAGE("run(): starting the main event loop");
 
-// 3.2 load SalomeApp dynamic library
-#ifdef WNT
-           SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp.dll", 0, 0 );
-#else
-            SUIT_Application* aGUIApp = aGUISession->startApplication( "libSalomeApp.so", 0, 0 );
-#endif
+           // 3.2 load SalomeApp dynamic library
+            SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
            if ( aGUIApp ) 
            {
-             _qappl->setHandler( aGUISession->handler() ); // after loading SalomeApp application
+             _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
                                                             // aGUISession contains SalomeApp_ExceptionHandler
-             result = _qappl->exec();
+             result = _qappl.exec();
            }
            break;
          }