Salome HOME
Improvement: support <button> tag to customize the buttons (to perform specific actio...
authorvsr <vsr@opencascade.com>
Mon, 30 Oct 2006 15:16:58 +0000 (15:16 +0000)
committervsr <vsr@opencascade.com>
Mon, 30 Oct 2006 15:16:58 +0000 (15:16 +0000)
src/SALOME_InstallWizard.cxx
src/SALOME_InstallWizard.hxx
src/SALOME_XmlHandler.cxx
src/globals.h

index 6bb5ee6aff6861e6e2466c146d7c2eacc782daae..9388818b5f0dc56100b1df12907f7ab4e93e18f5 100644 (file)
@@ -934,18 +934,29 @@ void SALOME_InstallWizard::setupReadmePage()
   pal.setColor( QColorGroup::Base, QApplication::palette().active().background() );
   readme->setPalette( pal );
   readme->setMinimumHeight( 10 );
-  // <Launch SALOME> 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() ) );
+
+  // Operation buttons
+  if ( buttons.count() > 0 ) {
+    QHBoxLayout* hLayout = new QHBoxLayout;
+    hLayout->setMargin( 0 ); hLayout->setSpacing( 6 );
+    ButtonList::Iterator it;
+    for ( it = buttons.begin(); it != buttons.end(); ++it ) {
+      QButton* b = new QPushButton( tr( (*it).label() ), readmePage );
+      if ( !(*it).tootip().isEmpty() ) {
+       QWhatsThis::add( b, tr( (*it).tootip() ) );
+       QToolTip::add  ( b, tr( (*it).tootip() ) );
+      }
+      hLayout->addWidget( b ); 
+      (*it).setButton( b );
+      connect( b, SIGNAL( clicked() ), this, SLOT( onFinishButton() ) );
+    }
+    hLayout->addStretch();
+    pageLayout->addLayout( hLayout );
+  }
+
   // loading README file
   QString readmeFile = QDir::currentDirPath() + "/README";
   QString text;
@@ -953,6 +964,7 @@ void SALOME_InstallWizard::setupReadmePage()
     readme->setText( text );
   else
     readme->setText( tr( "README file has not been found" ) );
+
   // adding page
   addPage( readmePage, tr( "Finish installation" ) );
 }
@@ -1133,15 +1145,56 @@ bool SALOME_InstallWizard::acceptData( const QString& pageTitle )
                               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() ));
+    // check sources/binaries archives directories existance
+    int nbSources = 0, nbBinaries = 0; 
+    QCheckListItem* nitem = (QCheckListItem*)( productsView->firstChild() );
+    while( nitem ) {
+      if ( productsMap.contains( nitem ) ) {
+       if ( nitem->childCount() > 0 ) {
+         if ( productsView->isBinaries( nitem ) )
+           nbBinaries++;
+         else if ( productsView->isSources( nitem ) )
+           nbSources++;
+       }
+       else if ( nitem->isOn() ) {
+         nbBinaries++;
+         nbSources++;
+       }
+      }
+      nitem = (QCheckListItem*)( nitem->nextSibling() );
+    }
+
+    if ( nbBinaries > 0 ) {
+      QString binDir = "./Products/BINARIES";
+      if ( !myOS.isEmpty() )
+       binDir += "/" + myOS;
+      QFileInfo fib( QDir::cleanDirPath( binDir ) );
+      if ( !fib.exists() ) {
+       if ( QMessageBox::warning( this, 
+                                  tr( "Warning" ), 
+                                  tr( "The directory %1 doesn't exist.\n"
+                                      "This directory must contain binaries archives.\n"
+                                      "Continue?" ).arg( fib.absFilePath() ),
+                                  QMessageBox::Yes,
+                                  QMessageBox::No,
+                                  QMessageBox::NoButton ) == QMessageBox::No )
+         return false;
+      }
+    }
+    if ( nbSources > 0 ) {
+      QString srcDir = "./Products/SOURCES";
+      QFileInfo fis( QDir::cleanDirPath( srcDir ) );
+      if ( !fis.exists() ) {
+       if ( QMessageBox::warning( this, 
+                                  tr( "Warning" ), 
+                                  tr( "The directory %1 doesn't exist.\n"
+                                      "This directory must contain sources archives.\n"
+                                      "Continue?" ).arg( fis.absFilePath() ),
+                                  QMessageBox::Yes,
+                                  QMessageBox::No,
+                                  QMessageBox::NoButton ) == QMessageBox::No )
+         return false;
+      }
     }
     // run script that checks available disk space for installing of products    // returns 1 in case of error
     QString script = "./config_files/checkSize.sh '";
@@ -1578,46 +1631,36 @@ void SALOME_InstallWizard::onMoreBtn()
 }
 // ================================================================
 /*!
- *  SALOME_InstallWizard::onLaunchSalome
- *  <Launch Salome> button slot
+ *  SALOME_InstallWizard::onFinishButton
+ *  Operation buttons slot
  */
 // ================================================================
-void SALOME_InstallWizard::onLaunchSalome()
+void SALOME_InstallWizard::onFinishButton()
 {
-  QString msg = tr( "You don't have SALOME binaries installed in the %1 directory!" ).arg( targetFolder->text() );
-
-  QCheckListItem* item = findItem( "KERNEL-Bin" );
-  if ( item ) {
-    QFileInfo fi( targetFolder->text() + "/KERNEL_" + item->text(1) + "/bin/salome/runSalome" );
-    QFileInfo fienv( targetFolder->text() + "/KERNEL_" + item->text(1) + "/salome.sh" );
-    if ( fienv.exists() ) {
-      if ( fi.exists() ) {
-       QString script;
-       script += "cd " + targetFolder->text() + "/KERNEL_" + item->text(1) + "; ";
-       script += "source salome.sh; ";
-       script += "cd bin/salome; ";
-       script += "runSalome > /dev/null";
-       script = "(bash -c '" + script + "')";
-       ___MESSAGE___( "script: " << script.latin1() );
-       if ( !system( script.latin1() ) )
-         return;
-       else
-         msg = tr( "Can't launch SALOME." );
+  const QObject* btn = sender();
+  ButtonList::Iterator it;
+  for ( it = buttons.begin(); it != buttons.end(); ++it ) {
+    if ( (*it).button() && (*it).button() == btn ) {
+      QString script;
+      script += "( cd " + QUOTE( QFileInfo( QDir::cleanDirPath( "./config_files/" ) ).absFilePath() ) + "; ";
+      script +=  + (*it).script();
+      script += " execute ";
+      script += QUOTE( QFileInfo( QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) ).absFilePath() ) + " ";
+      script += QUOTE( QFileInfo( QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME ).absFilePath() ) + " ";
+      script += " > /dev/null )";
+      ___MESSAGE___( "script: " << script.latin1() );
+      if ( (*it).script().isEmpty() || system( script.latin1() ) ) {
+       QMessageBox::warning( this, 
+                             tr( "Error" ), 
+                             tr( "Can't perform action!"),
+                             QMessageBox::Ok, 
+                             QMessageBox::NoButton,
+                             QMessageBox::NoButton );
       }
-      else
-       msg = tr( "Can't launch SALOME." ) + "\n" + tr( "runSalome file can not be found." );
+      return;
     }
-    else
-      msg = tr( "Can't launch SALOME." ) + "\n" + tr( "Can't find environment file." );
-  }
-  QMessageBox::warning( this, 
-                       tr( "Error" ), 
-                       msg,
-                       QMessageBox::Ok, 
-                       QMessageBox::NoButton,
-                       QMessageBox::NoButton );
+  }
 }
-
 // ================================================================
 /*!
  *  SALOME_InstallWizard::onAbout
@@ -1785,10 +1828,20 @@ void SALOME_InstallWizard::pageChanged( const QString & mytitle)
     }
   }
   else if ( aPage == readmePage ) {
-    QCheckListItem* item = findItem( "KERNEL-Bin" );
-    runSalomeBtn->setEnabled( item &&
-                             QFileInfo( targetFolder->text() + "/KERNEL_" + item->text(1) + "/bin/salome/runSalome" ).exists() &&
-                             QFileInfo( targetFolder->text() + "/KERNEL_" + item->text(1) + "/salome.csh" ).exists() );
+    ButtonList::Iterator it;
+    for ( it = buttons.begin(); it != buttons.end(); ++it ) {
+      if ( (*it).button() ) {
+       QString script;
+       script += "( cd " + QUOTE( QFileInfo( QDir::cleanDirPath( "./config_files/" ) ).absFilePath() ) + "; ";
+       script +=  + (*it).script();
+       script += " check_enabled ";
+       script += QUOTE( QFileInfo( QDir::cleanDirPath( targetFolder->text().stripWhiteSpace() ) ).absFilePath() ) + " ";
+       script += QUOTE( QFileInfo( QDir::cleanDirPath( tempFolder->text().stripWhiteSpace() ) + TEMPDIRNAME ).absFilePath() ) + " ";
+       script += " > /dev/null )";
+       ___MESSAGE___( "script: " << script.latin1() );
+       (*it).button()->setEnabled( !(*it).script().isEmpty() && !system( script.latin1() ) );
+      }
+    }
     finishButton()->setEnabled( true );
   }
   previousPage = aPage;
@@ -2229,6 +2282,19 @@ void SALOME_InstallWizard::setDependancies( QCheckListItem* item, Dependancies d
   productsMap[item] = dep;
 }
 // ================================================================
+/*!
+ *  SALOME_InstallWizard::addFinishButton
+ *  Add button for the <Finish> page
+ */
+// ================================================================
+void SALOME_InstallWizard::addFinishButton( const QString& label, 
+                                           const QString& tooltip, 
+                                           const QString& script)
+{
+  if ( !label.isEmpty() )
+    buttons.append( Button( label, tooltip, script ) );
+}
+// ================================================================
 /*!
  *  SALOME_InstallWizard::polish
  *  Polishing of the widget - to set right initial size
index ee7af23440509216b1f17813f48cea1419862dcc..2075da8fdb1203b525f85b14fcbbbe4455d5e3b0 100644 (file)
 #include "InstallWizard.h"
 
 #include <qmap.h>
+#include <qvaluelist.h>
 #include <qstringlist.h> 
 
+class QLineEdit;
+class QPushButton;
+class QListViewItem;
+class QCheckListItem;
+class QLabel;
+class QTextEdit;
+class QTextBrowser;
+class QProcess;
+class QCheckBox;
+class QSplitter;
+class QMyCheckBox;
+class ProcessThread;
+class ProductsView;
+class ProgressView;
+class HelpWindow;
+class InstallInfo;
+class QButton;
+
 /*! 
   Class Dependancies : Products info
   This class stores all product dependancies for correct work of installation procedure
-     smbName   - parameter for launching install shell script (e.g. cas for CASCADE4.0).
-     dependsOn - list of products needed for correct installation of product
-                 (e.g tcl is checked during installation of CASCADE 4).
-     sizeTotal - amount of disk space in Kbytes required for installation 
-                 of this product
-     sizeTemp  - amount of disk space in Kbytes required for the temporary files
 */
 class Dependancies
 {
@@ -86,24 +99,41 @@ class Dependancies
   bool        pickupEnv;        // "Pick-up environment" flag
 };
 
-class QLineEdit;
-class QPushButton;
-class QListViewItem;
-class QCheckListItem;
-class QLabel;
-class QTextEdit;
-class QTextBrowser;
-class QProcess;
-class QCheckBox;
-class QSplitter;
-class QMyCheckBox;
-class ProcessThread;
-class ProductsView;
-class ProgressView;
-class HelpWindow;
-class InstallInfo;
+/*! 
+  Class Button : Operation button info
+  This class stores information about the custom operation buttons which appear on
+  the <Finish> page of the Install Wizard.
+*/
+class Button
+{
+ public:
+  // default constructor, required for list
+  Button() : myButton( 0 ) {}
+  // constructor
+  Button( const QString& label, const QString& tooltip, const QString& script )
+    : myLabel( label ), myTootip( tooltip ), myScript( script ), myButton( 0 ) {}
+
+  // set operation button
+  void setButton( QButton* btn ) { myButton = btn; }
+
+  // get label
+  QString  label()  const { return myLabel;  } 
+  // get tooltip
+  QString  tootip() const { return myTootip; }
+  // get script name
+  QString  script() const { return myScript; }
+  // get operation button
+  QButton* button() const { return myButton; }
+
+ private:
+  QString  myLabel;    // button label
+  QString  myTootip;   // button tooltip
+  QString  myScript;   // operation script
+  QButton* myButton;   // operation button
+};
 
 typedef QMap<QCheckListItem*, Dependancies> MapProducts;
+typedef QValueList<Button>                  ButtonList;
 
 /*!
   Class SALOME_InstallWizard : Installation Wizard's main window
@@ -126,13 +156,11 @@ class SALOME_InstallWizard: public InstallWizard
   // set dependancies
   void setDependancies( QCheckListItem* item, Dependancies dep);
 
-  // process validation event (<val> is validation code)
-  void processValidateEvent( const int val, void* data );
+  // add button for the <Finish> page
+  void addFinishButton( const QString& label, 
+                       const QString& tooltip, 
+                       const QString& script);
 
- public slots:
-  // polishing of the widget
-  void polish();
-  
   // set version
   void setVersion( const QString& version ) { myVersion = version; }
   // set caption
@@ -156,6 +184,13 @@ class SALOME_InstallWizard: public InstallWizard
   QString getOS() { return myOS; }
   // get InstallWizard's name
   QString getIWName() { return myIWName; }
+
+  // process validation event (<val> is validation code)
+  void processValidateEvent( const int val, void* data );
+
+ public slots:
+  // polishing of the widget
+  void polish();
   
   // save install log to file
   void saveLog();
@@ -229,8 +264,10 @@ class SALOME_InstallWizard: public InstallWizard
   void onProdBtn();
   // <More...> button slot
   void onMoreBtn();
-  // <Launch Salome> button slot
-  void onLaunchSalome();
+
+  // <Finish> page buttons slot
+  void onFinishButton();
+
   // <About> button slot
   void onAbout();
 
@@ -296,10 +333,10 @@ class SALOME_InstallWizard: public InstallWizard
   QLineEdit*       passedParams;   // user can pass data to running script
   QTextEdit*       installProgress;// contains information about progress of installing selected products
   ProgressView*    progressView;   // displays information about progress of installing selected products
-  // --> readme page
+  // --> finish page
   QWidget*         readmePage;     // page itself
   QTextEdit*       readme;         // Readme information window
-  QPushButton*     runSalomeBtn;   // <Launch Salome> buttnon
+  ButtonList       buttons;        // operation buttons
 
   ProcessThread*   myThread;       // validation thread
 };
index dc6533aecc89a8800889fddf04a0bd44a60c189e..95e03c83600dcfaacce519a563d54402d687011a 100644 (file)
@@ -176,6 +176,20 @@ bool StructureParser::startElement( const QString&        /*namespaceURI*/,
        myWizard->setOS( myOS );
     }
   } 
+  else if (( qName == "button" ) && ( attributes.length() > 0 ) && myTree && myWizard ) {
+    if ( isBoolAttributeSet( attributes.value( "disable" ) ) )
+      return true;
+
+    QString myLabel, myTootip, myScript;
+    if ( attributes.value( "label" ) )
+      myLabel = attributes.value( "label" ).stripWhiteSpace();
+    if ( attributes.value( "tooltip" ) )
+      myTootip = attributes.value( "tooltip" ).stripWhiteSpace();
+    if ( attributes.value( "script" ) )
+      myScript = attributes.value( "script" ).stripWhiteSpace();
+    if ( !myLabel.isEmpty() )
+      myWizard->addFinishButton( myLabel, myTootip, myScript );
+  }
   else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) {
     if ( isBoolAttributeSet( attributes.value( "disable" ) ) )
       return true;
index 10fffb1e0ab93e92dcf69092452182a799db1c97..fe5caf08724c45d4cff853e7588209714e1c229b 100644 (file)
@@ -17,7 +17,7 @@
 
 #define __IW_VERSION_MAJOR__ 1
 #define __IW_VERSION_MINOR__ 0
-#define __IW_VERSION_PATCH__ 1
+#define __IW_VERSION_PATCH__ 2
 
 #define __IW_VERSION__ (__IW_VERSION_MAJOR__*10000 + \
                         __IW_VERSION_MINOR__*100   + \