Salome HOME
8c7fca3547cb909a56ee550fcdda2a15978091ee
[modules/gui.git] / src / TOOLSGUI / ToolsGUI_RegWidget.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 //  SALOME RegistryDisplay : GUI for Registry server implementation
23 //  File   : ToolsGUI_RegWidget.cxx
24 //  Author : Pascale NOYRET, EDF
25 //
26 # include "ToolsGUI_RegWidget.h"
27
28 # include <QAction>
29 # include <QDialog>
30 # include <QSpinBox>
31 # include <QPushButton>
32 # include <QTreeWidget>
33 # include <QTabWidget> 
34 # include <QStatusBar>
35 # include <QTextEdit>
36 # include <QTextStream>
37 # include <QTimer>
38 # include <QToolBar>
39 # include <QEvent>
40 # include <QKeyEvent>
41 # include <QCloseEvent>
42 # include <QFileInfo>
43 # include <QGridLayout>
44 # include <QLabel>
45 # include <QGroupBox>
46
47 # include <SALOME_NamingService.hxx>
48 # include <ServiceUnreachable.hxx>
49 # include <Utils_SINGLETON.hxx>
50 # include <Utils_CommException.hxx>
51
52 # include <utilities.h>
53 # include <OpUtil.hxx>
54
55 # include <Qtx.h>
56
57 typedef int PIXELS;
58
59 #define MARGIN_SIZE      11
60 #define SPACING_SIZE      6
61 #define MIN_SPIN_WIDTH  100 
62
63 #define BOLD( text ) ( QString( "<b>" ) + QString( text ) + QString( "</b>" ) )
64
65 static const char* const time_data[] = { 
66 "16 16 6 1",
67 ". c None",
68 "b c None",
69 "# c #000000",
70 "a c #4c4c4c",
71 "d c #878787",
72 "c c #ffffff",
73 ".....#####ab....",
74 "...##cc#dc##ab..",
75 "..#ccc###dcc#ab.",
76 ".#ccccc#dcccc#a.",
77 ".#ccccc#dcccc#ab",
78 "#cccccc#dccccc#a",
79 "#cccccc#dccc#c#a",
80 "#c##ccc########a",
81 "#ccddcccdddd#d#a",
82 "#cccccccccccdc#a",
83 ".#ccccccccccc#aa",
84 ".#ccccc#ccccc#a.",
85 "..#cccc#dccc#aa.",
86 "...##cccdc##aa..",
87 ".....#####aaa...",
88 "......aaaaa....."};
89
90 static const char* const close_data[] = { 
91 "16 16 6 1",
92 "d c None",
93 ". c None",
94 "# c #000000",
95 "a c #4c4c4c",
96 "c c #5b5b5b",
97 "b c #ffffff",
98 ".....#####a.....",
99 "...##bbbbb##a...",
100 "..#bbbbbbbbb#a..",
101 ".#b#cbbbbbb#d#a.",
102 ".#bc#cbbbb#cb#a.",
103 "#bbbc#cbb#cbbb#a",
104 "#bbbbc#c#cbbbb#a",
105 "#bbbbbc#cbbbbb#a",
106 "#bbbbc#c#cbbbb#a",
107 "#bbb#ccbb##bbb#a",
108 ".#b#c#bbbbc#b#aa",
109 ".#bc#bbbbbb#c#a.",
110 "..#bbbbbbbbb#aa.",
111 "...##bbbbb##aa..",
112 ".....#####aaa...",
113 "......aaaaa....."};
114
115 static const char* const refresh_data[] = { 
116 "16 16 5 1",
117 ". c None",
118 "# c #000000",
119 "a c #4c4c4c",
120 "c c #878787",
121 "b c #ffffff",
122 ".....#####a.....",
123 "...##bb#bb##a...",
124 "..#bbbbc#bbb#a..",
125 ".#bbbb####cbb#a.",
126 ".#bbb#cc#cbbb#a.",
127 "#bbb#cb#cbbbbb#a",
128 "#bb#cbbbbbb#bb#a",
129 "#bb#cbbbbbb#cb#a",
130 "#bb#cbbbbbb#cb#a",
131 "#bbbbbb#bb#cbb#a",
132 ".#bbbb#cb#cbb#aa",
133 ".#bbb####cbbb#a.",
134 "..#bbb#cbbbb#aa.",
135 "...##bb#cb##aa..",
136 ".....#####aaa...",
137 "......aaaaa....."};
138
139 /*!
140   \brief Create components list.
141   \internal
142   \param orb CORBA ORB reference
143   \return list of registered components
144 */
145 static Registry::Components_var MakeRegistry( CORBA::ORB_var& orb )
146 {
147
148   const char *registryName="Registry" ;
149   
150   SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
151   naming.init_orb( orb ) ;
152   
153   // Recuperation de la reference de l'objet
154   CORBA::Object_var object = 0 ;
155   try
156   {
157     SCRUTE(registryName) ;
158     object = naming.Resolve( registryName ) ;
159     if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
160   }
161   catch( const ServiceUnreachable& ex )
162   {
163     MESSAGE( ex.what() )
164     exit( EXIT_FAILURE ) ;
165   }
166   catch( const CORBA::Exception& )
167   {
168     exit( EXIT_FAILURE ) ;
169   }
170
171   // Specialisation de l'objet generique
172
173   return Registry::Components::_narrow( object ) ;
174 }
175
176 /*!
177   \class ToolsGUI_RegWidget::InfoWindow
178   \brief Information window.
179   \internal
180 */
181
182 class ToolsGUI_RegWidget::InfoWindow : public QMainWindow
183 {
184 public:
185   InfoWindow( QWidget* parent );
186
187   void setText( const QString& text );
188
189 protected:
190   void keyPressEvent( QKeyEvent * e );
191
192 private:
193   QTextEdit* myTextView;
194 };
195
196 /*!
197   \brief Constructor.
198   \internal
199   \param parent parent widget
200 */
201 ToolsGUI_RegWidget::InfoWindow::InfoWindow( QWidget* parent )
202 : QMainWindow( parent )
203 {
204   setAttribute( Qt::WA_DeleteOnClose );
205
206   myTextView = new QTextEdit( this );
207   myTextView->setReadOnly( true );
208   setCentralWidget( myTextView );
209   setMinimumSize( 450, 250 );
210 }
211
212 /*!
213   \brief Set text to the information window.
214   \internal
215   \param text ionfo text
216 */
217 void ToolsGUI_RegWidget::InfoWindow::setText( const QString& text )
218 {
219   myTextView->setText( text );
220 }
221
222 /*!
223   \brief Key press event handler. Closeswindow on \c Escape key pressing.
224   \internal
225   \param e key press event
226 */
227 void ToolsGUI_RegWidget::InfoWindow::keyPressEvent( QKeyEvent * e )
228 {
229   QMainWindow::keyPressEvent( e );
230   if ( e->key() == Qt::Key_Escape )
231     close();
232 }
233
234 /*!
235   \class ToolsGUI_RegWidget::HelpWindow
236   \brief Help window.
237   \internal
238 */
239
240 class ToolsGUI_RegWidget::HelpWindow : public QMainWindow
241 {
242 public:
243   HelpWindow( QWidget* parent );
244   ~HelpWindow();
245
246   void setText( const QString& text );
247
248 private:
249   QTextEdit* myTextView;
250 };
251
252 /*!
253   \brief Constructor.
254   \internal
255   \param parent parent widget
256 */
257 ToolsGUI_RegWidget::HelpWindow::HelpWindow( QWidget* parent ) 
258 : QMainWindow( parent )
259 {
260   setAttribute( Qt::WA_DeleteOnClose );
261   setWindowTitle( tr( "Help" ) );
262
263   myTextView = new QTextEdit( this );
264   myTextView->setReadOnly( true );
265   QPalette pal = myTextView->palette();
266
267   pal.setBrush( QPalette::Active, QPalette::Highlight,       QBrush( QColor( 0, 0, 128 ) ) );
268   pal.setBrush( QPalette::Active, QPalette::HighlightedText, QBrush( Qt::white ) );
269   pal.setBrush( QPalette::Active, QPalette::Base,            QBrush( QColor( 255,255,220 ) ) );
270   pal.setBrush( QPalette::Active, QPalette::Text,            QBrush( Qt::black ) );
271
272   pal.setBrush( QPalette::Inactive, QPalette::Highlight,       QBrush( QColor( 0, 0, 128 ) ) );
273   pal.setBrush( QPalette::Inactive, QPalette::HighlightedText, QBrush( Qt::white ) );
274   pal.setBrush( QPalette::Inactive, QPalette::Base,            QBrush( QColor( 255,255,220 ) ) );
275   pal.setBrush( QPalette::Inactive, QPalette::Text,            QBrush( Qt::black ) );
276
277   pal.setBrush( QPalette::Disabled, QPalette::Highlight,       QBrush( QColor( 0, 0, 128 ) ) );
278   pal.setBrush( QPalette::Disabled, QPalette::HighlightedText, QBrush( Qt::white ) );
279   pal.setBrush( QPalette::Disabled, QPalette::Base,            QBrush( QColor( 255,255,220 ) ) );
280   pal.setBrush( QPalette::Disabled, QPalette::Text,            QBrush( Qt::black ) );
281
282   myTextView->setPalette( pal );
283   
284   setCentralWidget( myTextView );
285   setMinimumSize( 450, 250 );
286
287   QFile f ( "tmp.txt" );
288   if ( f.open( QIODevice::ReadOnly ) ) {
289     QTextStream t( &f ); 
290     while ( !t.atEnd() ) {
291       myTextView->append( t.readLine() );
292     }
293   }
294   f.close();
295 }
296
297 /*!
298   \brief Destructor.
299   \internal
300 */
301 ToolsGUI_RegWidget::HelpWindow::~HelpWindow()
302 {
303 };
304
305 /*!
306   \brief Set text to the help window.
307   \internal
308   \param text help text
309 */
310 void ToolsGUI_RegWidget::HelpWindow::setText( const QString& text )
311 {
312   myTextView->setText( text );
313 }
314
315 /*!
316   \class ToolsGUI_RegWidget::IntervalWindow
317   \brief Dialog box to enter time delay between registry window updates
318   \internal
319 */
320
321 class ToolsGUI_RegWidget::IntervalWindow : public QDialog
322 {
323 public:
324   IntervalWindow( QWidget* parent );
325   ~IntervalWindow();
326   
327   QPushButton* Ok();
328   QPushButton* Cancel();
329
330   int getValue();
331   void setValue( int );
332
333 private:
334   QSpinBox* mySpinBox;
335   QPushButton* myButtonOk;
336   QPushButton* myButtonCancel;
337 };
338
339 /*!
340   \brief Constructor.
341   \internal
342   \param parent parent widget
343 */
344 ToolsGUI_RegWidget::IntervalWindow::IntervalWindow ( QWidget* parent )
345 : QDialog( parent )
346 {
347   setModal( true );
348   setAttribute( Qt::WA_DeleteOnClose );
349
350   setWindowTitle( tr( "Refresh Interval"  ) );
351   setSizeGripEnabled( true );
352
353   QGridLayout* topLayout = new QGridLayout( this );
354   topLayout->setSpacing( SPACING_SIZE );
355   topLayout->setMargin( MARGIN_SIZE );
356
357   QGroupBox* intervalGrp = new QGroupBox( this );
358   intervalGrp->setObjectName( "intervalGrp" );
359   QGridLayout* intervalGrpLayout = new QGridLayout( intervalGrp );
360   intervalGrpLayout->setAlignment( Qt::AlignTop );
361   intervalGrpLayout->setSpacing( SPACING_SIZE );
362   intervalGrpLayout->setMargin( MARGIN_SIZE  );  
363
364   QHBoxLayout* aBtnLayout = new QHBoxLayout;
365   aBtnLayout->setSpacing( SPACING_SIZE );
366   aBtnLayout->setMargin( 0 );
367
368   myButtonOk = new QPushButton( this );
369   myButtonOk->setObjectName( "buttonOk" );
370   myButtonOk->setText( tr( "BUT_OK"  ) );
371   myButtonOk->setAutoDefault( TRUE );
372   myButtonOk->setDefault( TRUE );
373   
374   myButtonCancel = new QPushButton( this );
375   myButtonCancel->setObjectName( "buttonCancel" );
376   myButtonCancel->setText( tr( "BUT_CANCEL"  ) );
377   myButtonCancel->setAutoDefault( TRUE );
378
379   QLabel* TextLabel = new QLabel( intervalGrp );
380   TextLabel->setObjectName( "TextLabel" );
381   TextLabel->setText( tr( "Please, enter a number of seconds:"  ) );
382
383   mySpinBox = new QSpinBox( intervalGrp );
384   mySpinBox->setMinimum( 1 );
385   mySpinBox->setMaximum( 999999999 );
386   mySpinBox->setSingleStep( 1 );
387   mySpinBox->setObjectName( "SpinBox" );
388   mySpinBox->setValue( 100 );
389   mySpinBox->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
390   mySpinBox->setMinimumWidth(MIN_SPIN_WIDTH);
391
392   intervalGrpLayout->addWidget(TextLabel, 0, 0);
393   intervalGrpLayout->addWidget(mySpinBox, 0, 1);
394
395   aBtnLayout->addWidget( myButtonOk );
396   aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
397   aBtnLayout->addWidget( myButtonCancel );
398
399   topLayout->addWidget( intervalGrp, 0, 0 );
400   topLayout->addLayout( aBtnLayout, 1, 0 ); 
401 }
402
403 /*!
404   \brief Destructor
405   \internal
406 */
407 ToolsGUI_RegWidget::IntervalWindow::~IntervalWindow()
408 {
409 }
410
411 /*!
412   \brief Set time interval value
413   \internal
414   \param size interval value
415 */
416 void ToolsGUI_RegWidget::IntervalWindow::setValue( const int size )
417 {
418   mySpinBox->setValue(size);
419 }
420
421 /*!
422   \brief Get time interval value
423   \internal
424   \return interval value
425 */
426 int ToolsGUI_RegWidget::IntervalWindow::getValue()
427 {
428   return mySpinBox->value();
429 }
430
431 /*!
432   \brief Get \c OK button
433   \internal
434   \return a pointer to \c OK button
435 */
436 QPushButton* ToolsGUI_RegWidget::IntervalWindow::Ok()
437 {
438   return myButtonOk;
439 }
440
441 /*!
442   \brief Get \c Cancel button
443   \internal
444   \return a pointer to \c Cancel button
445 */
446 QPushButton* ToolsGUI_RegWidget::IntervalWindow::Cancel()
447 {
448   return myButtonCancel;
449 }
450
451 /*!
452   \class ToolsGUI_RegWidget
453   \brief SALOME Registry tool window.
454 */
455
456 //! The only instance of Registry window
457 ToolsGUI_RegWidget* ToolsGUI_RegWidget::myRegWidgetPtr = 0;
458
459 /*!
460   \brief Create/get the only instance of the Registry window.
461   \param orb CORBA ORB reference
462   \param parent parent widget
463 */
464 ToolsGUI_RegWidget* ToolsGUI_RegWidget::GetRegWidget( CORBA::ORB_var& orb,
465                                                       QWidget* parent )
466 {
467   if ( !myRegWidgetPtr ) 
468     myRegWidgetPtr = new ToolsGUI_RegWidget( orb, parent );
469   return myRegWidgetPtr;
470 }
471
472 /*!
473   \brief This virtual function is reimplenented to disable popup menu on dock areas
474   (instead of QMainWindow::setDockMenuEnabled( false ) method used in Qt3).
475   \return always 0 to disable menu
476 */
477 QMenu* ToolsGUI_RegWidget::createPopupMenu()
478 {
479   QMenu* aPopup = 0;
480   return aPopup;
481 }
482
483 /*!
484   \brief Constructor
485   \param orb CORBA ORB reference
486   \param parent parent widget
487 */
488 ToolsGUI_RegWidget::ToolsGUI_RegWidget( CORBA::ORB_var& orb, QWidget* parent ) 
489 : QMainWindow( parent, Qt::Window ),
490   _VarComponents( MakeRegistry(orb) ),
491   _clients( 0 ), 
492   _history( 0 ), 
493   _parent( parent ),
494   _tabWidget( 0 ), 
495   _refresh( 0 ), 
496   _interval( 0 ),
497   myInfoWindow( 0 ), 
498   myHelpWindow( 0 ), 
499   myIntervalWindow( 0 )
500 {
501   setAttribute( Qt::WA_DeleteOnClose );
502
503   if ( parent )
504     setWindowIcon( parent->windowIcon() );
505
506   // pixmap for buttons
507   QPixmap image_refresh ( ( const char** ) refresh_data );
508   QPixmap image_interval( ( const char** ) time_data );
509   QPixmap image_close   ( ( const char** ) close_data );
510
511   // Buttons definition
512   QToolBar* topbar = new QToolBar( tr("Toolbar"), this );
513   topbar->setToolButtonStyle( Qt::ToolButtonTextBesideIcon );
514   addToolBar( Qt::TopToolBarArea, topbar );
515
516   _refresh = topbar->addAction(image_refresh, tr( "Refresh" ), this, SLOT( slotListeSelect() ));
517   _refresh->setToolTip( "" );
518   _refresh->setStatusTip( tr("Immediately updates list of components") );
519   
520   /* PAL5540 - this button is needless
521   QPushButton* help = new QPushButton( tr( "Help" ), topbar );
522   connect( help, SIGNAL( clicked() ), this, SLOT( slotHelp() ) );
523   QToolTip::add( help, "", toolTipGroup(), tr("Opens Help window") );
524   */
525   
526   _interval = topbar->addAction(image_interval, tr( "Interval" ), this, SLOT( slotSelectRefresh() ));
527   _interval->setToolTip( "" );
528   _interval->setStatusTip( tr("Changes refresh interval") );
529   
530   topbar->addSeparator();
531
532   _close = topbar->addAction( image_close, tr("Close"), this, SLOT( close() ));
533   _close->setToolTip( "" );
534   _close->setStatusTip( tr("Closes Registry window") );
535   
536   // Display area and associated slots definition
537   _tabWidget = new QTabWidget( this );
538   _clients   = new QTreeWidget( _tabWidget );
539   SetListe();
540   _history   = new QTreeWidget( _tabWidget );
541   SetListeHistory();
542   
543   _tabWidget->addTab( _clients, tr( "Running" ) );
544   _tabWidget->addTab( _history, tr( "History" ) );
545   connect( _tabWidget, SIGNAL( currentChanged( QWidget* )), this, SLOT( slotListeSelect() ) );
546   connect( _clients,   SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),        this, SLOT( slotClientChanged( QTreeWidgetItem* , int ) ) );
547   connect( _history,   SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ),        this, SLOT( slotHistoryChanged( QTreeWidgetItem* , int ) ) );
548   setCentralWidget( _tabWidget );
549   
550   // Timer definition (used to automaticaly refresh the display area)
551   _counter = new QTimer( this );
552   connect( _counter, SIGNAL( timeout() ), this, SLOT( slotListeSelect() ) );
553   myRefreshInterval = 10;
554   _counter->start( myRefreshInterval * 1000 );
555   
556   PIXELS xpos    = 160 ;
557   PIXELS ypos    = 100 ;
558   PIXELS largeur = 800 ;
559   PIXELS hauteur = 350 ;
560   setGeometry( xpos, ypos, largeur, hauteur ) ;
561   setWindowTitle( tr( "Registry" ) ) ;
562   statusBar()->showMessage("    ");
563
564   slotListeSelect();
565 }
566
567 /*!
568   \brief Destructor
569 */
570 ToolsGUI_RegWidget::~ToolsGUI_RegWidget()
571 {
572   _counter->stop();
573   myRegWidgetPtr = 0;
574 };
575
576 /*!
577   \brief Event filter
578   \param object event receiver
579   \param event event being processed
580   \return \c true if event processing should be stopped
581 */
582 bool ToolsGUI_RegWidget::eventFilter( QObject* object, QEvent* event )
583 {
584   if ( object ) {
585     if ( object == myHelpWindow && event->type() == QEvent::Close ) {
586       myHelpWindow = 0;
587     }
588     else if ( object == myInfoWindow && event->type() == QEvent::Close ) {
589       myInfoWindow = 0;
590     }
591     else if ( object == myIntervalWindow && event->type() == QEvent::Close ) {
592       myIntervalWindow = 0;
593     }
594     else if ( object == _clients && event->type() == QEvent::KeyPress ) {
595       QKeyEvent* ke = (QKeyEvent*)event;
596       if ( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) {
597         slotClientChanged( _clients->currentItem(), 0 );
598       }
599     }
600     else if ( object == _history && event->type() == QEvent::KeyPress ) {
601       QKeyEvent* ke = (QKeyEvent*)event;
602       if ( ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return ) {
603         slotHistoryChanged( _history->currentItem(), 0 );
604       }
605     }
606   }
607   return QMainWindow::eventFilter( object, event );
608 }
609
610 /*!
611   \brief Search item in the list.
612   \param name component name
613   \param pid PID
614   \param machine machine name
615   \param listclient list of registry data
616   \return item index or -1 if it is not found.
617 */
618 int ToolsGUI_RegWidget::numitem( const QString& name, 
619                                  const QString& pid, 
620                                  const QString& machine,
621                                  const Registry::AllInfos* listclient )
622 {
623   for (CORBA::ULong i=0; i<listclient->length(); i++) {       
624     const Registry::Infos & c_info=(*listclient)[i];
625     ASSERT( c_info.name!=NULL);
626     QString b;
627     b.setNum(int(c_info.pid));
628     if ( (name.compare(QString(c_info.name)) == 0) && 
629          (machine.compare(QString(c_info.machine)) == 0) && 
630          (pid.compare(b) == 0) ) {
631       return i;
632     }
633   }
634   return -1;
635 }
636
637 /*!
638   \brief Get description text, containing information about client.
639   \param c_info client info data
640   \return formatted client description
641 */
642 QString ToolsGUI_RegWidget::setlongText( const Registry::Infos& c_info )
643 {
644   ASSERT( c_info.name != NULL );
645   QString a = QString( "<hr><h2>" ) + tr( "Code" ) + QString( " : " );
646   a.append( QString( c_info.name ) );
647   a.append( "</h1><hr><br>" );
648   a.append( "<code>" ); // ASV: 28.07.06 : added <code> tags to make the text font be 
649                         // fixed width (looks much better on Windows)
650   a.append( tr( "Process Id" ) + QString( " : " ) );
651   a.append( BOLD( QString::number( int( c_info.pid ) ) ) );
652   a.append( QString( " " ) + tr( "on machine" ) + QString( " " ) );
653   a.append( BOLD( c_info.machine ) ); 
654   a.append( QString( " " ) + tr( "ip address" ) + QString( " : " ) );
655   a.append( BOLD( c_info.adip ) );
656   a.append( "<br>" );
657   
658   a.append( tr( "launched by user" ) + QString( " " ) );
659   a.append( BOLD( c_info.pwname ) );
660   a.append( QString( " ( " ) + tr( "pid" ) + QString( " : " ) );
661   a.append( BOLD( QString::number( int( c_info.uid ) ) ) );
662   a.append( QString( " )<br> " ) + tr( "in directory" ) + QString( " " ));
663   a.append( BOLD( c_info.cdir ) );
664
665   time_t aTime;
666   a.append( QString( "<br>" ) + tr( "begins" ) + QString( " " ) );
667   aTime = time_t(c_info.tc_start);
668   char * t1 = (char * )duplicate(ctime(&aTime));
669   t1 [strlen(t1) -1 ] = ' ';
670   a.append( BOLD( t1 ) ); 
671   delete [] t1;
672   a.append( "<br>" );
673   
674   if (c_info.tc_hello != 0 ) {
675     aTime = time_t(c_info.tc_hello);
676     char * t2 = (char * )duplicate(ctime(&aTime));
677     t2 [strlen(t2) -1 ] = ' ';
678     a.append( tr( "last signal" ) + QString(" : ") ); 
679     a.append( BOLD( t2 ) ); 
680     a.append( "<br>" );
681     delete [] t2;
682   }
683   if ((c_info.tc_end - c_info.difftime) != 0) {
684     aTime = time_t(c_info.tc_end);
685     char * t3 = (char * )duplicate(ctime(&aTime));
686     t3 [strlen(t3) -1 ] = ' ';
687     a.append( tr( "ends" ) + QString( " " ) ); 
688     a.append( BOLD( t3 ) ); 
689     a.append( "<br>" );
690     delete [] t3;
691   }
692   else {
693     a.append( tr( "still running" ) + QString( "<br>" ) );
694   }
695   
696   SCRUTE(c_info.difftime);
697   if (c_info.difftime!= 0) {
698     a.append( QString( "(" ) + tr( "Time on" ) + QString( " " ) ); 
699     a.append( BOLD( c_info.machine ) ); 
700     a.append( QString( " " ) + tr( "differs from server's time. The difference is" ) + QString( " " )); 
701     a.append( BOLD( QString::number( int( c_info.difftime ) ) ) );
702     a.append( QString( " " ) + tr( "seconds" ) + QString( ")<br>" ) );
703   }
704   a.append( "</code>" ); // ASV: 28.07.06 : added <code> tags to make the text font be 
705                          // fixed width (looks much better on Windows)
706   return a;
707   
708 }
709
710 /*!
711   \brief Close event handler.
712   \param e close event
713 */
714 void ToolsGUI_RegWidget::closeEvent( QCloseEvent* e )
715 {
716   if ( myInfoWindow )
717     myInfoWindow->close();
718   if ( myHelpWindow )
719     myHelpWindow->close();
720   if (myIntervalWindow)
721     myIntervalWindow->close();
722   e->accept();
723 };
724
725 /*!
726   \brief Setup clients list.
727 */
728 void ToolsGUI_RegWidget::SetListe()
729 {
730   _clients->installEventFilter( this );
731   _clients->setColumnCount(6);
732   _clients->setAllColumnsShowFocus( true );
733   QStringList aLabels;
734   aLabels << tr("Component") << tr("PID") << tr("User Name") << tr("Machine") << tr("begins") << tr("hello");
735   _clients->setHeaderLabels( aLabels );
736   //_clients->setColumnAlignment( 1, Qt::AlignRight );
737 }
738
739 /*!
740   \brief Setup history list.
741 */
742 void ToolsGUI_RegWidget::SetListeHistory()
743 {
744   _history->installEventFilter( this );
745    _history->setColumnCount(6);
746   _history->setAllColumnsShowFocus( true );
747   QStringList aLabels;
748   aLabels << tr("Component") << tr("PID") << tr("User Name") << tr("Machine") << tr("begins") << tr("ends");
749   _history->setHeaderLabels( aLabels );
750   //_history->setColumnAlignment( 1, Qt::AlignRight );
751 }
752
753 /*!
754   \brief Update history list
755 */
756 void ToolsGUI_RegWidget::InfoHistory()
757 {
758
759   _history->clear();
760   try {
761     time_t aTime;
762     _serverhistory = _VarComponents->history();
763     for (CORBA::ULong i=0; i<_serverhistory->length(); i++) {       
764       const Registry::Infos & c_info=(*_serverhistory)[i];
765       ASSERT( c_info.name!=NULL);
766       QString a;
767       a.setNum(int(c_info.pid));
768       aTime = time_t(c_info.tc_start);
769       char * t1 = (char * )duplicate(ctime(&aTime));
770       t1 [strlen(t1) -1 ] = ' ';
771       aTime = time_t(c_info.tc_end);
772       char * t2 = (char * )duplicate(ctime(&aTime));
773       t2 [strlen(t2) -1 ] = ' ';
774       QStringList anItem;
775       anItem << QString(c_info.name) << a << QString(c_info.pwname) << QString(c_info.machine) << QString(t1) << QString(t2);
776       QTreeWidgetItem * item = new QTreeWidgetItem(_history, anItem);
777       item=0 ;
778       delete [] t1;
779       delete [] t2;
780       
781     }
782   }
783   catch( ... ) {
784     _interval->setDisabled( TRUE ) ;
785     _refresh->setDisabled( TRUE ) ;
786     _counter->stop();
787     MESSAGE("Sorry, No more Registry Server") ;
788     statusBar()->showMessage( tr( "Sorry, No more Registry Server" ) ) ;
789   }
790 }
791
792 /*!
793   \brief Update clients list
794 */
795 void ToolsGUI_RegWidget::InfoReg()
796 {
797   _clients->clear();
798   try {
799     time_t aTime;
800     _serverclients = _VarComponents->getall();
801     for (CORBA::ULong i=0; i<_serverclients->length(); i++) {       
802       const Registry::Infos & c_info=(*_serverclients)[i];
803       ASSERT( c_info.name!=NULL);
804       QString a;
805       a.setNum(int(c_info.pid));
806       aTime = time_t(c_info.tc_start);
807       char * t1 = (char * )duplicate(ctime(&aTime));
808       t1 [strlen(t1) -1 ] = ' ';
809       aTime = time_t(c_info.tc_hello);
810       char * t2 = (char * )duplicate(ctime(&aTime));
811       t2 [strlen(t2) -1 ] = ' ';
812       QStringList anItem;
813       anItem << QString(c_info.name) << a << QString(c_info.pwname) << QString(c_info.machine) << QString(t1) << QString(t2);
814       QTreeWidgetItem * item = new QTreeWidgetItem(_clients, anItem);
815       item=0 ;
816       delete [] t1;
817       delete [] t2;
818       
819     }
820   }
821   catch( ... ) {
822     _interval->setDisabled( TRUE ) ;
823     _refresh->setDisabled( TRUE ) ;
824     _counter->stop();
825     MESSAGE("Sorry, No more Registry Server") ;
826     statusBar()->showMessage( tr( "Sorry, No more Registry Server" ) ) ;
827   }
828 }
829
830 /*!
831   \brief Called when \c Refresh button is clicked
832 */
833 void ToolsGUI_RegWidget::slotListeSelect()
834 {
835   try {
836     ASSERT(_tabWidget->currentWidget() != NULL);
837     if (_tabWidget->currentWidget () == _clients) InfoReg();
838     else if (_tabWidget->currentWidget () == _history) InfoHistory();
839   }
840   catch( ... ) {
841     MESSAGE("Sorry, No more Registry Server") ;
842     statusBar()->showMessage( tr( "Sorry, No more Registry Server" ) ) ;
843   }
844 }
845
846 /*!
847   \brief Called when \c Interval button is clicked (open dialog box to 
848   change refresh interval).
849 */
850 void ToolsGUI_RegWidget::slotSelectRefresh()
851 {
852   myIntervalWindow = new ToolsGUI_RegWidget::IntervalWindow(this);
853   myIntervalWindow->installEventFilter( this );
854   myIntervalWindow->setValue(myRefreshInterval);
855   myIntervalWindow->show();
856   connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( close() ) );
857   connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
858 }
859
860 /*!
861   \brief Called when IntervalWindow's \c OK button is clicked
862 */
863 void ToolsGUI_RegWidget::slotIntervalOk()
864 {
865   myRefreshInterval = myIntervalWindow->getValue();
866   _counter->start( myRefreshInterval * 1000 );
867   SCRUTE(myRefreshInterval);
868   myIntervalWindow->close();
869 }
870 /*!
871   \brief Called when \c Help button is clicked
872 */
873 void ToolsGUI_RegWidget::slotHelp()
874 {
875   if ( !myHelpWindow ) {
876     myHelpWindow  = new ToolsGUI_RegWidget::HelpWindow( this );
877     myHelpWindow->installEventFilter( this );
878   }
879   myHelpWindow->show();
880   myHelpWindow->raise();
881   myHelpWindow->activateWindow();
882 }
883
884 /*!
885   \brief Called when user clicks on item in \c Running list
886   \param item item clicked by the user
887 */
888 void ToolsGUI_RegWidget::slotClientChanged( QTreeWidgetItem* item, int col )
889 {
890   if ( !item || col < 0 )
891     return;
892
893   blockSignals( true ); // for sure that item will not be deleted when refreshing
894
895   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverclients);
896   SCRUTE(numeroItem) ;
897   SCRUTE(item->text(1).toLatin1().constData()) ;
898   
899   ASSERT(numeroItem>=0) ;
900   ASSERT((size_t)numeroItem<_serverclients->length()) ;
901   const Registry::Infos & c_info=(*_serverclients)[numeroItem];
902   ASSERT( c_info.name!=NULL);
903   
904   if ( !myInfoWindow ) {
905     myInfoWindow  = new ToolsGUI_RegWidget::InfoWindow( this );
906     myInfoWindow->installEventFilter( this );
907   }
908   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
909   myInfoWindow->setWindowTitle(a);
910   myInfoWindow->setText( ToolsGUI_RegWidget::setlongText( c_info) );
911   myInfoWindow->show();
912   myInfoWindow->raise();
913   myInfoWindow->activateWindow();
914
915   blockSignals( false ); // enabling signals again
916 }
917
918 /*!
919   \brief Called when user clicks on item in \c History list
920   \param item item clicked by the user
921 */
922 void ToolsGUI_RegWidget::slotHistoryChanged( QTreeWidgetItem* item, int col )
923 {
924   if ( !item || col < 0 )
925     return;
926
927   blockSignals( true ); // for sure that item will not be deleted when refreshing
928
929   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverhistory);
930   
931   SCRUTE(numeroItem) ;
932   SCRUTE(item->text(1).toLatin1().constData()) ;
933   ASSERT(numeroItem>=0) ;
934   ASSERT((size_t)numeroItem<_serverhistory->length()) ;
935   const Registry::Infos & c_info=(*_serverhistory)[numeroItem];
936   ASSERT( c_info.name!=NULL);
937   
938   if ( !myInfoWindow ) {
939     myInfoWindow  = new ToolsGUI_RegWidget::InfoWindow( this );
940     myInfoWindow->installEventFilter( this );
941   }
942   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
943   myInfoWindow->setWindowTitle(a);
944   myInfoWindow->setText( ToolsGUI_RegWidget::setlongText( c_info ) );
945   myInfoWindow->show();
946   myInfoWindow->raise();
947   myInfoWindow->activateWindow();
948
949   blockSignals( false ); // enabling signals again
950 }
951