Salome HOME
Move icons to the cxx file
[tools/install.git] / src / SALOME_InstallWizard.cxx
index 9a83803f0d64b2763397267427b56b4b14491755..ecc0a901f762b66de73df4561eefe1e8e18a26e3 100644 (file)
@@ -36,6 +36,7 @@
 #include <qfile.h>
 #include <qthread.h>
 #include <qwaitcondition.h>
+#include <qmutex.h>
 
 #ifdef WNT
 #include <iostream.h>
@@ -58,7 +59,8 @@ QString tmpDirName() { return QString(  "/INSTALLWORK" ) + QString::number( getp
  *  Class for executing systen commands
  */
 // ================================================================
-QWaitCondition myWC;
+static QMutex myMutex(false);
+static QWaitCondition myWC;
 class QProcessThread: public QThread
 {
   typedef QPtrList<QCheckListItem> ItemList;
@@ -81,9 +83,11 @@ public:
       QCheckListItem* item = myItems.first();
       myCommands.pop_front();
       myItems.removeFirst();
+      myMutex.lock();
       SALOME_InstallWizard::postValidateEvent( myWizard, result, (void*)item );
       if ( hasCommands() )
-       myWC.wait();
+       myWC.wait(&myMutex);
+      myMutex.unlock();
     };
   }
 
@@ -266,6 +270,19 @@ static bool hasSpace( const QString& dir )
   return false;
 }
 
+// ================================================================
+/*!
+ *  QMyCheckBox class : custom check box
+ *  The only goal is to give access to the protected setState() method
+ */
+// ================================================================
+class QMyCheckBox: public QCheckBox
+{
+public:
+  QMyCheckBox( const QString& text, QWidget* parent, const char* name = 0 ) : QCheckBox ( text, parent, name ) {}
+  void setState ( ToggleState s ) { QCheckBox::setState( s ); }
+};
+
 // ================================================================
 /*!
  *  SALOME_InstallWizard::SALOME_InstallWizard
@@ -286,12 +303,12 @@ SALOME_InstallWizard::SALOME_InstallWizard(QString aXmlFileName)
   setTitleFont( fnt );
 
   // set icon
-  setIcon( QPixmap( ( const char** ) image0_data ) );
+  setIcon( QPixmap( ( const char** ) image_icon ) );
   // enable sizegrip
   setSizeGripEnabled( true );
   
   // add logo
-  addLogo( QPixmap( (const char**)image1_data ) );
+  addLogo( QPixmap( (const char**)image_logo ) );
   
   // set defaults
   setVersion( "1.2" );
@@ -544,12 +561,23 @@ void SALOME_InstallWizard::setupProductsPage()
   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" ) );
-  // <Unselect All> buttons
-  unselectBtn  = new QPushButton( tr( "&Unselect All" ),    moreBox );
+  // <Unselect All> button
+  unselectBtn  = new QPushButton( tr( "&Unselect All" ), moreBox );
   QWhatsThis::add( unselectBtn, tr( "Unselects all products" ) );
   QToolTip::add  ( unselectBtn, tr( "Unselects all products" ) );
+  // <SALOME sources> / <SALOME binaries> tri-state checkboxes
+  selectSrcBtn  = new QMyCheckBox( tr( "SALOME sources" ), moreBox );
+  selectSrcBtn->setTristate( true );
+  QWhatsThis::add( selectSrcBtn, tr( "Selects/unselects SALOME sources" ) );
+  QToolTip::add  ( selectSrcBtn, tr( "Selects/unselects SALOME sources" ) );
+  selectBinBtn  = new QMyCheckBox( tr( "SALOME binaries" ), moreBox );
+  selectBinBtn->setTristate( true );
+  QWhatsThis::add( selectBinBtn, tr( "Selects/unselects SALOME binaries" ) );
+  QToolTip::add  ( selectBinBtn, tr( "Selects/unselects SALOME binaries" ) );
   QVBoxLayout* btnLayout = new QVBoxLayout; btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 );
   btnLayout->addWidget( unselectBtn );
+  btnLayout->addWidget( selectSrcBtn );
+  btnLayout->addWidget( selectBinBtn );
   // layouting advancet mode widgets
   moreBoxLayout->addMultiCellWidget( tempLab,      0, 0, 0, 2 );
   moreBoxLayout->addMultiCellWidget( tempFolder,   1, 1, 0, 1 );
@@ -595,6 +623,10 @@ void SALOME_InstallWizard::setupProductsPage()
   connect( productsView, SIGNAL( itemToggled( QCheckListItem* ) ), 
                                               this, SLOT( onItemToggled( QCheckListItem* ) ) );
   connect( unselectBtn,  SIGNAL( clicked() ), this, SLOT( onProdBtn() ) );
+  connect( selectSrcBtn, SIGNAL( stateChanged(int) ), 
+                                             this, SLOT( onProdBtn() ) );
+  connect( selectBinBtn, SIGNAL( stateChanged(int) ), 
+                                             this, SLOT( onProdBtn() ) );
   // connecting signals
   connect( targetFolder, SIGNAL( textChanged( const QString& ) ),
                                               this, SLOT( directoryChanged( const QString& ) ) );
@@ -1048,30 +1080,32 @@ bool SALOME_InstallWizard::acceptData( const QString& pageTitle )
     QString tmpFolder = QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME;
     QString tgtFolder = QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() );
     myThread->clearCommands();
-    for ( unsigned i = 0; i < natives.count(); i++ ) {
-      item = findItem( natives[ i ] );
-      if ( item ) {
-       QString dependOn = productsMap[ item ].getDependancies().join(" ");
-       QString script = "cd ./config_files/;" + item->text(2) + " try_native " +
-               QFileInfo( tmpFolder ).absFilePath() + " " + QDir::currentDirPath() + "/Products " + QFileInfo( tgtFolder ).absFilePath() + " " +
-               QUOTE(dependOn) + " " + item->text(0);
+    if ( natives.count() > 0 ) {
+      for ( unsigned i = 0; i < natives.count(); i++ ) {
+       item = findItem( natives[ i ] );
+       if ( item ) {
+         QString dependOn = productsMap[ item ].getDependancies().join(" ");
+         QString script = "cd ./config_files/;" + item->text(2) + " try_native " +
+                 QFileInfo( tmpFolder ).absFilePath() + " " + QDir::currentDirPath() + "/Products " + QFileInfo( tgtFolder ).absFilePath() + " " +
+                 QUOTE(dependOn) + " " + item->text(0);
 
-       myThread->addCommand( item, script );
-      }
-      else {
-       QMessageBox::warning( this, 
-                             tr( "Warning" ), 
-                             tr( "%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;
+         myThread->addCommand( item, script );
+       }
+       else {
+         QMessageBox::warning( this, 
+                               tr( "Warning" ), 
+                               tr( "%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;
+       }
       }
+      WarnDialog::showWarnDlg( this, true );
+      myThread->start();
+      return true; // return in order to avoid default postValidateEvent() action
     }
-    WarnDialog::showWarnDlg( this, true );
-    myThread->start();
-    return true; // return in order to avoid default postValidateEvent() action
   }
   return InstallWizard::acceptData( pageTitle );
 }
@@ -1128,6 +1162,29 @@ void SALOME_InstallWizard::checkProductPage()
   // update required size information
   requiredSize->setText( QString::number( tots )  + " Kb");
   requiredTemp->setText( QString::number( temps ) + " Kb");
+  
+  // update <SALOME sources>, <SALOME binaries> check boxes state
+  int totSrc = 0, selSrc = 0;
+  int totBin = 0, selBin = 0;
+  MapProducts::Iterator itProd;
+  for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) {
+    if ( itProd.data().getContext() == "salome sources" ) {
+      totSrc++;
+      if ( productsView->isSources( itProd.key() ) )
+       selSrc++;
+    }
+    if ( itProd.data().getContext() == "salome binaries" ) {
+      totBin++;
+      if ( productsView->isBinaries( itProd.key() ) )
+       selBin++;
+    }
+  }
+  selectSrcBtn->blockSignals( true );
+  selectBinBtn->blockSignals( true );
+  selectSrcBtn->setState( selSrc == 0 ? QButton::Off : ( selSrc == totSrc ? QButton::On : QButton::NoChange  ) );
+  selectBinBtn->setState( selBin == 0 ? QButton::Off : ( selBin == totBin ? QButton::On : QButton::NoChange  ) );
+  selectSrcBtn->blockSignals( false );
+  selectBinBtn->blockSignals( false );
 
   // enable/disable "Next" button
   setNextEnabled( productsPage, isAnyProductSelected && isTargetDirValid && isTempDirValid );
@@ -1278,14 +1335,15 @@ void SALOME_InstallWizard::launchScript()
     }
   }
   // <Next> button
-  nextButton()->setEnabled( true );
+  setNextEnabled( 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() ) );
+  disconnect( this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
+  disconnect( this, SIGNAL( nextClicked() ), this, SLOT( onStart() ) );
+  connect(    this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
   // <Back> button
-  backButton()->setEnabled( true );
+  setBackEnabled( true );
   // script parameters
   passedParams->clear();
   passedParams->setEnabled( false );
@@ -1475,8 +1533,9 @@ 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() ) );
+  disconnect( this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
+  disconnect( this, SIGNAL( nextClicked() ), this, SLOT( onStart() ) );
+  connect(    this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
   cancelButton()->disconnect();
   connect( cancelButton(), SIGNAL( clicked()), this, SLOT( reject() ) );
 
@@ -1505,9 +1564,10 @@ void SALOME_InstallWizard::pageChanged( const QString & mytitle)
       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 );
+      disconnect( this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
+      disconnect( this, SIGNAL( nextClicked() ), this, SLOT( onStart() ) );
+      connect(    this, SIGNAL( nextClicked() ), this, SLOT( onStart() ) );
+      setNextEnabled( true );
       // reconnect Cancel button to terminate process
       cancelButton()->disconnect();
       connect( cancelButton(), SIGNAL( clicked() ), this, SLOT( tryTerminate() ) );
@@ -1604,9 +1664,9 @@ void SALOME_InstallWizard::onStart()
   if ( !toInstall.isEmpty() ) {
     clean(false); // VSR 07/02/05 - bug fix: first we should clear temporary directory
     // disable <Next> button
-    nextButton()->setEnabled( false );
+    setNextEnabled( false );
     // disable <Back> button
-    backButton()->setEnabled ( false );
+    setBackEnabled( false );
     // enable script parameters line edit
     // VSR commented: 18/09/03: passedParams->setEnabled( true );
     // VSR commented: 18/09/03: passedParams->setFocus();
@@ -1665,14 +1725,15 @@ void SALOME_InstallWizard::productInstalled( )
     passedParams->setEnabled( false );
     QFont f = parametersLab->font(); f.setBold( false ); parametersLab->setFont( f );
     // enable <Next> button
-    nextButton()->setEnabled( true );
+    setNextEnabled( 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() ) );
+    disconnect( this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
+    disconnect( this, SIGNAL( nextClicked() ), this, SLOT( onStart() ) );
+    connect(    this, SIGNAL( nextClicked() ), this, SLOT( next() ) );
     // enable <Back> button
-    backButton()->setEnabled( true );
+    setBackEnabled( true );
   }
 }
 // ================================================================
@@ -1799,6 +1860,8 @@ void SALOME_InstallWizard::onProdBtn()
 {
   const QObject* snd = sender();
   productsView->blockSignals( true );
+  selectSrcBtn->blockSignals( true );
+  selectBinBtn->blockSignals( true );
   if ( snd == unselectBtn ) {
     QCheckListItem* item = (QCheckListItem*)( productsView->firstChild() );
     while( item ) {
@@ -1806,6 +1869,36 @@ void SALOME_InstallWizard::onProdBtn()
       item = (QCheckListItem*)( item->nextSibling() );
     }
   }
+  else if ( snd == selectSrcBtn )  {
+    QMyCheckBox* checkBox = ( QMyCheckBox* )snd;
+    if ( checkBox->state() == QButton::NoChange )
+      checkBox->setState( QButton::On );
+    MapProducts::Iterator itProd;
+    for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) {
+      if ( itProd.data().getContext() == "salome sources" ) {
+       if ( checkBox->state() == QButton::Off )
+         productsView->setNone( itProd.key() );
+       else
+         productsView->setSources( itProd.key() );
+      }
+    }
+  }
+  else if ( snd == selectBinBtn )  {
+    QMyCheckBox* checkBox = ( QMyCheckBox* )snd;
+    if ( checkBox->state() == QButton::NoChange )
+      checkBox->setState( QButton::On );
+    MapProducts::Iterator itProd;
+    for ( itProd = productsMap.begin(); itProd != productsMap.end(); ++itProd ) {
+      if ( itProd.data().getContext() == "salome binaries" ) {
+       if ( checkBox->state() == QButton::Off )
+         productsView->setNone( itProd.key() );
+       else
+         productsView->setBinaries( itProd.key() );
+      }
+    }
+  }
+  selectSrcBtn->blockSignals( false );
+  selectBinBtn->blockSignals( false );
   productsView->blockSignals( false );
   onSelectionChanged();
   checkProductPage();
@@ -1911,6 +2004,8 @@ void SALOME_InstallWizard::processValidateEvent( const int val, void* data )
     InstallWizard::processValidateEvent( val, data );
     return;
   }
+  myMutex.lock();
+  myMutex.unlock();
   QCheckListItem* item = (QCheckListItem*)data;
   if ( val > 0 ) {
     if ( val == 2 ) {
@@ -1924,8 +2019,11 @@ void SALOME_InstallWizard::processValidateEvent( const int val, void* data )
                                QMessageBox::NoButton ) == QMessageBox::No ) {
        myThread->clearCommands();
        myWC.wakeAll();
+       setNextEnabled( true );
+       setBackEnabled( true );
        return;
       }
+      WarnDialog::showWarnDlg( this, true );
     }
     else {
       WarnDialog::showWarnDlg( 0, false );
@@ -1935,9 +2033,11 @@ void SALOME_InstallWizard::processValidateEvent( const int val, void* data )
                           QMessageBox::Ok, 
                           QMessageBox::NoButton, 
                           QMessageBox::NoButton );
-      productsView->setNone( item );
       myThread->clearCommands();
       myWC.wakeAll();
+      setNextEnabled( true );
+      setBackEnabled( true );
+      productsView->setNone( item );
       return;
     }
   }