From a80ee008a40be516a4dc4218e4cb5ede4ae83311 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 29 Sep 2003 12:53:49 +0000 Subject: [PATCH] Initial version --- src/SALOME_InstallWizard.cxx | 1944 ++++++++++++++++++++++++++++++++++ 1 file changed, 1944 insertions(+) create mode 100644 src/SALOME_InstallWizard.cxx diff --git a/src/SALOME_InstallWizard.cxx b/src/SALOME_InstallWizard.cxx new file mode 100644 index 0000000..599b682 --- /dev/null +++ b/src/SALOME_InstallWizard.cxx @@ -0,0 +1,1944 @@ +// File : SALOME_InstallWizard.cxx +// Created : Thu Dec 18 12:01:00 2002 +// Author : Vadim SANDLER +// Project : SALOME Professional +// Module : InstallWizard +// Copyright : 2003 CEA/DEN, EDF R&D +// $Header$ + +#include "SALOME_InstallWizard.hxx" +#include "icons.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WNT +#include +#include +#else +#include +#include +#endif + +#ifdef WNT +#define max( x, y ) ( x ) > ( y ) ? ( x ) : ( y ) +#endif + +// ######################################## Globals ############################################## + +QString myVersion = "1.2"; +QString myCaption = QString("SALOME Professional %1 Installation Wizard").arg(myVersion); +QString myCopyright = "Copyright (C) 2003 CEA/DEN, EDF R&D"; +QString myLicense = "All right reserved"; +QString myOS = ""; + +#define TEMPDIRNAME ( "/INSTALLWORK" + QString::number( getpid() ) ) +/*! + Defines list of dependancies as string separated by space symbols +*/ +static QString DefineDependeces(MapProducts& theProductsMap) { + QStringList aProducts; + for ( MapProducts::Iterator mapIter = theProductsMap.begin(); mapIter != theProductsMap.end(); ++mapIter ) { + QCheckListItem* item = mapIter.key(); + Dependancies dep = mapIter.data(); + QStringList deps = dep.getDependancies(); + for (int i = 0; i<(int)deps.count(); i++ ) { + if ( !aProducts.contains( deps[i] ) ) + aProducts.append( deps[i] ); + } + if ( !aProducts.contains( item->text(0) ) ) + aProducts.append( item->text(0) ); + } + return aProducts.join(" "); +} + +#define QUOTE(arg) QString("'") + QString(arg) + QString("'") + +/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + T H E O L D I M P L E M E N T A T I O N +static QString DefineDependeces(MapProducts& theProductsMap, QCheckListItem* product ){ + QStringList aProducts; + if ( theProductsMap.contains( product ) ) { + Dependancies dep = theProductsMap[ product ]; + QStringList deps = dep.getDependancies(); + for (int i = 0; i<(int)deps.count(); i++ ) { + aProducts.append( deps[i] ); + } + } + return QString("\"") + aProducts.join(" ") + QString("\""); +} +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ + +/*! + Makes directory recursively, returns false if not succedes [ static ] +*/ +static bool makeDir( const QString& theDir, QString& theCreated ) +{ + theCreated = QString::null; + if ( theDir.isEmpty() ) + return false; + QString aDir = QDir::cleanDirPath( QFileInfo( theDir ).absFilePath() ); + int start = 1; + while ( start > 0 ) { + start = aDir.find( QDir::separator(), start ); + if ( start > 0 ) { + QFileInfo fi( aDir.left( start ) ); + if ( !fi.exists() ) { + // VSR: Create directory and set permissions to allow other users to remove it + QString script = "mkdir " + fi.absFilePath(); + script += "; chmod 777 " + fi.absFilePath(); + script += " > /dev/null"; + if ( system( script.latin1() ) ) + return false; + // VSR: Remember the top of the created directory (to remove it in the end of the installation) + if ( theCreated.isNull() ) + theCreated = fi.absFilePath(); + } + } + start++; + } + if ( !QFileInfo( aDir ).exists() ) { + // VSR: Create directory, other users should NOT have possibility to remove it!!! + QString script = "mkdir " + aDir; + script += " > /dev/null"; + if ( system( script.latin1() ) ) + return false; + // VSR: Remember the top of the created directory (to remove it in the end of the installation) + if ( theCreated.isNull() ) + theCreated = aDir; + } + return true; +} +/*! + Reads the file, returns false if can't open it +*/ +static bool readFile( const QString& fileName, QString& text ) +{ + if ( QFile::exists( fileName ) ) { + QFile file( fileName ); + if ( file.open( IO_ReadOnly ) ) { + QTextStream stream( &file ); + QString line; + while ( !stream.eof() ) { + line = stream.readLine(); // line of text excluding '\n' + text += line + "\n"; + } + file.close(); + return true; + } + } + return false; +} +// ###################################### Progress View ########################################### + +/*! + Constructor of progress view's item + - parent progress view + - full name of the product + - alias for he product used by the script + - initial status of the product, default is 'Waiting' +*/ +ProgressViewItem::ProgressViewItem( ProgressView* parent, QString productName, const QString installType, const QString scriptName, Status status ) + : QListViewItem( parent, productName, installType ), myScript( scriptName ) +{ + setStatus( status ); +} +/*! + Sets new status for the item +*/ +void ProgressViewItem::setStatus( Status status ) +{ + myStatus = status; + switch ( myStatus ) { + case Waiting: + setText( 2, "Waiting" ); break; + case Processing: + setText( 2, "Processing" ); break; + case Completed: + setText( 2, "Completed" ); break; + case Aborted: + setText( 2, "Aborted" ); break; + default: + break; + } + repaint(); +} +/*! + Paints the cell of the list view item +*/ +void ProgressViewItem::paintCell( QPainter* painter, const QColorGroup& cg, int column, int width, int align ) +{ + QColorGroup acg( cg ); + if ( column == 2 ) { + switch ( myStatus ) { + case Waiting: + acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break; + case Processing: + acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getProcessingColor() ); break; + case Completed: + acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getCompletedColor() ); break; + case Aborted: + acg.setColor( QColorGroup::Text, ( ( ProgressView* )listView() )->getWaitingColor() ); break; + default: + break; + } + } + QListViewItem::paintCell( painter, acg, column, width, align ); +} +/*! + Progress view's constructor +*/ +ProgressView::ProgressView( QWidget* parent ) : QListView( parent ) +{ + addColumn( tr( "Product" ) ); addColumn( tr( "Type" ) ); addColumn( tr( "Status" ) ); + header()->hide(); + setSelectionMode( QListView::NoSelection ); + setSorting( -1 ); + setResizeMode( QListView::AllColumns ); + setFocusPolicy( QWidget::NoFocus ); + setColors( QColor( "red" ), QColor( "orange" ), QColor( "green" ) ); +} +/*! + Sets status colors +*/ +void ProgressView::setColors( QColor wColor, QColor pColor, QColor cColor ) { + myWaitingColor = wColor; + myProcessingColor = pColor; + myCompletedColor = cColor; + repaint(); +} +/*! + Adds product item +*/ +void ProgressView::addProduct( const QString product, const QString type, const QString script ) { + QListViewItem* lastItem = this->lastItem(); + ProgressViewItem* newItem = new ProgressViewItem( this, product, type, script ); + if ( lastItem ) + newItem->moveItem( lastItem ); +} +/*! + Finds the first item with given status +*/ +QString ProgressView::findStatus( Status status ) { + ProgressViewItem* item = ( ProgressViewItem* )firstChild(); + while( item ) { + if ( item->getStatus() == status ) + return item->getProduct(); + item = ( ProgressViewItem* )( item->nextSibling() ); + } + return QString::null; +} +/*! + Sets new status for the product item +*/ +void ProgressView::setStatus( const QString product, Status status ) { + ProgressViewItem* item = findItem( product ); + if ( item ) { + item->setStatus( status ); + repaint(); + } +} +/*! + Scrolls the view to make item visible if necessary +*/ +void ProgressView::ensureVisible( const QString product ) { + ProgressViewItem* item = findItem( product ); + if ( item ) { + ensureItemVisible( item ); + } +} +/*! + Finds the item by the product name +*/ +ProgressViewItem* ProgressView::findItem( const QString product ) { + ProgressViewItem* item = ( ProgressViewItem* )firstChild(); + while( item ) { + if ( item->getProduct() == product ) + return item; + item = ( ProgressViewItem* )( item->nextSibling() ); + } + return 0; +} +/*! + Gets the product script +*/ +QString ProgressView::getScript( const QString product ) { + ProgressViewItem* item = ( ProgressViewItem* )firstChild(); + while( item ) { + if ( item->getProduct() == product ) + return item->getScript(); + item = ( ProgressViewItem* )( item->nextSibling() ); + } + return QString::null; +} + +// ###################################### Install Wizard ########################################### + +/*! + Constructor +*/ +SALOME_InstallWizard::SALOME_InstallWizard(QString aXmlFileName) + : InstallWizard( qApp->desktop(), "SALOME_InstallWizard", false, 0 ), helpWindow( NULL ), moreMode( false ), previousPage( 0 ), exitConfirmed( false ) +{ + tmpCreated = QString::null; + // set xml file + xmlFileName = aXmlFileName; + QFont fnt = font(); fnt.setPointSize( 14 ); fnt.setBold( true ); + setTitleFont( fnt ); + +#ifdef DEBUG + cout << "Config. file : " << xmlFileName << endl; +#endif + + // xml reader + QFile xmlfile(xmlFileName); + if ( xmlfile.exists() ) { + QXmlInputSource source( &xmlfile ); + QXmlSimpleReader reader; + + StructureParser * handler = new StructureParser(); + reader.setContentHandler( handler ); + reader.parse( source ); + } + // set caption + setCaption( myCaption ); + // set icon + setIcon( QPixmap( ( const char** ) image0_data ) ); + // enable sizegrip + setSizeGripEnabled( true ); + + // create instance of class for starting shell install script + shellProcess = new QProcess(this,"shellProcess"); + + // create introduction page + setupIntroPage(); + // create products page + setupProductsPage(); + // create prestart page + setupCheckPage(); + // create progress page + setupProgressPage(); + // create readme page + setupReadmePage(); + + // common buttons + QWhatsThis::add( backButton(), tr( "Returns to the previous step of the installation procedure" ) ); + QToolTip::add ( backButton(), tr( "Returns to the previous step of the installation procedure" ) ); + QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + QWhatsThis::add( finishButton(), tr( "Finishes installation and quits program" ) ); + QToolTip::add ( finishButton(), tr( "Finishes installation and quits program" ) ); + QWhatsThis::add( cancelButton(), tr( "Cancels installation and quits program" ) ); + QToolTip::add ( cancelButton(), tr( "Cancels installation and quits program" ) ); + QWhatsThis::add( helpButton(), tr( "Displays help information window" ) ); + QToolTip::add ( helpButton(), tr( "Displays help information window" ) ); + + // common signals connections + connect( this, SIGNAL( selected( const QString& ) ), + this, SLOT( pageChanged( const QString& ) ) ); + connect( this, SIGNAL( helpClicked() ), this, SLOT( helpClicked() ) ); + // catch signals from launched script + connect(shellProcess, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout() ) ); + connect(shellProcess, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr() ) ); + connect(shellProcess, SIGNAL( processExited() ), this, SLOT( productInstalled() ) ); + connect(shellProcess, SIGNAL( wroteToStdin() ), this, SLOT( wroteToStdin() ) ); +} +/*! + Destructor +*/ +SALOME_InstallWizard::~SALOME_InstallWizard() +{ + shellProcess->kill(); // kill it for sure + QString script = "kill -9 "; + int PID = (int)shellProcess->processIdentifier(); + if ( PID > 0 ) { + script += QString::number( PID ); + script += " > /dev/null"; +#ifdef DEBUG + cout << "script: "<< script.latin1() << endl; +#endif + if ( system( script.latin1() ) ) { + } + } +} +/*! + Event filter, spies for Help window closing +*/ +bool SALOME_InstallWizard::eventFilter( QObject* object, QEvent* event ) +{ + if ( object && object == helpWindow && event->type() == QEvent::Close ) + helpWindow = NULL; + return InstallWizard::eventFilter( object, event ); +} +/*! + Close event handler +*/ +void SALOME_InstallWizard::closeEvent( QCloseEvent* ce ) +{ + if ( !exitConfirmed ) { + if ( QMessageBox::information( this, + tr( "Exit" ), + tr( "Do you want to quit Installation Wizard?" ), + tr( "Yes" ), + tr( "No" ), + QString::null, + 0, + 1 ) == 1 ) { + ce->ignore(); + } + else { + ce->accept(); + exitConfirmed = true; + reject(); + } + } +} +/*! + Creates introduction page +*/ +void SALOME_InstallWizard::setupIntroPage() +{ + // create page + introPage = new QWidget( this, "IntroPage" ); + QGridLayout* pageLayout = new QGridLayout( introPage ); + pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 ); + // create logo picture + QPixmap logo( (const char**)SALOMEPRO_Logo_xpm ); + logoLab = new QLabel( introPage ); + logoLab->setPixmap( logo ); + logoLab->setScaledContents( false ); + logoLab->setFrameStyle( QLabel::Plain | QLabel::Box ); + logoLab->setAlignment( AlignCenter ); + // create version box + QVBox* versionBox = new QVBox( introPage ); versionBox->setSpacing( 6 ); + versionBox->setFrameStyle( QGroupBox::Panel | QGroupBox::Sunken ); + QWidget* stretch1 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch1, 5 ); + versionLab = new QLabel( QString("Version %1").arg(myVersion), versionBox ); + versionLab->setAlignment( AlignCenter ); + copyrightLab = new QLabel( myCopyright, versionBox ); + copyrightLab->setAlignment( AlignCenter ); + licenseLab = new QLabel( myLicense, versionBox ); + licenseLab->setAlignment( AlignCenter ); + QWidget* stretch2 = new QWidget( versionBox ); versionBox->setStretchFactor( stretch2, 5 ); + // create info box + info = new QLabel( introPage ); + info->setText( tr( "This program will install SALOME Professional Version %1." + "

The wizard will also help you to install all products " + "which are necessary for SALOME PRO platform and setup " + "your environment.

Click Cancel button to abort " + "installation and quit. Click Next button to continue with the " + "installation program.").arg(myVersion) ); + info->setFrameStyle( QGroupBox::WinPanel | QGroupBox::Sunken ); + info->setMargin( 6 ); + info->setAlignment( WordBreak ); + info->setMinimumSize( 250, 250 ); + QPalette pal = info->palette(); + pal.setColor( QColorGroup::Background, QApplication::palette().active().base() ); + info->setPalette( pal ); + info->setLineWidth( 2 ); + // layouting + pageLayout->addWidget( logoLab, 0, 0 ); + pageLayout->addWidget( versionBox, 1, 0 ); + pageLayout->addMultiCellWidget( info, 0, 1, 1, 1 ); + pageLayout->setColStretch( 1, 5 ); + pageLayout->setRowStretch( 1, 5 ); + // adding page + addPage( introPage, tr( "Introduction" ) ); +} +/*! + Creates products page +*/ +void SALOME_InstallWizard::setupProductsPage() +{ + // create page + productsPage = new QWidget( this, "ProductsPage" ); + QGridLayout* pageLayout = new QGridLayout( productsPage ); + pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 ); + // target directory + QLabel* targetLab = new QLabel( tr( "Type the target directory:" ), productsPage ); + targetFolder = new QLineEdit( productsPage ); + QWhatsThis::add( targetFolder, tr( "Enter target root directory where products will be installed" ) ); + QToolTip::add ( targetFolder, tr( "Enter target root directory where products will be installed" ) ); + targetBtn = new QPushButton( tr( "Browse..." ), productsPage ); + QWhatsThis::add( targetBtn, tr( "Click this to browse target directory" ) ); + QToolTip::add ( targetBtn, tr( "Click this to browse target directory" ) ); + // create advanced mode widgets container + moreBox = new QWidget( productsPage ); + QGridLayout* moreBoxLayout = new QGridLayout( moreBox ); + moreBoxLayout->setMargin( 0 ); moreBoxLayout->setSpacing( 6 ); + // temp directory + QLabel* tempLab = new QLabel( tr( "Type the directory for the temporary files:" ), moreBox ); + tempFolder = new QLineEdit( moreBox ); + // tempFolder->setText( "/tmp" ); // default is /tmp directory + QWhatsThis::add( tempFolder, tr( "Enter directory where to put temporary files" ) ); + QToolTip::add ( tempFolder, tr( "Enter directory where to put temporary files" ) ); + tempBtn = new QPushButton( tr( "Browse..." ), moreBox ); + tempBtn->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + QWhatsThis::add( tempBtn, tr( "Click this to browse temporary directory" ) ); + QToolTip::add ( tempBtn, tr( "Click this to browse temporary directory" ) ); + // create products list + productsView = new MyListView( moreBox ); + productsView->setMinimumSize( 200, 180 ); + QWhatsThis::add( productsView, tr( "This view lists the products you wish to be installed" ) ); + QToolTip::add ( productsView, tr( "This view lists the products you wish to be installed" ) ); + // products info box + productsInfo = new QTextBrowser( moreBox ); + productsInfo->setMinimumSize( 270, 135 ); + QWhatsThis::add( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) ); + QToolTip::add ( productsInfo, tr( "Shows info about the product: required disk space and prerequisites" ) ); + // disk space labels + QLabel* reqLab1 = new QLabel( tr( "Total disk space required:" ), moreBox ); + QWhatsThis::add( reqLab1, tr( "Shows total disk space required for installing selected products" ) ); + QToolTip::add ( reqLab1, tr( "Shows total disk space required for installing selected products" ) ); + requiredSize = new QLabel( moreBox ); + requiredSize->setMinimumWidth( 100 ); + QWhatsThis::add( requiredSize, tr( "Shows total disk space required for installing selected products" ) ); + QToolTip::add ( requiredSize, tr( "Shows total disk space required for installing selected products" ) ); + QLabel* reqLab2 = new QLabel( tr( "Space for temporary files:" ), moreBox ); + QWhatsThis::add( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) ); + QToolTip::add ( reqLab2, tr( "Shows additional disk space which is required for temporary files" ) ); + requiredTemp = new QLabel( moreBox ); + requiredTemp->setMinimumWidth( 100 ); + QWhatsThis::add( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) ); + QToolTip::add ( requiredTemp, tr( "Shows additional disk space which is required for temporary files" ) ); + QFont fnt = reqLab1->font(); + fnt.setBold( true ); + reqLab1->setFont( fnt ); + requiredSize->setFont( fnt ); + reqLab2->setFont( fnt ); + requiredTemp->setFont( fnt ); + QGridLayout* sizeLayout = new QGridLayout; sizeLayout->setMargin( 0 ); sizeLayout->setSpacing( 6 ); + sizeLayout->addWidget( reqLab1, 0, 0 ); + sizeLayout->addWidget( requiredSize, 0, 1 ); + sizeLayout->addWidget( reqLab2, 1, 0 ); + sizeLayout->addWidget( requiredTemp, 1, 1 ); + // prerequisites checkbox + prerequisites = new QCheckBox( tr( "Auto set prerequisites products" ), moreBox ); + prerequisites->setChecked( true ); + QWhatsThis::add( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) ); + QToolTip::add ( prerequisites, tr( "Check this if you want prerequisites products to be set on automatically" ) ); + // buttons + unselectBtn = new QPushButton( tr( "&Unselect All" ), moreBox ); + QWhatsThis::add( unselectBtn, tr( "Unselects all products" ) ); + QToolTip::add ( unselectBtn, tr( "Unselects all products" ) ); + QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 ); + btnLayout->addWidget( unselectBtn ); + // layouting advancet mode widgets + moreBoxLayout->addMultiCellWidget( tempLab, 0, 0, 0, 2 ); + moreBoxLayout->addMultiCellWidget( tempFolder, 1, 1, 0, 1 ); + moreBoxLayout->addWidget ( tempBtn, 1, 2 ); + moreBoxLayout->addMultiCellWidget( productsView, 2, 5, 0, 0 ); + moreBoxLayout->addMultiCellWidget( productsInfo, 2, 2, 1, 2 ); + moreBoxLayout->addMultiCellWidget( prerequisites,3, 3, 1, 2 ); + moreBoxLayout->addMultiCellLayout( btnLayout, 4, 4, 1, 2 ); + moreBoxLayout->addMultiCellLayout( sizeLayout, 5, 5, 1, 2 ); + // button + moreBtn = new QPushButton( tr( "More..." ), productsPage ); + // layouting + pageLayout->addMultiCellWidget( targetLab, 0, 0, 0, 1 ); + pageLayout->addWidget ( targetFolder, 1, 0 ); + pageLayout->addWidget ( targetBtn, 1, 1 ); + pageLayout->addMultiCellWidget( moreBox, 2, 2, 0, 1 ); + pageLayout->addWidget ( moreBtn, 3, 1 ); + pageLayout->setRowStretch( 2, 5 ); + //pageLayout->addRowSpacing( 6, 10 ); + // xml reader + QFile xmlfile(xmlFileName); + if ( xmlfile.exists() ) { + QXmlInputSource source( &xmlfile ); + QXmlSimpleReader reader; + + StructureParser * handler = new StructureParser(); + handler->setWizard( this ); + handler->setListView(productsView); + handler->setTargetDir(targetFolder); + handler->setTempDir(tempFolder); + reader.setContentHandler( handler ); + reader.parse( source ); + } + // set first item to be selected + if ( productsView->childCount() > 0 ) { + productsView->setSelected( productsView->firstChild(), true ); + onSelectionChanged( productsView->firstChild() ); + } + // adding page + addPage( productsPage, tr( "Installation settings" ) ); + // connecting signals + connect( productsView, SIGNAL( selectionChanged( QListViewItem* ) ), + this, SLOT( onSelectionChanged( QListViewItem* ) ) ); + connect( productsView, SIGNAL( itemToggled( QCheckListItem* ) ), + this, SLOT( onItemToggled( QCheckListItem* ) ) ); + connect( unselectBtn, SIGNAL( clicked() ), this, SLOT( onProdBtn() ) ); + // connecting signals + connect( targetFolder, SIGNAL( textChanged( const QString& ) ), + this, SLOT( directoryChanged( const QString& ) ) ); + connect( targetBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) ); + connect( tempFolder, SIGNAL( textChanged( const QString& ) ), + this, SLOT( directoryChanged( const QString& ) ) ); + connect( tempBtn, SIGNAL( clicked() ), this, SLOT( browseDirectory() ) ); + connect( moreBtn, SIGNAL( clicked() ), this, SLOT( onMoreBtn() ) ); + // start on default - non-advanced - mode + moreBox->hide(); +} +/*! + Creates prestart page +*/ +void SALOME_InstallWizard::setupCheckPage() +{ + // create page + prestartPage = new QWidget( this, "PrestartPage" ); + QVBoxLayout* pageLayout = new QVBoxLayout( prestartPage ); + pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 ); + // choice text view + choices = new QTextEdit( prestartPage ); + choices->setReadOnly( true ); + choices->setTextFormat( RichText ); + choices->setUndoRedoEnabled ( false ); + QWhatsThis::add( choices, tr( "Displays information about installation settings you made" ) ); + QToolTip::add ( choices, tr( "Displays information about installation settings you made" ) ); + QPalette pal = choices->palette(); + pal.setColor( QColorGroup::Base, QApplication::palette().active().background() ); + choices->setPalette( pal ); + choices->setMinimumHeight( 10 ); + // layouting + pageLayout->addWidget( choices ); + pageLayout->setStretchFactor( choices, 5 ); + // adding page + addPage( prestartPage, tr( "Check your choice" ) ); +} +/*! + Creates progress page +*/ +void SALOME_InstallWizard::setupProgressPage() +{ + // create page + progressPage = new QWidget( this, "progressPage" ); + QGridLayout* pageLayout = new QGridLayout( progressPage ); + pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 ); + // top splitter + splitter = new QSplitter( Vertical, progressPage ); + splitter->setOpaqueResize( true ); + // the parent for the widgets + QWidget* widget = new QWidget( splitter ); + QGridLayout* layout = new QGridLayout( widget ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + // installation progress view box + installInfo = new QTextEdit( widget ); + installInfo->setReadOnly( true ); + installInfo->setTextFormat( RichText ); + installInfo->setUndoRedoEnabled ( false ); + installInfo->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); + installInfo->setMinimumSize( 100, 10 ); + QWhatsThis::add( installInfo, tr( "Displays installation process" ) ); + QToolTip::add ( installInfo, tr( "Displays installation process" ) ); + // parameters for the script + parametersLab = new QLabel( tr( "Enter your answer here:" ), widget ); + passedParams = new QLineEdit ( widget ); + QWhatsThis::add( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") ); + QToolTip::add ( passedParams, tr( "Use this field to enter answer for the running script when it is necessary") ); + // layouting + layout->addWidget( installInfo, 0, 0 ); + layout->addWidget( parametersLab, 1, 0 ); + layout->addWidget( passedParams, 2, 0 ); + layout->addRowSpacing( 3, 6 ); + // the parent for the widgets + widget = new QWidget( splitter ); + layout = new QGridLayout( widget ); + layout->setMargin( 0 ); layout->setSpacing( 6 ); + // installation results view box + QLabel* resultLab = new QLabel( tr( "Installation Status:" ), widget ); + progressView = new ProgressView( widget ); + progressView->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); + progressView->setMinimumSize( 100, 10 ); + QWhatsThis::add( progressView, tr( "Displays installation status" ) ); + QToolTip::add ( progressView, tr( "Displays installation status" ) ); + // layouting + layout->addRowSpacing( 0, 6 ); + layout->addWidget( resultLab, 1, 0 ); + layout->addWidget( progressView, 2, 0 ); + // layouting + pageLayout->addWidget( splitter, 0, 0 ); + // adding page + addPage( progressPage, tr( "Installation progress" ) ); + // connect signals + connect( passedParams, SIGNAL( returnPressed() ), this, SLOT( onReturnPressed() ) ) ; +} +/*! + Creates readme page +*/ +void SALOME_InstallWizard::setupReadmePage() +{ + // create page + readmePage = new QWidget( this, "RedamePage" ); + QVBoxLayout* pageLayout = new QVBoxLayout( readmePage ); + pageLayout->setMargin( 0 ); pageLayout->setSpacing( 6 ); + // README info text box + readme = new QTextEdit( readmePage ); + readme->setReadOnly( true ); + readme->setTextFormat( PlainText ); + readme->setUndoRedoEnabled ( false ); + QWhatsThis::add( readme, tr( "Displays README information" ) ); + QToolTip::add ( readme, tr( "Displays README information" ) ); + QPalette pal = readme->palette(); + pal.setColor( QColorGroup::Base, QApplication::palette().active().background() ); + readme->setPalette( pal ); + readme->setMinimumHeight( 10 ); + // button + runSalomeBtn = new QPushButton( tr( "Launch SALOME" ), readmePage ); + QWhatsThis::add( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) ); + QToolTip::add ( runSalomeBtn, tr( "Click this button to run SALOME desktop" ) ); + QHBoxLayout* hLayout = new QHBoxLayout; + hLayout->addWidget( runSalomeBtn ); hLayout->addStretch(); + // layouting + pageLayout->addWidget( readme ); + pageLayout->setStretchFactor( readme, 5 ); + pageLayout->addLayout( hLayout ); + // connecting signals + connect( runSalomeBtn, SIGNAL( clicked() ), this, SLOT( onLaunchSalome() ) ); + // loading README file + QString readmeFile = QDir::currentDirPath() + "/README"; + QString text; + if ( readFile( readmeFile, text ) ) + readme->setText( text ); + else + readme->setText( "README file has not been found" ); + // adding page + addPage( readmePage, tr( "Finish installation" ) ); +} +/*! + Displays choice info +*/ +void SALOME_InstallWizard::showChoiceInfo() +{ + choices->clear(); + + long totSize, tempSize; + checkSize( &totSize, &tempSize ); + int nbProd = 0; + QString text; + + if ( !xmlFileName.isEmpty() ) { + text += tr( "Configuration file: " ) + xmlFileName + "
"; + text += "
"; + } + if ( !myOS.isEmpty() ) { + text += tr( "Target platform: " ) + myOS + "
"; + text += "
"; + } + text += tr( "Products to be used:
    " ); + QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() ); + while( item ) { + if ( productsMap.contains( item ) ) { + if ( item->childCount() > 0 ) { + // Neither "SALOME binaries", no "SALOME sources" + if ( productsView->isNative( item ) ) { + text += "
  • " + item->text() + " as native
    "; + nbProd++; + } + } + } + item = (QCheckListItem*)( item->nextSibling() ); + } + if ( nbProd == 0 ) { + text += "
  • none
    "; + } + text += "
"; + text += tr( "Products to be installed:
    " ); + item = (QCheckListItem*)( productsView->firstChild() ); + while( item ) { + if ( productsMap.contains( item ) ) { + if ( item->childCount() > 0 ) { + // Neither "SALOME binaries", no "SALOME sources" + if ( productsView->isBinaries( item ) ) { + text += "
  • " + item->text() + " as binaries
    "; + nbProd++; + } + else if ( productsView->isSources( item ) ) { + text+= "
  • " + item->text() + " as sources
    "; + nbProd++; + } + } + else if ( item->isOn() ) { + // "SALOME binaries" or "SALOME sources" + text+= "
  • " + item->text() + "
    "; + nbProd++; + } + } + item = (QCheckListItem*)( item->nextSibling() ); + } + if ( nbProd == 0 ) { + text += "
  • none
    "; + } + text += "
"; + text += "Total disk space required: " + QString::number( totSize ) + " Kb
" ; + text += "Space for temporary files required: " + QString::number( tempSize ) + " Kb
" ; + text += "
"; + text += "Target directory: " + QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) + "
"; + // VSR: Temporary folder is used always now and it is not necessary to disable it --> + // if ( tempSize > 0 ) + // VSR: <---------------------------------------------------------------------------- + text += "Temp directory: " + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + "
"; + text += "
"; + choices->setText( text ); +} +/*! + Checks if string contains spaces; used to check directory paths [ static ] +*/ +static bool hasSpace( const QString& dir ) +{ + for ( int i = 0; i < (int)dir.length(); i++ ) { + if ( dir[ i ].isSpace() ) + return true; + } + return false; +} +/*! + Validates page when button is clicked +*/ +bool SALOME_InstallWizard::acceptData( const QString& pageTitle ) +{ + QString tmpstr; + QWidget* aPage = InstallWizard::page( pageTitle ); + if ( aPage == productsPage ) { + // ########## check if any products are selected to be installed + long totSize, tempSize; + checkSize( &totSize, &tempSize ); + if ( totSize <= 0 ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "Select one or more products to install" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + // ########## check target and temp directories (existence and available disk space) + // get dirs + QString targetDir = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ); + QString tempDir = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ); + // directories should differ +// if (!targetDir.isEmpty() && tempDir == targetDir) { +// QMessageBox::warning( this, +// tr( "Warning" ), +// tr( "Target and temporary directories must be different"), +// QMessageBox::Ok, +// QMessageBox::NoButton, +// QMessageBox::NoButton ); +// return false; +// } + // check target directory + if ( targetDir.isEmpty() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "Please, enter valid target directory path" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + QFileInfo fi( QDir::cleanDirPath( targetDir ) ); + if ( !fi.exists() ) { + bool toCreate = + QMessageBox::warning( this, + tr( "Warning" ), + tr( "The directory %1 doesn't exist.\n" + "Do you want to create directory?" ).arg( fi.absFilePath() ), + QMessageBox::Yes, + QMessageBox::No, + QMessageBox::NoButton ) == QMessageBox::Yes; + if ( !toCreate) + return false; + if ( !makeDir( fi.absFilePath(), tmpstr ) ) { + QMessageBox::critical( this, + tr( "Error" ), + tr( "Can't create the directory\n%1").arg( fi.absFilePath() ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + } + if ( !fi.isDir() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "The directory %1 is not a directory.\n" + "Please, enter valid target directory path" ).arg( fi.absFilePath() ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + if ( !fi.isWritable() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "The directory %1 is not writeable.\n" + "Please, enter valid target directory path or change permissions" ).arg( fi.absFilePath() ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + if ( hasSpace( fi.absFilePath() ) && + QMessageBox::warning( this, + tr( "Warning" ), + tr( "The target directory contains space symbols.\n" + "This may cause problems with compiling or installing of products.\n\n" + "Do you want to continue?"), + QMessageBox::Yes, + QMessageBox::No, + QMessageBox::NoButton ) == QMessageBox::No ) { + return false; + } + QString binDir = "./Products/BINARIES"; + if ( !myOS.isEmpty() ) + binDir += "/" + myOS; + QFileInfo fib( QDir::cleanDirPath( binDir ) ); + if ( !fib.exists() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "The directory %1 doesn't exist.\n" + "This directory must contain binaries archives." ).arg( fib.absFilePath() )); + } + // run script that checks available disk space for installing of products // returns 1 in case of error + QString script = "./config_files/checkSize.sh '"; + script += fi.absFilePath(); + script += "' "; + script += QString( "%1" ).arg( totSize ); +#ifdef DEBUG + cout << "script = " << script << endl; +#endif + if ( system( script ) ) { + QMessageBox::critical( this, + tr( "Out of space" ), + tr( "There is not available disk space for installing of selected products" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + // check temp directory + if ( tempDir.isEmpty() ) { + if ( moreMode ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( "Please, enter valid temp directory path" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + else { + tempFolder->setText( "/tmp" ); + } + } + QFileInfo fit( QDir::cleanDirPath( tempDir ) ); + if ( !makeDir( fit.absFilePath() + TEMPDIRNAME, tmpCreated ) ) { + QMessageBox::critical( this, + tr( "Error" ), + tr( "Can't use temporary directory.\nCheck permissions for the %1 directory.").arg( fit.absFilePath() ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + // run script that check available disk space for temporary files + // returns 1 in case of error + QString tscript = "./config_files/checkSize.sh '"; + tscript += fit.absFilePath(); + tscript += "' "; + tscript += QString( "%1" ).arg( tempSize ); +#ifdef DEBUG + cout << "script = " << tscript << endl; +#endif + if ( system( tscript ) ) { + QMessageBox::critical( this, + tr( "Out of space" ), + tr( "There is not available disk space for the temporary files" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } +// VSR: <------------------------------------------------------------------------------ + // ########## check native products + QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() ); + QStringList natives; + while( item ) { + if ( productsMap.contains( item ) ) { + if ( item->childCount() > 0 ) { + if ( !productsView->isNone( item ) ) { + if ( item->text(2).isEmpty() || item->text(2).isNull() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( QString("You don't have a defined script for %1").arg(item->text(0))), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + productsView->setNone( item ); + return false; + } else { + QFileInfo fi( QString("./config_files/") + item->text(2) ); + if ( !fi.exists() ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( QString("%1 required for %2 doesn't exist.").arg("./config_files/" + item->text(2)).arg(item->text(0))), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + productsView->setNone( item ); + return false; + } + } + } + // collect native products + if ( productsView->isNative( item ) ) { + if ( natives.find( item->text(0) ) == natives.end() ) + natives.append( item->text(0) ); + } + else if ( productsView->isBinaries( item ) || productsView->isSources( item ) ) { + QStringList dependOn = productsMap[ item ].getDependancies(); + for ( int i = 0; i < (int)dependOn.count(); i++ ) { + QCheckListItem* depitem = findItem( dependOn[ i ] ); + if ( depitem ) { + if ( productsView->isNative( depitem ) && natives.find( depitem->text(0) ) == natives.end() ) + natives.append( depitem->text(0) ); + } + else { + QMessageBox::warning( this, + tr( "Warning" ), + tr( QString("%1 is required for %2 %3 installation.\n" + "Please, add this product in config.xml file.").arg(dependOn[ i ]).arg(item->text(0)).arg(item->text(1))), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + } + } + } + } + item = (QCheckListItem*)( item->nextSibling() ); + } + QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME; + QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ); + for ( unsigned i = 0; i < natives.count(); i++ ) { + item = findItem( natives[ i ] ); + if ( item ) { + QString script = "cd ./config_files/;" + item->text(2) + " try_native " + + QFileInfo( tmpFolder ).absFilePath() + " " + QDir::currentDirPath() + "/Products " + QFileInfo( tgtFolder ).absFilePath() + " " + + QUOTE(DefineDependeces(productsMap)) + " " + item->text(0); + +#ifdef DEBUG + cout << "1. Script : " << script << endl; +#endif + if ( system( script ) ) { + QMessageBox::warning( this, + tr( "Warning" ), + tr( QString("You don't have native %1 %2 installed").arg(item->text(0)).arg(item->text(1)) ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + productsView->setNone( item ); + return false; + } + } + else { + QMessageBox::warning( this, + tr( "Warning" ), + tr( QString("%The product %1 %2 required for installation.\n" + "Please, add this product in config.xml file.").arg(item->text(0)).arg(item->text(1)) ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + return false; + } + } + } + return InstallWizard::acceptData( pageTitle ); +} +/*! + Calculates disk space required for the installation +*/ +void SALOME_InstallWizard::checkSize( long* totSize, long* tempSize ) +{ + long tots = 0, temps = 0; + int nativeProd = 0; + + MapProducts::Iterator mapIter; + for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) { + QCheckListItem* item = mapIter.key(); + Dependancies dep = mapIter.data(); + if ( productsView->isBinaries( item ) ) { + tots += dep.getSize(); + } + else if ( productsView->isSources( item ) ) { + tots += dep.getSize(true); + temps = max( temps, dep.getTempSize() ); + } + else if ( productsView->isNative( item ) ) { + nativeProd++; + } + } + + requiredSize->setText( QString::number( tots ) + " Kb"); + requiredTemp->setText( QString::number( temps ) + " Kb"); + if ( totSize ) + *totSize = tots; + if ( tempSize ) + *tempSize = temps; + setNextEnabled( productsPage, (tots > 0) || (nativeProd > 0)); +} +/*! + Enabled/disables "Next" button for the directory page +*/ +void SALOME_InstallWizard::checkDirs() +{ + // VSR: Temporary folder is used always now and it is not necessary to disable it --> + // get disk space required + //long totSize, tempSize; + //checkSize( &totSize, &tempSize ); + // enable/disable temp directory controls + // tempFolder->setEnabled( tempSize > 0 ); + // tempBtn->setEnabled( tempSize > 0 ); + // VSR: <---------------------------------------------------------------------------- + // get dirs + QString targetDir = targetFolder->text().stripWhiteSpace(); + // enable/disable "Next" button + setNextEnabled( productsPage, !targetDir.isEmpty() ); +} +/*! + Sets the product and all products this one depends on to be checked ( recursively ) +*/ +void SALOME_InstallWizard::setProductOn( QCheckListItem* item, int install ) +{ + if ( !productsMap.contains( item ) ) + return; + if ( productsView->isNone( item ) ) { + if ( install == 1 ) + productsView->setBinaries( item ); + else if ( install == 0 ) + productsView->setSources( item ); + else if ( install == 2 ) + productsView->setNative( item ); + } + // get all prerequisites + QStringList dependOn = productsMap[ item ].getDependancies(); + for ( int i = 0; i < (int)dependOn.count(); i++ ) { + MapProducts::Iterator itProd; + for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) { + if ( itProd.data().getName() == dependOn[ i ] ) + setProductOn( itProd.key(), 1 ); + } + } +} +/*! + Runs installation script +*/ +void SALOME_InstallWizard::launchScript() +{ + // try to find product being processed now + QString prodProc = progressView->findStatus( Processing ); + if ( !prodProc.isNull() ) { +#ifdef DEBUG + cout << "Found : " << prodProc.latin1() << endl; +#endif + + // if found - set status to "completed" + progressView->setStatus( prodProc, Completed ); + // ... and call this method again + launchScript(); + return; + } + // else try to find next product which is not processed yet + prodProc = progressView->findStatus( Waiting ); + if ( !prodProc.isNull() ) { +#ifdef DEBUG + cout << "Found : " << prodProc.latin1() << endl; +#endif + // if found - set status to "processed" and run script + progressView->setStatus( prodProc, Processing ); + progressView->ensureVisible( prodProc ); + + QCheckListItem* item = findItem( prodProc ); + Dependancies dep = productsMap[ item ]; + // fill in script parameters + shellProcess->clearArguments(); + // ... script name + shellProcess->setWorkingDirectory( QDir::cleanDirPath( QFileInfo( "./config_files/" ).absFilePath() ) ); + shellProcess->addArgument( item->text(2) ); + + // ... temp folder + QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME; + if( !tempFolder->isEnabled() ) + tmpFolder = "/tmp"; + + // ... binaries ? + if ( productsView->isBinaries( item ) ) { + shellProcess->addArgument( "install_binary" ); + shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() ); + QString binDir = QDir::currentDirPath() + "/Products/BINARIES"; + if ( !myOS.isEmpty() ) + binDir += "/" + myOS; + shellProcess->addArgument( binDir ); + } + // ... sources ? + else if ( productsView->isSources( item ) ) { + shellProcess->addArgument( "install_source" ); + shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() ); + shellProcess->addArgument( QDir::currentDirPath() + "/Products/SOURCES" ); + } + // ... native ? + else if ( productsView->isNative( item ) ) { + shellProcess->addArgument( "try_native" ); + shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() ); + shellProcess->addArgument( QDir::currentDirPath() + "/Products" ); + } + // ... not install : try to find preinstalled + else { + shellProcess->addArgument( "try_preinstalled" ); + shellProcess->addArgument( QFileInfo( tmpFolder ).absFilePath() ); + shellProcess->addArgument( QDir::currentDirPath() + "/Products" ); + } + // ... target folder + QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ); + shellProcess->addArgument( QFileInfo( tgtFolder ).absFilePath() ); + + + QString depproducts = DefineDependeces(productsMap); +#ifdef DEBUG + cout << "Dependancies"<< depproducts.latin1() << endl; +#endif + + shellProcess->addArgument( depproducts ); + // ... product name - currently instaled product + shellProcess->addArgument( item->text(0) ); + + // run script + if ( !shellProcess->start() ) { + // error handling can be here +#ifdef DEBUG + cout << "error" << endl; +#endif + } + return; + } +#ifdef DEBUG + cout << "All products have been installed successfully" << endl; +#endif + // all products installed successfully + // button + nextButton()->setEnabled( true ); + nextButton()->setText( tr( "&Next >" ) ); + QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + nextButton()->disconnect(); + connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) ); + // button + backButton()->setEnabled( true ); + // script parameters + passedParams->clear(); + passedParams->setEnabled( false ); + QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f ); + if ( isMinimized() ) + showNormal(); + raise(); +} +/*! + button slot +*/ +void SALOME_InstallWizard::onMoreBtn() +{ + if ( moreMode ) { + moreBox->hide(); + moreBtn->setText( tr( "More..." ) ); + } + else { + moreBox->show(); + moreBtn->setText( tr( "Less..." ) ); + } + qApp->processEvents(); + moreMode = !moreMode; + InstallWizard::layOut(); + qApp->processEvents(); + if ( !isMaximized() ) { + //setGeometry( geometry().x(), geometry().y(), geometry().width(), 0 ); + resize( geometry().width(), 0 ); + qApp->processEvents(); + } +} +/*! + button slot +*/ +void SALOME_InstallWizard::onLaunchSalome() +{ + QCheckListItem* item = 0; + if ( ( item = findItem("SalomePro-Bin" ) ) ) { + QFileInfo fi( targetFolder->text() + "/SalomePro-" + item->text(1) + "/salome" ); + if ( fi.exists() ) { + QString script; + script += "cd " + targetFolder->text() + "/SalomePro-" + item->text(1) + "; "; + script += "source salome.csh; "; + //script += "cd bin; "; + //script += "runSalome > /dev/null"; + script += "salome -g > /dev/null"; + script = "(csh -c '" + script + "')"; +#ifdef DEBUG + cout << script.latin1() << endl; +#endif + if ( system( script.latin1() ) ){ + QMessageBox::warning( this, + tr( "Error" ), + tr( "Can't launch SALOME" ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + } + return; + } + } + QMessageBox::warning( this, + tr( "Error" ), + tr( "You don't have SALOME binaries installed in the %1 directory!" ).arg( targetFolder->text() ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); +} +/*! + Searches product listview item with given symbolic name +*/ +QCheckListItem* SALOME_InstallWizard::findItem( const QString& sName ) +{ + MapProducts::Iterator mapIter; + for ( mapIter = productsMap.begin(); mapIter != productsMap.end(); ++mapIter ) { + if ( mapIter.data().getName() == sName ) + return mapIter.key(); + } + return 0; +} +/*! + Sets progress state to Aborted +*/ +void SALOME_InstallWizard::abort() +{ + QString prod = progressView->findStatus( Processing ); + while ( !prod.isNull() ) { + progressView->setStatus( prod, Aborted ); + prod = progressView->findStatus( Processing ); + } + prod = progressView->findStatus( Waiting ); + while ( !prod.isNull() ) { + progressView->setStatus( prod, Aborted ); + prod = progressView->findStatus( Waiting ); + } +} +/*! + Reject slot, clears temporary directory and closes application +*/ +void SALOME_InstallWizard::reject() +{ +#ifdef DEBUG + cout << "REJECTED" << endl; +#endif + if ( !exitConfirmed ) { + if ( QMessageBox::information( this, + tr( "Exit" ), + tr( "Do you want to quit Installation Wizard?" ), + tr( "Yes" ), + tr( "No" ), + QString::null, + 0, + 1 ) == 1 ) { + return; + } + exitConfirmed = true; + } + clean(); + InstallWizard::reject(); +} +/*! + Accept slot, clears temporary directory and closes application +*/ +void SALOME_InstallWizard::accept() +{ +#ifdef DEBUG + cout << "ACCEPTED" << endl; +#endif + clean(); + InstallWizard::accept(); +} +/*! + Clears and removes temporary directory +*/ +void SALOME_InstallWizard::clean() +{ + // VSR: first remove temporary files + QString script = "cd ./config_files/; remove_tmp.sh '"; + script += tempFolder->text().stripWhiteSpace(); + script += "' "; + script += QUOTE(DefineDependeces(productsMap)); + script += " > /dev/null"; +#ifdef DEBUG + cout << "script = " << script << endl; +#endif + if ( system( script.latin1() ) ) { + } + // VSR: then try to remove created temporary directory + //script = "rm -rf " + QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME; + if ( !tmpCreated.isNull() ) { + script = "rm -rf " + tmpCreated; + script += " > /dev/null"; + if ( system( script.latin1() ) ) { + } +#ifdef DEBUG + cout << "script = " << script << endl; +#endif + } +} +/*! + Called when user moves from page to page +*/ +void SALOME_InstallWizard::pageChanged( const QString & mytitle) +{ + nextButton()->setText( tr( "&Next >" ) ); + QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + nextButton()->disconnect(); + connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) ); + cancelButton()->disconnect(); + connect( cancelButton(), SIGNAL( clicked()), this, SLOT( reject() ) ); + + QWidget* aPage = InstallWizard::page( mytitle ); + if ( !aPage ) + return; + setCaption( tr( myCaption ) + tr( " - Step ") + + QString::number( this->indexOf( aPage )+1 ) + + " of " + + QString::number( this->pageCount() ) ); + if ( aPage == productsPage ) { + // products page + checkSize(); + checkDirs(); + } + else if ( aPage == prestartPage ) { + // prestart page + showChoiceInfo(); + } + else if ( aPage == progressPage ) { + if ( previousPage == prestartPage ) { + // progress page + progressView->clear(); + installInfo->clear(); + passedParams->clear(); + passedParams->setEnabled( false ); + QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f ); + nextButton()->setText( tr("&Start") ); + QWhatsThis::add( nextButton(), tr( "Starts installation process" ) ); + QToolTip::add ( nextButton(), tr( "Starts installation process" ) ); + // reconnect Next button - to use it as Start button + nextButton()->disconnect(); + connect( nextButton(), SIGNAL( clicked() ), this, SLOT( onStart() ) ); + nextButton()->setEnabled( true ); + // reconnect Cancel button to terminate process + cancelButton()->disconnect(); + connect( cancelButton(), SIGNAL( clicked() ), this, SLOT( tryTerminate() ) ); + } + } + else if ( aPage == readmePage ) { + QCheckListItem* item = 0; + runSalomeBtn->setEnabled( ( item = findItem( "SalomePro-Bin" ) ) && + QFileInfo( targetFolder->text() + "/SalomePro-" + item->text(1) + "/salome" ).exists() ); + finishButton()->setEnabled( true ); + } + previousPage = aPage; +#ifdef DEBUG + cout << "previousPage = " << previousPage << endl; +#endif +} +/*! + Shows help window +*/ +void SALOME_InstallWizard::helpClicked() +{ + if ( helpWindow == NULL ) { + helpWindow = HelpWindow::openHelp(); + if ( helpWindow ) { + helpWindow->show(); + helpWindow->installEventFilter( this ); + } + else { + QMessageBox::warning( this, + tr( "Help file not found" ), + tr( "Sorry, help is unavailable" ) ); + } + } + else { + helpWindow->raise(); + helpWindow->setActiveWindow(); + } +} +/*! + Shows directory selection dialog +*/ +void SALOME_InstallWizard::browseDirectory() +{ + const QObject* theSender = sender(); + QLineEdit* theFolder; + if ( theSender == targetBtn ) + theFolder = targetFolder; + else if (theSender == tempBtn) + theFolder = tempFolder; + else + return; + QString typedDir = QFileDialog::getExistingDirectory( QDir::cleanDirPath( theFolder->text().stripWhiteSpace() ), this ); + if ( !typedDir.isNull() ) { + theFolder->setText( typedDir ); + theFolder->end( false ); + } + checkDirs(); +} +/*! + Called when directory path (target or temp) is changed +*/ +void SALOME_InstallWizard::directoryChanged( const QString& /*text*/ ) +{ + checkDirs(); +} +/*! + button's slot - runs installation +*/ +void SALOME_InstallWizard::onStart() +{ + // clear list of products to install ... + toInstall.clear(); + // ... and fill it for new process + QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() ); + while( item ) { +// if ( productsView->isBinaries( item ) || productsView->isSources( item ) || productsView->isNative( item ) ) { + if ( productsMap.contains( item ) ) + toInstall.append( productsMap[item].getName() ); +// } + item = (QCheckListItem*)( item->nextSibling() ); + } + // if something at all is selected + if ( !toInstall.isEmpty() ) { + // disable button + nextButton()->setEnabled( false ); + // disable button + backButton()->setEnabled ( false ); + // enable script parameters line edit + // VSR commented: 18/09/03: passedParams->setEnabled( true ); + // VSR commented: 18/09/03: passedParams->setFocus(); + // set status for all products + for ( int i = 0; i < (int)toInstall.count(); i++ ) { + item = findItem( toInstall[ i ] ); + QString type = ""; + if ( productsView->isBinaries( item ) ) + type = "binaries"; + else if ( productsView->isSources( item ) ) + type = "sources"; + else if ( productsView->isNative( item ) ) + type = "native"; + else + type = "not install"; + progressView->addProduct( item->text(0), type, item->text(2) ); + } + // launch install script + launchScript(); + } +} +/*! + Called when users tries to pass parameters for the script +*/ +void SALOME_InstallWizard::onReturnPressed() +{ + QString txt = passedParams->text(); + installInfo->append( txt ); + txt += "\n"; + shellProcess->writeToStdin( txt ); + passedParams->clear(); + progressView->setFocus(); + passedParams->setEnabled( false ); + QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f ); +} +/*! + Callback function - as response for the script finishing +*/ +void SALOME_InstallWizard::productInstalled( ) +{ +#ifdef DEBUG + cout << "process exited" << endl; +#endif + if ( shellProcess->normalExit() ) { +#ifdef DEBUG + cout << "...normal exit" << endl; +#endif + // normal exit - try to proceed installation further + launchScript(); + } + else { +#ifdef DEBUG + cout << "...abnormal exit" << endl; +#endif + // installation aborted + abort(); + // clear script passed parameters lineedit + passedParams->clear(); + passedParams->setEnabled( false ); + QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f ); + // enable button + nextButton()->setEnabled( true ); + nextButton()->setText( tr( "&Next >" ) ); + QWhatsThis::add( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + QToolTip::add ( nextButton(), tr( "Moves to the next step of the installation procedure" ) ); + nextButton()->disconnect(); + connect( nextButton(), SIGNAL( clicked() ), this, SLOT( next() ) ); + // enable button + backButton()->setEnabled( true ); + } +} +/*! + Slot, called when button is clicked during installation script running +*/ +void SALOME_InstallWizard::tryTerminate() +{ + if ( shellProcess->isRunning() ) { + if ( QMessageBox::information( this, + tr( "Exit" ), + tr( "Do you want to quit Installation Wizard?" ), + tr( "Yes" ), + tr( "No" ), + QString::null, + 0, + 1 ) == 1 ) { + return; + } + exitConfirmed = true; + // if process still running try to terminate it first + shellProcess->tryTerminate(); + abort(); + //QTimer::singleShot( 3000, this, SLOT( onCancel() ) ); + connect( shellProcess, SIGNAL( processExited() ), this, SLOT( onCancel() ) ); + } + else { + // else just quit install wizard + reject(); + } +} +/*! + Kills installation process and quits application +*/ +void SALOME_InstallWizard::onCancel() +{ + shellProcess->kill(); + reject(); +} +/*! + Called when selection is changed in the products list view +*/ +void SALOME_InstallWizard::onSelectionChanged( QListViewItem* item ) +{ + productsInfo->clear(); + if ( item->parent() ) + item = item->parent(); + QCheckListItem* aItem = (QCheckListItem*)item; + if ( !productsMap.contains( aItem ) ) + return; + Dependancies dep = productsMap[ aItem ]; + QString text = "" + aItem->text(0) + ""; + text += "

"; + if ( !aItem->text(1).stripWhiteSpace().isEmpty() ) + text += "version: " + aItem->text(1) + "
"; + if ( productsView->isBinaries( aItem ) ) + text += "Disk space required: " + QString::number( dep.getSize() ) + " Kb"; + else + text += "Disk space required: " + QString::number( dep.getSize(true) ) + " Kb"; + + text += "
"; + text += "Disk space for tmp files required: " + QString::number( dep.getTempSize() ) + " Kb"; + text += "

"; + QString req =( dep.getDependancies().count() > 0 ? dep.getDependancies().join(", ") : QString( "none" ) ); +// if ( item->depth() == 0 && item->childCount() == 0 ) { +// if ( dep.getName() == "salomedoc" ) +// req = "none"; // SALOME docs +// else +// req = "all products"; // SALOME sources and binaries +// } + text += "Prerequisites: " + req; + productsInfo->setText( text ); +} +/*! + Called when user checks/unchecks any product item + Recursively sets all prerequisites and updates "Next" button state +*/ +void SALOME_InstallWizard::onItemToggled( QCheckListItem* item ) +{ + if ( prerequisites->isChecked() ) { + if ( item->parent() ) + item = (QCheckListItem*)( item->parent() ); + if ( productsMap.contains( item ) ) { + productsView->blockSignals( true ); + if ( productsView->isNative( item ) ) + setProductOn( item, 2 ); + else if ( productsView->isBinaries( item ) ) + setProductOn( item, 1 ); + else if ( productsView->isSources( item ) ) + setProductOn( item, 0 ); + productsView->blockSignals( false ); + } + } + checkSize(); +} +/*! + This slot is called when user clicks one of , buttons ( products page ) +*/ +void SALOME_InstallWizard::onProdBtn() +{ + const QObject* snd = sender(); + productsView->blockSignals( true ); + if ( snd == unselectBtn ) { + QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() ); + while( item ) { + productsView->setNone( item ); + item = (QCheckListItem*)( item->nextSibling() ); + } + } + productsView->blockSignals( false ); + checkSize(); +} +/*! + QProcess slot: -->something was written to stdin +*/ +void SALOME_InstallWizard::wroteToStdin( ) +{ +#ifdef DEBUG + cout << "Something was sent to stdin" << endl; +#endif +} +/*! + QProcess slot: -->something was written to stdout +*/ +void SALOME_InstallWizard::readFromStdout( ) +{ +#ifdef DEBUG + cout << "Something was sent to stdout" << endl; +#endif + while ( shellProcess->canReadLineStdout() ) { + installInfo->append( QString( shellProcess->readLineStdout() ) ); + installInfo->scrollToBottom(); + } + QString str( shellProcess->readStdout() ); + if ( !str.isEmpty() ) { + installInfo->append( str ); + installInfo->scrollToBottom(); + } +} +/*! + QProcess slot: -->something was written to stderr +*/ +void SALOME_InstallWizard::readFromStderr( ) +{ +#ifdef DEBUG + cout << "Something was sent to stderr" << endl; +#endif + while ( shellProcess->canReadLineStderr() ) { + installInfo->append( QString( shellProcess->readLineStderr() ) ); + installInfo->scrollToBottom(); + } + QString str( shellProcess->readStderr() ); + if ( !str.isEmpty() ) { + installInfo->append( str ); + installInfo->scrollToBottom(); + } + passedParams->setEnabled( true ); + passedParams->setFocus(); + QFont f = parametersLab->font(); f.setBold( true ); parametersLab->setFont( f ); +} +/*! + Sets dependancies for the product item +*/ +void SALOME_InstallWizard::setDependancies( QCheckListItem* item, Dependancies dep) +{ + productsMap[item] = dep; +} +/*! + Polishing of the widget - to set right initial size +*/ +void SALOME_InstallWizard::polish() +{ + resize( 0, 0 ); + InstallWizard::polish(); +} + +// ###################################### Structure Parser ########################################### + +/*! + Constructor +*/ +StructureParser::StructureParser() + : QXmlDefaultHandler() +{ + wizard = NULL; + tree = NULL; +} +/*! + Sets install wizard's main window +*/ +void StructureParser::setWizard( SALOME_InstallWizard* awizard ) +{ + wizard = awizard; +} +/*! + Sets products list view +*/ +void StructureParser::setListView( MyListView * t ) +{ + tree = t; +} +/*! + Sets temp directory widget +*/ +void StructureParser::setTempDir( QLineEdit * dir ) +{ + tempdir = dir; +} +/*! + Sets target directory widget +*/ +void StructureParser::setTargetDir( QLineEdit * dir ) +{ + targetdir = dir; +} +/*! + Begins parsing of the xml dom-element +*/ +bool StructureParser::startElement( const QString& , + const QString& , + const QString& qName, + const QXmlAttributes& attributes) +{ +#ifdef DEBUG + cout << qName << endl; + cout << attributes.length() << endl; +#endif + QCheckListItem * element; + if (( qName == "config" ) && ( attributes.length() > 0 ) ) { + if ( attributes.value( "version" ) ) + myVersion = attributes.value( "version" ).stripWhiteSpace(); + if ( attributes.value( "caption" ) && !myCaption.isEmpty() ) + myCaption = QString(attributes.value( "caption" )).arg(myVersion).stripWhiteSpace(); + if ( attributes.value( "copyright" ) ) + myCopyright = attributes.value( "copyright" ).stripWhiteSpace(); + if ( attributes.value( "license" ) ) + myLicense = attributes.value( "license" ).stripWhiteSpace(); + if ( attributes.value( "os" ) ) + myOS = attributes.value( "os" ).stripWhiteSpace(); + +#ifdef DEBUG + cout << myCaption << endl; + cout << myVersion << endl; + cout << myCopyright << endl; + cout << myLicense << endl; +#endif + } else if (( qName == "product" ) && ( attributes.length() > 0 ) && tree && wizard ) { + if (attributes.value("disable") == "true" ) + return true; + + QString install = attributes.value( "install" ); + QStringList supported = QStringList::split(",", attributes.value("supported") ); + QString script = attributes.value( "script" ); + element = tree->addItem( attributes.value("name"), attributes.value("version"), install, supported, script ); + if ( attributes.value("dependancies") == "" ) { + QStringList diskspace = QStringList::split(",",attributes.value("installdiskspace")); + if (diskspace.count() == 2) + wizard->setDependancies( element, + Dependancies( attributes.value("name"), QStringList(), + diskspace[0].toInt(), + diskspace[1].toInt(), + attributes.value("temporarydiskspace").toInt()) ); + else + wizard->setDependancies( element, + Dependancies( attributes.value("name"), QStringList(), + diskspace[0].toInt(), + diskspace[0].toInt(), + attributes.value("temporarydiskspace").toInt()) ); + + } else { + QStringList diskspace = QStringList::split(",",attributes.value("installdiskspace")); + if (diskspace.count() == 2) + wizard->setDependancies( element, + Dependancies( attributes.value("name"), + QStringList::split(",", attributes.value("dependancies") ), + diskspace[0].toInt(), + diskspace[1].toInt(), + attributes.value("temporarydiskspace").toInt()) ); + else + wizard->setDependancies( element, + Dependancies( attributes.value("name"), + QStringList::split(",", attributes.value("dependancies") ), + diskspace[0].toInt(), + diskspace[0].toInt(), + attributes.value("temporarydiskspace").toInt()) ); + } + } else if (( qName == "path" ) && ( attributes.length() > 0 ) && wizard ) { + targetdir->setText( attributes.value("targetdir") ); + + if ( attributes.value("tempdir") == "" ) + tempdir->setText( "/tmp" ); + else + tempdir->setText( attributes.value("tempdir") ); + } + return true; +} +/*! + Finishes parsing of the xml dom-element +*/ +bool StructureParser::endElement( const QString&, const QString&, + const QString& ) +{ + return true; +} + +// ###################################### Main ########################################### + +/*! + Program starts here +*/ +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + QString xmlFileName( argc == 2 ? argv[1] : "config.xml" ); + + int result = -1; + QFile xmlfile(xmlFileName); + if ( xmlfile.exists() ) { + SALOME_InstallWizard wizard(xmlFileName); + a.setMainWidget( &wizard ); + wizard.show(); + result = a.exec(); + } + else { + QMessageBox::critical( 0, + QObject::tr( "Error" ), + QObject::tr( "Can't open config file:\n%1\n\nQuitting...").arg( xmlFileName ), + QMessageBox::Ok, + QMessageBox::NoButton, + QMessageBox::NoButton ); + } + return result; +} + -- 2.39.2