1 // SALOME RegistryDisplay : GUI for Registry server implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : RegWidget.cxx
25 // Author : Pascale NOYRET, EDF
30 # include <qpushbutton.h>
31 # include <qlistview.h>
32 # include <qtabwidget.h>
33 # include <qstatusbar.h>
34 # include <qtextview.h>
36 # include <qinputdialog.h>
37 # include <qtoolbar.h>
39 # include <qtooltip.h>
41 # include "SALOME_NamingService.hxx"
42 # include "ServiceUnreachable.hxx"
43 # include "Utils_SINGLETON.hxx"
44 # include "Utils_CommException.hxx"
46 # include "utilities.h"
47 # include "OpUtil.hxx"
49 # include "RegWidget.hxx"
50 # include "HelpWindow.hxx"
51 # include "IntervalWindow.hxx"
53 static QString addSlash( const QString& path );
56 RegWidget* RegWidget::myRegWidgetPtr = 0;
58 #define BOLD( text ) ( QString( "<b>" ) + QString( text ) + QString( "</b>" ) )
60 Creates components list
62 Registry::Components_var MakeRegistry( CORBA::ORB_var &orb )
65 const char *registryName="Registry" ;
67 SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
68 naming.init_orb( orb ) ;
70 // Recuperation de la reference de l'objet
71 CORBA::Object_var object = 0 ;
74 SCRUTE(registryName) ;
75 object = naming.Resolve( registryName ) ;
76 if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
78 catch( const ServiceUnreachable &ex )
81 exit( EXIT_FAILURE ) ;
83 catch( const CORBA::Exception &exx )
85 exit( EXIT_FAILURE ) ;
88 // Specialisation de l'objet generique
90 return Registry::Components::_narrow( object ) ;
94 Only one global registry window should exist at the moment
95 This method creates registry window if necessary and returns it
98 RegWidget* RegWidget::GetRegWidget( CORBA::ORB_var &orb , QWidget *parent, const char *name )
100 if ( !myRegWidgetPtr )
101 myRegWidgetPtr = new RegWidget( orb, parent, name );
102 return myRegWidgetPtr;
108 RegWidget::RegWidget(CORBA::ORB_var &orb, QWidget *parent, const char *name )
109 : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose ),
110 _VarComponents( MakeRegistry(orb) ),
111 _clients(0), _history(0), _parent( parent ),
112 _tabWidget(0), _refresh(0), _interval(0),
113 myInfoWindow(0), myHelpWindow(0), myIntervalWindow(0)
119 cenv = getenv( "KERNEL_ROOT_DIR" );
121 dir.sprintf( "%s", cenv );
122 if ( !dir.isEmpty() ) {
123 dir = addSlash(dir) ;
124 dir = dir + "share" ;
125 dir = addSlash(dir) ;
126 dir = dir + "salome" ;
127 dir = addSlash(dir) ;
128 dir = dir + "resources" ;
129 dir = addSlash(dir) ;
131 path = qDir.filePath( "default.png" );
134 // char* dir = getenv( "CSF_ResourcesDefaults" );
135 // QString path( "" );
138 // path = qDir.filePath( "default.png" );
144 // Buttons definition
145 QToolBar* topbar = new QToolBar( tr("Toolbar"), this );
146 setDockEnabled( topbar, DockTornOff, false );
147 setDockMenuEnabled( false );
149 _refresh = new QPushButton( tr( "Refresh" ), topbar );
150 connect( _refresh, SIGNAL( clicked() ), this, SLOT( slotListeSelect() ) );
151 QToolTip::add( _refresh, "", toolTipGroup(), tr("Immediately updates list of components") );
153 QPushButton* help = new QPushButton( tr( "Help" ), topbar );
154 connect( help, SIGNAL( clicked() ), this, SLOT( slotHelp() ) );
155 QToolTip::add( help, "", toolTipGroup(), tr("Opens Help window") );
157 _interval = new QPushButton( tr( "Interval" ), topbar );
158 connect( _interval, SIGNAL( clicked() ), this, SLOT( slotSelectRefresh() ) );
159 QToolTip::add( _interval, "", toolTipGroup(), tr("Changes refresh interval") );
161 // Display area and associated slots definition
162 _tabWidget = new QTabWidget( this );
163 _clients = new QListView( _tabWidget );
165 _history = new QListView( _tabWidget );
168 _tabWidget->addTab( _clients, tr( "Running" ) );
169 _tabWidget->addTab( _history, tr( "History" ) );
170 connect( _tabWidget, SIGNAL( currentChanged( QWidget* )), this, SLOT( slotListeSelect() ) );
171 connect( _clients, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( slotClientChanged( QListViewItem* ) ) );
172 connect( _history, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( slotHistoryChanged( QListViewItem* ) ) );
173 setCentralWidget( _tabWidget );
175 // Timer definition (used to automaticaly refresh the display area)
176 _counter = new QTimer( this );
177 connect( _counter, SIGNAL( timeout() ), this, SLOT( slotListeSelect() ) );
178 myRefreshInterval = 10;
179 _counter->start( myRefreshInterval * 1000 );
183 PIXELS largeur = 800 ;
184 PIXELS hauteur = 350 ;
185 setGeometry( xpos, ypos, largeur, hauteur ) ;
187 statusBar()->message(" ");
193 RegWidget::~RegWidget()
195 MESSAGE("Debut du Destructeur");
203 bool RegWidget::eventFilter( QObject* object, QEvent* event )
206 if ( object == myHelpWindow && event->type() == QEvent::Close ) {
209 else if ( object == myInfoWindow && event->type() == QEvent::Close ) {
212 else if ( object == myIntervalWindow && event->type() == QEvent::Close ) {
213 myIntervalWindow = 0;
216 return QMainWindow::eventFilter( object, event );
220 Searches item in the list and returns it's index or -1 if not found
222 int RegWidget::numitem(const QString &name, const QString &pid, const QString &machine,const Registry::AllInfos *listclient)
225 for (CORBA::ULong i=0; i<listclient->length(); i++)
227 const Registry::Infos & c_info=(*listclient)[i];
228 ASSERT( c_info.name!=NULL);
230 b.setNum(int(c_info.pid));
231 if ( (name.compare(QString(c_info.name)) == 0) &&
232 (machine.compare(QString(c_info.machine)) == 0) &&
233 (pid.compare(b) == 0) )
244 Returns text, containing information about client [ static ]
246 QString RegWidget::setlongText( const Registry::Infos &c_info)
248 BEGIN_OF("setlongText");
249 ASSERT( c_info.name != NULL );
250 QString a = QString( "<hr><h2>" ) + tr( "Code" ) + QString( " : " );
251 a.append( QString( c_info.name ) );
252 a.append( "</h1><hr><br>" );
253 a.append( tr( "Process Id" ) + QString( " : " ) );
254 a.append( BOLD( QString::number( int( c_info.pid ) ) ) );
255 a.append( QString( " " ) + tr( "on machine" ) + QString( " " ) );
256 a.append( BOLD( c_info.machine ) );
257 a.append( QString( " " ) + tr( "ip address" ) + QString( " : " ) );
258 a.append( BOLD( c_info.adip ) );
261 a.append( tr( "launched by user" ) + QString( " " ) );
262 a.append( BOLD( c_info.pwname ) );
263 a.append( QString( " ( " ) + tr( "pid" ) + QString( " : " ) );
264 a.append( BOLD( QString::number( int( c_info.uid ) ) ) );
265 a.append( QString( " )<br> " ) + tr( "in directory" ) + QString( " " ));
266 a.append( BOLD( c_info.cdir ) );
268 a.append( QString( "<br>" ) + tr( "begins" ) + QString( " " ) );
269 char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
270 t1 [strlen(t1) -1 ] = ' ';
271 a.append( BOLD( t1 ) );
275 if (c_info.tc_hello != 0 )
277 char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
278 t2 [strlen(t2) -1 ] = ' ';
279 a.append( tr( "last signal" ) + QString(" : ") );
280 a.append( BOLD( t2 ) );
284 if ((c_info.tc_end - c_info.difftime) != 0)
286 char * t3 = (char * )duplicate(ctime(&c_info.tc_end));
287 t3 [strlen(t3) -1 ] = ' ';
288 a.append( tr( "ends" ) + QString( " " ) );
289 a.append( BOLD( t3 ) );
295 a.append( tr( "still running" ) + QString( "<br>" ) );
298 SCRUTE(c_info.difftime);
299 if (c_info.difftime!= 0)
301 a.append( QString( "(" ) + tr( "Time on" ) + QString( " " ) );
302 a.append( BOLD( c_info.machine ) );
303 a.append( QString( " " ) + tr( "differs from server's time. The difference is" ) + QString( " " ));
304 a.append( BOLD( QString::number( int( c_info.difftime ) ) ) );
305 a.append( QString( " " ) + tr( "seconds" ) + QString( ")<br>" ) );
307 END_OF("setlongText");
315 void RegWidget::closeEvent( QCloseEvent *e)
317 BEGIN_OF("closeEvent");
319 myInfoWindow->close();
321 myHelpWindow->close();
322 if (myIntervalWindow)
323 myIntervalWindow->close();
325 END_OF("closeEvent");
331 void RegWidget::SetListe()
333 BEGIN_OF("SetListe");
334 _clients->addColumn( tr( "Component" ), -1);
335 _clients->addColumn( tr( "PID" ), -1 );
336 _clients->addColumn( tr( "User Name" ), -1 );
337 _clients->addColumn( tr( "Machine" ), -1 );
338 _clients->addColumn( tr( "begins" ), -1 );
339 _clients->addColumn( tr( "hello" ) , -1 );
340 _clients->setColumnAlignment( 1, Qt::AlignRight );
347 void RegWidget::SetListeHistory()
349 BEGIN_OF("SetListeHistory")
350 _history->addColumn( tr( "Component" ), -1);
351 _history->addColumn( tr( "PID" ), -1 );
352 _history->addColumn( tr( "User Name" ), -1 );
353 _history->addColumn( tr( "Machine" ), -1 );
354 _history->addColumn( tr( "begins" ), -1 );
355 _history->addColumn( tr( "ends" ), -1 );
356 _history->setColumnAlignment( 1, Qt::AlignRight );
357 END_OF("SetListeHistory")
363 void RegWidget::InfoHistory()
366 BEGIN_OF("InfoHistory")
370 _serverhistory = _VarComponents->history();
371 for (CORBA::ULong i=0; i<_serverhistory->length(); i++)
373 const Registry::Infos & c_info=(*_serverhistory)[i];
374 ASSERT( c_info.name!=NULL);
376 a.setNum(int(c_info.pid));
377 char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
378 t1 [strlen(t1) -1 ] = ' ';
379 char * t2 = (char * )duplicate(ctime(&c_info.tc_end));
380 t2 [strlen(t2) -1 ] = ' ';
381 QListViewItem * item = new QListViewItem(_history, QString(c_info.name),\
382 a, QString(c_info.pwname), QString(c_info.machine), \
383 QString(t1), QString(t2));
392 _interval->setDisabled( TRUE ) ;
393 _refresh->setDisabled( TRUE ) ;
395 MESSAGE("Sorry, No more Registry Server") ;
396 statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
398 END_OF("InfoHistory")
404 void RegWidget::InfoReg()
410 _serverclients = _VarComponents->getall();
411 for (CORBA::ULong i=0; i<_serverclients->length(); i++)
413 const Registry::Infos & c_info=(*_serverclients)[i];
414 ASSERT( c_info.name!=NULL);
416 a.setNum(int(c_info.pid));
417 char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
418 t1 [strlen(t1) -1 ] = ' ';
419 char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
420 t2 [strlen(t2) -1 ] = ' ';
421 QListViewItem * item = new QListViewItem(_clients, QString(c_info.name),\
422 a, QString(c_info.pwname), QString(c_info.machine), \
423 QString(t1), QString(t2));
432 _interval->setDisabled( TRUE ) ;
433 _refresh->setDisabled( TRUE ) ;
435 MESSAGE("Sorry, No more Registry Server") ;
436 statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
442 Called when <Refresh> button is clicked
444 void RegWidget::slotListeSelect()
448 ASSERT(_tabWidget->currentPage() != NULL);
449 if (_tabWidget->currentPage () == _clients) InfoReg();
450 else if (_tabWidget->currentPage () == _history) InfoHistory();
454 MESSAGE("Sorry, No more Registry Server") ;
455 statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
460 Called when <Interval> button is clicked (changing refresh interval)
462 void RegWidget::slotSelectRefresh()
464 BEGIN_OF("slotSelectRefresh");
465 myIntervalWindow = new IntervalWindow(this);
466 myIntervalWindow->installEventFilter( this );
467 myIntervalWindow->setValue(myRefreshInterval);
468 myIntervalWindow->show();
469 connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( reject() ) );
470 connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
471 END_OF("slotSelectRefresh");
474 void RegWidget::slotIntervalOk()
476 BEGIN_OF("slotIntervalOk");
477 myRefreshInterval = myIntervalWindow->getValue();
478 _counter->changeInterval( myRefreshInterval * 1000 );
479 SCRUTE(myRefreshInterval);
480 myIntervalWindow->close();
481 END_OF("slotIntervalOk");
484 Called when <Help> button is clicked
486 void RegWidget::slotHelp()
488 BEGIN_OF("slotHelp()");
490 if ( !myHelpWindow ) {
491 myHelpWindow = new HelpWindow( this );
492 myHelpWindow->installEventFilter( this );
494 myHelpWindow->show();
495 myHelpWindow->raise();
496 myHelpWindow->setActiveWindow();
498 END_OF("slotHelp()") ;
502 Called when user clicks on item in <Running> list
504 void RegWidget::slotClientChanged( QListViewItem* item )
506 BEGIN_OF("slotClientChanged()") ;
511 blockSignals( true ); // for sure that item will not be deleted when refreshing
513 int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverclients);
515 SCRUTE(item->text(1)) ;
517 ASSERT(numeroItem>=0) ;
518 ASSERT((size_t)numeroItem<_serverclients->length()) ;
519 const Registry::Infos & c_info=(*_serverclients)[numeroItem];
520 ASSERT( c_info.name!=NULL);
522 if ( !myInfoWindow ) {
523 myInfoWindow = new InfoWindow( this );
524 myInfoWindow->installEventFilter( this );
526 QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
527 myInfoWindow->setCaption(a);
528 myInfoWindow->setText( RegWidget::setlongText( c_info) );
529 myInfoWindow->show();
530 myInfoWindow->raise();
531 myInfoWindow->setActiveWindow();
533 blockSignals( false ); // enabling signals again
535 END_OF("slotClientChanged()") ;
540 Called when user clicks on item in <History> list
542 void RegWidget::slotHistoryChanged( QListViewItem* item )
545 BEGIN_OF("slotHistoryChanged()") ;
550 blockSignals( true ); // for sure that item will not be deleted when refreshing
552 int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverhistory);
555 SCRUTE(item->text(1)) ;
556 ASSERT(numeroItem>=0) ;
557 ASSERT((size_t)numeroItem<_serverhistory->length()) ;
558 const Registry::Infos & c_info=(*_serverhistory)[numeroItem];
559 ASSERT( c_info.name!=NULL);
561 if ( !myInfoWindow ) {
562 myInfoWindow = new InfoWindow( this );
563 myInfoWindow->installEventFilter( this );
565 QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
566 myInfoWindow->setCaption(a);
567 myInfoWindow->setText( RegWidget::setlongText( c_info ) );
568 myInfoWindow->show();
569 myInfoWindow->raise();
570 myInfoWindow->setActiveWindow();
572 blockSignals( false ); // enabling signals again
574 END_OF("slotHistoryChanged()") ;
581 InfoWindow::InfoWindow( QWidget* parent, const char* name )
582 : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose )
584 BEGIN_OF("InfoWindow");
585 myTextView = new QTextView( this, "myTextView" );
586 setCentralWidget( myTextView );
587 setMinimumSize( 450, 250 );
588 END_OF("InfoWindow");
594 void InfoWindow::setText( const QString& text )
596 myTextView->setText( text );
599 QString addSlash( const QString& path )
601 if (!path.isNull()) {
607 if ( path.at(path.length()-1) != slash )