Salome HOME
0425cc268980f0abede1b4d12a01dbca6393d64b
[modules/gui.git] / src / RegistryDisplay / RegWidget.cxx
1 //  SALOME RegistryDisplay : GUI for Registry server implementation
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : RegWidget.cxx
25 //  Author : Pascale NOYRET, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 # include <qpushbutton.h>
30 # include <qlistview.h>
31 # include <qtabwidget.h> 
32 # include <qstatusbar.h>
33 # include <qtextview.h>
34 # include <qtimer.h>
35 # include <qinputdialog.h>
36 # include <qtoolbar.h>
37 # include <qdir.h>
38 # include <qtooltip.h>
39
40 # include "SALOME_NamingService.hxx"
41 # include "ServiceUnreachable.hxx"
42 # include "Utils_SINGLETON.hxx"
43 # include "Utils_CommException.hxx"
44
45 # include "utilities.h"
46 # include "OpUtil.hxx"
47
48 # include "RegWidget.h"
49 # include "HelpWindow.hxx" 
50 # include "IntervalWindow.hxx"
51 using namespace std;
52
53 typedef int PIXELS;
54 RegWidget* RegWidget::myRegWidgetPtr = 0;
55 QString addSlash( const QString& );
56 QString findFile( QString filename );
57
58 #define BOLD( text ) ( QString( "<b>" ) + QString( text ) + QString( "</b>" ) )
59
60 static const char* const time_data[] = { 
61 "16 16 6 1",
62 ". c None",
63 "b c None",
64 "# c #000000",
65 "a c #4c4c4c",
66 "d c #878787",
67 "c c #ffffff",
68 ".....#####ab....",
69 "...##cc#dc##ab..",
70 "..#ccc###dcc#ab.",
71 ".#ccccc#dcccc#a.",
72 ".#ccccc#dcccc#ab",
73 "#cccccc#dccccc#a",
74 "#cccccc#dccc#c#a",
75 "#c##ccc########a",
76 "#ccddcccdddd#d#a",
77 "#cccccccccccdc#a",
78 ".#ccccccccccc#aa",
79 ".#ccccc#ccccc#a.",
80 "..#cccc#dccc#aa.",
81 "...##cccdc##aa..",
82 ".....#####aaa...",
83 "......aaaaa....."};
84
85 static const char* const close_data[] = { 
86 "16 16 6 1",
87 "d c None",
88 ". c None",
89 "# c #000000",
90 "a c #4c4c4c",
91 "c c #5b5b5b",
92 "b c #ffffff",
93 ".....#####a.....",
94 "...##bbbbb##a...",
95 "..#bbbbbbbbb#a..",
96 ".#b#cbbbbbb#d#a.",
97 ".#bc#cbbbb#cb#a.",
98 "#bbbc#cbb#cbbb#a",
99 "#bbbbc#c#cbbbb#a",
100 "#bbbbbc#cbbbbb#a",
101 "#bbbbc#c#cbbbb#a",
102 "#bbb#ccbb##bbb#a",
103 ".#b#c#bbbbc#b#aa",
104 ".#bc#bbbbbb#c#a.",
105 "..#bbbbbbbbb#aa.",
106 "...##bbbbb##aa..",
107 ".....#####aaa...",
108 "......aaaaa....."};
109
110 static const char* const refresh_data[] = { 
111 "16 16 5 1",
112 ". c None",
113 "# c #000000",
114 "a c #4c4c4c",
115 "c c #878787",
116 "b c #ffffff",
117 ".....#####a.....",
118 "...##bb#bb##a...",
119 "..#bbbbc#bbb#a..",
120 ".#bbbb####cbb#a.",
121 ".#bbb#cc#cbbb#a.",
122 "#bbb#cb#cbbbbb#a",
123 "#bb#cbbbbbb#bb#a",
124 "#bb#cbbbbbb#cb#a",
125 "#bb#cbbbbbb#cb#a",
126 "#bbbbbb#bb#cbb#a",
127 ".#bbbb#cb#cbb#aa",
128 ".#bbb####cbbb#a.",
129 "..#bbb#cbbbb#aa.",
130 "...##bb#cb##aa..",
131 ".....#####aaa...",
132 "......aaaaa....."};
133
134 /*!
135   Creates components list
136 */
137
138 Registry::Components_var MakeRegistry( CORBA::ORB_var &orb )
139 {
140
141   const char *registryName="Registry" ;
142   
143   SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
144   naming.init_orb( orb ) ;
145   
146   // Recuperation de la reference de l'objet
147   CORBA::Object_var object = 0 ;
148   try
149     {
150       SCRUTE(registryName) ;
151       object = naming.Resolve( registryName ) ;
152       if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
153     }
154   catch( const ServiceUnreachable &ex )
155     {
156       MESSAGE( ex.what() )
157       exit( EXIT_FAILURE ) ;
158     }
159   catch( const CORBA::Exception &exx )
160     {
161       exit( EXIT_FAILURE ) ;
162     }
163   
164   // Specialisation de l'objet generique
165   
166   return Registry::Components::_narrow( object ) ;
167 }
168
169 /*!
170   Only one global registry window should exist at the moment
171   This method creates registry window if necessary and returns it
172   [ static ] 
173 */
174 RegWidget* RegWidget::GetRegWidget( CORBA::ORB_var &orb , QWidget *parent, const char *name )
175 {
176   if ( !myRegWidgetPtr ) 
177     myRegWidgetPtr = new RegWidget( orb, parent, name );
178   return myRegWidgetPtr;
179 }
180
181 /*!
182   Constructor  
183 */
184 RegWidget::RegWidget(CORBA::ORB_var &orb, QWidget *parent, const char *name ) 
185      : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose ),
186        _VarComponents( MakeRegistry(orb) ),
187        _clients(0), _history(0), _parent( parent ),
188        _tabWidget(0), _refresh(0), _interval(0),
189        myInfoWindow(0), myHelpWindow(0), myIntervalWindow(0)
190 {
191    QString aFile = findFile("default.png");
192  /* char* dir = getenv( "CSF_ResourcesDefaults" );
193   QString path( "" );
194   if ( dir ) {
195     QDir qDir( dir );
196     path = qDir.filePath( "default.png" );
197   }*/
198   QPixmap pm ( aFile );
199   if ( !pm.isNull() )
200     setIcon( pm );
201
202   // pixmap for buttons
203   QPixmap image_refresh ( ( const char** ) refresh_data );
204   QPixmap image_interval( ( const char** ) time_data );
205   QPixmap image_close   ( ( const char** ) close_data );
206
207   // Buttons definition
208   QToolBar* topbar = new QToolBar( tr("Toolbar"), this );
209   setDockEnabled( topbar, DockTornOff, false );
210   setDockMenuEnabled( false );
211
212   _refresh = new QPushButton( tr( "Refresh" ), topbar );
213   _refresh->setIconSet( image_refresh );
214   _refresh->setFocusPolicy( NoFocus );
215   connect( _refresh, SIGNAL( clicked() ), this, SLOT( slotListeSelect() ) );
216   QToolTip::add( _refresh, "", toolTipGroup(), tr("Immediately updates list of components") );
217   
218   /* PAL5540 - this button is needless
219   QPushButton* help = new QPushButton( tr( "Help" ), topbar );
220   connect( help, SIGNAL( clicked() ), this, SLOT( slotHelp() ) );
221   QToolTip::add( help, "", toolTipGroup(), tr("Opens Help window") );
222   */
223   
224   _interval = new QPushButton( tr( "Interval" ), topbar );
225   _interval->setIconSet( image_interval );
226   _interval->setFocusPolicy( NoFocus );
227   connect( _interval, SIGNAL( clicked() ), this, SLOT( slotSelectRefresh() ) );
228   QToolTip::add( _interval, "", toolTipGroup(), tr("Changes refresh interval") );
229   
230   topbar->addSeparator();
231   _close = new QPushButton( tr("Close"), topbar );
232   _close->setIconSet( image_close );
233   _close->setFocusPolicy( NoFocus );
234   connect( _close, SIGNAL( clicked() ), this, SLOT( close() ) );
235   QToolTip::add( _close, "", toolTipGroup(), tr("Closes Registry window") );
236   
237   // Display area and associated slots definition
238   _tabWidget = new QTabWidget( this );
239   _clients   = new QListView( _tabWidget );
240   SetListe();
241   _history   = new QListView( _tabWidget );
242   SetListeHistory();
243   
244   _tabWidget->addTab( _clients, tr( "Running" ) );
245   _tabWidget->addTab( _history, tr( "History" ) );
246   connect( _tabWidget, SIGNAL( currentChanged( QWidget* )), this, SLOT( slotListeSelect() ) );
247   connect( _clients,   SIGNAL( clicked( QListViewItem* ) ),        this, SLOT( slotClientChanged( QListViewItem* ) ) );
248   connect( _history,   SIGNAL( clicked( QListViewItem* ) ),        this, SLOT( slotHistoryChanged( QListViewItem* ) ) );
249   setCentralWidget( _tabWidget );
250   
251   // Timer definition (used to automaticaly refresh the display area)
252   _counter = new QTimer( this );
253   connect( _counter, SIGNAL( timeout() ), this, SLOT( slotListeSelect() ) );
254   myRefreshInterval = 10;
255   _counter->start( myRefreshInterval * 1000 );
256   
257   PIXELS xpos    = 160 ;
258   PIXELS ypos    = 100 ;
259   PIXELS largeur = 800 ;
260   PIXELS hauteur = 350 ;
261   setGeometry( xpos, ypos, largeur, hauteur ) ;
262   setCaption( name ) ;
263   statusBar()->message("    ");
264 }
265
266 /*!
267   Destructor
268 */
269 RegWidget::~RegWidget()
270 {
271   MESSAGE("Debut du Destructeur");
272   _counter->stop();
273   myRegWidgetPtr = 0;
274 };
275
276 /*!
277   Event filter
278 */
279 bool RegWidget::eventFilter( QObject* object, QEvent* event )
280 {
281   if ( object ) {
282     if ( object == myHelpWindow && event->type() == QEvent::Close ) {
283       myHelpWindow = 0;
284     }
285     else if ( object == myInfoWindow && event->type() == QEvent::Close ) {
286       myInfoWindow = 0;
287     }
288     else if ( object == myIntervalWindow && event->type() == QEvent::Close ) {
289       myIntervalWindow = 0;
290     }
291     else if ( object == _clients && event->type() == QEvent::KeyPress ) {
292       QKeyEvent* ke = (QKeyEvent*)event;
293       if ( ke->key() == Key_Enter || ke->key() == Key_Return ) {
294         slotClientChanged( _clients->currentItem() );
295       }
296     }
297     else if ( object == _history && event->type() == QEvent::KeyPress ) {
298       QKeyEvent* ke = (QKeyEvent*)event;
299       if ( ke->key() == Key_Enter || ke->key() == Key_Return ) {
300         slotHistoryChanged( _history->currentItem() );
301       }
302     }
303   }
304   return QMainWindow::eventFilter( object, event );
305 }
306
307 /*!
308   Searches item in the list and returns it's index or -1 if not found
309 */
310 int RegWidget::numitem(const QString &name, const QString &pid, const QString &machine,const Registry::AllInfos *listclient)
311 {
312   BEGIN_OF("numitem");
313   for (CORBA::ULong i=0; i<listclient->length(); i++)
314     {       
315       const Registry::Infos & c_info=(*listclient)[i];
316       ASSERT( c_info.name!=NULL);
317       QString b;
318       b.setNum(int(c_info.pid));
319       if ( (name.compare(QString(c_info.name)) == 0) && 
320           (machine.compare(QString(c_info.machine)) == 0) && 
321           (pid.compare(b) == 0) )
322         {
323           END_OF("numitem");
324           return i;
325         }
326     }
327   END_OF("numitem");
328   return -1;
329 }
330
331 /*!
332   Returns text, containing information about client [ static ]
333 */
334 QString RegWidget::setlongText( const Registry::Infos &c_info)
335 {
336   BEGIN_OF("setlongText");
337   ASSERT( c_info.name != NULL );
338   QString a = QString( "<hr><h2>" ) + tr( "Code" ) + QString( " : " );
339   a.append( QString( c_info.name ) );
340   a.append( "</h1><hr><br>" );
341   a.append( tr( "Process Id" ) + QString( " : " ) );
342   a.append( BOLD( QString::number( int( c_info.pid ) ) ) );
343   a.append( QString( " " ) + tr( "on machine" ) + QString( " " ) );
344   a.append( BOLD( c_info.machine ) ); 
345   a.append( QString( " " ) + tr( "ip address" ) + QString( " : " ) );
346   a.append( BOLD( c_info.adip ) );
347   a.append( "<br>" );
348   
349   a.append( tr( "launched by user" ) + QString( " " ) );
350   a.append( BOLD( c_info.pwname ) );
351   a.append( QString( " ( " ) + tr( "pid" ) + QString( " : " ) );
352   a.append( BOLD( QString::number( int( c_info.uid ) ) ) );
353   a.append( QString( " )<br> " ) + tr( "in directory" ) + QString( " " ));
354   a.append( BOLD( c_info.cdir ) );
355   
356   a.append( QString( "<br>" ) + tr( "begins" ) + QString( " " ) );
357   char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
358   t1 [strlen(t1) -1 ] = ' ';
359   a.append( BOLD( t1 ) ); 
360   delete [] t1;
361   a.append( "<br>" );
362   
363   if (c_info.tc_hello != 0 )
364     {
365       char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
366       t2 [strlen(t2) -1 ] = ' ';
367       a.append( tr( "last signal" ) + QString(" : ") ); 
368       a.append( BOLD( t2 ) ); 
369       a.append( "<br>" );
370       delete [] t2;
371     }
372   if ((c_info.tc_end - c_info.difftime) != 0)
373     {
374       char * t3 = (char * )duplicate(ctime(&c_info.tc_end));
375       t3 [strlen(t3) -1 ] = ' ';
376       a.append( tr( "ends" ) + QString( " " ) ); 
377       a.append( BOLD( t3 ) ); 
378       a.append( "<br>" );
379       delete [] t3;
380     }
381   else
382     {
383       a.append( tr( "still running" ) + QString( "<br>" ) );
384     }
385   
386   SCRUTE(c_info.difftime);
387   if (c_info.difftime!= 0)
388     {
389       a.append( QString( "(" ) + tr( "Time on" ) + QString( " " ) ); 
390       a.append( BOLD( c_info.machine ) ); 
391       a.append( QString( " " ) + tr( "differs from server's time. The difference is" ) + QString( " " )); 
392       a.append( BOLD( QString::number( int( c_info.difftime ) ) ) );
393       a.append( QString( " " ) + tr( "seconds" ) + QString( ")<br>" ) );
394     }
395   END_OF("setlongText");  
396   return a;
397   
398 }
399
400 /*!
401   Close event
402 */
403 void RegWidget::closeEvent( QCloseEvent *e)
404 {
405   BEGIN_OF("closeEvent");
406   if ( myInfoWindow )
407     myInfoWindow->close();
408   if ( myHelpWindow )
409     myHelpWindow->close();
410   if (myIntervalWindow)
411     myIntervalWindow->close();
412   e->accept();
413   END_OF("closeEvent");
414 };
415
416 /*!
417   Setups Clients list
418 */
419 void RegWidget::SetListe()
420 {
421   BEGIN_OF("SetListe");
422   _clients->installEventFilter( this );
423   _clients->setAllColumnsShowFocus( true );
424   _clients->addColumn( tr( "Component" ), -1);
425   _clients->addColumn( tr( "PID" ), -1 );
426   _clients->addColumn( tr( "User Name" ), -1 );
427   _clients->addColumn( tr( "Machine" ), -1 );
428   _clients->addColumn( tr( "begins" ), -1 );
429   _clients->addColumn( tr( "hello" ) , -1 );
430   _clients->setColumnAlignment( 1, Qt::AlignRight );
431   END_OF("SetListe");
432 }
433
434 /*!
435   Setups History list
436 */
437 void RegWidget::SetListeHistory()
438 {
439    BEGIN_OF("SetListeHistory")
440   _history->installEventFilter( this );
441   _history->setAllColumnsShowFocus( true );
442   _history->addColumn( tr( "Component" ), -1);
443   _history->addColumn( tr( "PID" ), -1 );
444   _history->addColumn( tr( "User Name" ), -1 );
445   _history->addColumn( tr( "Machine" ), -1 );
446   _history->addColumn( tr( "begins" ), -1 );
447   _history->addColumn( tr( "ends" ), -1 );
448   _history->setColumnAlignment( 1, Qt::AlignRight );
449    END_OF("SetListeHistory")
450 }
451
452 /*!
453   Updates History list
454 */
455 void RegWidget::InfoHistory()
456 {
457
458   BEGIN_OF("InfoHistory")
459     _history->clear();
460   try
461     {
462       _serverhistory = _VarComponents->history();
463       for (CORBA::ULong i=0; i<_serverhistory->length(); i++)
464         {       
465           const Registry::Infos & c_info=(*_serverhistory)[i];
466           ASSERT( c_info.name!=NULL);
467           QString a;
468           a.setNum(int(c_info.pid));
469           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
470           t1 [strlen(t1) -1 ] = ' ';
471           char * t2 = (char * )duplicate(ctime(&c_info.tc_end));
472           t2 [strlen(t2) -1 ] = ' ';
473           QListViewItem * item = new QListViewItem(_history, QString(c_info.name),\
474                                                    a, QString(c_info.pwname), QString(c_info.machine), \
475                                                    QString(t1), QString(t2));
476           item=0 ;
477           delete [] t1;
478           delete [] t2;
479           
480         }
481     }
482   catch( ... )
483     {
484       _interval->setDisabled( TRUE ) ;
485       _refresh->setDisabled( TRUE ) ;
486       _counter->stop();
487       MESSAGE("Sorry, No more Registry Server") ;
488       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
489     }
490   END_OF("InfoHistory")
491 }
492
493 /*!
494   Updates clients list
495 */
496 void RegWidget::InfoReg()
497 {
498   BEGIN_OF("InfoReg")
499   _clients->clear();
500   try
501     {
502       _serverclients = _VarComponents->getall();
503       for (CORBA::ULong i=0; i<_serverclients->length(); i++)
504         {       
505           const Registry::Infos & c_info=(*_serverclients)[i];
506           ASSERT( c_info.name!=NULL);
507           QString a;
508           a.setNum(int(c_info.pid));
509           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
510           t1 [strlen(t1) -1 ] = ' ';
511           char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
512           t2 [strlen(t2) -1 ] = ' ';
513           QListViewItem * item = new QListViewItem(_clients, QString(c_info.name),\
514                                                    a, QString(c_info.pwname), QString(c_info.machine), \
515                                                    QString(t1), QString(t2));
516           item=0 ;
517           delete [] t1;
518           delete [] t2;
519           
520         }
521     }
522   catch( ... )
523     {
524       _interval->setDisabled( TRUE ) ;
525       _refresh->setDisabled( TRUE ) ;
526       _counter->stop();
527       MESSAGE("Sorry, No more Registry Server") ;
528       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
529     }
530   END_OF("InfoReg")
531 }
532
533 /*!
534   Called when <Refresh> button is clicked
535 */
536 void RegWidget::slotListeSelect()
537 {
538   try
539     {
540       ASSERT(_tabWidget->currentPage() != NULL);
541       if (_tabWidget->currentPage () == _clients) InfoReg();
542       else if (_tabWidget->currentPage () == _history) InfoHistory();
543     }
544   catch( ... )
545     {
546       MESSAGE("Sorry, No more Registry Server") ;
547       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
548     }
549 }
550
551 /*!
552   Called when <Interval> button is clicked (changing refresh interval)
553 */
554 void RegWidget::slotSelectRefresh()
555 {
556   BEGIN_OF("slotSelectRefresh");
557   myIntervalWindow = new IntervalWindow(this);
558   myIntervalWindow->installEventFilter( this );
559   myIntervalWindow->setValue(myRefreshInterval);
560   myIntervalWindow->show();
561   connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( close() ) );
562   connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
563   END_OF("slotSelectRefresh");
564 }
565
566 void RegWidget::slotIntervalOk()
567 {
568   BEGIN_OF("slotIntervalOk");
569   myRefreshInterval = myIntervalWindow->getValue();
570   _counter->changeInterval( myRefreshInterval * 1000 );
571   SCRUTE(myRefreshInterval);
572   myIntervalWindow->close();
573   END_OF("slotIntervalOk");
574 }
575 /*!
576   Called when <Help> button is clicked
577 */
578 void RegWidget::slotHelp()
579 {
580   BEGIN_OF("slotHelp()");
581
582   if ( !myHelpWindow ) {
583     myHelpWindow  = new HelpWindow( this );
584     myHelpWindow->installEventFilter( this );
585   }
586   myHelpWindow->show();
587   myHelpWindow->raise();
588   myHelpWindow->setActiveWindow();
589   
590   END_OF("slotHelp()") ;
591 }
592
593 /*!
594   Called when user clicks on item in <Running> list
595 */
596 void RegWidget::slotClientChanged( QListViewItem* item )
597 {
598   BEGIN_OF("slotClientChanged()") ;
599
600   if ( item <= 0)
601     return;
602
603   blockSignals( true ); // for sure that item will not be deleted when refreshing
604
605   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverclients);
606   SCRUTE(numeroItem) ;
607   SCRUTE(item->text(1)) ;
608   
609   ASSERT(numeroItem>=0) ;
610   ASSERT((size_t)numeroItem<_serverclients->length()) ;
611   const Registry::Infos & c_info=(*_serverclients)[numeroItem];
612   ASSERT( c_info.name!=NULL);
613   
614   if ( !myInfoWindow ) {
615     myInfoWindow  = new InfoWindow( this );
616     myInfoWindow->installEventFilter( this );
617   }
618   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
619   myInfoWindow->setCaption(a);
620   myInfoWindow->setText( RegWidget::setlongText( c_info) );
621   myInfoWindow->show();
622   myInfoWindow->raise();
623   myInfoWindow->setActiveWindow();
624
625   blockSignals( false ); // enabling signals again
626
627   END_OF("slotClientChanged()") ;
628   return ;
629 }
630
631 /*!
632   Called when user clicks on item in <History> list
633 */
634 void RegWidget::slotHistoryChanged( QListViewItem* item )
635 {
636
637   BEGIN_OF("slotHistoryChanged()") ;
638   
639   if ( item <= 0)
640     return;
641
642   blockSignals( true ); // for sure that item will not be deleted when refreshing
643
644   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverhistory);
645   
646   SCRUTE(numeroItem) ;
647   SCRUTE(item->text(1)) ;
648   ASSERT(numeroItem>=0) ;
649   ASSERT((size_t)numeroItem<_serverhistory->length()) ;
650   const Registry::Infos & c_info=(*_serverhistory)[numeroItem];
651   ASSERT( c_info.name!=NULL);
652   
653   if ( !myInfoWindow ) {
654     myInfoWindow  = new InfoWindow( this );
655     myInfoWindow->installEventFilter( this );
656   }
657   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
658   myInfoWindow->setCaption(a);
659   myInfoWindow->setText( RegWidget::setlongText( c_info ) );
660   myInfoWindow->show();
661   myInfoWindow->raise();
662   myInfoWindow->setActiveWindow();
663
664   blockSignals( false ); // enabling signals again
665
666   END_OF("slotHistoryChanged()") ;
667   return ;
668 }
669
670 /*!
671   Constructor
672 */
673 InfoWindow::InfoWindow( QWidget* parent, const char* name )
674      : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose )
675 {
676   BEGIN_OF("InfoWindow");
677   myTextView = new QTextView( this, "myTextView" );
678   setCentralWidget( myTextView );
679   setMinimumSize( 450, 250 );
680   END_OF("InfoWindow");
681 }
682
683 /*!
684   Sets text
685 */
686 void InfoWindow::setText( const QString& text )
687 {
688   myTextView->setText( text );
689 }
690
691 /*!
692   Key press event
693 */
694 void InfoWindow::keyPressEvent( QKeyEvent * e )
695 {
696   QMainWindow::keyPressEvent( e );
697   if ( e->key() == Key_Escape )
698     close();
699 }
700
701 static const char* SEPARATOR    = ":";
702
703 QString findFile( QString filename )
704 {
705   QString dir;
706   char* cenv;
707   
708   // Try ${HOME}/.salome/resources directory
709   cenv = getenv( "HOME" );
710   if ( cenv ) {
711     dir.sprintf( "%s", cenv );
712     if ( !dir.isEmpty() ) {
713       dir = addSlash(dir) ;
714       dir = dir + ".salome" ;
715       dir = addSlash(dir) ;
716       dir = dir + "resources" ;
717       dir = addSlash(dir) ;
718       QFileInfo fileInfo( dir + filename );
719       if ( fileInfo.isFile() && fileInfo.exists() )
720         return fileInfo.filePath();
721     }
722   }
723   // Try ${SALOME_SITE_DIR}/share/salome/resources directory
724   cenv = getenv( "SALOME_SITE_DIR" );
725   if ( cenv ) {
726     dir.sprintf( "%s", cenv );
727     if ( !dir.isEmpty() ) {
728       dir = addSlash(dir) ;
729       dir = dir + "share" ;
730       dir = addSlash(dir) ;
731       cenv = getenv("SALOME_SITE_NAME");
732       if (cenv)  dir = dir + cenv;
733       else       dir = dir + "salome" ;
734       dir = addSlash(dir) ;
735       dir = dir + "resources" ;
736       dir = addSlash(dir) ;
737       QFileInfo fileInfo( dir + filename );
738       if ( fileInfo.isFile() && fileInfo.exists() )
739         return fileInfo.filePath();
740     }
741   }
742   // Try ${KERNEL_ROOT_DIR}/share/salome/resources directory
743   cenv = getenv( "KERNEL_ROOT_DIR" );
744   if ( cenv ) {
745     dir.sprintf( "%s", cenv );
746     if ( !dir.isEmpty() ) {
747       dir = addSlash(dir) ;
748       dir = dir + "share" ;
749       dir = addSlash(dir) ;
750       dir = dir + "salome" ;
751       dir = addSlash(dir) ;
752       dir = dir + "resources" ;
753       dir = addSlash(dir) ;
754       QFileInfo fileInfo( dir + filename );
755       if ( fileInfo.isFile() && fileInfo.exists() )
756         return fileInfo.filePath();
757     }
758   }
759
760   //SRN Added support for SALOMEGUI
761   cenv = getenv( "SALOMEGUI_ROOT_DIR" );
762   if ( cenv ) {
763     dir.sprintf( "%s", cenv );
764     if ( !dir.isEmpty() ) {
765       dir = addSlash(dir) ;
766       dir = dir + "share" ;
767       dir = addSlash(dir) ;
768       dir = dir + "salome" ;
769       dir = addSlash(dir) ;
770       dir = dir + "resources" ;
771       dir = addSlash(dir) ;
772       QFileInfo fileInfo( dir + filename );
773       if ( fileInfo.isFile() && fileInfo.exists() )
774         return fileInfo.filePath();
775     }
776   }
777
778   // Try CSF_SaloameResources env.var directory ( or directory list )
779   cenv = getenv( "CSF_SalomeResources" );
780   if ( cenv ) {
781     dir.sprintf( "%s", cenv );
782     if ( !dir.isEmpty() ) {
783       QStringList dirList = QStringList::split( SEPARATOR, dir, false ); // skip empty entries
784       for ( int i = 0; i < dirList.count(); i++ ) {
785         QFileInfo fileInfo( addSlash( dirList[ i ] ) + filename );
786         if ( fileInfo.isFile() && fileInfo.exists() )
787           return fileInfo.filePath();
788       }
789     }
790   }
791   return filename;
792 }
793 QString addSlash( const QString& path )
794 {
795   if (!path.isNull()) {
796 #ifdef WNT
797     QChar slash ('\\');
798 #else
799     QChar slash ('/');
800 #endif
801     if ( path.at(path.length()-1) != slash )
802       return path + slash;
803   }
804   return path;
805 }