// File : SALOME_XmlHandler.cxx
// Created : Thu Dec 18 12:01:00 2002
// Author : Vadim SANDLER
-// Project : PAL/SALOME
-// Module : InstallWizard
-// Copyright : 2004 CEA
-// $Header$
+// Project : SALOME
+// Module : Installation Wizard
+// Copyright : 2004-2005 CEA
+
+#include "globals.h"
#include "SALOME_XmlHandler.hxx"
#include "SALOME_ProductsView.hxx"
#include "SALOME_InstallWizard.hxx"
#include <qlineedit.h>
+#include <qdir.h>
+#include <qregexp.h>
+
+// ================================================================
+/*!
+ * ::isBoolAttributeSet [ static ]
+ * Returns true if the attribute stores boolean value and
+ * corresponds to True value
+ */
+// ================================================================
+static bool isBoolAttributeSet( const QString& attr ) {
+ return ( attr.lower() == "true" ||
+ attr.lower() == "yes" ||
+ attr.lower() == "ok" ||
+ ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) );
+}
+
+// ================================================================
+/*!
+ * ::environmentVariable [ static ]
+ * Seraches for the environment variable and returns it's
+ * position on the given string
+ */
+// ================================================================
+QString environmentVariable( const QString& str, int& start, int& len ) {
+ QString varName = QString::null;
+ len = 0;
+
+ // Environment variable can be given in the form:
+ // - ${VARIABLE} or
+ // - $(VARIABLE) or
+ // - $VARIABLE or
+ // - %VARIABLE%
+ // The first symbol should be the letter.
+ QRegExp rx( "\\$\\{([a-zA-Z]+[a-zA-Z0-9_]*)\\}|\\$\\(([a-zA-Z]+[a-zA-Z0-9_]*)\\)|\\$([a-zA-Z]+[a-zA-Z0-9_]*)|\\%([a-zA-Z]+[a-zA-Z0-9_]*)\\%" );
+
+ int pos = rx.search( str, start );
+ if ( pos != -1 )
+ {
+ start = pos;
+ len = rx.matchedLength();
+ QStringList caps = rx.capturedTexts();
+ for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ )
+ varName = *caps.at( i );
+ }
+ return varName;
+}
+// ================================================================
+/*!
+ * ::substituteVars [ static ]
+ * Substitutes environment variables in the given string
+ * by their values
+ */
+// ================================================================
+static QString substituteVars( const QString& str ) {
+ QString res = str;
+
+ int start( 0 ), len( 0 );
+ while ( true ) {
+ QString envName = environmentVariable( res, start, len );
+ if ( envName.isNull() )
+ break;
+
+ QString newStr = QString::null;
+ if ( ::getenv( envName ) )
+ newStr = QString( ::getenv( envName ) );
+
+ res.replace( start, len, newStr );
+ }
+
+ return res;
+}
// ================================================================
/*!
// ================================================================
void StructureParser::setTargetDir( QLineEdit* dir )
{
+ QString home = QDir::homeDirPath();
myTargetDir = dir;
+ if ( myTargetDir && !home.isEmpty() )
+ myTargetDir->setText( home + QDir::separator() + "salome" );
}
// ================================================================
/*!
void StructureParser::setTempDir( QLineEdit* dir )
{
myTempDir = dir;
+ if ( myTempDir )
+ myTempDir->setText( "/tmp" );
}
// ================================================================
/*!
const QString& qName,
const QXmlAttributes& attributes)
{
-#ifdef DEBUG
- cout << qName << endl;
- cout << attributes.length() << endl;
-#endif
+ ___MESSAGE___( qName );
+ ___MESSAGE___( attributes.length() );
QCheckListItem* element;
if (( qName == "config" ) && ( attributes.length() > 0 ) ) {
QString myVersion, myCaption, myCopyright, myLicense, myOS;
}
}
else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) {
- if (attributes.value( "disable" ) == "true" )
+ 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 );
- if ( attributes.value( "dependancies" ) == "" ) {
- QStringList diskspace = QStringList::split( ",",attributes.value( "installdiskspace" ) );
- if (diskspace.count() == 2)
- myWizard->setDependancies( element,
- Dependancies( attributes.value( "name" ), QStringList(),
- diskspace[0].toInt(),
- diskspace[1].toInt(),
- attributes.value( "temporarydiskspace" ).toInt() ) );
- else
- myWizard->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)
- myWizard->setDependancies( element,
- Dependancies( attributes.value( "name" ),
- QStringList::split( ",", attributes.value( "dependancies" ) ),
- diskspace[0].toInt(),
- diskspace[1].toInt(),
- attributes.value( "temporarydiskspace" ).toInt() ) );
- else
- myWizard->setDependancies( element,
- Dependancies( attributes.value( "name" ),
- QStringList::split( ",", attributes.value( "dependancies" ) ),
- diskspace[0].toInt(),
- diskspace[0].toInt(),
- attributes.value( "temporarydiskspace" ).toInt() ) );
- }
- }
+ 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( attributes.value( "targetdir" ) );
+ myTargetDir->setText( substituteVars( attributes.value( "targetdir" ) ) );
if ( myTempDir ) {
- if ( attributes.value( "tempdir" ) == "" )
- myTempDir->setText( "/tmp" );
- else
- myTempDir->setText( attributes.value( "tempdir" ) );
+ if ( !attributes.value( "tempdir" ).stripWhiteSpace().isEmpty() )
+ myTempDir->setText( substituteVars( attributes.value( "tempdir" ) ) );
}
}
return true;