1 // File : SALOME_InstallWizard.cxx
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER
4 // Project : SALOME Professional
5 // Module : InstallWizard
6 // Copyright : 2003 CEA/DEN, EDF R&D
9 #include "SALOME_InstallWizard.hxx"
12 #include <qbuttongroup.h>
14 #include <qfiledialog.h>
15 #include <qapplication.h>
16 #include <qtextbrowser.h>
17 #include <qdesktopwidget.h>
18 #include <qfileinfo.h>
19 #include <qmessagebox.h>
21 #include <qhbuttongroup.h>
22 #include <qradiobutton.h>
24 #include <qwhatsthis.h>
38 #define max( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
41 // ######################################## Globals ##############################################
43 QString myVersion = "1.2";
44 QString myCaption = QString("SALOME Professional %1 Installation Wizard").arg(myVersion);
45 QString myCopyright = "Copyright (C) 2003 CEA/DEN, EDF R&D";
46 QString myLicense = "All right reserved";
49 #define TEMPDIRNAME ( "/INSTALLWORK" + QString::number( getpid() ) )
51 Defines list of dependancies as string separated by space symbols
53 static QString DefineDependeces(MapProducts& theProductsMap) {
54 QStringList aProducts;
55 for ( MapProducts::Iterator mapIter = theProductsMap.begin(); mapIter != theProductsMap.end(); ++mapIter ) {
56 QCheckListItem* item = mapIter.key();
57 Dependancies dep = mapIter.data();
58 QStringList deps = dep.getDependancies();
59 for (int i = 0; i<(int)deps.count(); i++ ) {
60 if ( !aProducts.contains( deps[i] ) )
61 aProducts.append( deps[i] );
63 if ( !aProducts.contains( item->text(0) ) )
64 aProducts.append( item->text(0) );
66 return aProducts.join(" ");
69 #define QUOTE(arg) QString("'") + QString(arg) + QString("'")
71 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
72 T H E O L D I M P L E M E N T A T I O N
73 static QString DefineDependeces(MapProducts& theProductsMap, QCheckListItem* product ){
74 QStringList aProducts;
75 if ( theProductsMap.contains( product ) ) {
76 Dependancies dep = theProductsMap[ product ];
77 QStringList deps = dep.getDependancies();
78 for (int i = 0; i<(int)deps.count(); i++ ) {
79 aProducts.append( deps[i] );
82 return QString("\"") + aProducts.join(" ") + QString("\"");
84 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
87 Makes directory recursively, returns false if not succedes [ static ]
89 static bool makeDir( const QString& theDir, QString& theCreated )
91 theCreated = QString::null;
92 if ( theDir.isEmpty() )
94 QString aDir = QDir::cleanDirPath( QFileInfo( theDir ).absFilePath() );
97 start = aDir.find( QDir::separator(), start );
99 QFileInfo fi( aDir.left( start ) );
100 if ( !fi.exists() ) {
101 // VSR: Create directory and set permissions to allow other users to remove it
102 QString script = "mkdir " + fi.absFilePath();
103 script += "; chmod 777 " + fi.absFilePath();
104 script += " > /dev/null";
105 if ( system( script.latin1() ) )
107 // VSR: Remember the top of the created directory (to remove it in the end of the installation)
108 if ( theCreated.isNull() )
109 theCreated = fi.absFilePath();
114 if ( !QFileInfo( aDir ).exists() ) {
115 // VSR: Create directory, other users should NOT have possibility to remove it!!!
116 QString script = "mkdir " + aDir;
117 script += " > /dev/null";
118 if ( system( script.latin1() ) )
120 // VSR: Remember the top of the created directory (to remove it in the end of the installation)
121 if ( theCreated.isNull() )
127 Reads the file, returns false if can't open it
129 static bool readFile( const QString& fileName, QString& text )
131 if ( QFile::exists( fileName ) ) {
132 QFile file( fileName );
133 if ( file.open( IO_ReadOnly ) ) {
134 QTextStream stream( &file );
136 while ( !stream.eof() ) {
137 line = stream.readLine(); // line of text excluding '\n'
146 // ###################################### Progress View ###########################################
149 Constructor of progress view's item
150 <parent> - parent progress view
151 <productName> - full name of the product
152 <smbName> - alias for he product used by the script
153 <status> - initial status of the product, default is 'Waiting'
155 ProgressViewItem::ProgressViewItem( ProgressView* parent, QString productName, const QString installType, const QString scriptName, Status status )
156 : QListViewItem( parent, productName, installType ), myScript( scriptName )
161 Sets new status for the item
163 void ProgressViewItem::setStatus( Status status )
166 switch ( myStatus ) {
168 setText( 2, "Waiting" ); break;
170 setText( 2, "Processing" ); break;
172 setText( 2, "Completed" ); break;
174 setText( 2, "Aborted" ); break;
181 Paints the cell of the list view item
183 void ProgressViewItem::paintCell( QPainter* painter, const QColorGroup& cg, int column, int width, int align )
185 QColorGroup acg( cg );
187 switch ( myStatus ) {
189 acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
191 acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getProcessingColor() ); break;
193 acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getCompletedColor() ); break;
195 acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break;
200 QListViewItem::paintCell( painter, acg, column, width, align );
203 Progress view's constructor
205 ProgressView::ProgressView( QWidget* parent ) : QListView( parent )
207 addColumn( tr( "Product" ) ); addColumn( tr( "Type" ) ); addColumn( tr( "Status" ) );
209 setSelectionMode( QListView::NoSelection );
211 setResizeMode( QListView::AllColumns );
212 setFocusPolicy( QWidget::NoFocus );
213 setColors( QColor( "red" ), QColor( "orange" ), QColor( "green" ) );
218 void ProgressView::setColors( QColor wColor, QColor pColor, QColor cColor ) {
219 myWaitingColor = wColor;
220 myProcessingColor = pColor;
221 myCompletedColor = cColor;
227 void ProgressView::addProduct( const QString product, const QString type, const QString script ) {
228 QListViewItem* lastItem = this->lastItem();
229 ProgressViewItem* newItem = new ProgressViewItem( this, product, type, script );
231 newItem->moveItem( lastItem );
234 Finds the first item with given status
236 QString ProgressView::findStatus( Status status ) {
237 ProgressViewItem* item = ( ProgressViewItem* )firstChild();
239 if ( item->getStatus() == status )
240 return item->getProduct();
241 item = ( ProgressViewItem* )( item->nextSibling() );
243 return QString::null;
246 Sets new status for the product item
248 void ProgressView::setStatus( const QString product, Status status ) {
249 ProgressViewItem* item = findItem( product );
251 item->setStatus( status );
256 Scrolls the view to make item visible if necessary
258 void ProgressView::ensureVisible( const QString product ) {
259 ProgressViewItem* item = findItem( product );
261 ensureItemVisible( item );
265 Finds the item by the product name
267 ProgressViewItem* ProgressView::findItem( const QString product ) {
268 ProgressViewItem* item = ( ProgressViewItem* )firstChild();
270 if ( item->getProduct() == product )
272 item = ( ProgressViewItem* )( item->nextSibling() );
277 Gets the product script
279 QString ProgressView::getScript( const QString product ) {
280 ProgressViewItem* item = ( ProgressViewItem* )firstChild();
282 if ( item->getProduct() == product )
283 return item->getScript();
284 item = ( ProgressViewItem* )( item->nextSibling() );
286 return QString::null;
289 // ###################################### Install Wizard ###########################################
294 SALOME_InstallWizard::SALOME_InstallWizard(QString aXmlFileName)
295 : InstallWizard( qApp->desktop(), "SALOME_InstallWizard", false, 0 ), helpWindow( NULL ), moreMode( false ), previousPage( 0 ), exitConfirmed( false )
297 tmpCreated = QString::null;
299 xmlFileName = aXmlFileName;
300 QFont fnt = font(); fnt.setPointSize( 14 ); fnt.setBold( true );
304 cout << "Config. file : " << xmlFileName << endl;
308 QFile xmlfile(xmlFileName);
309 if ( xmlfile.exists() ) {
310 QXmlInputSource source( &xmlfile );
311 QXmlSimpleReader reader;
313 StructureParser * handler = new StructureParser();
314 reader.setContentHandler( handler );
315 reader.parse( source );
318 setCaption( myCaption );
320 setIcon( QPixmap( ( const char** ) image0_data ) );
322 setSizeGripEnabled( true );
324 // create instance of class for starting shell install script
325 shellProcess = new QProcess(this,"shellProcess");
327 // create introduction page
329 // create products page
331 // create prestart page
333 // create progress page
335 // create readme page
339 QWhatsThis::add( backButton(), tr( "Returns to the previous step of the installation procedure" ) );
340 QToolTip::add ( backButton(), tr( "Returns to the previous step of the installation procedure" ) );
341 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
342 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
343 QWhatsThis::add( finishButton(), tr( "Finishes installation and quits program" ) );
344 QToolTip::add ( finishButton(), tr( "Finishes installation and quits program" ) );
345 QWhatsThis::add( cancelButton(), tr( "Cancels installation and quits program" ) );
346 QToolTip::add ( cancelButton(), tr( "Cancels installation and quits program" ) );
347 QWhatsThis::add( helpButton(), tr( "Displays help information window" ) );
348 QToolTip::add ( helpButton(), tr( "Displays help information window" ) );
350 // common signals connections
351 connect( this, SIGNAL( selected( const QString& ) ),
352 this, SLOT( pageChanged( const QString& ) ) );
353 connect( this, SIGNAL( helpClicked() ), this, SLOT( helpClicked() ) );
354 // catch signals from launched script
355 connect(shellProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) );
356 connect(shellProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) );
357 connect(shellProcess, SIGNAL( processExited() ), this, SLOT( productInstalled() ) );
358 connect(shellProcess, SIGNAL( wroteToStdin() ), this, SLOT( wroteToStdin() ) );
363 SALOME_InstallWizard::~SALOME_InstallWizard()
365 shellProcess->kill(); // kill it for sure
366 QString script = "kill -9 ";
367 int PID = (int)shellProcess->processIdentifier();
369 script += QString::number( PID );
370 script += " > /dev/null";
372 cout << "script: "<< script.latin1() << endl;
374 if ( system( script.latin1() ) ) {
379 Event filter, spies for Help window closing
381 bool SALOME_InstallWizard::eventFilter( QObject* object, QEvent* event )
383 if ( object && object == helpWindow && event->type() == QEvent::Close )
385 return InstallWizard::eventFilter( object, event );
390 void SALOME_InstallWizard::closeEvent( QCloseEvent* ce )
392 if ( !exitConfirmed ) {
393 if ( QMessageBox::information( this,
395 tr( "Do you want to quit Installation Wizard?" ),
405 exitConfirmed = true;
411 Creates introduction page
413 void SALOME_InstallWizard::setupIntroPage()
416 introPage = new QWidget( this, "IntroPage" );
417 QGridLayout* pageLayout = new QGridLayout( introPage );
418 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
419 // create logo picture
420 QPixmap logo( (const char**)SALOMEPRO_Logo_xpm );
421 logoLab = new QLabel( introPage );
422 logoLab->setPixmap( logo );
423 logoLab->setScaledContents( false );
424 logoLab->setFrameStyle( QLabel::Plain | QLabel::Box );
425 logoLab->setAlignment( AlignCenter );
426 // create version box
427 QVBox* versionBox = new QVBox( introPage ); versionBox->setSpacing( 6 );
428 versionBox->setFrameStyle( QGroupBox::Panel | QGroupBox::Sunken );
429 QWidget* stretch1 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch1, 5 );
430 versionLab = new QLabel( QString("Version %1").arg(myVersion), versionBox );
431 versionLab->setAlignment( AlignCenter );
432 copyrightLab = new QLabel( myCopyright, versionBox );
433 copyrightLab->setAlignment( AlignCenter );
434 licenseLab = new QLabel( myLicense, versionBox );
435 licenseLab->setAlignment( AlignCenter );
436 QWidget* stretch2 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch2, 5 );
438 info = new QLabel( introPage );
439 info->setText( tr( "This program will install <b>SALOME Professional Version %1</b>."
440 "<br><br>The wizard will also help you to install all products "
441 "which are necessary for <b>SALOME PRO</b> platform and setup "
442 "your environment.<br><br>Click <code>Cancel</code> button to abort "
443 "installation and quit. Click <code>Next</code> button to continue with the "
444 "installation program.").arg(myVersion) );
445 info->setFrameStyle( QGroupBox::WinPanel | QGroupBox::Sunken );
446 info->setMargin( 6 );
447 info->setAlignment( WordBreak );
448 info->setMinimumSize( 250, 250 );
449 QPalette pal = info->palette();
450 pal.setColor( QColorGroup::Background, QApplication::palette().active().base() );
451 info->setPalette( pal );
452 info->setLineWidth( 2 );
454 pageLayout->addWidget( logoLab, 0, 0 );
455 pageLayout->addWidget( versionBox, 1, 0 );
456 pageLayout->addMultiCellWidget( info, 0, 1, 1, 1 );
457 pageLayout->setColStretch( 1, 5 );
458 pageLayout->setRowStretch( 1, 5 );
460 addPage( introPage, tr( "Introduction" ) );
463 Creates products page
465 void SALOME_InstallWizard::setupProductsPage()
468 productsPage = new QWidget( this, "ProductsPage" );
469 QGridLayout* pageLayout = new QGridLayout( productsPage );
470 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
472 QLabel* targetLab = new QLabel( tr( "Type the target directory:" ), productsPage );
473 targetFolder = new QLineEdit( productsPage );
474 QWhatsThis::add( targetFolder, tr( "Enter target root directory where products will be installed" ) );
475 QToolTip::add ( targetFolder, tr( "Enter target root directory where products will be installed" ) );
476 targetBtn = new QPushButton( tr( "Browse..." ), productsPage );
477 QWhatsThis::add( targetBtn, tr( "Click this to browse target directory" ) );
478 QToolTip::add ( targetBtn, tr( "Click this to browse target directory" ) );
479 // create advanced mode widgets container
480 moreBox = new QWidget( productsPage );
481 QGridLayout* moreBoxLayout = new QGridLayout( moreBox );
482 moreBoxLayout->setMargin( 0 ); moreBoxLayout->setSpacing( 6 );
484 QLabel* tempLab = new QLabel( tr( "Type the directory for the temporary files:" ), moreBox );
485 tempFolder = new QLineEdit( moreBox );
486 // tempFolder->setText( "/tmp" ); // default is /tmp directory
487 QWhatsThis::add( tempFolder, tr( "Enter directory where to put temporary files" ) );
488 QToolTip::add ( tempFolder, tr( "Enter directory where to put temporary files" ) );
489 tempBtn = new QPushButton( tr( "Browse..." ), moreBox );
490 tempBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
491 QWhatsThis::add( tempBtn, tr( "Click this to browse temporary directory" ) );
492 QToolTip::add ( tempBtn, tr( "Click this to browse temporary directory" ) );
493 // create products list
494 productsView = new MyListView( moreBox );
495 productsView->setMinimumSize( 200, 180 );
496 QWhatsThis::add( productsView, tr( "This view lists the products you wish to be installed" ) );
497 QToolTip::add ( productsView, tr( "This view lists the products you wish to be installed" ) );
499 productsInfo = new QTextBrowser( moreBox );
500 productsInfo->setMinimumSize( 270, 135 );
501 QWhatsThis::add( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) );
502 QToolTip::add ( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) );
504 QLabel* reqLab1 = new QLabel( tr( "Total disk space required:" ), moreBox );
505 QWhatsThis::add( reqLab1, tr( "Shows total disk space required for installing selected products" ) );
506 QToolTip::add ( reqLab1, tr( "Shows total disk space required for installing selected products" ) );
507 requiredSize = new QLabel( moreBox );
508 requiredSize->setMinimumWidth( 100 );
509 QWhatsThis::add( requiredSize, tr( "Shows total disk space required for installing selected products" ) );
510 QToolTip::add ( requiredSize, tr( "Shows total disk space required for installing selected products" ) );
511 QLabel* reqLab2 = new QLabel( tr( "Space for temporary files:" ), moreBox );
512 QWhatsThis::add( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) );
513 QToolTip::add ( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) );
514 requiredTemp = new QLabel( moreBox );
515 requiredTemp->setMinimumWidth( 100 );
516 QWhatsThis::add( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) );
517 QToolTip::add ( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) );
518 QFont fnt = reqLab1->font();
520 reqLab1->setFont( fnt );
521 requiredSize->setFont( fnt );
522 reqLab2->setFont( fnt );
523 requiredTemp->setFont( fnt );
524 QGridLayout* sizeLayout = new QGridLayout; sizeLayout->setMargin( 0 ); sizeLayout->setSpacing( 6 );
525 sizeLayout->addWidget( reqLab1, 0, 0 );
526 sizeLayout->addWidget( requiredSize, 0, 1 );
527 sizeLayout->addWidget( reqLab2, 1, 0 );
528 sizeLayout->addWidget( requiredTemp, 1, 1 );
529 // prerequisites checkbox
530 prerequisites = new QCheckBox( tr( "Auto set prerequisites products" ), moreBox );
531 prerequisites->setChecked( true );
532 QWhatsThis::add( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) );
533 QToolTip::add ( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) );
534 // <Unselect All> buttons
535 unselectBtn = new QPushButton( tr( "&Unselect All" ), moreBox );
536 QWhatsThis::add( unselectBtn, tr( "Unselects all products" ) );
537 QToolTip::add ( unselectBtn, tr( "Unselects all products" ) );
538 QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 );
539 btnLayout->addWidget( unselectBtn );
540 // layouting advancet mode widgets
541 moreBoxLayout->addMultiCellWidget( tempLab, 0, 0, 0, 2 );
542 moreBoxLayout->addMultiCellWidget( tempFolder, 1, 1, 0, 1 );
543 moreBoxLayout->addWidget ( tempBtn, 1, 2 );
544 moreBoxLayout->addMultiCellWidget( productsView, 2, 5, 0, 0 );
545 moreBoxLayout->addMultiCellWidget( productsInfo, 2, 2, 1, 2 );
546 moreBoxLayout->addMultiCellWidget( prerequisites,3, 3, 1, 2 );
547 moreBoxLayout->addMultiCellLayout( btnLayout, 4, 4, 1, 2 );
548 moreBoxLayout->addMultiCellLayout( sizeLayout, 5, 5, 1, 2 );
550 moreBtn = new QPushButton( tr( "More..." ), productsPage );
552 pageLayout->addMultiCellWidget( targetLab, 0, 0, 0, 1 );
553 pageLayout->addWidget ( targetFolder, 1, 0 );
554 pageLayout->addWidget ( targetBtn, 1, 1 );
555 pageLayout->addMultiCellWidget( moreBox, 2, 2, 0, 1 );
556 pageLayout->addWidget ( moreBtn, 3, 1 );
557 pageLayout->setRowStretch( 2, 5 );
558 //pageLayout->addRowSpacing( 6, 10 );
560 QFile xmlfile(xmlFileName);
561 if ( xmlfile.exists() ) {
562 QXmlInputSource source( &xmlfile );
563 QXmlSimpleReader reader;
565 StructureParser * handler = new StructureParser();
566 handler->setWizard( this );
567 handler->setListView(productsView);
568 handler->setTargetDir(targetFolder);
569 handler->setTempDir(tempFolder);
570 reader.setContentHandler( handler );
571 reader.parse( source );
573 // set first item to be selected
574 if ( productsView->childCount() > 0 ) {
575 productsView->setSelected( productsView->firstChild(), true );
576 onSelectionChanged( productsView->firstChild() );
579 addPage( productsPage, tr( "Installation settings" ) );
580 // connecting signals
581 connect( productsView, SIGNAL( selectionChanged( QListViewItem* ) ),
582 this, SLOT( onSelectionChanged( QListViewItem* ) ) );
583 connect( productsView, SIGNAL( itemToggled( QCheckListItem* ) ),
584 this, SLOT( onItemToggled( QCheckListItem* ) ) );
585 connect( unselectBtn, SIGNAL( clicked() ), this, SLOT( onProdBtn() ) );
586 // connecting signals
587 connect( targetFolder, SIGNAL( textChanged( const QString& ) ),
588 this, SLOT( directoryChanged( const QString& ) ) );
589 connect( targetBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) );
590 connect( tempFolder, SIGNAL( textChanged( const QString& ) ),
591 this, SLOT( directoryChanged( const QString& ) ) );
592 connect( tempBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) );
593 connect( moreBtn, SIGNAL( clicked() ), this, SLOT( onMoreBtn() ) );
594 // start on default - non-advanced - mode
598 Creates prestart page
600 void SALOME_InstallWizard::setupCheckPage()
603 prestartPage = new QWidget( this, "PrestartPage" );
604 QVBoxLayout* pageLayout = new QVBoxLayout( prestartPage );
605 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
607 choices = new QTextEdit( prestartPage );
608 choices->setReadOnly( true );
609 choices->setTextFormat( RichText );
610 choices->setUndoRedoEnabled ( false );
611 QWhatsThis::add( choices, tr( "Displays information about installation settings you made" ) );
612 QToolTip::add ( choices, tr( "Displays information about installation settings you made" ) );
613 QPalette pal = choices->palette();
614 pal.setColor( QColorGroup::Base, QApplication::palette().active().background() );
615 choices->setPalette( pal );
616 choices->setMinimumHeight( 10 );
618 pageLayout->addWidget( choices );
619 pageLayout->setStretchFactor( choices, 5 );
621 addPage( prestartPage, tr( "Check your choice" ) );
624 Creates progress page
626 void SALOME_InstallWizard::setupProgressPage()
629 progressPage = new QWidget( this, "progressPage" );
630 QGridLayout* pageLayout = new QGridLayout( progressPage );
631 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
633 splitter = new QSplitter( Vertical, progressPage );
634 splitter->setOpaqueResize( true );
635 // the parent for the widgets
636 QWidget* widget = new QWidget( splitter );
637 QGridLayout* layout = new QGridLayout( widget );
638 layout->setMargin( 0 ); layout->setSpacing( 6 );
639 // installation progress view box
640 installInfo = new QTextEdit( widget );
641 installInfo->setReadOnly( true );
642 installInfo->setTextFormat( RichText );
643 installInfo->setUndoRedoEnabled ( false );
644 installInfo->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
645 installInfo->setMinimumSize( 100, 10 );
646 QWhatsThis::add( installInfo, tr( "Displays installation process" ) );
647 QToolTip::add ( installInfo, tr( "Displays installation process" ) );
648 // parameters for the script
649 parametersLab = new QLabel( tr( "Enter your answer here:" ), widget );
650 passedParams = new QLineEdit ( widget );
651 QWhatsThis::add( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") );
652 QToolTip::add ( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") );
654 layout->addWidget( installInfo, 0, 0 );
655 layout->addWidget( parametersLab, 1, 0 );
656 layout->addWidget( passedParams, 2, 0 );
657 layout->addRowSpacing( 3, 6 );
658 // the parent for the widgets
659 widget = new QWidget( splitter );
660 layout = new QGridLayout( widget );
661 layout->setMargin( 0 ); layout->setSpacing( 6 );
662 // installation results view box
663 QLabel* resultLab = new QLabel( tr( "Installation Status:" ), widget );
664 progressView = new ProgressView( widget );
665 progressView->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
666 progressView->setMinimumSize( 100, 10 );
667 QWhatsThis::add( progressView, tr( "Displays installation status" ) );
668 QToolTip::add ( progressView, tr( "Displays installation status" ) );
670 layout->addRowSpacing( 0, 6 );
671 layout->addWidget( resultLab, 1, 0 );
672 layout->addWidget( progressView, 2, 0 );
674 pageLayout->addWidget( splitter, 0, 0 );
676 addPage( progressPage, tr( "Installation progress" ) );
678 connect( passedParams, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ) ;
683 void SALOME_InstallWizard::setupReadmePage()
686 readmePage = new QWidget( this, "RedamePage" );
687 QVBoxLayout* pageLayout = new QVBoxLayout( readmePage );
688 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
689 // README info text box
690 readme = new QTextEdit( readmePage );
691 readme->setReadOnly( true );
692 readme->setTextFormat( PlainText );
693 readme->setUndoRedoEnabled ( false );
694 QWhatsThis::add( readme, tr( "Displays README information" ) );
695 QToolTip::add ( readme, tr( "Displays README information" ) );
696 QPalette pal = readme->palette();
697 pal.setColor( QColorGroup::Base, QApplication::palette().active().background() );
698 readme->setPalette( pal );
699 readme->setMinimumHeight( 10 );
700 // <Launch SALOME> button
701 runSalomeBtn = new QPushButton( tr( "Launch SALOME" ), readmePage );
702 QWhatsThis::add( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) );
703 QToolTip::add ( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) );
704 QHBoxLayout* hLayout = new QHBoxLayout;
705 hLayout->addWidget( runSalomeBtn ); hLayout->addStretch();
707 pageLayout->addWidget( readme );
708 pageLayout->setStretchFactor( readme, 5 );
709 pageLayout->addLayout( hLayout );
710 // connecting signals
711 connect( runSalomeBtn, SIGNAL( clicked() ), this, SLOT( onLaunchSalome() ) );
712 // loading README file
713 QString readmeFile = QDir::currentDirPath() + "/README";
715 if ( readFile( readmeFile, text ) )
716 readme->setText( text );
718 readme->setText( "README file has not been found" );
720 addPage( readmePage, tr( "Finish installation" ) );
725 void SALOME_InstallWizard::showChoiceInfo()
729 long totSize, tempSize;
730 checkSize( &totSize, &tempSize );
734 if ( !xmlFileName.isEmpty() ) {
735 text += tr( "Configuration file: <b>" ) + xmlFileName + "</b><br>";
738 if ( !myOS.isEmpty() ) {
739 text += tr( "Target platform: <b>" ) + myOS + "</b><br>";
742 text += tr( "Products to be used:<ul>" );
743 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
745 if ( productsMap.contains( item ) ) {
746 if ( item->childCount() > 0 ) {
747 // Neither "SALOME binaries", no "SALOME sources"
748 if ( productsView->isNative( item ) ) {
749 text += "<li><b>" + item->text() + "</b> as native<br>";
754 item = (QCheckListItem*)( item->nextSibling() );
757 text += "<li><b>none</b><br>";
760 text += tr( "Products to be installed:<ul>" );
761 item = (QCheckListItem*)( productsView->firstChild() );
763 if ( productsMap.contains( item ) ) {
764 if ( item->childCount() > 0 ) {
765 // Neither "SALOME binaries", no "SALOME sources"
766 if ( productsView->isBinaries( item ) ) {
767 text += "<li><b>" + item->text() + "</b> as binaries<br>";
770 else if ( productsView->isSources( item ) ) {
771 text+= "<li><b>" + item->text() + "</b> as sources<br>";
775 else if ( item->isOn() ) {
776 // "SALOME binaries" or "SALOME sources"
777 text+= "<li><b>" + item->text() + "</b><br>";
781 item = (QCheckListItem*)( item->nextSibling() );
784 text += "<li><b>none</b><br>";
787 text += "Total disk space required: <b>" + QString::number( totSize ) + " Kb</b><br>" ;
788 text += "Space for temporary files required: <b>" + QString::number( tempSize ) + " Kb</b><br>" ;
790 text += "Target directory: <b>" + QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) + "</b><br>";
791 // VSR: Temporary folder is used always now and it is not necessary to disable it -->
792 // if ( tempSize > 0 )
793 // VSR: <----------------------------------------------------------------------------
794 text += "Temp directory: <b>" + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + "</b><br>";
796 choices->setText( text );
799 Checks if string contains spaces; used to check directory paths [ static ]
801 static bool hasSpace( const QString& dir )
803 for ( int i = 0; i < (int)dir.length(); i++ ) {
804 if ( dir[ i ].isSpace() )
810 Validates page when <Next> button is clicked
812 bool SALOME_InstallWizard::acceptData( const QString& pageTitle )
815 QWidget* aPage = InstallWizard::page( pageTitle );
816 if ( aPage == productsPage ) {
817 // ########## check if any products are selected to be installed
818 long totSize, tempSize;
819 checkSize( &totSize, &tempSize );
820 if ( totSize <= 0 ) {
821 QMessageBox::warning( this,
823 tr( "Select one or more products to install" ),
825 QMessageBox::NoButton,
826 QMessageBox::NoButton );
829 // ########## check target and temp directories (existence and available disk space)
831 QString targetDir = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
832 QString tempDir = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() );
833 // directories should differ
834 // if (!targetDir.isEmpty() && tempDir == targetDir) {
835 // QMessageBox::warning( this,
837 // tr( "Target and temporary directories must be different"),
839 // QMessageBox::NoButton,
840 // QMessageBox::NoButton );
843 // check target directory
844 if ( targetDir.isEmpty() ) {
845 QMessageBox::warning( this,
847 tr( "Please, enter valid target directory path" ),
849 QMessageBox::NoButton,
850 QMessageBox::NoButton );
853 QFileInfo fi( QDir::cleanDirPath( targetDir ) );
854 if ( !fi.exists() ) {
856 QMessageBox::warning( this,
858 tr( "The directory %1 doesn't exist.\n"
859 "Do you want to create directory?" ).arg( fi.absFilePath() ),
862 QMessageBox::NoButton ) == QMessageBox::Yes;
865 if ( !makeDir( fi.absFilePath(), tmpstr ) ) {
866 QMessageBox::critical( this,
868 tr( "Can't create the directory\n%1").arg( fi.absFilePath() ),
870 QMessageBox::NoButton,
871 QMessageBox::NoButton );
876 QMessageBox::warning( this,
878 tr( "The directory %1 is not a directory.\n"
879 "Please, enter valid target directory path" ).arg( fi.absFilePath() ),
881 QMessageBox::NoButton,
882 QMessageBox::NoButton );
885 if ( !fi.isWritable() ) {
886 QMessageBox::warning( this,
888 tr( "The directory %1 is not writeable.\n"
889 "Please, enter valid target directory path or change permissions" ).arg( fi.absFilePath() ),
891 QMessageBox::NoButton,
892 QMessageBox::NoButton );
895 if ( hasSpace( fi.absFilePath() ) &&
896 QMessageBox::warning( this,
898 tr( "The target directory contains space symbols.\n"
899 "This may cause problems with compiling or installing of products.\n\n"
900 "Do you want to continue?"),
903 QMessageBox::NoButton ) == QMessageBox::No ) {
906 QString binDir = "./Products/BINARIES";
907 if ( !myOS.isEmpty() )
908 binDir += "/" + myOS;
909 QFileInfo fib( QDir::cleanDirPath( binDir ) );
910 if ( !fib.exists() ) {
911 QMessageBox::warning( this,
913 tr( "The directory %1 doesn't exist.\n"
914 "This directory must contain binaries archives." ).arg( fib.absFilePath() ));
916 // run script that checks available disk space for installing of products // returns 1 in case of error
917 QString script = "./config_files/checkSize.sh '";
918 script += fi.absFilePath();
920 script += QString( "%1" ).arg( totSize );
922 cout << "script = " << script << endl;
924 if ( system( script ) ) {
925 QMessageBox::critical( this,
926 tr( "Out of space" ),
927 tr( "There is not available disk space for installing of selected products" ),
929 QMessageBox::NoButton,
930 QMessageBox::NoButton );
933 // check temp directory
934 if ( tempDir.isEmpty() ) {
936 QMessageBox::warning( this,
938 tr( "Please, enter valid temp directory path" ),
940 QMessageBox::NoButton,
941 QMessageBox::NoButton );
945 tempFolder->setText( "/tmp" );
948 QFileInfo fit( QDir::cleanDirPath( tempDir ) );
949 if ( !makeDir( fit.absFilePath() + TEMPDIRNAME, tmpCreated ) ) {
950 QMessageBox::critical( this,
952 tr( "Can't use temporary directory.\nCheck permissions for the %1 directory.").arg( fit.absFilePath() ),
954 QMessageBox::NoButton,
955 QMessageBox::NoButton );
958 // run script that check available disk space for temporary files
959 // returns 1 in case of error
960 QString tscript = "./config_files/checkSize.sh '";
961 tscript += fit.absFilePath();
963 tscript += QString( "%1" ).arg( tempSize );
965 cout << "script = " << tscript << endl;
967 if ( system( tscript ) ) {
968 QMessageBox::critical( this,
969 tr( "Out of space" ),
970 tr( "There is not available disk space for the temporary files" ),
972 QMessageBox::NoButton,
973 QMessageBox::NoButton );
976 // VSR: <------------------------------------------------------------------------------
977 // ########## check native products
978 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
981 if ( productsMap.contains( item ) ) {
982 if ( item->childCount() > 0 ) {
983 if ( !productsView->isNone( item ) ) {
984 if ( item->text(2).isEmpty() || item->text(2).isNull() ) {
985 QMessageBox::warning( this,
987 tr( QString("You don't have a defined script for %1").arg(item->text(0))),
989 QMessageBox::NoButton,
990 QMessageBox::NoButton );
991 productsView->setNone( item );
994 QFileInfo fi( QString("./config_files/") + item->text(2) );
995 if ( !fi.exists() ) {
996 QMessageBox::warning( this,
998 tr( QString("%1 required for %2 doesn't exist.").arg("./config_files/" + item->text(2)).arg(item->text(0))),
1000 QMessageBox::NoButton,
1001 QMessageBox::NoButton );
1002 productsView->setNone( item );
1007 // collect native products
1008 if ( productsView->isNative( item ) ) {
1009 if ( natives.find( item->text(0) ) == natives.end() )
1010 natives.append( item->text(0) );
1012 else if ( productsView->isBinaries( item ) || productsView->isSources( item ) ) {
1013 QStringList dependOn = productsMap[ item ].getDependancies();
1014 for ( int i = 0; i < (int)dependOn.count(); i++ ) {
1015 QCheckListItem* depitem = findItem( dependOn[ i ] );
1017 if ( productsView->isNative( depitem ) && natives.find( depitem->text(0) ) == natives.end() )
1018 natives.append( depitem->text(0) );
1021 QMessageBox::warning( this,
1023 tr( QString("%1 is required for %2 %3 installation.\n"
1024 "Please, add this product in config.xml file.").arg(dependOn[ i ]).arg(item->text(0)).arg(item->text(1))),
1026 QMessageBox::NoButton,
1027 QMessageBox::NoButton );
1034 item = (QCheckListItem*)( item->nextSibling() );
1036 QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1037 QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
1038 for ( unsigned i = 0; i < natives.count(); i++ ) {
1039 item = findItem( natives[ i ] );
1041 QString script = "cd ./config_files/;" + item->text(2) + " try_native " +
1042 QFileInfo( tmpFolder ).absFilePath() + " " + QDir::currentDirPath() + "/Products " + QFileInfo( tgtFolder ).absFilePath() + " " +
1043 QUOTE(DefineDependeces(productsMap)) + " " + item->text(0);
1046 cout << "1. Script : " << script << endl;
1048 if ( system( script ) ) {
1049 QMessageBox::warning( this,
1051 tr( QString("You don't have native %1 %2 installed").arg(item->text(0)).arg(item->text(1)) ),
1053 QMessageBox::NoButton,
1054 QMessageBox::NoButton );
1055 productsView->setNone( item );
1060 QMessageBox::warning( this,
1062 tr( QString("%The product %1 %2 required for installation.\n"
1063 "Please, add this product in config.xml file.").arg(item->text(0)).arg(item->text(1)) ),
1065 QMessageBox::NoButton,
1066 QMessageBox::NoButton );
1071 return InstallWizard::acceptData( pageTitle );
1074 Calculates disk space required for the installation
1076 void SALOME_InstallWizard::checkSize( long* totSize, long* tempSize )
1078 long tots = 0, temps = 0;
1081 MapProducts::Iterator mapIter;
1082 for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) {
1083 QCheckListItem* item = mapIter.key();
1084 Dependancies dep = mapIter.data();
1085 if ( productsView->isBinaries( item ) ) {
1086 tots += dep.getSize();
1088 else if ( productsView->isSources( item ) ) {
1089 tots += dep.getSize(true);
1090 temps = max( temps, dep.getTempSize() );
1092 else if ( productsView->isNative( item ) ) {
1097 requiredSize->setText( QString::number( tots ) + " Kb");
1098 requiredTemp->setText( QString::number( temps ) + " Kb");
1103 setNextEnabled( productsPage, (tots > 0) || (nativeProd > 0));
1106 Enabled/disables "Next" button for the directory page
1108 void SALOME_InstallWizard::checkDirs()
1110 // VSR: Temporary folder is used always now and it is not necessary to disable it -->
1111 // get disk space required
1112 //long totSize, tempSize;
1113 //checkSize( &totSize, &tempSize );
1114 // enable/disable temp directory controls
1115 // tempFolder->setEnabled( tempSize > 0 );
1116 // tempBtn->setEnabled( tempSize > 0 );
1117 // VSR: <----------------------------------------------------------------------------
1119 QString targetDir = targetFolder->text().stripWhiteSpace();
1120 // enable/disable "Next" button
1121 setNextEnabled( productsPage, !targetDir.isEmpty() );
1124 Sets the product and all products this one depends on to be checked ( recursively )
1126 void SALOME_InstallWizard::setProductOn( QCheckListItem* item, int install )
1128 if ( !productsMap.contains( item ) )
1130 if ( productsView->isNone( item ) ) {
1132 productsView->setBinaries( item );
1133 else if ( install == 0 )
1134 productsView->setSources( item );
1135 else if ( install == 2 )
1136 productsView->setNative( item );
1138 // get all prerequisites
1139 QStringList dependOn = productsMap[ item ].getDependancies();
1140 for ( int i = 0; i < (int)dependOn.count(); i++ ) {
1141 MapProducts::Iterator itProd;
1142 for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) {
1143 if ( itProd.data().getName() == dependOn[ i ] )
1144 setProductOn( itProd.key(), 1 );
1149 Runs installation script
1151 void SALOME_InstallWizard::launchScript()
1153 // try to find product being processed now
1154 QString prodProc = progressView->findStatus( Processing );
1155 if ( !prodProc.isNull() ) {
1157 cout << "Found <Processing>: " << prodProc.latin1() << endl;
1160 // if found - set status to "completed"
1161 progressView->setStatus( prodProc, Completed );
1162 // ... and call this method again
1166 // else try to find next product which is not processed yet
1167 prodProc = progressView->findStatus( Waiting );
1168 if ( !prodProc.isNull() ) {
1170 cout << "Found <Waiting>: " << prodProc.latin1() << endl;
1172 // if found - set status to "processed" and run script
1173 progressView->setStatus( prodProc, Processing );
1174 progressView->ensureVisible( prodProc );
1176 QCheckListItem* item = findItem( prodProc );
1177 Dependancies dep = productsMap[ item ];
1178 // fill in script parameters
1179 shellProcess->clearArguments();
1181 shellProcess->setWorkingDirectory( QDir::cleanDirPath( QFileInfo( "./config_files/" ).absFilePath() ) );
1182 shellProcess->addArgument( item->text(2) );
1185 QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1186 if( !tempFolder->isEnabled() )
1190 if ( productsView->isBinaries( item ) ) {
1191 shellProcess->addArgument( "install_binary" );
1192 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1193 QString binDir = QDir::currentDirPath() + "/Products/BINARIES";
1194 if ( !myOS.isEmpty() )
1195 binDir += "/" + myOS;
1196 shellProcess->addArgument( binDir );
1199 else if ( productsView->isSources( item ) ) {
1200 shellProcess->addArgument( "install_source" );
1201 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1202 shellProcess->addArgument( QDir::currentDirPath() + "/Products/SOURCES" );
1205 else if ( productsView->isNative( item ) ) {
1206 shellProcess->addArgument( "try_native" );
1207 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1208 shellProcess->addArgument( QDir::currentDirPath() + "/Products" );
1210 // ... not install : try to find preinstalled
1212 shellProcess->addArgument( "try_preinstalled" );
1213 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1214 shellProcess->addArgument( QDir::currentDirPath() + "/Products" );
1216 // ... target folder
1217 QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
1218 shellProcess->addArgument( QFileInfo( tgtFolder ).absFilePath() );
1221 QString depproducts = DefineDependeces(productsMap);
1223 cout << "Dependancies"<< depproducts.latin1() << endl;
1226 shellProcess->addArgument( depproducts );
1227 // ... product name - currently instaled product
1228 shellProcess->addArgument( item->text(0) );
1231 if ( !shellProcess->start() ) {
1232 // error handling can be here
1234 cout << "error" << endl;
1240 cout << "All products have been installed successfully" << endl;
1242 // all products installed successfully
1244 nextButton()->setEnabled( true );
1245 nextButton()->setText( tr( "&Next >" ) );
1246 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1247 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1248 nextButton()->disconnect();
1249 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1251 backButton()->setEnabled( true );
1252 // script parameters
1253 passedParams->clear();
1254 passedParams->setEnabled( false );
1255 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1256 if ( isMinimized() )
1261 <More...> button slot
1263 void SALOME_InstallWizard::onMoreBtn()
1267 moreBtn->setText( tr( "More..." ) );
1271 moreBtn->setText( tr( "Less..." ) );
1273 qApp->processEvents();
1274 moreMode = !moreMode;
1275 InstallWizard::layOut();
1276 qApp->processEvents();
1277 if ( !isMaximized() ) {
1278 //setGeometry( geometry().x(), geometry().y(), geometry().width(), 0 );
1279 resize( geometry().width(), 0 );
1280 qApp->processEvents();
1284 <Launch Salome> button slot
1286 void SALOME_InstallWizard::onLaunchSalome()
1288 QCheckListItem* item = 0;
1289 if ( ( item = findItem("SalomePro-Bin" ) ) ) {
1290 QFileInfo fi( targetFolder->text() + "/SalomePro-" + item->text(1) + "/salome" );
1291 if ( fi.exists() ) {
1293 script += "cd " + targetFolder->text() + "/SalomePro-" + item->text(1) + "; ";
1294 script += "source salome.csh; ";
1295 //script += "cd bin; ";
1296 //script += "runSalome > /dev/null";
1297 script += "salome -g > /dev/null";
1298 script = "(csh -c '" + script + "')";
1300 cout << script.latin1() << endl;
1302 if ( system( script.latin1() ) ){
1303 QMessageBox::warning( this,
1305 tr( "Can't launch SALOME" ),
1307 QMessageBox::NoButton,
1308 QMessageBox::NoButton );
1313 QMessageBox::warning( this,
1315 tr( "You don't have SALOME binaries installed in the %1 directory!" ).arg( targetFolder->text() ),
1317 QMessageBox::NoButton,
1318 QMessageBox::NoButton );
1321 Searches product listview item with given symbolic name
1323 QCheckListItem* SALOME_InstallWizard::findItem( const QString& sName )
1325 MapProducts::Iterator mapIter;
1326 for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) {
1327 if ( mapIter.data().getName() == sName )
1328 return mapIter.key();
1333 Sets progress state to Aborted
1335 void SALOME_InstallWizard::abort()
1337 QString prod = progressView->findStatus( Processing );
1338 while ( !prod.isNull() ) {
1339 progressView->setStatus( prod, Aborted );
1340 prod = progressView->findStatus( Processing );
1342 prod = progressView->findStatus( Waiting );
1343 while ( !prod.isNull() ) {
1344 progressView->setStatus( prod, Aborted );
1345 prod = progressView->findStatus( Waiting );
1349 Reject slot, clears temporary directory and closes application
1351 void SALOME_InstallWizard::reject()
1354 cout << "REJECTED" << endl;
1356 if ( !exitConfirmed ) {
1357 if ( QMessageBox::information( this,
1359 tr( "Do you want to quit Installation Wizard?" ),
1367 exitConfirmed = true;
1370 InstallWizard::reject();
1373 Accept slot, clears temporary directory and closes application
1375 void SALOME_InstallWizard::accept()
1378 cout << "ACCEPTED" << endl;
1381 InstallWizard::accept();
1384 Clears and removes temporary directory
1386 void SALOME_InstallWizard::clean()
1388 // VSR: first remove temporary files
1389 QString script = "cd ./config_files/; remove_tmp.sh '";
1390 script += tempFolder->text().stripWhiteSpace();
1392 script += QUOTE(DefineDependeces(productsMap));
1393 script += " > /dev/null";
1395 cout << "script = " << script << endl;
1397 if ( system( script.latin1() ) ) {
1399 // VSR: then try to remove created temporary directory
1400 //script = "rm -rf " + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1401 if ( !tmpCreated.isNull() ) {
1402 script = "rm -rf " + tmpCreated;
1403 script += " > /dev/null";
1404 if ( system( script.latin1() ) ) {
1407 cout << "script = " << script << endl;
1412 Called when user moves from page to page
1414 void SALOME_InstallWizard::pageChanged( const QString & mytitle)
1416 nextButton()->setText( tr( "&Next >" ) );
1417 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1418 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1419 nextButton()->disconnect();
1420 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1421 cancelButton()->disconnect();
1422 connect( cancelButton(), SIGNAL( clicked()), this, SLOT( reject() ) );
1424 QWidget* aPage = InstallWizard::page( mytitle );
1427 setCaption( tr( myCaption ) + tr( " - Step ") +
1428 QString::number( this->indexOf( aPage )+1 ) +
1430 QString::number( this->pageCount() ) );
1431 if ( aPage == productsPage ) {
1436 else if ( aPage == prestartPage ) {
1440 else if ( aPage == progressPage ) {
1441 if ( previousPage == prestartPage ) {
1443 progressView->clear();
1444 installInfo->clear();
1445 passedParams->clear();
1446 passedParams->setEnabled( false );
1447 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1448 nextButton()->setText( tr("&Start") );
1449 QWhatsThis::add( nextButton(), tr( "Starts installation process" ) );
1450 QToolTip::add ( nextButton(), tr( "Starts installation process" ) );
1451 // reconnect Next button - to use it as Start button
1452 nextButton()->disconnect();
1453 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( onStart() ) );
1454 nextButton()->setEnabled( true );
1455 // reconnect Cancel button to terminate process
1456 cancelButton()->disconnect();
1457 connect( cancelButton(), SIGNAL( clicked() ), this, SLOT( tryTerminate() ) );
1460 else if ( aPage == readmePage ) {
1461 QCheckListItem* item = 0;
1462 runSalomeBtn->setEnabled( ( item = findItem( "SalomePro-Bin" ) ) &&
1463 QFileInfo( targetFolder->text() + "/SalomePro-" + item->text(1) + "/salome" ).exists() );
1464 finishButton()->setEnabled( true );
1466 previousPage = aPage;
1468 cout << "previousPage = " << previousPage << endl;
1474 void SALOME_InstallWizard::helpClicked()
1476 if ( helpWindow == NULL ) {
1477 helpWindow = HelpWindow::openHelp();
1480 helpWindow->installEventFilter( this );
1483 QMessageBox::warning( this,
1484 tr( "Help file not found" ),
1485 tr( "Sorry, help is unavailable" ) );
1489 helpWindow->raise();
1490 helpWindow->setActiveWindow();
1494 Shows directory selection dialog
1496 void SALOME_InstallWizard::browseDirectory()
1498 const QObject* theSender = sender();
1499 QLineEdit* theFolder;
1500 if ( theSender == targetBtn )
1501 theFolder = targetFolder;
1502 else if (theSender == tempBtn)
1503 theFolder = tempFolder;
1506 QString typedDir = QFileDialog::getExistingDirectory( QDir::cleanDirPath( theFolder->text().stripWhiteSpace() ), this );
1507 if ( !typedDir.isNull() ) {
1508 theFolder->setText( typedDir );
1509 theFolder->end( false );
1514 Called when directory path (target or temp) is changed
1516 void SALOME_InstallWizard::directoryChanged( const QString& /*text*/ )
1521 <Start> button's slot - runs installation
1523 void SALOME_InstallWizard::onStart()
1525 // clear list of products to install ...
1527 // ... and fill it for new process
1528 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
1530 // if ( productsView->isBinaries( item ) || productsView->isSources( item ) || productsView->isNative( item ) ) {
1531 if ( productsMap.contains( item ) )
1532 toInstall.append( productsMap[item].getName() );
1534 item = (QCheckListItem*)( item->nextSibling() );
1536 // if something at all is selected
1537 if ( !toInstall.isEmpty() ) {
1538 // disable <Next> button
1539 nextButton()->setEnabled( false );
1540 // disable <Back> button
1541 backButton()->setEnabled ( false );
1542 // enable script parameters line edit
1543 // VSR commented: 18/09/03: passedParams->setEnabled( true );
1544 // VSR commented: 18/09/03: passedParams->setFocus();
1545 // set status for all products
1546 for ( int i = 0; i < (int)toInstall.count(); i++ ) {
1547 item = findItem( toInstall[ i ] );
1549 if ( productsView->isBinaries( item ) )
1551 else if ( productsView->isSources( item ) )
1553 else if ( productsView->isNative( item ) )
1556 type = "not install";
1557 progressView->addProduct( item->text(0), type, item->text(2) );
1559 // launch install script
1564 Called when users tries to pass parameters for the script
1566 void SALOME_InstallWizard::onReturnPressed()
1568 QString txt = passedParams->text();
1569 installInfo->append( txt );
1571 shellProcess->writeToStdin( txt );
1572 passedParams->clear();
1573 progressView->setFocus();
1574 passedParams->setEnabled( false );
1575 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1578 Callback function - as response for the script finishing
1580 void SALOME_InstallWizard::productInstalled( )
1583 cout << "process exited" << endl;
1585 if ( shellProcess->normalExit() ) {
1587 cout << "...normal exit" << endl;
1589 // normal exit - try to proceed installation further
1594 cout << "...abnormal exit" << endl;
1596 // installation aborted
1598 // clear script passed parameters lineedit
1599 passedParams->clear();
1600 passedParams->setEnabled( false );
1601 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1602 // enable <Next> button
1603 nextButton()->setEnabled( true );
1604 nextButton()->setText( tr( "&Next >" ) );
1605 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1606 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1607 nextButton()->disconnect();
1608 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1609 // enable <Back> button
1610 backButton()->setEnabled( true );
1614 Slot, called when <Cancel> button is clicked during installation script running
1616 void SALOME_InstallWizard::tryTerminate()
1618 if ( shellProcess->isRunning() ) {
1619 if ( QMessageBox::information( this,
1621 tr( "Do you want to quit Installation Wizard?" ),
1629 exitConfirmed = true;
1630 // if process still running try to terminate it first
1631 shellProcess->tryTerminate();
1633 //QTimer::singleShot( 3000, this, SLOT( onCancel() ) );
1634 connect( shellProcess, SIGNAL( processExited() ), this, SLOT( onCancel() ) );
1637 // else just quit install wizard
1642 Kills installation process and quits application
1644 void SALOME_InstallWizard::onCancel()
1646 shellProcess->kill();
1650 Called when selection is changed in the products list view
1652 void SALOME_InstallWizard::onSelectionChanged( QListViewItem* item )
1654 productsInfo->clear();
1655 if ( item->parent() )
1656 item = item->parent();
1657 QCheckListItem* aItem = (QCheckListItem*)item;
1658 if ( !productsMap.contains( aItem ) )
1660 Dependancies dep = productsMap[ aItem ];
1661 QString text = "<b>" + aItem->text(0) + "</b>";
1663 if ( !aItem->text(1).stripWhiteSpace().isEmpty() )
1664 text += "version: " + aItem->text(1) + "<br>";
1665 if ( productsView->isBinaries( aItem ) )
1666 text += "Disk space required: " + QString::number( dep.getSize() ) + " Kb";
1668 text += "Disk space required: " + QString::number( dep.getSize(true) ) + " Kb";
1671 text += "Disk space for tmp files required: " + QString::number( dep.getTempSize() ) + " Kb";
1673 QString req =( dep.getDependancies().count() > 0 ? dep.getDependancies().join(", ") : QString( "none" ) );
1674 // if ( item->depth() == 0 && item->childCount() == 0 ) {
1675 // if ( dep.getName() == "salomedoc" )
1676 // req = "none"; // SALOME docs
1678 // req = "all products"; // SALOME sources and binaries
1680 text += "Prerequisites: " + req;
1681 productsInfo->setText( text );
1684 Called when user checks/unchecks any product item
1685 Recursively sets all prerequisites and updates "Next" button state
1687 void SALOME_InstallWizard::onItemToggled( QCheckListItem* item )
1689 if ( prerequisites->isChecked() ) {
1690 if ( item->parent() )
1691 item = (QCheckListItem*)( item->parent() );
1692 if ( productsMap.contains( item ) ) {
1693 productsView->blockSignals( true );
1694 if ( productsView->isNative( item ) )
1695 setProductOn( item, 2 );
1696 else if ( productsView->isBinaries( item ) )
1697 setProductOn( item, 1 );
1698 else if ( productsView->isSources( item ) )
1699 setProductOn( item, 0 );
1700 productsView->blockSignals( false );
1706 This slot is called when user clicks one of <Select Sources>,
1707 <Select Binaries>, <Unselect All> buttons ( products page )
1709 void SALOME_InstallWizard::onProdBtn()
1711 const QObject* snd = sender();
1712 productsView->blockSignals( true );
1713 if ( snd == unselectBtn ) {
1714 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
1716 productsView->setNone( item );
1717 item = (QCheckListItem*)( item->nextSibling() );
1720 productsView->blockSignals( false );
1724 QProcess slot: -->something was written to stdin
1726 void SALOME_InstallWizard::wroteToStdin( )
1729 cout << "Something was sent to stdin" << endl;
1733 QProcess slot: -->something was written to stdout
1735 void SALOME_InstallWizard::readFromStdout( )
1738 cout << "Something was sent to stdout" << endl;
1740 while ( shellProcess->canReadLineStdout() ) {
1741 installInfo->append( QString( shellProcess->readLineStdout() ) );
1742 installInfo->scrollToBottom();
1744 QString str( shellProcess->readStdout() );
1745 if ( !str.isEmpty() ) {
1746 installInfo->append( str );
1747 installInfo->scrollToBottom();
1751 QProcess slot: -->something was written to stderr
1753 void SALOME_InstallWizard::readFromStderr( )
1756 cout << "Something was sent to stderr" << endl;
1758 while ( shellProcess->canReadLineStderr() ) {
1759 installInfo->append( QString( shellProcess->readLineStderr() ) );
1760 installInfo->scrollToBottom();
1762 QString str( shellProcess->readStderr() );
1763 if ( !str.isEmpty() ) {
1764 installInfo->append( str );
1765 installInfo->scrollToBottom();
1767 passedParams->setEnabled( true );
1768 passedParams->setFocus();
1769 QFont f = parametersLab->font(); f.setBold( true ); parametersLab->setFont( f );
1772 Sets dependancies for the product item
1774 void SALOME_InstallWizard::setDependancies( QCheckListItem* item, Dependancies dep)
1776 productsMap[item] = dep;
1779 Polishing of the widget - to set right initial size
1781 void SALOME_InstallWizard::polish()
1784 InstallWizard::polish();
1787 // ###################################### Structure Parser ###########################################
1792 StructureParser::StructureParser()
1793 : QXmlDefaultHandler()
1799 Sets install wizard's main window
1801 void StructureParser::setWizard( SALOME_InstallWizard* awizard )
1806 Sets products list view
1808 void StructureParser::setListView( MyListView * t )
1813 Sets temp directory widget
1815 void StructureParser::setTempDir( QLineEdit * dir )
1820 Sets target directory widget
1822 void StructureParser::setTargetDir( QLineEdit * dir )
1827 Begins parsing of the xml dom-element
1829 bool StructureParser::startElement( const QString& ,
1831 const QString& qName,
1832 const QXmlAttributes& attributes)
1835 cout << qName << endl;
1836 cout << attributes.length() << endl;
1838 QCheckListItem * element;
1839 if (( qName == "config" ) && ( attributes.length() > 0 ) ) {
1840 if ( attributes.value( "version" ) )
1841 myVersion = attributes.value( "version" ).stripWhiteSpace();
1842 if ( attributes.value( "caption" ) && !myCaption.isEmpty() )
1843 myCaption = QString(attributes.value( "caption" )).arg(myVersion).stripWhiteSpace();
1844 if ( attributes.value( "copyright" ) )
1845 myCopyright = attributes.value( "copyright" ).stripWhiteSpace();
1846 if ( attributes.value( "license" ) )
1847 myLicense = attributes.value( "license" ).stripWhiteSpace();
1848 if ( attributes.value( "os" ) )
1849 myOS = attributes.value( "os" ).stripWhiteSpace();
1852 cout << myCaption << endl;
1853 cout << myVersion << endl;
1854 cout << myCopyright << endl;
1855 cout << myLicense << endl;
1857 } else if (( qName == "product" ) && ( attributes.length() > 0 ) && tree && wizard ) {
1858 if (attributes.value("disable") == "true" )
1861 QString install = attributes.value( "install" );
1862 QStringList supported = QStringList::split(",", attributes.value("supported") );
1863 QString script = attributes.value( "script" );
1864 element = tree->addItem( attributes.value("name"), attributes.value("version"), install, supported, script );
1865 if ( attributes.value("dependancies") == "" ) {
1866 QStringList diskspace = QStringList::split(",",attributes.value("installdiskspace"));
1867 if (diskspace.count() == 2)
1868 wizard->setDependancies( element,
1869 Dependancies( attributes.value("name"), QStringList(),
1870 diskspace[0].toInt(),
1871 diskspace[1].toInt(),
1872 attributes.value("temporarydiskspace").toInt()) );
1874 wizard->setDependancies( element,
1875 Dependancies( attributes.value("name"), QStringList(),
1876 diskspace[0].toInt(),
1877 diskspace[0].toInt(),
1878 attributes.value("temporarydiskspace").toInt()) );
1881 QStringList diskspace = QStringList::split(",",attributes.value("installdiskspace"));
1882 if (diskspace.count() == 2)
1883 wizard->setDependancies( element,
1884 Dependancies( attributes.value("name"),
1885 QStringList::split(",", attributes.value("dependancies") ),
1886 diskspace[0].toInt(),
1887 diskspace[1].toInt(),
1888 attributes.value("temporarydiskspace").toInt()) );
1890 wizard->setDependancies( element,
1891 Dependancies( attributes.value("name"),
1892 QStringList::split(",", attributes.value("dependancies") ),
1893 diskspace[0].toInt(),
1894 diskspace[0].toInt(),
1895 attributes.value("temporarydiskspace").toInt()) );
1897 } else if (( qName == "path" ) && ( attributes.length() > 0 ) && wizard ) {
1898 targetdir->setText( attributes.value("targetdir") );
1900 if ( attributes.value("tempdir") == "" )
1901 tempdir->setText( "/tmp" );
1903 tempdir->setText( attributes.value("tempdir") );
1908 Finishes parsing of the xml dom-element
1910 bool StructureParser::endElement( const QString&, const QString&,
1916 // ###################################### Main ###########################################
1921 int main( int argc, char **argv )
1923 QApplication a( argc, argv );
1924 QString xmlFileName( argc == 2 ? argv[1] : "config.xml" );
1927 QFile xmlfile(xmlFileName);
1928 if ( xmlfile.exists() ) {
1929 SALOME_InstallWizard wizard(xmlFileName);
1930 a.setMainWidget( &wizard );
1935 QMessageBox::critical( 0,
1936 QObject::tr( "Error" ),
1937 QObject::tr( "Can't open config file:\n%1\n\nQuitting...").arg( xmlFileName ),
1939 QMessageBox::NoButton,
1940 QMessageBox::NoButton );