1 // File : SALOME_InstallWizard.cxx
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER
5 // Module : Installation Wizard
6 // Copyright : 2004-2005 CEA
10 #include "SALOME_InstallWizard.hxx"
11 #include "SALOME_ProductsView.hxx"
12 #include "SALOME_ProgressView.hxx"
13 #include "SALOME_XmlHandler.hxx"
14 #include "SALOME_HelpWindow.hxx"
18 #include <qlineedit.h>
19 #include <qpushbutton.h>
20 #include <qlistview.h>
22 #include <qtextedit.h>
23 #include <qtextbrowser.h>
25 #include <qcheckbox.h>
26 #include <qsplitter.h>
28 #include <qfiledialog.h>
29 #include <qapplication.h>
30 #include <qfileinfo.h>
31 #include <qmessagebox.h>
34 #include <qwhatsthis.h>
38 #include <qwaitcondition.h>
50 #define max( x, y ) ( x ) > ( y ) ? ( x ) : ( y )
53 QString tmpDirName() { return QString( "/INSTALLWORK" ) + QString::number( getpid() ); }
54 #define TEMPDIRNAME tmpDirName()
56 // ================================================================
59 * Class for executing systen commands
61 // ================================================================
62 static QMutex myMutex(false);
63 static QWaitCondition myWC;
64 class QProcessThread: public QThread
66 typedef QPtrList<QCheckListItem> ItemList;
68 QProcessThread( SALOME_InstallWizard* iw ) : QThread(), myWizard( iw ) { myItems.setAutoDelete( false ); }
70 void addCommand( QCheckListItem* item, const QString& cmd ) {
71 myItems.append( item );
72 myCommands.push_back( cmd );
75 bool hasCommands() const { return myCommands.count() > 0; }
76 void clearCommands() { myCommands.clear(); myItems.clear(); }
79 while ( hasCommands() ) {
80 ___MESSAGE___( "QProcessThread::run - Processing command : " << myCommands[ 0 ].latin1() );
81 int result = system( myCommands[ 0 ] ) / 256; // return code is <errno> * 256
82 ___MESSAGE___( "QProcessThread::run - Result : " << result );
83 QCheckListItem* item = myItems.first();
84 myCommands.pop_front();
85 myItems.removeFirst();
87 SALOME_InstallWizard::postValidateEvent( myWizard, result, (void*)item );
95 QStringList myCommands;
97 SALOME_InstallWizard* myWizard;
100 // ================================================================
105 // ================================================================
106 class WarnDialog: public QDialog
108 static WarnDialog* myDlg;
111 WarnDialog( QWidget* parent )
112 : QDialog( parent, "WarnDialog", true, WDestructiveClose ) {
113 setCaption( tr( "Information" ) );
115 QLabel* lab = new QLabel( tr( "Please, wait while checking native products configuration ..." ), this );
116 lab->setAlignment( AlignCenter );
117 lab->setFrameStyle( QFrame::Box | QFrame::Plain );
118 QVBoxLayout* l = new QVBoxLayout( this );
121 this->setFixedSize( lab->sizeHint().width() + 50,
122 lab->sizeHint().height() * 5 );
124 void accept() { return; }
125 void reject() { return; }
126 void closeEvent( QCloseEvent* e) { if ( !myCloseFlag ) return; QDialog::closeEvent( e ); }
128 ~WarnDialog() { myDlg = 0; }
130 static void showWarnDlg( QWidget* parent, bool show ) {
133 myDlg = new WarnDialog( parent );
134 QSize sh = myDlg->size();
135 myDlg->move( parent->x() + (parent->width()-sh.width())/2,
136 parent->y() + (parent->height()-sh.height())/2 );
144 myDlg->myCloseFlag = true;
149 static bool isWarnDlgShown() { return myDlg != 0; }
151 WarnDialog* WarnDialog::myDlg = 0;
153 // ================================================================
155 * DefineDependeces [ static ]
156 * Defines list of dependancies as string separated by space symbols
158 // ================================================================
159 static QString DefineDependeces(MapProducts& theProductsMap)
161 QStringList aProducts;
162 for ( MapProducts::Iterator mapIter = theProductsMap.begin(); mapIter != theProductsMap.end(); ++mapIter ) {
163 QCheckListItem* item = mapIter.key();
164 Dependancies dep = mapIter.data();
165 QStringList deps = dep.getDependancies();
166 for (int i = 0; i<(int)deps.count(); i++ ) {
167 if ( !aProducts.contains( deps[i] ) )
168 aProducts.append( deps[i] );
170 if ( !aProducts.contains( item->text(0) ) )
171 aProducts.append( item->text(0) );
173 return aProducts.join(" ");
176 #define QUOTE(arg) QString("'") + QString(arg) + QString("'")
178 /* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
179 T H E O L D I M P L E M E N T A T I O N
180 static QString DefineDependeces(MapProducts& theProductsMap, QCheckListItem* product ){
181 QStringList aProducts;
182 if ( theProductsMap.contains( product ) ) {
183 Dependancies dep = theProductsMap[ product ];
184 QStringList deps = dep.getDependancies();
185 for (int i = 0; i<(int)deps.count(); i++ ) {
186 aProducts.append( deps[i] );
189 return QString("\"") + aProducts.join(" ") + QString("\"");
191 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
193 // ================================================================
196 * Makes directory recursively, returns false if not succedes
198 // ================================================================
199 static bool makeDir( const QString& theDir, QString& theCreated )
201 if ( theDir.isEmpty() )
203 QString aDir = QDir::cleanDirPath( QFileInfo( theDir ).absFilePath() );
205 while ( start > 0 ) {
206 start = aDir.find( QDir::separator(), start );
208 QFileInfo fi( aDir.left( start ) );
209 if ( !fi.exists() ) {
210 // VSR: Create directory and set permissions to allow other users to remove it
211 QString script = "mkdir " + fi.absFilePath();
212 script += "; chmod 777 " + fi.absFilePath();
213 script += " > /dev/null";
214 if ( system( script.latin1() ) )
216 // VSR: Remember the top of the created directory (to remove it in the end of the installation)
217 if ( theCreated.isNull() )
218 theCreated = fi.absFilePath();
223 if ( !QFileInfo( aDir ).exists() ) {
224 // VSR: Create directory, other users should NOT have possibility to remove it!!!
225 QString script = "mkdir " + aDir;
226 script += " > /dev/null";
227 if ( system( script.latin1() ) )
229 // VSR: Remember the top of the created directory (to remove it in the end of the installation)
230 if ( theCreated.isNull() )
235 // ================================================================
237 * readFile [ static ]
238 * Reads the file, returns false if can't open it
240 // ================================================================
241 static bool readFile( const QString& fileName, QString& text )
243 if ( QFile::exists( fileName ) ) {
244 QFile file( fileName );
245 if ( file.open( IO_ReadOnly ) ) {
246 QTextStream stream( &file );
248 while ( !stream.eof() ) {
249 line = stream.readLine(); // line of text excluding '\n'
258 // ================================================================
260 * hasSpace [ static ]
261 * Checks if string contains spaces; used to check directory paths
263 // ================================================================
264 static bool hasSpace( const QString& dir )
266 for ( int i = 0; i < (int)dir.length(); i++ ) {
267 if ( dir[ i ].isSpace() )
273 // ================================================================
275 * SALOME_InstallWizard::SALOME_InstallWizard
278 // ================================================================
279 SALOME_InstallWizard::SALOME_InstallWizard(QString aXmlFileName)
280 : InstallWizard( qApp->desktop(), "SALOME_InstallWizard", false, 0 ),
284 exitConfirmed( false )
286 myIWName = tr( "Installation Wizard" );
287 tmpCreated = QString::null;
288 xmlFileName = aXmlFileName;
289 QFont fnt = font(); fnt.setPointSize( 14 ); fnt.setBold( true );
293 setIcon( QPixmap( ( const char** ) image0_data ) );
295 setSizeGripEnabled( true );
298 addLogo( QPixmap( (const char**)image1_data ) );
302 setCaption( tr( "PAL/SALOME %1" ).arg( myVersion ) );
303 setCopyright( tr( "Copyright (C) 2004 CEA" ) );
304 setLicense( tr( "All right reserved" ) );
307 ___MESSAGE___( "Config. file : " << xmlFileName );
310 QFile xmlfile(xmlFileName);
311 if ( xmlfile.exists() ) {
312 QXmlInputSource source( &xmlfile );
313 QXmlSimpleReader reader;
315 StructureParser* handler = new StructureParser( this );
316 reader.setContentHandler( handler );
317 reader.parse( source );
320 // create instance of class for starting shell install script
321 shellProcess = new QProcess( this, "shellProcess" );
323 // create introduction page
325 // create products page
327 // create prestart page
329 // create progress page
331 // create readme page
335 QWhatsThis::add( backButton(), tr( "Returns to the previous step of the installation procedure" ) );
336 QToolTip::add ( backButton(), tr( "Returns to the previous step of the installation procedure" ) );
337 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
338 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
339 QWhatsThis::add( finishButton(), tr( "Finishes installation and quits program" ) );
340 QToolTip::add ( finishButton(), tr( "Finishes installation and quits program" ) );
341 QWhatsThis::add( cancelButton(), tr( "Cancels installation and quits program" ) );
342 QToolTip::add ( cancelButton(), tr( "Cancels installation and quits program" ) );
343 QWhatsThis::add( helpButton(), tr( "Displays help information window" ) );
344 QToolTip::add ( helpButton(), tr( "Displays help information window" ) );
346 // common signals connections
347 connect( this, SIGNAL( selected( const QString& ) ),
348 this, SLOT( pageChanged( const QString& ) ) );
349 connect( this, SIGNAL( helpClicked() ), this, SLOT( helpClicked() ) );
350 // catch signals from launched script
351 connect(shellProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) );
352 connect(shellProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) );
353 connect(shellProcess, SIGNAL( processExited() ), this, SLOT( productInstalled() ) );
354 connect(shellProcess, SIGNAL( wroteToStdin() ), this, SLOT( wroteToStdin() ) );
356 // create validation thread
357 myThread = new QProcessThread( this );
359 // ================================================================
361 * SALOME_InstallWizard::~SALOME_InstallWizard
364 // ================================================================
365 SALOME_InstallWizard::~SALOME_InstallWizard()
367 shellProcess->kill(); // kill it for sure
368 QString script = "kill -9 ";
369 int PID = (int)shellProcess->processIdentifier();
371 script += QString::number( PID );
372 script += " > /dev/null";
373 ___MESSAGE___( "script: " << script.latin1() );
374 if ( system( script.latin1() ) ) {
379 // ================================================================
381 * SALOME_InstallWizard::eventFilter
382 * Event filter, spies for Help window closing
384 // ================================================================
385 bool SALOME_InstallWizard::eventFilter( QObject* object, QEvent* event )
387 if ( object && object == helpWindow && event->type() == QEvent::Close )
389 return InstallWizard::eventFilter( object, event );
391 // ================================================================
393 * SALOME_InstallWizard::closeEvent
394 * Close event handler
396 // ================================================================
397 void SALOME_InstallWizard::closeEvent( QCloseEvent* ce )
399 if ( WarnDialog::isWarnDlgShown() ) {
403 if ( !exitConfirmed ) {
404 if ( QMessageBox::information( this,
406 tr( "Do you want to quit %1?" ).arg( getIWName() ),
416 exitConfirmed = true;
421 // ================================================================
423 * SALOME_InstallWizard::setupIntroPage
424 * Creates introduction page
426 // ================================================================
427 void SALOME_InstallWizard::setupIntroPage()
430 introPage = new QWidget( this, "IntroPage" );
431 QGridLayout* pageLayout = new QGridLayout( introPage );
432 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
433 // create logo picture
434 QPixmap logo( (const char**)SALOME_Logo_xpm );
435 logoLab = new QLabel( introPage );
436 logoLab->setPixmap( logo );
437 logoLab->setScaledContents( false );
438 logoLab->setFrameStyle( QLabel::Plain | QLabel::Box );
439 logoLab->setAlignment( AlignCenter );
440 // create version box
441 QVBox* versionBox = new QVBox( introPage ); versionBox->setSpacing( 6 );
442 versionBox->setFrameStyle( QVBox::Panel | QVBox::Sunken );
443 QWidget* stretch1 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch1, 5 );
444 versionLab = new QLabel( QString("%1 %2").arg( tr( "Version" ) ).arg(myVersion), versionBox );
445 versionLab->setAlignment( AlignCenter );
446 copyrightLab = new QLabel( myCopyright, versionBox );
447 copyrightLab->setAlignment( AlignCenter );
448 licenseLab = new QLabel( myLicense, versionBox );
449 licenseLab->setAlignment( AlignCenter );
450 QWidget* stretch2 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch2, 5 );
452 info = new QLabel( introPage );
453 info->setText( tr( "This program will install <b>%1</b>."
454 "<br><br>The wizard will also help you to install all products "
455 "which are necessary for <b>%2</b> and setup "
456 "your environment.<br><br>Click <code>Cancel</code> button to abort "
457 "installation and quit. Click <code>Next</code> button to continue with the "
458 "installation program." ).arg( myCaption ).arg( myCaption ) );
459 info->setFrameStyle( QLabel::WinPanel | QLabel::Sunken );
460 info->setMargin( 6 );
461 info->setAlignment( WordBreak );
462 info->setMinimumWidth( 250 );
463 QPalette pal = info->palette();
464 pal.setColor( QColorGroup::Background, QApplication::palette().active().base() );
465 info->setPalette( pal );
466 info->setLineWidth( 2 );
468 pageLayout->addWidget( logoLab, 0, 0 );
469 pageLayout->addWidget( versionBox, 1, 0 );
470 pageLayout->addMultiCellWidget( info, 0, 1, 1, 1 );
471 pageLayout->setColStretch( 1, 5 );
472 pageLayout->setRowStretch( 1, 5 );
474 addPage( introPage, tr( "Introduction" ) );
476 // ================================================================
478 * SALOME_InstallWizard::setupProductsPage
479 * Creates products page
481 // ================================================================
482 void SALOME_InstallWizard::setupProductsPage()
485 productsPage = new QWidget( this, "ProductsPage" );
486 QGridLayout* pageLayout = new QGridLayout( productsPage );
487 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
489 QLabel* targetLab = new QLabel( tr( "Type the target directory:" ), productsPage );
490 targetFolder = new QLineEdit( productsPage );
491 QWhatsThis::add( targetFolder, tr( "Enter target root directory where products will be installed" ) );
492 QToolTip::add ( targetFolder, tr( "Enter target root directory where products will be installed" ) );
493 targetBtn = new QPushButton( tr( "Browse..." ), productsPage );
494 QWhatsThis::add( targetBtn, tr( "Click this to browse target directory" ) );
495 QToolTip::add ( targetBtn, tr( "Click this to browse target directory" ) );
496 // create advanced mode widgets container
497 moreBox = new QWidget( productsPage );
498 QGridLayout* moreBoxLayout = new QGridLayout( moreBox );
499 moreBoxLayout->setMargin( 0 ); moreBoxLayout->setSpacing( 6 );
501 QLabel* tempLab = new QLabel( tr( "Type the directory for the temporary files:" ), moreBox );
502 tempFolder = new QLineEdit( moreBox );
503 // tempFolder->setText( "/tmp" ); // default is /tmp directory
504 QWhatsThis::add( tempFolder, tr( "Enter directory where to put temporary files" ) );
505 QToolTip::add ( tempFolder, tr( "Enter directory where to put temporary files" ) );
506 tempBtn = new QPushButton( tr( "Browse..." ), moreBox );
507 tempBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
508 QWhatsThis::add( tempBtn, tr( "Click this to browse temporary directory" ) );
509 QToolTip::add ( tempBtn, tr( "Click this to browse temporary directory" ) );
510 // create products list
511 productsView = new ProductsView( moreBox );
512 productsView->setMinimumSize( 250, 180 );
513 QWhatsThis::add( productsView, tr( "This view lists the products you wish to be installed" ) );
514 QToolTip::add ( productsView, tr( "This view lists the products you wish to be installed" ) );
516 productsInfo = new QTextBrowser( moreBox );
517 productsInfo->setMinimumSize( 270, 135 );
518 QWhatsThis::add( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) );
519 QToolTip::add ( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) );
521 QLabel* reqLab1 = new QLabel( tr( "Total disk space required:" ), moreBox );
522 QWhatsThis::add( reqLab1, tr( "Shows total disk space required for installing selected products" ) );
523 QToolTip::add ( reqLab1, tr( "Shows total disk space required for installing selected products" ) );
524 requiredSize = new QLabel( moreBox );
525 requiredSize->setMinimumWidth( 100 );
526 QWhatsThis::add( requiredSize, tr( "Shows total disk space required for installing selected products" ) );
527 QToolTip::add ( requiredSize, tr( "Shows total disk space required for installing selected products" ) );
528 QLabel* reqLab2 = new QLabel( tr( "Space for temporary files:" ), moreBox );
529 QWhatsThis::add( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) );
530 QToolTip::add ( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) );
531 requiredTemp = new QLabel( moreBox );
532 requiredTemp->setMinimumWidth( 100 );
533 QWhatsThis::add( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) );
534 QToolTip::add ( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) );
535 QFont fnt = reqLab1->font();
537 reqLab1->setFont( fnt );
538 requiredSize->setFont( fnt );
539 reqLab2->setFont( fnt );
540 requiredTemp->setFont( fnt );
541 QGridLayout* sizeLayout = new QGridLayout; sizeLayout->setMargin( 0 ); sizeLayout->setSpacing( 6 );
542 sizeLayout->addWidget( reqLab1, 0, 0 );
543 sizeLayout->addWidget( requiredSize, 0, 1 );
544 sizeLayout->addWidget( reqLab2, 1, 0 );
545 sizeLayout->addWidget( requiredTemp, 1, 1 );
546 // prerequisites checkbox
547 prerequisites = new QCheckBox( tr( "Auto set prerequisites products" ), moreBox );
548 prerequisites->setChecked( true );
549 QWhatsThis::add( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) );
550 QToolTip::add ( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) );
551 // <Unselect All> buttons
552 unselectBtn = new QPushButton( tr( "&Unselect All" ), moreBox );
553 QWhatsThis::add( unselectBtn, tr( "Unselects all products" ) );
554 QToolTip::add ( unselectBtn, tr( "Unselects all products" ) );
555 QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 );
556 btnLayout->addWidget( unselectBtn );
557 // layouting advancet mode widgets
558 moreBoxLayout->addMultiCellWidget( tempLab, 0, 0, 0, 2 );
559 moreBoxLayout->addMultiCellWidget( tempFolder, 1, 1, 0, 1 );
560 moreBoxLayout->addWidget ( tempBtn, 1, 2 );
561 moreBoxLayout->addMultiCellWidget( productsView, 2, 5, 0, 0 );
562 moreBoxLayout->addMultiCellWidget( productsInfo, 2, 2, 1, 2 );
563 moreBoxLayout->addMultiCellWidget( prerequisites,3, 3, 1, 2 );
564 moreBoxLayout->addMultiCellLayout( btnLayout, 4, 4, 1, 2 );
565 moreBoxLayout->addMultiCellLayout( sizeLayout, 5, 5, 1, 2 );
567 moreBtn = new QPushButton( tr( "More..." ), productsPage );
569 pageLayout->addMultiCellWidget( targetLab, 0, 0, 0, 1 );
570 pageLayout->addWidget ( targetFolder, 1, 0 );
571 pageLayout->addWidget ( targetBtn, 1, 1 );
572 pageLayout->addMultiCellWidget( moreBox, 2, 2, 0, 1 );
573 pageLayout->addWidget ( moreBtn, 3, 1 );
574 pageLayout->setRowStretch( 2, 5 );
575 //pageLayout->addRowSpacing( 6, 10 );
577 QFile xmlfile(xmlFileName);
578 if ( xmlfile.exists() ) {
579 QXmlInputSource source( &xmlfile );
580 QXmlSimpleReader reader;
582 StructureParser* handler = new StructureParser( this );
583 handler->setProductsList(productsView);
584 handler->setTargetDir(targetFolder);
585 handler->setTempDir(tempFolder);
586 reader.setContentHandler( handler );
587 reader.parse( source );
589 // set first item to be selected
590 if ( productsView->childCount() > 0 ) {
591 productsView->setSelected( productsView->firstChild(), true );
592 onSelectionChanged();
595 addPage( productsPage, tr( "Installation settings" ) );
596 // connecting signals
597 connect( productsView, SIGNAL( selectionChanged() ),
598 this, SLOT( onSelectionChanged() ) );
599 connect( productsView, SIGNAL( itemToggled( QCheckListItem* ) ),
600 this, SLOT( onItemToggled( QCheckListItem* ) ) );
601 connect( unselectBtn, SIGNAL( clicked() ), this, SLOT( onProdBtn() ) );
602 // connecting signals
603 connect( targetFolder, SIGNAL( textChanged( const QString& ) ),
604 this, SLOT( directoryChanged( const QString& ) ) );
605 connect( targetBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) );
606 connect( tempFolder, SIGNAL( textChanged( const QString& ) ),
607 this, SLOT( directoryChanged( const QString& ) ) );
608 connect( tempBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) );
609 connect( moreBtn, SIGNAL( clicked() ), this, SLOT( onMoreBtn() ) );
610 // start on default - non-advanced - mode
613 // ================================================================
615 * SALOME_InstallWizard::setupCheckPage
616 * Creates prestart page
618 // ================================================================
619 void SALOME_InstallWizard::setupCheckPage()
622 prestartPage = new QWidget( this, "PrestartPage" );
623 QVBoxLayout* pageLayout = new QVBoxLayout( prestartPage );
624 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
626 choices = new QTextEdit( prestartPage );
627 choices->setReadOnly( true );
628 choices->setTextFormat( RichText );
629 choices->setUndoRedoEnabled ( false );
630 QWhatsThis::add( choices, tr( "Displays information about installation settings you made" ) );
631 QToolTip::add ( choices, tr( "Displays information about installation settings you made" ) );
632 QPalette pal = choices->palette();
633 pal.setColor( QColorGroup::Base, QApplication::palette().active().background() );
634 choices->setPalette( pal );
635 choices->setMinimumHeight( 10 );
637 pageLayout->addWidget( choices );
638 pageLayout->setStretchFactor( choices, 5 );
640 addPage( prestartPage, tr( "Check your choice" ) );
642 // ================================================================
644 * SALOME_InstallWizard::setupProgressPage
645 * Creates progress page
647 // ================================================================
648 void SALOME_InstallWizard::setupProgressPage()
651 progressPage = new QWidget( this, "progressPage" );
652 QGridLayout* pageLayout = new QGridLayout( progressPage );
653 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
655 splitter = new QSplitter( Vertical, progressPage );
656 splitter->setOpaqueResize( true );
657 // the parent for the widgets
658 QWidget* widget = new QWidget( splitter );
659 QGridLayout* layout = new QGridLayout( widget );
660 layout->setMargin( 0 ); layout->setSpacing( 6 );
661 // installation progress view box
662 installInfo = new QTextEdit( widget );
663 installInfo->setReadOnly( true );
664 installInfo->setTextFormat( RichText );
665 installInfo->setUndoRedoEnabled ( false );
666 installInfo->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
667 installInfo->setMinimumSize( 100, 10 );
668 QWhatsThis::add( installInfo, tr( "Displays installation process" ) );
669 QToolTip::add ( installInfo, tr( "Displays installation process" ) );
670 // parameters for the script
671 parametersLab = new QLabel( tr( "Enter your answer here:" ), widget );
672 passedParams = new QLineEdit ( widget );
673 QWhatsThis::add( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") );
674 QToolTip::add ( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") );
676 layout->addWidget( installInfo, 0, 0 );
677 layout->addWidget( parametersLab, 1, 0 );
678 layout->addWidget( passedParams, 2, 0 );
679 layout->addRowSpacing( 3, 6 );
680 // the parent for the widgets
681 widget = new QWidget( splitter );
682 layout = new QGridLayout( widget );
683 layout->setMargin( 0 ); layout->setSpacing( 6 );
684 // installation results view box
685 QLabel* resultLab = new QLabel( tr( "Installation Status:" ), widget );
686 progressView = new ProgressView( widget );
687 progressView->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
688 progressView->setMinimumSize( 100, 10 );
689 QWhatsThis::add( progressView, tr( "Displays installation status" ) );
690 QToolTip::add ( progressView, tr( "Displays installation status" ) );
692 layout->addRowSpacing( 0, 6 );
693 layout->addWidget( resultLab, 1, 0 );
694 layout->addWidget( progressView, 2, 0 );
696 pageLayout->addWidget( splitter, 0, 0 );
698 addPage( progressPage, tr( "Installation progress" ) );
700 connect( passedParams, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ) ;
702 // ================================================================
704 * SALOME_InstallWizard::setupReadmePage
705 * Creates readme page
707 // ================================================================
708 void SALOME_InstallWizard::setupReadmePage()
711 readmePage = new QWidget( this, "ReadmePage" );
712 QVBoxLayout* pageLayout = new QVBoxLayout( readmePage );
713 pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 );
714 // README info text box
715 readme = new QTextEdit( readmePage );
716 readme->setReadOnly( true );
717 readme->setTextFormat( PlainText );
718 readme->setFont( QFont( "Fixed", 10 ) );
719 readme->setUndoRedoEnabled ( false );
720 QWhatsThis::add( readme, tr( "Displays README information" ) );
721 QToolTip::add ( readme, tr( "Displays README information" ) );
722 QPalette pal = readme->palette();
723 pal.setColor( QColorGroup::Base, QApplication::palette().active().background() );
724 readme->setPalette( pal );
725 readme->setMinimumHeight( 10 );
726 // <Launch SALOME> button
727 runSalomeBtn = new QPushButton( tr( "Launch SALOME" ), readmePage );
728 QWhatsThis::add( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) );
729 QToolTip::add ( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) );
730 QHBoxLayout* hLayout = new QHBoxLayout;
731 hLayout->addWidget( runSalomeBtn ); hLayout->addStretch();
733 pageLayout->addWidget( readme );
734 pageLayout->setStretchFactor( readme, 5 );
735 pageLayout->addLayout( hLayout );
736 // connecting signals
737 connect( runSalomeBtn, SIGNAL( clicked() ), this, SLOT( onLaunchSalome() ) );
738 // loading README file
739 QString readmeFile = QDir::currentDirPath() + "/README";
741 if ( readFile( readmeFile, text ) )
742 readme->setText( text );
744 readme->setText( tr( "README file has not been found" ) );
746 addPage( readmePage, tr( "Finish installation" ) );
748 // ================================================================
750 * SALOME_InstallWizard::showChoiceInfo
751 * Displays choice info
753 // ================================================================
754 void SALOME_InstallWizard::showChoiceInfo()
758 long totSize, tempSize;
759 checkSize( &totSize, &tempSize );
763 if ( !xmlFileName.isEmpty() ) {
764 text += tr( "Configuration file" )+ ": <b>" + xmlFileName + "</b><br>";
767 if ( !myOS.isEmpty() ) {
768 text += tr( "Target platform" ) + ": <b>" + myOS + "</b><br>";
771 text += tr( "Products to be used" ) + ":<ul>";
772 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
774 if ( productsMap.contains( item ) ) {
775 if ( item->childCount() > 0 ) {
776 if ( productsView->isNative( item ) ) {
777 text += "<li><b>" + item->text() + "</b> " + tr( "as native" ) + "<br>";
782 item = (QCheckListItem*)( item->nextSibling() );
785 text += "<li><b>" + tr( "none" ) + "</b><br>";
789 text += tr( "Products to be installed" ) + ":<ul>";
790 item = (QCheckListItem*)( productsView->firstChild() );
792 if ( productsMap.contains( item ) ) {
793 if ( item->childCount() > 0 ) {
794 if ( productsView->isBinaries( item ) ) {
795 text += "<li><b>" + item->text() + "</b> " + tr( "as binaries" ) + "<br>";
798 else if ( productsView->isSources( item ) ) {
799 text+= "<li><b>" + item->text() + "</b> " + tr( "as sources" ) + "<br>";
803 else if ( item->isOn() ) {
804 text+= "<li><b>" + item->text() + "</b><br>";
808 item = (QCheckListItem*)( item->nextSibling() );
811 text += "<li><b>" + tr( "none" ) + "</b><br>";
814 text += tr( "Total disk space required:" ) + " <b>" + QString::number( totSize ) + " Kb</b><br>" ;
815 text += tr( "Space for temporary files required:" ) + " <b>" + QString::number( tempSize ) + " Kb</b><br>" ;
817 text += tr( "Target directory:" ) + " <b>" + QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) + "</b><br>";
818 // VSR: Temporary folder is used always now and it is not necessary to disable it -->
819 // if ( tempSize > 0 )
820 // VSR: <----------------------------------------------------------------------------
821 text += tr( "Temp directory:" ) + " <b>" + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + "</b><br>";
823 choices->setText( text );
825 // ================================================================
827 * SALOME_InstallWizard::acceptData
828 * Validates page when <Next> button is clicked
830 // ================================================================
831 bool SALOME_InstallWizard::acceptData( const QString& pageTitle )
834 QWidget* aPage = InstallWizard::page( pageTitle );
835 if ( aPage == productsPage ) {
836 // ########## check if any products are selected to be installed
837 long totSize, tempSize;
838 bool anySelected = checkSize( &totSize, &tempSize );
839 if ( !anySelected ) {
840 QMessageBox::warning( this,
842 tr( "Select one or more products to install" ),
844 QMessageBox::NoButton,
845 QMessageBox::NoButton );
848 // ########## check target and temp directories (existence and available disk space)
850 QString targetDir = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
851 QString tempDir = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() );
852 // directories should differ
853 // if (!targetDir.isEmpty() && tempDir == targetDir) {
854 // QMessageBox::warning( this,
856 // tr( "Target and temporary directories must be different"),
858 // QMessageBox::NoButton,
859 // QMessageBox::NoButton );
862 // check target directory
863 if ( targetDir.isEmpty() ) {
864 QMessageBox::warning( this,
866 tr( "Please, enter valid target directory path" ),
868 QMessageBox::NoButton,
869 QMessageBox::NoButton );
872 QFileInfo fi( QDir::cleanDirPath( targetDir ) );
873 if ( !fi.exists() ) {
875 QMessageBox::warning( this,
877 tr( "The directory %1 doesn't exist.\n"
878 "Do you want to create directory?" ).arg( fi.absFilePath() ),
881 QMessageBox::NoButton ) == QMessageBox::Yes;
884 if ( !makeDir( fi.absFilePath(), tmpstr ) ) {
885 QMessageBox::critical( this,
887 tr( "Can't create the directory\n%1").arg( fi.absFilePath() ),
889 QMessageBox::NoButton,
890 QMessageBox::NoButton );
895 QMessageBox::warning( this,
897 tr( "The directory %1 is not a directory.\n"
898 "Please, enter valid target directory path" ).arg( fi.absFilePath() ),
900 QMessageBox::NoButton,
901 QMessageBox::NoButton );
904 if ( !fi.isWritable() ) {
905 QMessageBox::warning( this,
907 tr( "The directory %1 is not writeable.\n"
908 "Please, enter valid target directory path or change permissions" ).arg( fi.absFilePath() ),
910 QMessageBox::NoButton,
911 QMessageBox::NoButton );
914 if ( hasSpace( fi.absFilePath() ) &&
915 QMessageBox::warning( this,
917 tr( "The target directory contains space symbols.\n"
918 "This may cause problems with compiling or installing of products.\n\n"
919 "Do you want to continue?"),
922 QMessageBox::NoButton ) == QMessageBox::No ) {
925 QString binDir = "./Products/BINARIES";
926 if ( !myOS.isEmpty() )
927 binDir += "/" + myOS;
928 QFileInfo fib( QDir::cleanDirPath( binDir ) );
929 if ( !fib.exists() ) {
930 QMessageBox::warning( this,
932 tr( "The directory %1 doesn't exist.\n"
933 "This directory must contain binaries archives." ).arg( fib.absFilePath() ));
935 // run script that checks available disk space for installing of products // returns 1 in case of error
936 QString script = "./config_files/checkSize.sh '";
937 script += fi.absFilePath();
939 script += QString( "%1" ).arg( totSize );
940 ___MESSAGE___( "script = " << script );
941 if ( system( script ) ) {
942 QMessageBox::critical( this,
943 tr( "Out of space" ),
944 tr( "There is not available disk space for installing of selected products" ),
946 QMessageBox::NoButton,
947 QMessageBox::NoButton );
950 // check temp directory
951 if ( tempDir.isEmpty() ) {
953 QMessageBox::warning( this,
955 tr( "Please, enter valid temp directory path" ),
957 QMessageBox::NoButton,
958 QMessageBox::NoButton );
963 tempFolder->setText( tempDir );
966 QFileInfo fit( QDir::cleanDirPath( tempDir ) );
967 if ( !makeDir( fit.absFilePath() + TEMPDIRNAME, tmpCreated ) ) {
968 QMessageBox::critical( this,
970 tr( "Can't use temporary directory.\nCheck permissions for the %1 directory.").arg( fit.absFilePath() ),
972 QMessageBox::NoButton,
973 QMessageBox::NoButton );
976 // run script that check available disk space for temporary files
977 // returns 1 in case of error
978 QString tscript = "./config_files/checkSize.sh '";
979 tscript += fit.absFilePath();
981 tscript += QString( "%1" ).arg( tempSize );
982 ___MESSAGE___( "script = " << tscript );
983 if ( system( tscript ) ) {
984 QMessageBox::critical( this,
985 tr( "Out of space" ),
986 tr( "There is not available disk space for the temporary files" ),
988 QMessageBox::NoButton,
989 QMessageBox::NoButton );
992 // VSR: <------------------------------------------------------------------------------
993 // ########## check native products
994 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
997 if ( productsMap.contains( item ) ) {
998 if ( item->childCount() > 0 ) {
999 if ( !productsView->isNone( item ) ) {
1000 if ( item->text(2).isEmpty() || item->text(2).isNull() ) {
1001 QMessageBox::warning( this,
1003 tr( "You don't have a defined script for %1").arg(item->text(0)),
1005 QMessageBox::NoButton,
1006 QMessageBox::NoButton );
1007 productsView->setNone( item );
1010 QFileInfo fi( QString("./config_files/") + item->text(2) );
1011 if ( !fi.exists() ) {
1012 QMessageBox::warning( this,
1014 tr( "%1 required for %2 doesn't exist.").arg("./config_files/" + item->text(2)).arg(item->text(0)),
1016 QMessageBox::NoButton,
1017 QMessageBox::NoButton );
1018 productsView->setNone( item );
1023 // collect native products
1024 if ( productsView->isNative( item ) ) {
1025 if ( natives.find( item->text(0) ) == natives.end() )
1026 natives.append( item->text(0) );
1028 else if ( productsView->isBinaries( item ) || productsView->isSources( item ) ) {
1029 QStringList dependOn = productsMap[ item ].getDependancies();
1030 for ( int i = 0; i < (int)dependOn.count(); i++ ) {
1031 QCheckListItem* depitem = findItem( dependOn[ i ] );
1033 if ( productsView->isNative( depitem ) && natives.find( depitem->text(0) ) == natives.end() )
1034 natives.append( depitem->text(0) );
1037 QMessageBox::warning( this,
1039 tr( "%1 is required for %2 %3 installation.\n"
1040 "Please, add this product in config.xml file.").arg(dependOn[ i ]).arg(item->text(0)).arg(item->text(1)),
1042 QMessageBox::NoButton,
1043 QMessageBox::NoButton );
1050 item = (QCheckListItem*)( item->nextSibling() );
1052 QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1053 QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
1054 myThread->clearCommands();
1055 if ( natives.count() > 0 ) {
1056 for ( unsigned i = 0; i < natives.count(); i++ ) {
1057 item = findItem( natives[ i ] );
1059 QString dependOn = productsMap[ item ].getDependancies().join(" ");
1060 QString script = "cd ./config_files/;" + item->text(2) + " try_native " +
1061 QFileInfo( tmpFolder ).absFilePath() + " " + QDir::currentDirPath() + "/Products " + QFileInfo( tgtFolder ).absFilePath() + " " +
1062 QUOTE(dependOn) + " " + item->text(0);
1064 myThread->addCommand( item, script );
1067 QMessageBox::warning( this,
1069 tr( "%The product %1 %2 required for installation.\n"
1070 "Please, add this product in config.xml file.").arg(item->text(0)).arg(item->text(1)),
1072 QMessageBox::NoButton,
1073 QMessageBox::NoButton );
1077 WarnDialog::showWarnDlg( this, true );
1079 return true; // return in order to avoid default postValidateEvent() action
1082 return InstallWizard::acceptData( pageTitle );
1084 // ================================================================
1086 * SALOME_InstallWizard::checkSize
1087 * Calculates disk space required for the installation
1089 // ================================================================
1090 bool SALOME_InstallWizard::checkSize( long* totSize, long* tempSize )
1092 long tots = 0, temps = 0;
1095 MapProducts::Iterator mapIter;
1096 for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) {
1097 QCheckListItem* item = mapIter.key();
1098 Dependancies dep = mapIter.data();
1099 if ( productsView->isBinaries( item ) ) {
1100 tots += dep.getSize();
1102 else if ( productsView->isSources( item ) ) {
1103 tots += dep.getSize(true);
1104 temps = max( temps, dep.getTempSize() );
1106 if ( !productsView->isNone( item ) )
1114 return ( nbSelected > 0 );
1116 // ================================================================
1118 * SALOME_InstallWizard::checkProductPage
1119 * Checks products page validity (directories and products selection) and
1120 * enabled/disables "Next" button for the Products page
1122 // ================================================================
1123 void SALOME_InstallWizard::checkProductPage()
1125 long tots = 0, temps = 0;
1127 // check if any product is selected;
1128 bool isAnyProductSelected = checkSize( &tots, &temps );
1129 // check if target directory is valid
1130 bool isTargetDirValid = !targetFolder->text().stripWhiteSpace().isEmpty();
1131 // check if temp directory is valid
1132 bool isTempDirValid = !moreMode || !tempFolder->text().stripWhiteSpace().isEmpty();
1134 // update required size information
1135 requiredSize->setText( QString::number( tots ) + " Kb");
1136 requiredTemp->setText( QString::number( temps ) + " Kb");
1138 // enable/disable "Next" button
1139 setNextEnabled( productsPage, isAnyProductSelected && isTargetDirValid && isTempDirValid );
1141 // ================================================================
1143 * SALOME_InstallWizard::setPrerequisites
1144 * Sets the product and all products this one depends on to be checked ( recursively )
1146 // ================================================================
1147 void SALOME_InstallWizard::setPrerequisites( QCheckListItem* item )
1149 if ( !productsMap.contains( item ) )
1151 if ( productsView->isNone( item ) )
1153 // get all prerequisites
1154 QStringList dependOn = productsMap[ item ].getDependancies();
1155 for ( int i = 0; i < (int)dependOn.count(); i++ ) {
1156 MapProducts::Iterator itProd;
1157 for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) {
1158 if ( itProd.data().getName() == dependOn[ i ] ) {
1159 if ( productsView->isNone( itProd.key() ) ) {
1160 QString defMode = itProd.data().getDefault();
1161 if ( defMode.isEmpty() )
1162 defMode = tr( "install binaries" );
1163 if ( defMode == tr( "install binaries" ) )
1164 productsView->setBinaries( itProd.key() );
1165 else if ( defMode == tr( "install sources" ) )
1166 productsView->setSources( itProd.key() );
1167 else if ( defMode == tr( "use native" ) )
1168 productsView->setNative( itProd.key() );
1169 setPrerequisites( itProd.key() );
1175 // ================================================================
1177 * SALOME_InstallWizard::launchScript
1178 * Runs installation script
1180 // ================================================================
1181 void SALOME_InstallWizard::launchScript()
1183 // try to find product being processed now
1184 QString prodProc = progressView->findStatus( Processing );
1185 if ( !prodProc.isNull() ) {
1186 ___MESSAGE___( "Found <Processing>: " );
1188 // if found - set status to "completed"
1189 progressView->setStatus( prodProc, Completed );
1190 // ... and call this method again
1194 // else try to find next product which is not processed yet
1195 prodProc = progressView->findStatus( Waiting );
1196 if ( !prodProc.isNull() ) {
1197 ___MESSAGE___( "Found <Waiting>: " << prodProc.latin1() );
1198 // if found - set status to "processed" and run script
1199 progressView->setStatus( prodProc, Processing );
1200 progressView->ensureVisible( prodProc );
1202 QCheckListItem* item = findItem( prodProc );
1203 // fill in script parameters
1204 shellProcess->clearArguments();
1206 shellProcess->setWorkingDirectory( QDir::cleanDirPath( QFileInfo( "./config_files/" ).absFilePath() ) );
1207 shellProcess->addArgument( item->text(2) );
1210 QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1211 //if( !tempFolder->isEnabled() )
1212 //tmpFolder = "/tmp";
1215 if ( productsView->isBinaries( item ) ) {
1216 shellProcess->addArgument( "install_binary" );
1217 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1218 QString binDir = QDir::currentDirPath() + "/Products/BINARIES";
1219 if ( !myOS.isEmpty() )
1220 binDir += "/" + myOS;
1221 shellProcess->addArgument( binDir );
1224 else if ( productsView->isSources( item ) ) {
1225 shellProcess->addArgument( "install_source" );
1226 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1227 shellProcess->addArgument( QDir::currentDirPath() + "/Products/SOURCES" );
1230 else if ( productsView->isNative( item ) ) {
1231 shellProcess->addArgument( "try_native" );
1232 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1233 shellProcess->addArgument( QDir::currentDirPath() + "/Products" );
1235 // ... not install : try to find preinstalled
1237 shellProcess->addArgument( "try_preinstalled" );
1238 shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() );
1239 shellProcess->addArgument( QDir::currentDirPath() + "/Products" );
1241 // ... target folder
1242 QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
1243 shellProcess->addArgument( QFileInfo( tgtFolder ).absFilePath() );
1246 QString depproducts = DefineDependeces(productsMap);
1247 ___MESSAGE___( "Dependancies"<< depproducts.latin1() );
1249 shellProcess->addArgument( depproducts );
1250 // ... product name - currently instaled product
1251 shellProcess->addArgument( item->text(0) );
1254 if ( !shellProcess->start() ) {
1255 // error handling can be here
1256 ___MESSAGE___( "error" );
1260 ___MESSAGE___( "All products have been installed successfully" );
1261 // all products are installed successfully
1262 QString workDir = QDir::cleanDirPath( QFileInfo( "./config_files/" ).absFilePath() );
1263 MapProducts::Iterator mapIter;
1264 ___MESSAGE___( "starting pick-up environment" );
1265 for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) {
1266 QCheckListItem* item = mapIter.key();
1267 Dependancies dep = mapIter.data();
1268 QString depproducts = QUOTE( DefineDependeces(productsMap) );
1269 if ( dep.pickUpEnvironment() ) {
1270 ___MESSAGE___( "... for " << dep.getName() );
1272 script += "cd " + QUOTE( QFileInfo( QDir::cleanDirPath( "./config_files/" ) ).absFilePath() ) + "; ";
1273 script += item->text(2) + " ";
1274 script += "pickup_env ";
1275 script += QUOTE( QFileInfo( QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME ).absFilePath() ) + " ";
1276 script += QUOTE( QFileInfo( QDir::cleanDirPath( QDir::currentDirPath() + "/Products" ) ).absFilePath() ) + " ";
1277 script += QUOTE( QFileInfo( QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) ).absFilePath() ) + " ";
1278 script += depproducts + " ";
1279 script += item->text(0);
1280 ___MESSAGE___( "... --> " << script.latin1() );
1281 if ( system( script.latin1() ) ) {
1282 ___MESSAGE___( "ERROR" );
1287 setNextEnabled( true );
1288 nextButton()->setText( tr( "&Next >" ) );
1289 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1290 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1291 nextButton()->disconnect();
1292 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1294 setBackEnabled( true );
1295 // script parameters
1296 passedParams->clear();
1297 passedParams->setEnabled( false );
1298 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1299 if ( isMinimized() )
1303 // ================================================================
1305 * SALOME_InstallWizard::onMoreBtn
1306 * <More...> button slot
1308 // ================================================================
1309 void SALOME_InstallWizard::onMoreBtn()
1313 moreBtn->setText( tr( "More..." ) );
1317 moreBtn->setText( tr( "Less..." ) );
1319 qApp->processEvents();
1320 moreMode = !moreMode;
1321 InstallWizard::layOut();
1322 qApp->processEvents();
1323 if ( !isMaximized() ) {
1324 //setGeometry( geometry().x(), geometry().y(), geometry().width(), 0 );
1325 resize( geometry().width(), 0 );
1326 qApp->processEvents();
1330 // ================================================================
1332 * SALOME_InstallWizard::onLaunchSalome
1333 * <Launch Salome> button slot
1335 // ================================================================
1336 void SALOME_InstallWizard::onLaunchSalome()
1338 QString msg = tr( "You don't have SALOME binaries installed in the %1 directory!" ).arg( targetFolder->text() );
1340 QCheckListItem* item = findItem( "KERNEL-Bin" );
1342 QFileInfo fi( targetFolder->text() + "/KERNEL_" + item->text(1) + "/bin/salome/runSalome" );
1343 QFileInfo fienv( targetFolder->text() + "/KERNEL_" + item->text(1) + "/salome.csh" );
1344 if ( fienv.exists() ) {
1345 if ( fi.exists() ) {
1347 script += "cd " + targetFolder->text() + "/KERNEL_" + item->text(1) + "; ";
1348 script += "source salome.csh; ";
1349 script += "cd bin/salome; ";
1350 script += "runSalome > /dev/null";
1351 script = "(csh -c '" + script + "')";
1352 ___MESSAGE___( "script: " << script.latin1() );
1353 if ( !system( script.latin1() ) )
1356 msg = tr( "Can't launch SALOME." );
1359 msg = tr( "Can't launch SALOME." ) + "\n" + tr( "runSalome file can not be found." );
1362 msg = tr( "Can't launch SALOME." ) + "\n" + tr( "Can't find environment file." );
1364 QMessageBox::warning( this,
1368 QMessageBox::NoButton,
1369 QMessageBox::NoButton );
1371 // ================================================================
1373 * SALOME_InstallWizard::findItem
1374 * Searches product listview item with given symbolic name
1376 // ================================================================
1377 QCheckListItem* SALOME_InstallWizard::findItem( const QString& sName )
1379 MapProducts::Iterator mapIter;
1380 for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) {
1381 if ( mapIter.data().getName() == sName )
1382 return mapIter.key();
1386 // ================================================================
1388 * SALOME_InstallWizard::abort
1389 * Sets progress state to Aborted
1391 // ================================================================
1392 void SALOME_InstallWizard::abort()
1394 QString prod = progressView->findStatus( Processing );
1395 while ( !prod.isNull() ) {
1396 progressView->setStatus( prod, Aborted );
1397 prod = progressView->findStatus( Processing );
1399 prod = progressView->findStatus( Waiting );
1400 while ( !prod.isNull() ) {
1401 progressView->setStatus( prod, Aborted );
1402 prod = progressView->findStatus( Waiting );
1405 // ================================================================
1407 * SALOME_InstallWizard::reject
1408 * Reject slot, clears temporary directory and closes application
1410 // ================================================================
1411 void SALOME_InstallWizard::reject()
1413 ___MESSAGE___( "REJECTED" );
1414 if ( !exitConfirmed ) {
1415 if ( QMessageBox::information( this,
1417 tr( "Do you want to quit %1?" ).arg( getIWName() ),
1425 exitConfirmed = true;
1428 InstallWizard::reject();
1430 // ================================================================
1432 * SALOME_InstallWizard::accept
1433 * Accept slot, clears temporary directory and closes application
1435 // ================================================================
1436 void SALOME_InstallWizard::accept()
1438 ___MESSAGE___( "ACCEPTED" );
1440 InstallWizard::accept();
1442 // ================================================================
1444 * SALOME_InstallWizard::clean
1445 * Clears and (optionally) removes temporary directory
1447 // ================================================================
1448 void SALOME_InstallWizard::clean(bool rmDir)
1450 WarnDialog::showWarnDlg( 0, false );
1451 myThread->clearCommands();
1453 while ( myThread->running() );
1454 // VSR: first remove temporary files
1455 QString script = "cd ./config_files/; remove_tmp.sh '";
1456 script += tempFolder->text().stripWhiteSpace() + TEMPDIRNAME;
1458 script += QUOTE(DefineDependeces(productsMap));
1459 script += " > /dev/null";
1460 ___MESSAGE___( "script = " << script );
1461 if ( system( script.latin1() ) ) {
1463 // VSR: then try to remove created temporary directory
1464 //script = "rm -rf " + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
1465 if ( rmDir && !tmpCreated.isNull() ) {
1466 script = "rm -rf " + tmpCreated;
1467 script += " > /dev/null";
1468 if ( system( script.latin1() ) ) {
1470 ___MESSAGE___( "script = " << script );
1473 // ================================================================
1475 * SALOME_InstallWizard::pageChanged
1476 * Called when user moves from page to page
1478 // ================================================================
1479 void SALOME_InstallWizard::pageChanged( const QString & mytitle)
1481 nextButton()->setText( tr( "&Next >" ) );
1482 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1483 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1484 nextButton()->disconnect();
1485 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1486 cancelButton()->disconnect();
1487 connect( cancelButton(), SIGNAL( clicked()), this, SLOT( reject() ) );
1489 QWidget* aPage = InstallWizard::page( mytitle );
1493 if ( aPage == productsPage ) {
1495 onSelectionChanged();
1498 else if ( aPage == prestartPage ) {
1502 else if ( aPage == progressPage ) {
1503 if ( previousPage == prestartPage ) {
1505 progressView->clear();
1506 installInfo->clear();
1507 passedParams->clear();
1508 passedParams->setEnabled( false );
1509 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1510 nextButton()->setText( tr( "&Start" ) );
1511 QWhatsThis::add( nextButton(), tr( "Starts installation process" ) );
1512 QToolTip::add ( nextButton(), tr( "Starts installation process" ) );
1513 // reconnect Next button - to use it as Start button
1514 nextButton()->disconnect();
1515 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( onStart() ) );
1516 setNextEnabled( true );
1517 // reconnect Cancel button to terminate process
1518 cancelButton()->disconnect();
1519 connect( cancelButton(), SIGNAL( clicked() ), this, SLOT( tryTerminate() ) );
1522 else if ( aPage == readmePage ) {
1523 QCheckListItem* item = findItem( "KERNEL-Bin" );
1524 runSalomeBtn->setEnabled( item &&
1525 QFileInfo( targetFolder->text() + "/KERNEL_" + item->text(1) + "/bin/salome/runSalome" ).exists() &&
1526 QFileInfo( targetFolder->text() + "/KERNEL_" + item->text(1) + "/salome.csh" ).exists() );
1527 finishButton()->setEnabled( true );
1529 previousPage = aPage;
1530 ___MESSAGE___( "previousPage = " << previousPage );
1532 // ================================================================
1534 * SALOME_InstallWizard::helpClicked
1537 // ================================================================
1538 void SALOME_InstallWizard::helpClicked()
1540 if ( helpWindow == NULL ) {
1541 helpWindow = HelpWindow::openHelp( this );
1544 helpWindow->installEventFilter( this );
1547 QMessageBox::warning( this,
1548 tr( "Help file not found" ),
1549 tr( "Sorry, help is unavailable" ) );
1553 helpWindow->raise();
1554 helpWindow->setActiveWindow();
1557 // ================================================================
1559 * SALOME_InstallWizard::browseDirectory
1560 * Shows directory selection dialog
1562 // ================================================================
1563 void SALOME_InstallWizard::browseDirectory()
1565 const QObject* theSender = sender();
1566 QLineEdit* theFolder;
1567 if ( theSender == targetBtn )
1568 theFolder = targetFolder;
1569 else if (theSender == tempBtn)
1570 theFolder = tempFolder;
1573 QString typedDir = QFileDialog::getExistingDirectory( QDir::cleanDirPath( theFolder->text().stripWhiteSpace() ), this );
1574 if ( !typedDir.isNull() ) {
1575 theFolder->setText( typedDir );
1576 theFolder->end( false );
1580 // ================================================================
1582 * SALOME_InstallWizard::directoryChanged
1583 * Called when directory path (target or temp) is changed
1585 // ================================================================
1586 void SALOME_InstallWizard::directoryChanged( const QString& /*text*/ )
1590 // ================================================================
1592 * SALOME_InstallWizard::onStart
1593 * <Start> button's slot - runs installation
1595 // ================================================================
1596 void SALOME_InstallWizard::onStart()
1598 // clear list of products to install ...
1600 // ... and fill it for new process
1601 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
1603 // if ( productsView->isBinaries( item ) || productsView->isSources( item ) || productsView->isNative( item ) ) {
1604 if ( productsMap.contains( item ) )
1605 toInstall.append( productsMap[item].getName() );
1607 item = (QCheckListItem*)( item->nextSibling() );
1609 // if something at all is selected
1610 if ( !toInstall.isEmpty() ) {
1611 clean(false); // VSR 07/02/05 - bug fix: first we should clear temporary directory
1612 // disable <Next> button
1613 setNextEnabled( false );
1614 // disable <Back> button
1615 setBackEnabled( false );
1616 // enable script parameters line edit
1617 // VSR commented: 18/09/03: passedParams->setEnabled( true );
1618 // VSR commented: 18/09/03: passedParams->setFocus();
1619 // set status for all products
1620 for ( int i = 0; i < (int)toInstall.count(); i++ ) {
1621 item = findItem( toInstall[ i ] );
1623 if ( productsView->isBinaries( item ) )
1624 type = tr( "binaries" );
1625 else if ( productsView->isSources( item ) )
1626 type = tr( "sources" );
1627 else if ( productsView->isNative( item ) )
1628 type = tr( "native" );
1630 type = tr( "not install" );
1631 progressView->addProduct( item->text(0), type, item->text(2) );
1633 // launch install script
1637 // ================================================================
1639 * SALOME_InstallWizard::onReturnPressed
1640 * Called when users tries to pass parameters for the script
1642 // ================================================================
1643 void SALOME_InstallWizard::onReturnPressed()
1645 QString txt = passedParams->text();
1646 installInfo->append( txt );
1648 shellProcess->writeToStdin( txt );
1649 passedParams->clear();
1650 progressView->setFocus();
1651 passedParams->setEnabled( false );
1652 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1655 Callback function - as response for the script finishing
1657 void SALOME_InstallWizard::productInstalled( )
1659 ___MESSAGE___( "process exited" );
1660 if ( shellProcess->normalExit() ) {
1661 ___MESSAGE___( "...normal exit" );
1662 // normal exit - try to proceed installation further
1666 ___MESSAGE___( "...abnormal exit" );
1667 // installation aborted
1669 // clear script passed parameters lineedit
1670 passedParams->clear();
1671 passedParams->setEnabled( false );
1672 QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
1673 // enable <Next> button
1674 setNextEnabled( true );
1675 nextButton()->setText( tr( "&Next >" ) );
1676 QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1677 QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) );
1678 nextButton()->disconnect();
1679 connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) );
1680 // enable <Back> button
1681 setBackEnabled( true );
1684 // ================================================================
1686 * SALOME_InstallWizard::tryTerminate
1687 * Slot, called when <Cancel> button is clicked during installation script running
1689 // ================================================================
1690 void SALOME_InstallWizard::tryTerminate()
1692 if ( shellProcess->isRunning() ) {
1693 if ( QMessageBox::information( this,
1695 tr( "Do you want to quit %1?" ).arg( getIWName() ),
1703 exitConfirmed = true;
1704 // if process still running try to terminate it first
1705 shellProcess->tryTerminate();
1707 //QTimer::singleShot( 3000, this, SLOT( onCancel() ) );
1708 connect( shellProcess, SIGNAL( processExited() ), this, SLOT( onCancel() ) );
1711 // else just quit install wizard
1715 // ================================================================
1717 * SALOME_InstallWizard::onCancel
1718 * Kills installation process and quits application
1720 // ================================================================
1721 void SALOME_InstallWizard::onCancel()
1723 shellProcess->kill();
1726 // ================================================================
1728 * SALOME_InstallWizard::onSelectionChanged
1729 * Called when selection is changed in the products list view
1731 // ================================================================
1732 void SALOME_InstallWizard::onSelectionChanged()
1734 productsInfo->clear();
1735 QListViewItem* item = productsView->selectedItem();
1738 if ( item->parent() )
1739 item = item->parent();
1740 QCheckListItem* aItem = (QCheckListItem*)item;
1741 if ( !productsMap.contains( aItem ) )
1743 Dependancies dep = productsMap[ aItem ];
1744 QString text = "<b>" + aItem->text(0) + "</b>" + "<br>";
1745 if ( !aItem->text(1).stripWhiteSpace().isEmpty() )
1746 text += tr( "Version" ) + ": " + aItem->text(1) + "<br>";
1748 if ( !dep.getDescription().isEmpty() ) {
1749 text += "<i>" + dep.getDescription() + "</i><br><br>";
1751 text += tr( "User choice" ) + ": ";
1752 long totSize = 0, tempSize = 0;
1753 if ( productsView->isBinaries( aItem ) ) {
1754 text += "<b>" + tr( "install binaries" ) + "</b>" + "<br>";
1755 totSize = dep.getSize();
1757 else if ( productsView->isSources( aItem ) ) {
1758 text += "<b>" + tr( "install sources" ) + "</b>" + "<br>";
1759 totSize = dep.getSize( true );
1760 tempSize = dep.getTempSize();
1762 else if ( productsView->isNative( aItem ) ) {
1763 text += "<b>" + tr( "use native" ) + "</b>" + "<br>";
1766 text += "<b>" + tr( "not install" ) + "</b>" + "<br>";
1769 text += tr( "Disk space required" ) + ": " + QString::number( totSize ) + " Kb<br>";
1770 text += tr( "Disk space for tmp files required" ) + ": " + QString::number( tempSize ) + " Kb<br>";
1772 QString req = ( dep.getDependancies().count() > 0 ? dep.getDependancies().join(", ") : tr( "none" ) );
1773 text += tr( "Prerequisites" ) + ": " + req;
1774 productsInfo->setText( text );
1776 // ================================================================
1778 * SALOME_InstallWizard::onItemToggled
1779 * Called when user checks/unchecks any product item
1780 * Recursively sets all prerequisites and updates "Next" button state
1782 // ================================================================
1783 void SALOME_InstallWizard::onItemToggled( QCheckListItem* item )
1785 if ( prerequisites->isChecked() ) {
1786 if ( item->parent() )
1787 item = (QCheckListItem*)( item->parent() );
1788 if ( productsMap.contains( item ) ) {
1789 productsView->blockSignals( true );
1790 setPrerequisites( item );
1791 productsView->blockSignals( false );
1794 onSelectionChanged();
1797 // ================================================================
1799 * SALOME_InstallWizard::onProdBtn
1800 * This slot is called when user clicks one of <Select Sources>,
1801 * <Select Binaries>, <Unselect All> buttons ( products page )
1803 // ================================================================
1804 void SALOME_InstallWizard::onProdBtn()
1806 const QObject* snd = sender();
1807 productsView->blockSignals( true );
1808 if ( snd == unselectBtn ) {
1809 QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
1811 productsView->setNone( item );
1812 item = (QCheckListItem*)( item->nextSibling() );
1815 productsView->blockSignals( false );
1816 onSelectionChanged();
1819 // ================================================================
1821 * SALOME_InstallWizard::wroteToStdin
1822 * QProcess slot: -->something was written to stdin
1824 // ================================================================
1825 void SALOME_InstallWizard::wroteToStdin( )
1827 ___MESSAGE___( "Something was sent to stdin" );
1829 // ================================================================
1831 * SALOME_InstallWizard::readFromStdout
1832 * QProcess slot: -->something was written to stdout
1834 // ================================================================
1835 void SALOME_InstallWizard::readFromStdout( )
1837 ___MESSAGE___( "Something was sent to stdout" );
1838 while ( shellProcess->canReadLineStdout() ) {
1839 installInfo->append( QString( shellProcess->readLineStdout() ) );
1840 installInfo->scrollToBottom();
1842 QString str( shellProcess->readStdout() );
1843 if ( !str.isEmpty() ) {
1844 installInfo->append( str );
1845 installInfo->scrollToBottom();
1848 // ================================================================
1850 * SALOME_InstallWizard::readFromStderr
1851 * QProcess slot: -->something was written to stderr
1853 // ================================================================
1854 void SALOME_InstallWizard::readFromStderr( )
1856 ___MESSAGE___( "Something was sent to stderr" );
1857 while ( shellProcess->canReadLineStderr() ) {
1858 installInfo->append( QString( shellProcess->readLineStderr() ) );
1859 installInfo->scrollToBottom();
1861 QString str( shellProcess->readStderr() );
1862 if ( !str.isEmpty() ) {
1863 installInfo->append( str );
1864 installInfo->scrollToBottom();
1866 passedParams->setEnabled( true );
1867 passedParams->setFocus();
1868 QFont f = parametersLab->font(); f.setBold( true ); parametersLab->setFont( f );
1870 // ================================================================
1872 * SALOME_InstallWizard::setDependancies
1873 * Sets dependancies for the product item
1875 // ================================================================
1876 void SALOME_InstallWizard::setDependancies( QCheckListItem* item, Dependancies dep)
1878 productsMap[item] = dep;
1880 // ================================================================
1882 * SALOME_InstallWizard::polish
1883 * Polishing of the widget - to set right initial size
1885 // ================================================================
1886 void SALOME_InstallWizard::polish()
1889 InstallWizard::polish();
1891 // ================================================================
1893 * SALOME_InstallWizard::updateCaption
1894 * Updates caption according to the current page number
1896 // ================================================================
1897 void SALOME_InstallWizard::updateCaption()
1899 QWidget* aPage = InstallWizard::currentPage();
1902 InstallWizard::setCaption( tr( myCaption ) + " " +
1903 tr( getIWName() ) + " - " +
1904 tr( "Step %1 of %2").arg( QString::number( this->indexOf( aPage )+1 ) ).arg( QString::number( this->pageCount() ) ) );
1907 // ================================================================
1909 * SALOME_InstallWizard::processValidateEvent
1910 * Processes validation event (<val> is validation code)
1912 // ================================================================
1913 void SALOME_InstallWizard::processValidateEvent( const int val, void* data )
1915 QWidget* aPage = InstallWizard::currentPage();
1916 if ( aPage != productsPage ) {
1917 InstallWizard::processValidateEvent( val, data );
1922 QCheckListItem* item = (QCheckListItem*)data;
1925 WarnDialog::showWarnDlg( 0, false );
1926 // when try_native returns 2 it means that native product version is higher than that is prerequisited
1927 if ( QMessageBox::warning( this,
1929 tr( "You have newer version of %1 installed on your computer than that is required (%2).\nContinue?").arg(item->text(0)).arg(item->text(1)),
1932 QMessageBox::NoButton ) == QMessageBox::No ) {
1933 myThread->clearCommands();
1935 setNextEnabled( true );
1936 setBackEnabled( true );
1939 WarnDialog::showWarnDlg( this, true );
1942 WarnDialog::showWarnDlg( 0, false );
1943 QMessageBox::warning( this,
1945 tr( "You don't have native %1 %2 installed").arg(item->text(0)).arg(item->text(1)),
1947 QMessageBox::NoButton,
1948 QMessageBox::NoButton );
1949 myThread->clearCommands();
1951 setNextEnabled( true );
1952 setBackEnabled( true );
1953 productsView->setNone( item );
1957 if ( myThread->hasCommands() )
1960 WarnDialog::showWarnDlg( 0, false );
1961 InstallWizard::processValidateEvent( val, data );