Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / RegistryDisplay / RegWidget.cxx
index fd1371b2949a93b510f6f05fb022978ab062b3a5..a2cb69e3bbc361f6cd2d9bfbf129d239d95f7456 100644 (file)
@@ -1,13 +1,30 @@
-using namespace std;
-//=============================================================================
-// File      : RegWidget.cxx
-// Created   : Mon Nov  5 17:26:23 CET 2001
-// Author    : Pascale NOYRET, EDF
-// Project   : SALOME
-// Copyright : EDF 2001
-// $Header$
-//=============================================================================
-
+//  SALOME RegistryDisplay : GUI for Registry server implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : RegWidget.cxx
+//  Author : Pascale NOYRET, EDF
+//  Module : SALOME
+//  $Header$
 
 # include <qpushbutton.h>
 # include <qlistview.h>
@@ -31,14 +48,19 @@ using namespace std;
 # include "RegWidget.hxx"
 # include "HelpWindow.hxx" 
 # include "IntervalWindow.hxx"
+using namespace std;
 
 typedef int PIXELS;
 RegWidget* RegWidget::myRegWidgetPtr = 0;
+QString addSlash( const QString& );
+QString findFile( QString filename );
 
 #define BOLD( text ) ( QString( "<b>" ) + QString( text ) + QString( "</b>" ) )
+
 /*!
   Creates components list
 */
+
 Registry::Components_var MakeRegistry( CORBA::ORB_var &orb )
 {
 
@@ -92,13 +114,14 @@ RegWidget::RegWidget(CORBA::ORB_var &orb, QWidget *parent, const char *name )
        _tabWidget(0), _refresh(0), _interval(0),
        myInfoWindow(0), myHelpWindow(0), myIntervalWindow(0)
 {
-  char* dir = getenv( "CSF_ResourcesDefaults" );
+   QString aFile = findFile("default.png");
+ /* char* dir = getenv( "CSF_ResourcesDefaults" );
   QString path( "" );
   if ( dir ) {
     QDir qDir( dir );
     path = qDir.filePath( "default.png" );
-  }
-  QPixmap pm ( path );
+  }*/
+  QPixmap pm ( aFile );
   if ( !pm.isNull() )
     setIcon( pm );
 
@@ -111,9 +134,11 @@ RegWidget::RegWidget(CORBA::ORB_var &orb, QWidget *parent, const char *name )
   connect( _refresh, SIGNAL( clicked() ), this, SLOT( slotListeSelect() ) );
   QToolTip::add( _refresh, "", toolTipGroup(), tr("Immediately updates list of components") );
   
+  /* PAL5540 - this button is needless
   QPushButton* help = new QPushButton( tr( "Help" ), topbar );
   connect( help, SIGNAL( clicked() ), this, SLOT( slotHelp() ) );
   QToolTip::add( help, "", toolTipGroup(), tr("Opens Help window") );
+  */
   
   _interval = new QPushButton( tr( "Interval" ), topbar );
   connect( _interval, SIGNAL( clicked() ), this, SLOT( slotSelectRefresh() ) );
@@ -427,7 +452,7 @@ void RegWidget::slotSelectRefresh()
   myIntervalWindow->installEventFilter( this );
   myIntervalWindow->setValue(myRefreshInterval);
   myIntervalWindow->show();
-  connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( reject() ) );
+  connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( close() ) );
   connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
   END_OF("slotSelectRefresh");
 }
@@ -556,3 +581,90 @@ void InfoWindow::setText( const QString& text )
 {
   myTextView->setText( text );
 }
+
+static const char* SEPARATOR    = ":";
+
+QString findFile( QString filename )
+{
+  QString dir;
+  char* cenv;
+  
+  // Try ${HOME}/.salome/resources directory
+  cenv = getenv( "HOME" );
+  if ( cenv ) {
+    dir.sprintf( "%s", cenv );
+    if ( !dir.isEmpty() ) {
+      dir = addSlash(dir) ;
+      dir = dir + ".salome" ;
+      dir = addSlash(dir) ;
+      dir = dir + "resources" ;
+      dir = addSlash(dir) ;
+      QFileInfo fileInfo( dir + filename );
+      if ( fileInfo.isFile() && fileInfo.exists() )
+       return fileInfo.filePath();
+    }
+  }
+  // Try ${SALOME_SITE_DIR}/share/salome/resources directory
+  cenv = getenv( "SALOME_SITE_DIR" );
+  if ( cenv ) {
+    dir.sprintf( "%s", cenv );
+    if ( !dir.isEmpty() ) {
+      dir = addSlash(dir) ;
+      dir = dir + "share" ;
+      dir = addSlash(dir) ;
+      cenv = getenv("SALOME_SITE_NAME");
+      if (cenv)  dir = dir + cenv;
+      else       dir = dir + "salome" ;
+      dir = addSlash(dir) ;
+      dir = dir + "resources" ;
+      dir = addSlash(dir) ;
+      QFileInfo fileInfo( dir + filename );
+      if ( fileInfo.isFile() && fileInfo.exists() )
+       return fileInfo.filePath();
+    }
+  }
+  // Try ${KERNEL_ROOT_DIR}/share/salome/resources directory
+  cenv = getenv( "KERNEL_ROOT_DIR" );
+  if ( cenv ) {
+    dir.sprintf( "%s", cenv );
+    if ( !dir.isEmpty() ) {
+      dir = addSlash(dir) ;
+      dir = dir + "share" ;
+      dir = addSlash(dir) ;
+      dir = dir + "salome" ;
+      dir = addSlash(dir) ;
+      dir = dir + "resources" ;
+      dir = addSlash(dir) ;
+      QFileInfo fileInfo( dir + filename );
+      if ( fileInfo.isFile() && fileInfo.exists() )
+       return fileInfo.filePath();
+    }
+  }
+  // Try CSF_SaloameResources env.var directory ( or directory list )
+  cenv = getenv( "CSF_SalomeResources" );
+  if ( cenv ) {
+    dir.sprintf( "%s", cenv );
+    if ( !dir.isEmpty() ) {
+      QStringList dirList = QStringList::split( SEPARATOR, dir, false ); // skip empty entries
+      for ( int i = 0; i < dirList.count(); i++ ) {
+       QFileInfo fileInfo( addSlash( dirList[ i ] ) + filename );
+       if ( fileInfo.isFile() && fileInfo.exists() )
+         return fileInfo.filePath();
+      }
+    }
+  }
+  return filename;
+}
+QString addSlash( const QString& path )
+{
+  if (!path.isNull()) {
+#ifdef WNT
+    QChar slash ('\\');
+#else
+    QChar slash ('/');
+#endif
+    if ( path.at(path.length()-1) != slash )
+      return path + slash;
+  }
+  return path;
+}