Salome HOME
DCQ : Merge with Ecole_ete_a6.
[modules/kernel.git] / src / RegistryDisplay / 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   : RegWidget.cxx
25 //  Author : Pascale NOYRET, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 # include <qpushbutton.h>
31 # include <qlistview.h>
32 # include <qtabwidget.h> 
33 # include <qstatusbar.h>
34 # include <qtextview.h>
35 # include <qtimer.h>
36 # include <qinputdialog.h>
37 # include <qtoolbar.h>
38 # include <qdir.h>
39 # include <qtooltip.h>
40
41 # include "SALOME_NamingService.hxx"
42 # include "ServiceUnreachable.hxx"
43 # include "Utils_SINGLETON.hxx"
44 # include "Utils_CommException.hxx"
45
46 # include "utilities.h"
47 # include "OpUtil.hxx"
48
49 # include "RegWidget.hxx"
50 # include "HelpWindow.hxx" 
51 # include "IntervalWindow.hxx"
52
53 typedef int PIXELS;
54 RegWidget* RegWidget::myRegWidgetPtr = 0;
55 QString addSlash( const QString& );
56 QString findFile( QString filename );
57
58 #define BOLD( text ) ( QString( "<b>" ) + QString( text ) + QString( "</b>" ) )
59
60 /*!
61   Creates components list
62 */
63
64 Registry::Components_var MakeRegistry( CORBA::ORB_var &orb )
65 {
66
67   const char *registryName="Registry" ;
68   
69   SALOME_NamingService &naming = *SINGLETON_<SALOME_NamingService>::Instance() ;
70   naming.init_orb( orb ) ;
71   
72   // Recuperation de la reference de l'objet
73   CORBA::Object_var object = 0 ;
74   try
75     {
76       SCRUTE(registryName) ;
77       object = naming.Resolve( registryName ) ;
78       if(CORBA::is_nil(object)) throw CommException( "unable to find the RegistryService" ) ;
79     }
80   catch( const ServiceUnreachable &ex )
81     {
82       MESSAGE( ex.what() )
83       exit( EXIT_FAILURE ) ;
84     }
85   catch( const CORBA::Exception &exx )
86     {
87       exit( EXIT_FAILURE ) ;
88     }
89   
90   // Specialisation de l'objet generique
91   
92   return Registry::Components::_narrow( object ) ;
93 }
94
95 /*!
96   Only one global registry window should exist at the moment
97   This method creates registry window if necessary and returns it
98   [ static ] 
99 */
100 RegWidget* RegWidget::GetRegWidget( CORBA::ORB_var &orb , QWidget *parent, const char *name )
101 {
102   if ( !myRegWidgetPtr ) 
103     myRegWidgetPtr = new RegWidget( orb, parent, name );
104   return myRegWidgetPtr;
105 }
106
107 /*!
108   Constructor  
109 */
110 RegWidget::RegWidget(CORBA::ORB_var &orb, QWidget *parent, const char *name ) 
111      : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose ),
112        _VarComponents( MakeRegistry(orb) ),
113        _clients(0), _history(0), _parent( parent ),
114        _tabWidget(0), _refresh(0), _interval(0),
115        myInfoWindow(0), myHelpWindow(0), myIntervalWindow(0)
116 {
117    QString aFile = findFile("default.png");
118  /* char* dir = getenv( "CSF_ResourcesDefaults" );
119   QString path( "" );
120   if ( dir ) {
121     QDir qDir( dir );
122     path = qDir.filePath( "default.png" );
123   }*/
124   QPixmap pm ( aFile );
125   if ( !pm.isNull() )
126     setIcon( pm );
127
128   // Buttons definition
129   QToolBar* topbar = new QToolBar( tr("Toolbar"), this );
130   setDockEnabled( topbar, DockTornOff, false );
131   setDockMenuEnabled( false );
132
133   _refresh = new QPushButton( tr( "Refresh" ), topbar );
134   connect( _refresh, SIGNAL( clicked() ), this, SLOT( slotListeSelect() ) );
135   QToolTip::add( _refresh, "", toolTipGroup(), tr("Immediately updates list of components") );
136   
137   QPushButton* help = new QPushButton( tr( "Help" ), topbar );
138   connect( help, SIGNAL( clicked() ), this, SLOT( slotHelp() ) );
139   QToolTip::add( help, "", toolTipGroup(), tr("Opens Help window") );
140   
141   _interval = new QPushButton( tr( "Interval" ), topbar );
142   connect( _interval, SIGNAL( clicked() ), this, SLOT( slotSelectRefresh() ) );
143   QToolTip::add( _interval, "", toolTipGroup(), tr("Changes refresh interval") );
144   
145   // Display area and associated slots definition
146   _tabWidget = new QTabWidget( this );
147   _clients   = new QListView( _tabWidget );
148   SetListe();
149   _history   = new QListView( _tabWidget );
150   SetListeHistory();
151   
152   _tabWidget->addTab( _clients, tr( "Running" ) );
153   _tabWidget->addTab( _history, tr( "History" ) );
154   connect( _tabWidget, SIGNAL( currentChanged( QWidget* )), this, SLOT( slotListeSelect() ) );
155   connect( _clients,   SIGNAL( clicked( QListViewItem* ) ),        this, SLOT( slotClientChanged( QListViewItem* ) ) );
156   connect( _history,   SIGNAL( clicked( QListViewItem* ) ),        this, SLOT( slotHistoryChanged( QListViewItem* ) ) );
157   setCentralWidget( _tabWidget );
158   
159   // Timer definition (used to automaticaly refresh the display area)
160   _counter = new QTimer( this );
161   connect( _counter, SIGNAL( timeout() ), this, SLOT( slotListeSelect() ) );
162   myRefreshInterval = 10;
163   _counter->start( myRefreshInterval * 1000 );
164   
165   PIXELS xpos    = 160 ;
166   PIXELS ypos    = 100 ;
167   PIXELS largeur = 800 ;
168   PIXELS hauteur = 350 ;
169   setGeometry( xpos, ypos, largeur, hauteur ) ;
170   setCaption( name ) ;
171   statusBar()->message("    ");
172 }
173
174 /*!
175   Destructor
176 */
177 RegWidget::~RegWidget()
178 {
179   MESSAGE("Debut du Destructeur");
180   _counter->stop();
181   myRegWidgetPtr = 0;
182 };
183
184 /*!
185   Event filter
186 */
187 bool RegWidget::eventFilter( QObject* object, QEvent* event )
188 {
189   if ( object ) {
190     if ( object == myHelpWindow && event->type() == QEvent::Close ) {
191       myHelpWindow = 0;
192     }
193     else if ( object == myInfoWindow && event->type() == QEvent::Close ) {
194       myInfoWindow = 0;
195     }
196     else if ( object == myIntervalWindow && event->type() == QEvent::Close ) {
197       myIntervalWindow = 0;
198     }
199   }
200   return QMainWindow::eventFilter( object, event );
201 }
202
203 /*!
204   Searches item in the list and returns it's index or -1 if not found
205 */
206 int RegWidget::numitem(const QString &name, const QString &pid, const QString &machine,const Registry::AllInfos *listclient)
207 {
208   BEGIN_OF("numitem");
209   for (CORBA::ULong i=0; i<listclient->length(); i++)
210     {       
211       const Registry::Infos & c_info=(*listclient)[i];
212       ASSERT( c_info.name!=NULL);
213       QString b;
214       b.setNum(int(c_info.pid));
215       if ( (name.compare(QString(c_info.name)) == 0) && 
216           (machine.compare(QString(c_info.machine)) == 0) && 
217           (pid.compare(b) == 0) )
218         {
219           END_OF("numitem");
220           return i;
221         }
222     }
223   END_OF("numitem");
224   return -1;
225 }
226
227 /*!
228   Returns text, containing information about client [ static ]
229 */
230 QString RegWidget::setlongText( const Registry::Infos &c_info)
231 {
232   BEGIN_OF("setlongText");
233   ASSERT( c_info.name != NULL );
234   QString a = QString( "<hr><h2>" ) + tr( "Code" ) + QString( " : " );
235   a.append( QString( c_info.name ) );
236   a.append( "</h1><hr><br>" );
237   a.append( tr( "Process Id" ) + QString( " : " ) );
238   a.append( BOLD( QString::number( int( c_info.pid ) ) ) );
239   a.append( QString( " " ) + tr( "on machine" ) + QString( " " ) );
240   a.append( BOLD( c_info.machine ) ); 
241   a.append( QString( " " ) + tr( "ip address" ) + QString( " : " ) );
242   a.append( BOLD( c_info.adip ) );
243   a.append( "<br>" );
244   
245   a.append( tr( "launched by user" ) + QString( " " ) );
246   a.append( BOLD( c_info.pwname ) );
247   a.append( QString( " ( " ) + tr( "pid" ) + QString( " : " ) );
248   a.append( BOLD( QString::number( int( c_info.uid ) ) ) );
249   a.append( QString( " )<br> " ) + tr( "in directory" ) + QString( " " ));
250   a.append( BOLD( c_info.cdir ) );
251   
252   a.append( QString( "<br>" ) + tr( "begins" ) + QString( " " ) );
253   char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
254   t1 [strlen(t1) -1 ] = ' ';
255   a.append( BOLD( t1 ) ); 
256   delete [] t1;
257   a.append( "<br>" );
258   
259   if (c_info.tc_hello != 0 )
260     {
261       char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
262       t2 [strlen(t2) -1 ] = ' ';
263       a.append( tr( "last signal" ) + QString(" : ") ); 
264       a.append( BOLD( t2 ) ); 
265       a.append( "<br>" );
266       delete [] t2;
267     }
268   if ((c_info.tc_end - c_info.difftime) != 0)
269     {
270       char * t3 = (char * )duplicate(ctime(&c_info.tc_end));
271       t3 [strlen(t3) -1 ] = ' ';
272       a.append( tr( "ends" ) + QString( " " ) ); 
273       a.append( BOLD( t3 ) ); 
274       a.append( "<br>" );
275       delete [] t3;
276     }
277   else
278     {
279       a.append( tr( "still running" ) + QString( "<br>" ) );
280     }
281   
282   SCRUTE(c_info.difftime);
283   if (c_info.difftime!= 0)
284     {
285       a.append( QString( "(" ) + tr( "Time on" ) + QString( " " ) ); 
286       a.append( BOLD( c_info.machine ) ); 
287       a.append( QString( " " ) + tr( "differs from server's time. The difference is" ) + QString( " " )); 
288       a.append( BOLD( QString::number( int( c_info.difftime ) ) ) );
289       a.append( QString( " " ) + tr( "seconds" ) + QString( ")<br>" ) );
290     }
291   END_OF("setlongText");  
292   return a;
293   
294 }
295
296 /*!
297   Close event
298 */
299 void RegWidget::closeEvent( QCloseEvent *e)
300 {
301   BEGIN_OF("closeEvent");
302   if ( myInfoWindow )
303     myInfoWindow->close();
304   if ( myHelpWindow )
305     myHelpWindow->close();
306   if (myIntervalWindow)
307     myIntervalWindow->close();
308   e->accept();
309   END_OF("closeEvent");
310 };
311
312 /*!
313   Setups Clients list
314 */
315 void RegWidget::SetListe()
316 {
317   BEGIN_OF("SetListe");
318   _clients->addColumn( tr( "Component" ), -1);
319   _clients->addColumn( tr( "PID" ), -1 );
320   _clients->addColumn( tr( "User Name" ), -1 );
321   _clients->addColumn( tr( "Machine" ), -1 );
322   _clients->addColumn( tr( "begins" ), -1 );
323   _clients->addColumn( tr( "hello" ) , -1 );
324   _clients->setColumnAlignment( 1, Qt::AlignRight );
325   END_OF("SetListe");
326 }
327
328 /*!
329   Setups History list
330 */
331 void RegWidget::SetListeHistory()
332 {
333    BEGIN_OF("SetListeHistory")
334   _history->addColumn( tr( "Component" ), -1);
335   _history->addColumn( tr( "PID" ), -1 );
336   _history->addColumn( tr( "User Name" ), -1 );
337   _history->addColumn( tr( "Machine" ), -1 );
338   _history->addColumn( tr( "begins" ), -1 );
339   _history->addColumn( tr( "ends" ), -1 );
340   _history->setColumnAlignment( 1, Qt::AlignRight );
341    END_OF("SetListeHistory")
342 }
343
344 /*!
345   Updates History list
346 */
347 void RegWidget::InfoHistory()
348 {
349
350   BEGIN_OF("InfoHistory")
351     _history->clear();
352   try
353     {
354       _serverhistory = _VarComponents->history();
355       for (CORBA::ULong i=0; i<_serverhistory->length(); i++)
356         {       
357           const Registry::Infos & c_info=(*_serverhistory)[i];
358           ASSERT( c_info.name!=NULL);
359           QString a;
360           a.setNum(int(c_info.pid));
361           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
362           t1 [strlen(t1) -1 ] = ' ';
363           char * t2 = (char * )duplicate(ctime(&c_info.tc_end));
364           t2 [strlen(t2) -1 ] = ' ';
365           QListViewItem * item = new QListViewItem(_history, QString(c_info.name),\
366                                                    a, QString(c_info.pwname), QString(c_info.machine), \
367                                                    QString(t1), QString(t2));
368           item=0 ;
369           delete [] t1;
370           delete [] t2;
371           
372         }
373     }
374   catch( ... )
375     {
376       _interval->setDisabled( TRUE ) ;
377       _refresh->setDisabled( TRUE ) ;
378       _counter->stop();
379       MESSAGE("Sorry, No more Registry Server") ;
380       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
381     }
382   END_OF("InfoHistory")
383 }
384
385 /*!
386   Updates clients list
387 */
388 void RegWidget::InfoReg()
389 {
390   BEGIN_OF("InfoReg")
391   _clients->clear();
392   try
393     {
394       _serverclients = _VarComponents->getall();
395       for (CORBA::ULong i=0; i<_serverclients->length(); i++)
396         {       
397           const Registry::Infos & c_info=(*_serverclients)[i];
398           ASSERT( c_info.name!=NULL);
399           QString a;
400           a.setNum(int(c_info.pid));
401           char * t1 = (char * )duplicate(ctime(&c_info.tc_start));
402           t1 [strlen(t1) -1 ] = ' ';
403           char * t2 = (char * )duplicate(ctime(&c_info.tc_hello));
404           t2 [strlen(t2) -1 ] = ' ';
405           QListViewItem * item = new QListViewItem(_clients, QString(c_info.name),\
406                                                    a, QString(c_info.pwname), QString(c_info.machine), \
407                                                    QString(t1), QString(t2));
408           item=0 ;
409           delete [] t1;
410           delete [] t2;
411           
412         }
413     }
414   catch( ... )
415     {
416       _interval->setDisabled( TRUE ) ;
417       _refresh->setDisabled( TRUE ) ;
418       _counter->stop();
419       MESSAGE("Sorry, No more Registry Server") ;
420       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
421     }
422   END_OF("InfoReg")
423 }
424
425 /*!
426   Called when <Refresh> button is clicked
427 */
428 void RegWidget::slotListeSelect()
429 {
430   try
431     {
432       ASSERT(_tabWidget->currentPage() != NULL);
433       if (_tabWidget->currentPage () == _clients) InfoReg();
434       else if (_tabWidget->currentPage () == _history) InfoHistory();
435     }
436   catch( ... )
437     {
438       MESSAGE("Sorry, No more Registry Server") ;
439       statusBar()->message( tr( "Sorry, No more Registry Server" ) ) ;
440     }
441 }
442
443 /*!
444   Called when <Interval> button is clicked (changing refresh interval)
445 */
446 void RegWidget::slotSelectRefresh()
447 {
448   BEGIN_OF("slotSelectRefresh");
449   myIntervalWindow = new IntervalWindow(this);
450   myIntervalWindow->installEventFilter( this );
451   myIntervalWindow->setValue(myRefreshInterval);
452   myIntervalWindow->show();
453   connect( myIntervalWindow->Cancel(), SIGNAL( clicked() ), myIntervalWindow, SLOT( close() ) );
454   connect( myIntervalWindow->Ok(), SIGNAL( clicked() ), this, SLOT( slotIntervalOk() ) );
455   END_OF("slotSelectRefresh");
456 }
457
458 void RegWidget::slotIntervalOk()
459 {
460   BEGIN_OF("slotIntervalOk");
461   myRefreshInterval = myIntervalWindow->getValue();
462   _counter->changeInterval( myRefreshInterval * 1000 );
463   SCRUTE(myRefreshInterval);
464   myIntervalWindow->close();
465   END_OF("slotIntervalOk");
466 }
467 /*!
468   Called when <Help> button is clicked
469 */
470 void RegWidget::slotHelp()
471 {
472   BEGIN_OF("slotHelp()");
473
474   if ( !myHelpWindow ) {
475     myHelpWindow  = new HelpWindow( this );
476     myHelpWindow->installEventFilter( this );
477   }
478   myHelpWindow->show();
479   myHelpWindow->raise();
480   myHelpWindow->setActiveWindow();
481   
482   END_OF("slotHelp()") ;
483 }
484
485 /*!
486   Called when user clicks on item in <Running> list
487 */
488 void RegWidget::slotClientChanged( QListViewItem* item )
489 {
490   BEGIN_OF("slotClientChanged()") ;
491
492   if ( item <= 0)
493     return;
494
495   blockSignals( true ); // for sure that item will not be deleted when refreshing
496
497   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverclients);
498   SCRUTE(numeroItem) ;
499   SCRUTE(item->text(1)) ;
500   
501   ASSERT(numeroItem>=0) ;
502   ASSERT((size_t)numeroItem<_serverclients->length()) ;
503   const Registry::Infos & c_info=(*_serverclients)[numeroItem];
504   ASSERT( c_info.name!=NULL);
505   
506   if ( !myInfoWindow ) {
507     myInfoWindow  = new InfoWindow( this );
508     myInfoWindow->installEventFilter( this );
509   }
510   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
511   myInfoWindow->setCaption(a);
512   myInfoWindow->setText( RegWidget::setlongText( c_info) );
513   myInfoWindow->show();
514   myInfoWindow->raise();
515   myInfoWindow->setActiveWindow();
516
517   blockSignals( false ); // enabling signals again
518
519   END_OF("slotClientChanged()") ;
520   return ;
521 }
522
523 /*!
524   Called when user clicks on item in <History> list
525 */
526 void RegWidget::slotHistoryChanged( QListViewItem* item )
527 {
528
529   BEGIN_OF("slotHistoryChanged()") ;
530   
531   if ( item <= 0)
532     return;
533
534   blockSignals( true ); // for sure that item will not be deleted when refreshing
535
536   int numeroItem = numitem(item->text(0), item->text(1), item->text(3), _serverhistory);
537   
538   SCRUTE(numeroItem) ;
539   SCRUTE(item->text(1)) ;
540   ASSERT(numeroItem>=0) ;
541   ASSERT((size_t)numeroItem<_serverhistory->length()) ;
542   const Registry::Infos & c_info=(*_serverhistory)[numeroItem];
543   ASSERT( c_info.name!=NULL);
544   
545   if ( !myInfoWindow ) {
546     myInfoWindow  = new InfoWindow( this );
547     myInfoWindow->installEventFilter( this );
548   }
549   QString a = tr( "More about" ) + QString( " " ) + QString( c_info.name );
550   myInfoWindow->setCaption(a);
551   myInfoWindow->setText( RegWidget::setlongText( c_info ) );
552   myInfoWindow->show();
553   myInfoWindow->raise();
554   myInfoWindow->setActiveWindow();
555
556   blockSignals( false ); // enabling signals again
557
558   END_OF("slotHistoryChanged()") ;
559   return ;
560 }
561
562 /*!
563   Constructor
564 */
565 InfoWindow::InfoWindow( QWidget* parent, const char* name )
566      : QMainWindow( parent, name, WType_TopLevel | WDestructiveClose )
567 {
568   BEGIN_OF("InfoWindow");
569   myTextView = new QTextView( this, "myTextView" );
570   setCentralWidget( myTextView );
571   setMinimumSize( 450, 250 );
572   END_OF("InfoWindow");
573 }
574
575 /*!
576   Sets text
577 */
578 void InfoWindow::setText( const QString& text )
579 {
580   myTextView->setText( text );
581 }
582
583 static const char* SEPARATOR    = ":";
584
585 QString findFile( QString filename )
586 {
587   QString dir;
588   char* cenv;
589   
590   // Try ${HOME}/.salome/resources directory
591   cenv = getenv( "HOME" );
592   if ( cenv ) {
593     dir.sprintf( "%s", cenv );
594     if ( !dir.isEmpty() ) {
595       dir = addSlash(dir) ;
596       dir = dir + ".salome" ;
597       dir = addSlash(dir) ;
598       dir = dir + "resources" ;
599       dir = addSlash(dir) ;
600       QFileInfo fileInfo( dir + filename );
601       if ( fileInfo.isFile() && fileInfo.exists() )
602         return fileInfo.filePath();
603     }
604   }
605   // Try ${SALOME_SITE_DIR}/share/salome/resources directory
606   cenv = getenv( "SALOME_SITE_DIR" );
607   if ( cenv ) {
608     dir.sprintf( "%s", cenv );
609     if ( !dir.isEmpty() ) {
610       dir = addSlash(dir) ;
611       dir = dir + "share" ;
612       dir = addSlash(dir) ;
613       cenv = getenv("SALOME_SITE_NAME");
614       if (cenv)  dir = dir + cenv;
615       else       dir = dir + "salome" ;
616       dir = addSlash(dir) ;
617       dir = dir + "resources" ;
618       dir = addSlash(dir) ;
619       QFileInfo fileInfo( dir + filename );
620       if ( fileInfo.isFile() && fileInfo.exists() )
621         return fileInfo.filePath();
622     }
623   }
624   // Try ${KERNEL_ROOT_DIR}/share/salome/resources directory
625   cenv = getenv( "KERNEL_ROOT_DIR" );
626   if ( cenv ) {
627     dir.sprintf( "%s", cenv );
628     if ( !dir.isEmpty() ) {
629       dir = addSlash(dir) ;
630       dir = dir + "share" ;
631       dir = addSlash(dir) ;
632       dir = dir + "salome" ;
633       dir = addSlash(dir) ;
634       dir = dir + "resources" ;
635       dir = addSlash(dir) ;
636       QFileInfo fileInfo( dir + filename );
637       if ( fileInfo.isFile() && fileInfo.exists() )
638         return fileInfo.filePath();
639     }
640   }
641   // Try CSF_SaloameResources env.var directory ( or directory list )
642   cenv = getenv( "CSF_SalomeResources" );
643   if ( cenv ) {
644     dir.sprintf( "%s", cenv );
645     if ( !dir.isEmpty() ) {
646       QStringList dirList = QStringList::split( SEPARATOR, dir, false ); // skip empty entries
647       for ( int i = 0; i < dirList.count(); i++ ) {
648         QFileInfo fileInfo( addSlash( dirList[ i ] ) + filename );
649         if ( fileInfo.isFile() && fileInfo.exists() )
650           return fileInfo.filePath();
651       }
652     }
653   }
654   return filename;
655 }
656 QString addSlash( const QString& path )
657 {
658   if (!path.isNull()) {
659 #ifdef WNT
660     QChar slash ('\\');
661 #else
662     QChar slash ('/');
663 #endif
664     if ( path.at(path.length()-1) != slash )
665       return path + slash;
666   }
667   return path;
668 }