Salome HOME
Fix for bug 10438: Crash during Explode on Blocks operation (Global selection on...
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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   a.append( QString( "<br>" ) + tr( "begins" ) + QString( " " ) );
361   char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
362   t1 [strlen(t1) -1 ] = ' ';
363   a.append( BOLD( t1 ) ); 
364   delete [] t1;
365   a.append( "<br>" );
366   
367   if (c_info.tc_hello != 0 )
368     {
369       char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
370       t2 [strlen(t2) -1 ] = ' ';
371       a.append( tr( "last signal" ) + QString(" : ") ); 
372       a.append( BOLD( t2 ) ); 
373       a.append( "<br>" );
374       delete [] t2;
375     }
376   if ((c_info.tc_end - c_info.difftime) != 0)
377     {
378       char * t3 = (char * )duplicate(ctime(&c_info.tc_end));
379       t3 [strlen(t3) -1 ] = ' ';
380       a.append( tr( "ends" ) + QString( " " ) ); 
381       a.append( BOLD( t3 ) ); 
382       a.append( "<br>" );
383       delete [] t3;
384     }
385   else
386     {
387       a.append( tr( "still running" ) + QString( "<br>" ) );
388     }
389   
390   SCRUTE(c_info.difftime);
391   if (c_info.difftime!= 0)
392     {
393       a.append( QString( "(" ) + tr( "Time on" ) + QString( " " ) ); 
394       a.append( BOLD( c_info.machine ) ); 
395       a.append( QString( " " ) + tr( "differs from server's time. The difference is" ) + QString( " " )); 
396       a.append( BOLD( QString::number( int( c_info.difftime ) ) ) );
397       a.append( QString( " " ) + tr( "seconds" ) + QString( ")<br>" ) );
398     }
399   END_OF("setlongText");  
400   return a;
401   
402 }
403
404 /*!
405   Close event
406 */
407 void ToolsGUI_RegWidget::closeEvent( QCloseEvent *e)
408 {
409   BEGIN_OF("closeEvent");
410   if ( myInfoWindow )
411     myInfoWindow->close();
412   if ( myHelpWindow )
413     myHelpWindow->close();
414   if (myIntervalWindow)
415     myIntervalWindow->close();
416   e->accept();
417   END_OF("closeEvent");
418 };
419
420 /*!
421   Setups Clients list
422 */
423 void ToolsGUI_RegWidget::SetListe()
424 {
425   BEGIN_OF("SetListe");
426   _clients->installEventFilter( this );
427   _clients->setAllColumnsShowFocus( true );
428   _clients->addColumn( tr( "Component" ), -1);
429   _clients->addColumn( tr( "PID" ), -1 );
430   _clients->addColumn( tr( "User Name" ), -1 );
431   _clients->addColumn( tr( "Machine" ), -1 );
432   _clients->addColumn( tr( "begins" ), -1 );
433   _clients->addColumn( tr( "hello" ) , -1 );
434   _clients->setColumnAlignment( 1, Qt::AlignRight );
435   END_OF("SetListe");
436 }
437
438 /*!
439   Setups History list
440 */
441 void ToolsGUI_RegWidget::SetListeHistory()
442 {
443    BEGIN_OF("SetListeHistory")
444   _history->installEventFilter( this );
445   _history->setAllColumnsShowFocus( true );
446   _history->addColumn( tr( "Component" ), -1);
447   _history->addColumn( tr( "PID" ), -1 );
448   _history->addColumn( tr( "User Name" ), -1 );
449   _history->addColumn( tr( "Machine" ), -1 );
450   _history->addColumn( tr( "begins" ), -1 );
451   _history->addColumn( tr( "ends" ), -1 );
452   _history->setColumnAlignment( 1, Qt::AlignRight );
453    END_OF("SetListeHistory")
454 }
455
456 /*!
457   Updates History list
458 */
459 void ToolsGUI_RegWidget::InfoHistory()
460 {
461
462   BEGIN_OF("InfoHistory")
463     _history->clear();
464   try
465     {
466       _serverhistory = _VarComponents->history();
467       for (CORBA::ULong i=0; i<_serverhistory->length(); i++)
468         {       
469           const Registry::Infos & c_info=(*_serverhistory)[i];
470           ASSERT( c_info.name!=NULL);
471           QString a;
472           a.setNum(int(c_info.pid));
473           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
474           t1 [strlen(t1) -1 ] = ' ';
475           char * t2 = (char * )duplicate(ctime(&c_info.tc_end));
476           t2 [strlen(t2) -1 ] = ' ';
477           QListViewItem * item = new QListViewItem(_history, QString(c_info.name),\
478                                                    a, QString(c_info.pwname), QString(c_info.machine), \
479                                                    QString(t1), QString(t2));
480           item=0 ;
481           delete [] t1;
482           delete [] t2;
483           
484         }
485     }
486   catch( ... )
487     {
488       _interval->setDisabled( TRUE ) ;
489       _refresh->setDisabled( TRUE ) ;
490       _counter->stop();
491       MESSAGE("Sorry, No more Registry Server") ;
492       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
493     }
494   END_OF("InfoHistory")
495 }
496
497 /*!
498   Updates clients list
499 */
500 void ToolsGUI_RegWidget::InfoReg()
501 {
502   BEGIN_OF("InfoReg")
503   _clients->clear();
504   try
505     {
506       _serverclients = _VarComponents->getall();
507       for (CORBA::ULong i=0; i<_serverclients->length(); i++)
508         {       
509           const Registry::Infos & c_info=(*_serverclients)[i];
510           ASSERT( c_info.name!=NULL);
511           QString a;
512           a.setNum(int(c_info.pid));
513           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
514           t1 [strlen(t1) -1 ] = ' ';
515           char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
516           t2 [strlen(t2) -1 ] = ' ';
517           QListViewItem * item = new QListViewItem(_clients, QString(c_info.name),\
518                                                    a, QString(c_info.pwname), QString(c_info.machine), \
519                                                    QString(t1), QString(t2));
520           item=0 ;
521           delete [] t1;
522           delete [] t2;
523           
524         }
525     }
526   catch( ... )
527     {
528       _interval->setDisabled( TRUE ) ;
529       _refresh->setDisabled( TRUE ) ;
530       _counter->stop();
531       MESSAGE("Sorry, No more Registry Server") ;
532       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
533     }
534   END_OF("InfoReg")
535 }
536
537 /*!
538   Called when <Refresh> button is clicked
539 */
540 void ToolsGUI_RegWidget::slotListeSelect()
541 {
542   try
543     {
544       ASSERT(_tabWidget->currentPage() != NULL);
545       if (_tabWidget->currentPage () == _clients) InfoReg();
546       else if (_tabWidget->currentPage () == _history) InfoHistory();
547     }
548   catch( ... )
549     {
550       MESSAGE("Sorry, No more Registry Server") ;
551       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
552     }
553 }
554
555 /*!
556   Called when <Interval> button is clicked (changing refresh interval)
557 */
558 void ToolsGUI_RegWidget::slotSelectRefresh()
559 {
560   BEGIN_OF("slotSelectRefresh");
561   myIntervalWindow = new ToolsGUI_IntervalWindow(this);
562   myIntervalWindow->installEventFilter( this );
563   myIntervalWindow->setValue(myRefreshInterval);
564   myIntervalWindow->show();
565   connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( close() ) );
566   connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
567   END_OF("slotSelectRefresh");
568 }
569
570 void ToolsGUI_RegWidget::slotIntervalOk()
571 {
572   BEGIN_OF("slotIntervalOk");
573   myRefreshInterval = myIntervalWindow->getValue();
574   _counter->changeInterval( myRefreshInterval * 1000 );
575   SCRUTE(myRefreshInterval);
576   myIntervalWindow->close();
577   END_OF("slotIntervalOk");
578 }
579 /*!
580   Called when <Help> button is clicked
581 */
582 void ToolsGUI_RegWidget::slotHelp()
583 {
584   BEGIN_OF("slotHelp()");
585
586   if ( !myHelpWindow ) {
587     myHelpWindow  = new ToolsGUI_HelpWindow( this );
588     myHelpWindow->installEventFilter( this );
589   }
590   myHelpWindow->show();
591   myHelpWindow->raise();
592   myHelpWindow->setActiveWindow();
593   
594   END_OF("slotHelp()") ;
595 }
596
597 /*!
598   Called when user clicks on item in <Running> list
599 */
600 void ToolsGUI_RegWidget::slotClientChanged( QListViewItem* item )
601 {
602   BEGIN_OF("slotClientChanged()") ;
603
604   if ( item <= 0)
605     return;
606
607   blockSignals( true ); // for sure that item will not be deleted when refreshing
608
609   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverclients);
610   SCRUTE(numeroItem) ;
611   SCRUTE(item->text(1)) ;
612   
613   ASSERT(numeroItem>=0) ;
614   ASSERT((size_t)numeroItem<_serverclients->length()) ;
615   const Registry::Infos & c_info=(*_serverclients)[numeroItem];
616   ASSERT( c_info.name!=NULL);
617   
618   if ( !myInfoWindow ) {
619     myInfoWindow  = new ToolsGUI_InfoWindow( this );
620     myInfoWindow->installEventFilter( this );
621   }
622   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
623   myInfoWindow->setCaption(a);
624   myInfoWindow->setText( ToolsGUI_RegWidget::setlongText( c_info) );
625   myInfoWindow->show();
626   myInfoWindow->raise();
627   myInfoWindow->setActiveWindow();
628
629   blockSignals( false ); // enabling signals again
630
631   END_OF("slotClientChanged()") ;
632   return ;
633 }
634
635 /*!
636   Called when user clicks on item in <History> list
637 */
638 void ToolsGUI_RegWidget::slotHistoryChanged( QListViewItem* item )
639 {
640
641   BEGIN_OF("slotHistoryChanged()") ;
642   
643   if ( item <= 0)
644     return;
645
646   blockSignals( true ); // for sure that item will not be deleted when refreshing
647
648   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverhistory);
649   
650   SCRUTE(numeroItem) ;
651   SCRUTE(item->text(1)) ;
652   ASSERT(numeroItem>=0) ;
653   ASSERT((size_t)numeroItem<_serverhistory->length()) ;
654   const Registry::Infos & c_info=(*_serverhistory)[numeroItem];
655   ASSERT( c_info.name!=NULL);
656   
657   if ( !myInfoWindow ) {
658     myInfoWindow  = new ToolsGUI_InfoWindow( this );
659     myInfoWindow->installEventFilter( this );
660   }
661   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
662   myInfoWindow->setCaption(a);
663   myInfoWindow->setText( ToolsGUI_RegWidget::setlongText( c_info ) );
664   myInfoWindow->show();
665   myInfoWindow->raise();
666   myInfoWindow->setActiveWindow();
667
668   blockSignals( false ); // enabling signals again
669
670   END_OF("slotHistoryChanged()") ;
671   return ;
672 }
673
674 /*!
675   Constructor
676 */
677 ToolsGUI_InfoWindow::ToolsGUI_InfoWindow( QWidget* parent, const char* name )
678      : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose )
679 {
680   BEGIN_OF("InfoWindow");
681   myTextView = new QTextView( this, "myTextView" );
682   setCentralWidget( myTextView );
683   setMinimumSize( 450, 250 );
684   END_OF("InfoWindow");
685 }
686
687 /*!
688   Sets text
689 */
690 void ToolsGUI_InfoWindow::setText( const QString& text )
691 {
692   myTextView->setText( text );
693 }
694
695 /*!
696   Key press event
697 */
698 void ToolsGUI_InfoWindow::keyPressEvent( QKeyEvent * e )
699 {
700   QMainWindow::keyPressEvent( e );
701   if ( e->key() == Key_Escape )
702     close();
703 }
704
705 static const char* SEPARATOR    = ":";
706
707 QString findFile( QString filename )
708 {
709   QString dir;
710   char* cenv;
711   
712   // Try ${HOME}/.salome/resources directory
713   cenv = getenv( "HOME" );
714   if ( cenv ) {
715     dir.sprintf( "%s", cenv );
716     if ( !dir.isEmpty() ) {
717       dir = addSlash(dir) ;
718       dir = dir + ".salome" ;
719       dir = addSlash(dir) ;
720       dir = dir + "resources" ;
721       dir = addSlash(dir) ;
722       QFileInfo fileInfo( dir + filename );
723       if ( fileInfo.isFile() && fileInfo.exists() )
724         return fileInfo.filePath();
725     }
726   }
727   // Try ${SALOME_SITE_DIR}/share/salome/resources directory
728   cenv = getenv( "SALOME_SITE_DIR" );
729   if ( cenv ) {
730     dir.sprintf( "%s", cenv );
731     if ( !dir.isEmpty() ) {
732       dir = addSlash(dir) ;
733       dir = dir + "share" ;
734       dir = addSlash(dir) ;
735       cenv = getenv("SALOME_SITE_NAME");
736       if (cenv)  dir = dir + cenv;
737       else       dir = dir + "salome" ;
738       dir = addSlash(dir) ;
739       dir = dir + "resources" ;
740       dir = addSlash(dir) ;
741       QFileInfo fileInfo( dir + filename );
742       if ( fileInfo.isFile() && fileInfo.exists() )
743         return fileInfo.filePath();
744     }
745   }
746   // Try ${KERNEL_ROOT_DIR}/share/salome/resources directory
747   cenv = getenv( "KERNEL_ROOT_DIR" );
748   if ( cenv ) {
749     dir.sprintf( "%s", cenv );
750     if ( !dir.isEmpty() ) {
751       dir = addSlash(dir) ;
752       dir = dir + "share" ;
753       dir = addSlash(dir) ;
754       dir = dir + "salome" ;
755       dir = addSlash(dir) ;
756       dir = dir + "resources" ;
757       dir = addSlash(dir) ;
758       QFileInfo fileInfo( dir + filename );
759       if ( fileInfo.isFile() && fileInfo.exists() )
760         return fileInfo.filePath();
761     }
762   }
763
764   //SRN Added support for SALOMEGUI
765   cenv = getenv( "SALOMEGUI_ROOT_DIR" );
766   if ( cenv ) {
767     dir.sprintf( "%s", cenv );
768     if ( !dir.isEmpty() ) {
769       dir = addSlash(dir) ;
770       dir = dir + "share" ;
771       dir = addSlash(dir) ;
772       dir = dir + "salome" ;
773       dir = addSlash(dir) ;
774       dir = dir + "resources" ;
775       dir = addSlash(dir) ;
776       QFileInfo fileInfo( dir + filename );
777       if ( fileInfo.isFile() && fileInfo.exists() )
778         return fileInfo.filePath();
779     }
780   }
781
782   // Try CSF_SaloameResources env.var directory ( or directory list )
783   cenv = getenv( "CSF_SalomeResources" );
784   if ( cenv ) {
785     dir.sprintf( "%s", cenv );
786     if ( !dir.isEmpty() ) {
787       QStringList dirList = QStringList::split( SEPARATOR, dir, false ); // skip empty entries
788       for ( int i = 0; i < dirList.count(); i++ ) {
789         QFileInfo fileInfo( addSlash( dirList[ i ] ) + filename );
790         if ( fileInfo.isFile() && fileInfo.exists() )
791           return fileInfo.filePath();
792       }
793     }
794   }
795   return filename;
796 }
797 QString addSlash( const QString& path )
798 {
799   return Qtx::addSlash( path );
800 //  if (!path.isNull()) {
801 //#ifdef WNT
802 //    QChar slash ('\\');
803 //#else
804 //    QChar slash ('/');
805 //#endif
806 //    if ( path.at(path.length()-1) != slash )
807 //      return path + slash;
808 //  }
809 //  return path;
810 }