1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # include "ToolsGUI_RegWidget.h"
25 #include <QApplication>
26 #include <QInputDialog>
33 #include <QTreeWidget>
34 #include <QVBoxLayout>
38 #include <SALOME_NamingService.hxx>
39 #include <Utils_SINGLETON.hxx>
40 #include <Utils_CommException.hxx>
42 #define MARGIN_SIZE 11
43 #define SPACING_SIZE 6
44 #define MIN_SPIN_WIDTH 100
46 #define BOLD( text ) QString( "<b>%1</b>" ).arg( QString( text ) )
48 static const char* const time_data[] = {
73 static const char* const close_data[] = {
98 static const char* const refresh_data[] = {
123 \brief Get access to the Registry service
125 \param orb CORBA ORB reference
126 \return reference to the Registry service
128 static Registry::Components_ptr GetRegistry( CORBA::ORB_ptr orb )
130 static const char* registryName = "Registry";
131 Registry::Components_var aRegistry;
133 SALOME_NamingService& naming = *SINGLETON_<SALOME_NamingService>::Instance();
134 naming.init_orb( orb );
136 CORBA::Object_var object = 0;
139 object = naming.Resolve( registryName );
140 if ( CORBA::is_nil( object ) ) throw CommException( "Unable to find the Registry service" );
141 aRegistry = Registry::Components::_narrow( object );
143 catch( const CORBA::Exception& ex )
145 MESSAGE( "Error: can't access Registry server" );
148 return aRegistry._retn();
152 \class ToolsGUI_RegWidget
153 \brief SALOME Registry tool window.
156 //! The only instance of Registry window
157 ToolsGUI_RegWidget* ToolsGUI_RegWidget::myRegWidgetPtr = 0;
160 \brief Create/get the only instance of the Registry window.
161 \param orb CORBA ORB reference
162 \param parent parent widget
164 ToolsGUI_RegWidget* ToolsGUI_RegWidget::GetRegWidget( CORBA::ORB_ptr orb,
167 if ( !myRegWidgetPtr )
168 myRegWidgetPtr = new ToolsGUI_RegWidget( orb, parent );
169 return myRegWidgetPtr;
174 \param orb CORBA ORB reference
175 \param parent parent widget
177 ToolsGUI_RegWidget::ToolsGUI_RegWidget( CORBA::ORB_ptr orb, QWidget* parent )
178 : QMainWindow( parent )
180 myOrb = CORBA::ORB::_duplicate( orb );
182 // set window attributes
183 setAttribute( Qt::WA_DeleteOnClose );
184 setWindowTitle( tr( "TLT_REGISTRY" ) );
190 QMenuBar* mainMenu = menuBar();
192 // add 'Actions' menu
193 QMenu* m = mainMenu->addMenu( tr( "MNU_ACTIONS" ) );
194 // add 'Actions' toolbar
195 QToolBar* tb = addToolBar( tr( "TB_ACTIONS" ) );
198 myActions[Refresh] = new QAction( QPixmap( refresh_data ), tr( "MEN_REFRESH" ), this );
199 myActions[Refresh]->setStatusTip( tr( "STB_REFRESH" ) );
200 connect( myActions[Refresh], SIGNAL( triggered() ), this, SLOT( refresh() ) );
201 m->addAction( myActions[Refresh] );
202 tb->addAction( myActions[Refresh] );
204 myActions[Interval] = new QAction( QPixmap( time_data ), tr( "MEN_INTERVAL" ), this );
205 myActions[Interval]->setStatusTip( tr( "STB_INTERVAL" ) );
206 connect( myActions[Interval], SIGNAL( triggered() ), this, SLOT( refreshInterval() ) );
207 m->addAction( myActions[Interval] );
208 tb->addAction( myActions[Interval] );
213 myActions[Close] = new QAction( QPixmap( close_data ), tr( "MEN_CLOSE" ), this );
214 myActions[Close]->setStatusTip( tr( "STB_CLOSE" ) );
215 connect( myActions[Close], SIGNAL( triggered() ), this, SLOT( close() ) );
216 m->addAction( myActions[Close] );
217 tb->addAction( myActions[Close] );
220 setCentralWidget( new QWidget( this ) );
222 // Create tab widget: SALOME serives list (running and history)
223 QTabWidget* tabWidget = new QTabWidget( centralWidget() );
225 myViews[Clients] = new QTreeWidget( tabWidget );
226 myViews[Clients]->setColumnCount( 6 );
227 myViews[Clients]->setAllColumnsShowFocus( true );
228 myViews[Clients]->setRootIsDecorated( false );
229 QStringList runningLabels;
230 runningLabels << tr( "HDR_COMPONENT" ) << tr( "HDR_PID" ) << tr( "HDR_USERNAME" )
231 << tr( "HDR_HOSTNAME" ) << tr( "HDR_STARTED" ) << tr( "HDR_HELLO" );
232 myViews[Clients]->setHeaderLabels( runningLabels );
233 tabWidget->addTab( myViews[Clients], tr( "TAB_RUNNING" ) );
235 myViews[History] = new QTreeWidget( tabWidget );
236 myViews[History]->setColumnCount(6);
237 myViews[History]->setAllColumnsShowFocus( true );
238 myViews[History]->setRootIsDecorated( false );
239 QStringList historyLabels;
240 historyLabels << tr( "HDR_COMPONENT" ) << tr( "HDR_PID" ) << tr( "HDR_USERNAME" )
241 << tr( "HDR_HOSTNAME" ) << tr( "HDR_STARTED" ) << tr( "HDR_FINISHED" );
242 myViews[History]->setHeaderLabels( historyLabels );
243 tabWidget->addTab( myViews[History], tr( "TAB_HISTORY" ) );
245 connect( tabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( refresh() ) );
246 connect( myViews[Clients], SIGNAL( itemActivated( QTreeWidgetItem*, int ) ),
247 this, SLOT( showDetails( QTreeWidgetItem*, int ) ) );
248 connect( myViews[History], SIGNAL( itemActivated( QTreeWidgetItem*, int ) ),
249 this, SLOT( showDetails( QTreeWidgetItem*, int ) ) );
251 // create information window
252 myDetails = new QTextEdit( centralWidget() );
253 myDetails->setReadOnly( true );
254 myDetails->setMinimumHeight( 100 );
257 QVBoxLayout* topLayout = new QVBoxLayout( centralWidget() );
258 topLayout->setMargin( 0 );
259 topLayout->setSpacing( SPACING_SIZE );
260 topLayout->addWidget( tabWidget );
261 topLayout->addWidget( myDetails );
263 // install auto-update timer
264 myTimer = new QTimer( this );
265 connect( myTimer, SIGNAL( timeout() ), this, SLOT( refresh() ) );
266 myTimer->start( 10000 ); // 10 seconds by default
268 // resize window and set its position
270 Qtx::alignWidget( (QWidget*)this, (QWidget*)QApplication::desktop(), Qtx::AlignCenter );
272 // refresh registry information
279 ToolsGUI_RegWidget::~ToolsGUI_RegWidget()
285 \brief Get description text, containing information about the service.
286 \param c_info client info data
287 \return formatted client description
289 QString ToolsGUI_RegWidget::getDetails( const Registry::Infos& c_info )
292 if ( c_info.name != NULL ) {
293 time_t aStarted( c_info.tc_start );
294 time_t aLastPing( c_info.tc_hello );
295 time_t aFinished( c_info.tc_end );
297 a.append( BOLD( tr( "INFO_SERVICE" ).arg( QString( c_info.name ) ) ) );
300 a.append( tr( "INFO_PROCESS" ).arg( BOLD( QString::number( c_info.pid ) ),
301 BOLD( c_info.machine ),
303 BOLD( c_info.pwname ),
304 BOLD( QString::number( c_info.uid ) ),
305 BOLD( c_info.cdir ) ) );
308 a.append( tr( "INFO_STARTED" ).arg( BOLD( QString( ctime( &aStarted ) ).trimmed() ) ) );
310 if ( c_info.tc_hello != 0 ) {
311 a.append( tr( "INFO_LAST_PING" ).arg( BOLD( QString( ctime( &aLastPing ) ).trimmed() ) ) );
314 if ( c_info.tc_end - c_info.difftime != 0 ) {
315 a.append( tr( "INFO_FINISHED" ).arg( BOLD( QString( ctime( &aFinished ) ).trimmed() ) ) );
319 a.append( tr( "INFO_RUNNING" ) );
322 if ( c_info.difftime != 0 ) {
323 a.append( tr( "INFO_TIME_DIFF" ).arg( BOLD( c_info.machine ), BOLD( QString::number( c_info.difftime ) ) ) );
326 a.append( "</code>" ); // ASV: 28.07.06 : added <code> tags to make the text font be
327 // fixed width (looks much better on Windows)
333 \brief Refresh registry information
335 void ToolsGUI_RegWidget::refresh()
338 // get reference to the Registry service
339 Registry::Components_var aRegistry = GetRegistry( myOrb );
340 if ( aRegistry->_is_nil() ) {
341 myActions[Interval]->setDisabled( true );
342 myActions[Refresh]->setDisabled( true );
344 MESSAGE( "Sorry, no more Registry Server" );
345 statusBar()->showMessage( tr( "ERR_NO_REGISTRY" ) );
349 myData[Clients] = aRegistry->getall();
350 myData[History] = aRegistry->history();
352 // update current services list
353 myViews[Clients]->clear();
354 for ( int i = 0; i < myData[Clients]->length(); i++ ) {
355 const Registry::Infos& c_info = (*myData[Clients])[i];
356 time_t aStarted = time_t( c_info.tc_start );
357 time_t aLastPing = time_t( c_info.tc_hello );
359 aData << QString( c_info.name )
360 << QString::number( c_info.pid )
361 << QString( c_info.pwname )
362 << QString( c_info.machine )
363 << QString( ctime( &aStarted ) ).trimmed()
364 << QString( ctime( &aLastPing ) ).trimmed();
365 myViews[Clients]->addTopLevelItem( new QTreeWidgetItem( aData ) );
369 myViews[History]->clear();
370 for ( int i = 0; i < myData[History]->length(); i++ ) {
371 const Registry::Infos& c_info = (*myData[History])[i];
372 time_t aStarted = time_t( c_info.tc_start );
373 time_t aFinished = time_t( c_info.tc_end );
375 aData << QString( c_info.name )
376 << QString::number( c_info.pid )
377 << QString( c_info.pwname )
378 << QString( c_info.machine )
379 << QString( ctime( &aStarted ) ).trimmed()
380 << QString( ctime( &aFinished ) ).trimmed();
381 myViews[History]->addTopLevelItem( new QTreeWidgetItem( aData ) );
385 myActions[Interval]->setDisabled( true );
386 myActions[Refresh]->setDisabled( true );
388 MESSAGE( "Sorry, no more Registry Server" );
389 statusBar()->showMessage( tr( "ERR_NO_REGISTRY" ) );
394 \brief Called when \c Interval button is clicked (open dialog box to
395 change refresh interval).
397 void ToolsGUI_RegWidget::refreshInterval()
400 int sec = QInputDialog::getInt( this, tr( "TLT_REFRESH_INTERVAL" ), tr( "LAB_REFRESH_INTERVAL" ),
401 myTimer->interval() / 1000, 1, 24 * 60 * 60, 1, &ok );
403 myTimer->start( sec * 1000 );
407 \brief Show details about the chosen service.
408 \param item item activated by the user
409 \param column column index
411 void ToolsGUI_RegWidget::showDetails( QTreeWidgetItem* item, int column )
413 if ( !item || column < 0 ) return;
414 int i = sender() == myViews[Clients] ? Clients : History;
415 int idx = myViews[i]->indexOfTopLevelItem( item );
416 int size = myData[i]->length();
417 if ( idx < 0 || idx > size-1 ) return;
418 const Registry::Infos& c_info = (*myData[i])[idx];
419 myDetails->setText( getDetails( c_info ) );