1 // File : SALOME_XmlHandler.cxx
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
5 // Module : Installation Wizard
6 // Copyright : 2002-2007 CEA
10 #include "SALOME_XmlHandler.hxx"
11 #include "SALOME_ProductsView.hxx"
12 #include "SALOME_InstallWizard.hxx"
14 #include <qlineedit.h>
17 #include <qstringlist.h>
20 // ================================================================
22 * ::isBoolAttributeSet [ static ]
23 * Returns true if the attribute stores boolean value and
24 * corresponds to True value
26 // ================================================================
27 static bool isBoolAttributeSet( const QString& attr ) {
28 return ( attr.lower() == "true" ||
29 attr.lower() == "yes" ||
30 attr.lower() == "ok" ||
31 ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) );
33 // ================================================================
35 * ::environmentVariable [ static ]
36 * Seraches for the environment variable and returns it's
37 * position on the given string
39 // ================================================================
40 QString environmentVariable( const QString& str, int& start, int& len ) {
41 QString varName = QString::null;
44 // Environment variable can be given in the form:
49 // The first symbol should be the letter.
50 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_]*)\\%" );
52 int pos = rx.search( str, start );
56 len = rx.matchedLength();
57 QStringList caps = rx.capturedTexts();
58 for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ )
59 varName = *caps.at( i );
63 // ================================================================
65 * ::substituteVars [ static ]
66 * Substitutes environment variables in the given string
69 // ================================================================
70 static QString substituteVars( const QString& str ) {
73 int start( 0 ), len( 0 );
75 QString envName = environmentVariable( res, start, len );
76 if ( envName.isNull() )
79 QString newStr = QString::null;
80 if ( ::getenv( envName ) )
81 newStr = QString( ::getenv( envName ) );
83 res.replace( start, len, newStr );
89 // ================================================================
91 * StructureParser::StructureParser
94 // ================================================================
95 StructureParser::StructureParser( SALOME_InstallWizard* wizard )
103 // ================================================================
105 * StructureParser::setProductsLists
106 * Sets products list view
108 // ================================================================
109 void StructureParser::setProductsLists( ProductsView* mtree, ProductsView* ptree )
114 // ================================================================
116 * StructureParser::setTargetDir
117 * Sets target directory widget
119 // ================================================================
120 void StructureParser::setTargetDir( QLineEdit* dir )
122 QString home = QDir::homeDirPath();
124 if ( myTargetDir && !home.isEmpty() )
125 myTargetDir->setText( home + QDir::separator() + "salome" );
127 // ================================================================
129 * StructureParser::setTempDir
130 * Sets temp directory widget
132 // ================================================================
133 void StructureParser::setTempDir( QLineEdit* dir )
137 myTempDir->setText( "/tmp" );
139 // ================================================================
141 * StructureParser::getConfigInfo
142 * Parse 'config' part of the XML file
144 // ================================================================
145 void StructureParser::getConfigInfo(const QDomElement &theElem)
147 QString myVersion, myCaption, myCopyright, myLicense, myPlatforms;
148 if ( theElem.attribute( "version" ) ) {
149 myVersion = theElem.attribute( "version" ).stripWhiteSpace();
150 if ( myWizard && !myVersion.isEmpty() )
151 myWizard->setVersion( myVersion );
153 if ( theElem.attribute( "caption" ) ) {
154 myCaption = theElem.attribute( "caption" ).arg( myVersion ).stripWhiteSpace();
155 if ( myWizard && !myCaption.isEmpty() )
156 myWizard->setCaption( myCaption );
158 if ( theElem.attribute( "copyright" ) ) {
159 myCopyright = theElem.attribute( "copyright" ).stripWhiteSpace();
160 if ( myWizard && !myCopyright.isEmpty() )
161 myWizard->setCopyright( myCopyright );
163 if ( theElem.attribute( "license" ) ) {
164 myLicense = theElem.attribute( "license" ).stripWhiteSpace();
165 if ( myWizard && !myLicense.isEmpty() )
166 myWizard->setLicense( myLicense );
168 if ( theElem.attribute( "platforms" ) ) {
169 // myPlatforms = theElem.attribute( "platforms" ).stripWhiteSpace();
170 // if ( myWizard && !myPlatforms.isEmpty() )
171 // myWizard->setPlatforms( myPlatforms );
173 if ( theElem.attribute( "targetdir" ) ) {
175 myTargetDir->setText( substituteVars( theElem.attribute( "targetdir" ) ) );
177 if ( theElem.attribute( "tempdir" ) ) {
179 myTempDir->setText( substituteVars( theElem.attribute( "tempdir" ) ) );
182 // ================================================================
184 * StructureParser::getButtonsInfo
185 * Parse 'buttons' part of the XML file
187 // ================================================================
188 void StructureParser::getButtonsInfo(const QDomNode &theNode)
190 QString aLabel, aTootip, aScript;
191 for( QDomNode node = theNode.firstChild(); !node.isNull(); node = node.nextSibling() ) {
192 if ( !node.isElement() )
194 QDomElement elem = node.toElement();
195 if ( isBoolAttributeSet( elem.attribute( "disable" ) ) )
197 aLabel = ""; aTootip = ""; aScript = "";
198 if ( elem.attribute( "label" ) )
199 aLabel = elem.attribute( "label" ).stripWhiteSpace();
200 if ( elem.attribute( "tooltip" ) )
201 aTootip = elem.attribute( "tooltip" ).stripWhiteSpace();
202 if ( elem.attribute( "script" ) )
203 aScript = elem.attribute( "script" ).stripWhiteSpace();
204 if ( !aLabel.isEmpty() ) {
205 if ( node == theNode.firstChild() )
206 myWizard->addFinishButton( aLabel, aTootip, aScript, true );
208 myWizard->addFinishButton( aLabel, aTootip, aScript );
212 // ================================================================
214 * StructureParser::getProductsInfo
215 * Parse 'products' part of the XML file
217 // ================================================================
218 void StructureParser::getProductsInfo( const QDomNode &theNode )
220 MapDependencies mapDeps;
221 QCheckListItem* element;
223 QDomNode docNode = theNode.parentNode();
224 getDependenciesInfo( docNode, mapDeps );
226 for( QDomNode prodNode = theNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) {
227 if ( !prodNode.isElement() )
229 for( QDomNode instNode = prodNode.firstChild(); !instNode.isNull(); instNode = instNode.nextSibling() ) {
230 if ( !instNode.isElement() )
232 QDomElement instElem = instNode.toElement();
233 if ( instElem.attribute( "os" ) != myWizard->getPlatform() && instElem.attribute( "os" ) != "all" )
235 if ( isBoolAttributeSet( instElem.attribute( "disable" ) ) )
236 break; // current product is skip
237 QDomElement prodElem = prodNode.toElement();
239 QStringList diskspace = QStringList::split( ",", instElem.attribute( "installdiskspace" ) );
240 long binreq = diskspace[ 0 ].toInt();
241 long srcreq = diskspace[ 1 ].toInt();
242 long cmplreq = diskspace[ 2 ].toInt();
244 QString name = prodElem.attribute( "name" ).stripWhiteSpace();
245 QString type = prodElem.attribute( "type" ).stripWhiteSpace().lower();
246 bool pickUp = isBoolAttributeSet( instElem.attribute( "pickupenv" ) );
247 QString script = instElem.attribute( "script" );
248 QStringList typesList = QStringList::split( ",", type );
249 if ( typesList.find( "component" ) != typesList.end() )
250 element = myModules->addItem( name,
254 element = myPrereqs->addItem( name,
257 QString descr = QString::null;
258 if ( prodElem.attribute( "description" ) != "" )
259 descr = prodElem.attribute( "description" ).stripWhiteSpace();
260 myWizard->setDependancies
267 instElem.attribute( "temporarydiskspace" ).toInt(),
268 instElem.attribute( "version" ),
275 // ================================================================
277 * StructureParser::getDependencies
278 * Parse 'dependencies' part of the XML file
280 // ================================================================
281 void StructureParser::getDependenciesInfo( QDomNode &theNode, MapDependencies &theDepends )
283 QDomNode depsNode = theNode.namedItem( "dependencies" );
284 QStringList depsList = QStringList();
285 for( QDomNode prodNode = depsNode.firstChild(); !prodNode.isNull(); prodNode = prodNode.nextSibling() ) {
286 if ( !prodNode.isElement() )
288 QDomElement prodElem = prodNode.toElement();
289 QString prodName = prodElem.attribute( "name" ).stripWhiteSpace();
290 if ( theDepends.contains( prodName ) )
293 for ( QDomNode depNode = prodNode.firstChild(); !depNode.isNull(); depNode = depNode.nextSibling() ) {
294 if ( !depNode.isElement() )
296 QDomElement depElem = depNode.toElement();
297 QString depName = depElem.text();
298 if ( depName.isEmpty() )
300 if ( !depsList.contains( depName ) )
301 depsList.append( depName );
303 theDepends[ prodName ] = depsList;
306 // ================================================================
308 * StructureParser::readXmlFile
309 * Read XML configuration file for the current platform
311 // ================================================================
312 void StructureParser::readXmlFile(QString theFileName)
314 QDomDocument doc( "xml_doc" );
315 QFile file( theFileName );
316 if ( !file.open( IO_ReadOnly ) )
318 if ( !doc.setContent( &file ) ) {
324 QDomElement docElem = doc.documentElement();
326 for( QDomNode node = docElem.firstChild(); !node.isNull(); node = node.nextSibling() ) {
327 QString nodeName = node.nodeName();
328 if ( nodeName == "config" && node.isElement() ) {
329 getConfigInfo( node.toElement() );
331 else if ( nodeName == "buttons" && node.hasChildNodes() && myModules && myWizard ) {
332 getButtonsInfo( node );
334 else if ( nodeName == "products" && node.hasChildNodes() && myModules && myWizard ) {
335 getProductsInfo( node );