Salome HOME
Update copyrights 2014.
[tools/install.git] / src / SALOME_XmlHandler.cxx
index f0a8be4deedd8b6bf8ba7cb665881ae2c4c6acb9..2cbee860ba38cfeae5209799354f9e59bb068b15 100644 (file)
@@ -3,7 +3,7 @@
 //  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
 //  Project   : SALOME
 //  Module    : Installation Wizard
-//  Copyright : 2002-2007 CEA
+//  Copyright : 2002-2014 CEA
 
 #include "globals.h"
 
@@ -14,6 +14,8 @@
 #include <qlineedit.h>
 #include <qdir.h>
 #include <qregexp.h>
+#include <qstringlist.h>
+#include <iostream.h>
 
 // ================================================================
 /*!
@@ -28,7 +30,6 @@ static bool isBoolAttributeSet( const QString& attr ) {
           attr.lower() == "ok"   || 
           ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) );
 }
-
 // ================================================================
 /*!
  *  ::environmentVariable [ static ]
@@ -92,22 +93,23 @@ static QString substituteVars( const QString& str ) {
  */
 // ================================================================
 StructureParser::StructureParser( SALOME_InstallWizard* wizard )
-     : QXmlDefaultHandler(), 
-       myWizard( wizard ), 
-       myTree( 0 ), 
+     : myWizard( wizard ), 
+       myModules( 0 ), 
+       myPrereqs( 0 ), 
        myTargetDir( 0 ), 
        myTempDir( 0 )
 {
 }
 // ================================================================
 /*!
- *  StructureParser::setProductsList
+ *  StructureParser::setProductsLists
  *  Sets products list view
  */
 // ================================================================
-void StructureParser::setProductsList( ProductsView* tree )
+void StructureParser::setProductsLists( ProductsView* mtree, ProductsView* ptree )
 {
-  myTree = tree;
+  myModules = mtree;
+  myPrereqs = ptree;
 }
 // ================================================================
 /*!
@@ -136,111 +138,212 @@ void StructureParser::setTempDir( QLineEdit* dir )
 }
 // ================================================================
 /*!
- *  StructureParser::startElement
- *  Begins parsing of the xml dom-element
- */  
-// ================================================================
-bool StructureParser::startElement( const QString&        /*namespaceURI*/,
-                                   const QString&        /*localName*/,
-                                    const QString&        qName,
-                                    const QXmlAttributes& attributes)
+ *  StructureParser::getConfigInfo
+ *  Parse 'config' part of the XML file
+ */
+// ================================================================
+void StructureParser::getConfigInfo(const QDomElement &theElem)
 {
-  ___MESSAGE___( qName );
-  ___MESSAGE___( attributes.length() );
-  QCheckListItem* element;
-  if (( qName == "config" ) && ( attributes.length() > 0 ) ) {
-    QString myVersion, myCaption, myCopyright, myLicense, myOS;
-    if ( attributes.value( "version" ) ) {
-      myVersion = attributes.value( "version" ).stripWhiteSpace();
+  QString myVersion, myCaption, myCopyright, myLicense, myPlatforms, myOptLibs;
+    if ( theElem.attribute( "version" ) ) {
+      myVersion = theElem.attribute( "version" ).stripWhiteSpace();
       if ( myWizard && !myVersion.isEmpty() ) 
        myWizard->setVersion( myVersion );
     }
-    if ( attributes.value( "caption" ) ) {
-      myCaption = attributes.value( "caption" ).arg( myVersion ).stripWhiteSpace();
+    if ( theElem.attribute( "caption" ) ) {
+      myCaption = theElem.attribute( "caption" ).arg( myVersion ).stripWhiteSpace();
       if ( myWizard && !myCaption.isEmpty() ) 
        myWizard->setCaption( myCaption );
     }
-    if ( attributes.value( "copyright" ) ) {
-      myCopyright = attributes.value( "copyright" ).stripWhiteSpace();
+    if ( theElem.attribute( "copyright" ) ) {
+      myCopyright = theElem.attribute( "copyright" ).stripWhiteSpace();
       if ( myWizard && !myCopyright.isEmpty() ) 
        myWizard->setCopyright( myCopyright );
     }
-    if ( attributes.value( "license" ) ) {
-      myLicense = attributes.value( "license" ).stripWhiteSpace();
+    if ( theElem.attribute( "license" ) ) {
+      myLicense = theElem.attribute( "license" ).stripWhiteSpace();
       if ( myWizard && !myLicense.isEmpty() ) 
        myWizard->setLicense( myLicense );
     }
-    if ( attributes.value( "os" ) ) {
-      myOS = attributes.value( "os" ).stripWhiteSpace();
-      if ( myWizard && !myOS.isEmpty() ) 
-       myWizard->setOS( myOS );
+    if ( theElem.attribute( "platforms" ) ) {
+//       myPlatforms = theElem.attribute( "platforms" ).stripWhiteSpace();
+//       if ( myWizard && !myPlatforms.isEmpty() ) 
+//     myWizard->setPlatforms( myPlatforms );
+    }
+    if ( theElem.attribute( "targetdir" ) ) {
+      if ( myTargetDir )
+       myTargetDir->setText( substituteVars( theElem.attribute( "targetdir" ) ) );
+    }
+    if ( theElem.attribute( "tempdir" ) ) {
+      if ( myTempDir )
+       myTempDir->setText( substituteVars( theElem.attribute( "tempdir" ) ) );
+    }
+    if ( theElem.attribute( "optionallibs" ) ) {
+      myOptLibs = theElem.attribute( "optionallibs" ).stripWhiteSpace();
+      if ( myWizard && !myOptLibs.isEmpty() ) 
+       myWizard->setOptionalLibs( myOptLibs );
+    }
+}
+// ================================================================
+/*!
+ *  StructureParser::getButtonsInfo
+ *  Parse 'buttons' part of the XML file
+ */
+// ================================================================
+void StructureParser::getButtonsInfo(const QDomNode &theNode)
+{
+  QString aLabel, aTootip, aScript;
+  for( QDomNode node = theNode.firstChild(); !node.isNull(); node = node.nextSibling() ) {
+    if ( !node.isElement() ) 
+      continue;
+    QDomElement elem = node.toElement();
+    if ( isBoolAttributeSet( elem.attribute( "disable" ) ) ) 
+      continue;
+    aLabel = ""; aTootip = ""; aScript = "";
+    if ( elem.attribute( "label" ) )
+      aLabel = elem.attribute( "label" ).stripWhiteSpace();
+    if ( elem.attribute( "tooltip" ) )
+      aTootip = elem.attribute( "tooltip" ).stripWhiteSpace();
+    if ( elem.attribute( "script" ) )
+      aScript = elem.attribute( "script" ).stripWhiteSpace();
+    if ( !aLabel.isEmpty() ) {
+      if ( node == theNode.firstChild() )
+       myWizard->addFinishButton( aLabel, aTootip, aScript, true );
+      else
+       myWizard->addFinishButton( aLabel, aTootip, aScript );
     }
-  } 
-  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;
-    
-    QString install = attributes.value( "install" );
-    QStringList supported = QStringList::split( ",", attributes.value( "supported" ) );
-    QString script = attributes.value( "script" );
-    QStringList deps = QStringList();
-    if ( attributes.value( "dependancies" ) != "" )
-      deps = QStringList::split( ",", attributes.value( "dependancies" ), false );
-    element = myTree->addItem( attributes.value( "name" ), attributes.value( "version" ), install, supported, script );
-    QStringList diskspace = QStringList::split(",",attributes.value( "installdiskspace" ) );
-    QString descr = QString::null;
-    if ( attributes.value( "description" ) != "" )
-      descr = attributes.value( "description" ).stripWhiteSpace();
-    QString ctx = QString::null;
-    if ( attributes.value( "context" ) != "" )
-      ctx = attributes.value( "context" ).stripWhiteSpace().lower();
-    bool pickUp = isBoolAttributeSet( attributes.value( "pickupenv" ) );
-    myWizard->setDependancies( element, 
-                              Dependancies( attributes.value( "name" ), 
-                                            deps,
-                                            ( diskspace.count() > 0 ? diskspace[ 0 ].toInt() : 0 ), 
-                                            ( diskspace.count() > 1 ? diskspace[1].toInt() : ( diskspace.count() > 0 ? diskspace[0].toInt() : 0 ) ), 
-                                            attributes.value( "temporarydiskspace" ).toInt(),
-                                            install,
-                                            descr,
-                                            ctx,
-                                            pickUp ) );
   }
-  else if (( qName == "path" ) && ( attributes.length() > 0 ) && myWizard ) {
-    if ( myTargetDir )
-      myTargetDir->setText( substituteVars( attributes.value( "targetdir" ) ) );
+}
+// ================================================================
+/*!
+ *  StructureParser::getProductsInfo
+ *  Parse 'products' part of the XML file
+ */
+// ================================================================
+void StructureParser::getProductsInfo( const QDomNode &theNode )
+{
+  MapDependencies mapDeps;
+  QCheckListItem* element;
 
-    if ( myTempDir ) {
-      if ( !attributes.value( "tempdir" ).stripWhiteSpace().isEmpty() )
-       myTempDir->setText( substituteVars( attributes.value( "tempdir" ) ) );
-    }
+  QDomNode docNode = theNode.parentNode();
+  getDependenciesInfo( docNode, mapDeps );
+
+  for( QDomNode prodNode = theNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) {
+    if ( !prodNode.isElement() ) 
+      continue;
+    for( QDomNode instNode = prodNode.firstChild(); !instNode.isNull(); instNode = instNode.nextSibling() ) {
+      if ( !instNode.isElement() ) 
+       continue;
+      QDomElement instElem = instNode.toElement();
+      if ( instElem.attribute( "os" ) != myWizard->getPlatform() && instElem.attribute( "os" ) != "all" ) 
+       continue;
+      if ( isBoolAttributeSet( instElem.attribute( "disable" ) ) )
+       break; // current product is skipped
+      QDomElement prodElem = prodNode.toElement();
+      
+      QStringList diskspace = QStringList::split( ",", instElem.attribute( "installdiskspace" ) );
+      long binreq = diskspace[ 0 ].toInt();
+      long srcreq = diskspace[ 1 ].toInt();
+      long cmplreq = diskspace[ 2 ].toInt();
+      
+      QString name = prodElem.attribute( "name" ).stripWhiteSpace();
+      QString type = prodElem.attribute( "type" ).stripWhiteSpace().lower();
+      BoolTristate woGuiMode = NotDefined;
+      bool pickUp = isBoolAttributeSet( instElem.attribute( "pickupenv" ) );
+      QString script = instElem.attribute( "script" );
+      QStringList typesList = QStringList::split( ",", type );
+      if ( typesList.find( "component" ) != typesList.end() ) {
+       QString woGuiAttr = instElem.attribute( "woguimode" );
+       if ( !woGuiAttr.isNull() )
+         woGuiMode = BoolTristate( isBoolAttributeSet( woGuiAttr ) );
+       element = myModules->addItem( name, 
+                                     "unknown", 
+                                     script );
+      }
+      else
+       element = myPrereqs->addItem( name,
+                                     "unknown", 
+                                     script );
+      QString descr = QString::null;
+      if ( prodElem.attribute( "description" ) != "" )
+       descr = prodElem.attribute( "description" ).stripWhiteSpace();
+      myWizard->setDependancies
+       ( element, 
+         Dependancies( name, 
+                       mapDeps[ name ],
+                       binreq, 
+                       srcreq, 
+                       cmplreq, 
+                       instElem.attribute( "temporarydiskspace" ).toInt(),
+                       instElem.attribute( "version" ),
+                       descr,
+                       type,
+                       pickUp, 
+                       woGuiMode ) );
+    } 
   }
-  return true;
 }
 // ================================================================
 /*!
- *  StructureParser::endElement
- *  Finishes parsing of the xml dom-element
+ *  StructureParser::getDependencies
+ *  Parse 'dependencies' part of the XML file
  */
 // ================================================================
-bool StructureParser::endElement( const QString&, 
-                                 const QString&,
-                                  const QString& )
+void StructureParser::getDependenciesInfo( QDomNode &theNode, MapDependencies &theDepends )
 {
-  return true;
+  QDomNode depsNode = theNode.namedItem( "dependencies" );
+  QStringList depsList = QStringList();
+  for( QDomNode prodNode = depsNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) {
+    if ( !prodNode.isElement() ) 
+      continue;
+    QDomElement prodElem = prodNode.toElement();
+    QString prodName = prodElem.attribute( "name" ).stripWhiteSpace();
+    if ( theDepends.contains( prodName ) ) 
+      continue;
+    depsList.clear();
+    for ( QDomNode depNode = prodNode.firstChild(); !depNode.isNull(); depNode = depNode.nextSibling() ) {
+      if ( !depNode.isElement() ) 
+       continue;
+      QDomElement depElem = depNode.toElement();
+      QString depName = depElem.text();
+      if ( depName.isEmpty() )
+       continue;
+      if ( !depsList.contains( depName ) )
+       depsList.append( depName );
+    }
+    theDepends[ prodName ] = depsList;
+  }
 }
+// ================================================================
+/*!
+ *  StructureParser::readXmlFile
+ *  Read XML configuration file for the current platform
+ */
+// ================================================================
+void StructureParser::readXmlFile(QString theFileName)
+{
+  QDomDocument doc( "xml_doc" );
+  QFile file( theFileName );
+  if ( !file.open( IO_ReadOnly ) )
+    return;
+  if ( !doc.setContent( &file ) ) {
+    file.close();
+    return;
+  }
+  file.close();
+  
+  QDomElement docElem = doc.documentElement();
 
+  for( QDomNode node = docElem.firstChild(); !node.isNull(); node = node.nextSibling() ) {
+    QString nodeName = node.nodeName();
+    if ( nodeName == "config" && node.isElement() ) {
+      getConfigInfo( node.toElement() );
+    }
+    else if ( nodeName == "buttons" && node.hasChildNodes() && myModules && myWizard ) {
+      getButtonsInfo( node );
+    }
+    else if ( nodeName == "products" && node.hasChildNodes() && myModules && myWizard ) {
+      getProductsInfo( node );
+    }
+  }
+}