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