1 // File : SALOME_XmlHandler.cxx
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER
5 // Module : Installation Wizard
6 // Copyright : 2004-2005 CEA
10 #include "SALOME_XmlHandler.hxx"
11 #include "SALOME_ProductsView.hxx"
12 #include "SALOME_InstallWizard.hxx"
14 #include <qlineedit.h>
18 // ================================================================
20 * ::isBoolAttributeSet [ static ]
21 * Returns true if the attribute stores boolean value and
22 * corresponds to True value
24 // ================================================================
25 static bool isBoolAttributeSet( const QString& attr ) {
26 return ( attr.lower() == "true" ||
27 attr.lower() == "yes" ||
28 attr.lower() == "ok" ||
29 ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) );
32 // ================================================================
34 * ::environmentVariable [ static ]
35 * Seraches for the environment variable and returns it's
36 * position on the given string
38 // ================================================================
39 QString environmentVariable( const QString& str, int& start, int& len ) {
40 QString varName = QString::null;
43 // Environment variable can be given in the form:
48 // The first symbol should be the letter.
49 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_]*)\\%" );
51 int pos = rx.search( str, start );
55 len = rx.matchedLength();
56 QStringList caps = rx.capturedTexts();
57 for ( uint i = 1; i <= caps.count() && varName.isEmpty(); i++ )
58 varName = *caps.at( i );
62 // ================================================================
64 * ::substituteVars [ static ]
65 * Substitutes environment variables in the given string
68 // ================================================================
69 static QString substituteVars( const QString& str ) {
72 int start( 0 ), len( 0 );
74 QString envName = environmentVariable( res, start, len );
75 if ( envName.isNull() )
78 QString newStr = QString::null;
79 if ( ::getenv( envName ) )
80 newStr = QString( ::getenv( envName ) );
82 res.replace( start, len, newStr );
88 // ================================================================
90 * StructureParser::StructureParser
93 // ================================================================
94 StructureParser::StructureParser( SALOME_InstallWizard* wizard )
95 : QXmlDefaultHandler(),
102 // ================================================================
104 * StructureParser::setProductsList
105 * Sets products list view
107 // ================================================================
108 void StructureParser::setProductsList( ProductsView* tree )
112 // ================================================================
114 * StructureParser::setTargetDir
115 * Sets target directory widget
117 // ================================================================
118 void StructureParser::setTargetDir( QLineEdit* dir )
120 QString home = QDir::homeDirPath();
122 if ( myTargetDir && !home.isEmpty() )
123 myTargetDir->setText( home + QDir::separator() + "salome" );
125 // ================================================================
127 * StructureParser::setTempDir
128 * Sets temp directory widget
130 // ================================================================
131 void StructureParser::setTempDir( QLineEdit* dir )
135 myTempDir->setText( "/tmp" );
137 // ================================================================
139 * StructureParser::startElement
140 * Begins parsing of the xml dom-element
142 // ================================================================
143 bool StructureParser::startElement( const QString& /*namespaceURI*/,
144 const QString& /*localName*/,
145 const QString& qName,
146 const QXmlAttributes& attributes)
148 ___MESSAGE___( qName );
149 ___MESSAGE___( attributes.length() );
150 QCheckListItem* element;
151 if (( qName == "config" ) && ( attributes.length() > 0 ) ) {
152 QString myVersion, myCaption, myCopyright, myLicense, myOS;
153 if ( attributes.value( "version" ) ) {
154 myVersion = attributes.value( "version" ).stripWhiteSpace();
155 if ( myWizard && !myVersion.isEmpty() )
156 myWizard->setVersion( myVersion );
158 if ( attributes.value( "caption" ) ) {
159 myCaption = attributes.value( "caption" ).arg( myVersion ).stripWhiteSpace();
160 if ( myWizard && !myCaption.isEmpty() )
161 myWizard->setCaption( myCaption );
163 if ( attributes.value( "copyright" ) ) {
164 myCopyright = attributes.value( "copyright" ).stripWhiteSpace();
165 if ( myWizard && !myCopyright.isEmpty() )
166 myWizard->setCopyright( myCopyright );
168 if ( attributes.value( "license" ) ) {
169 myLicense = attributes.value( "license" ).stripWhiteSpace();
170 if ( myWizard && !myLicense.isEmpty() )
171 myWizard->setLicense( myLicense );
173 if ( attributes.value( "os" ) ) {
174 myOS = attributes.value( "os" ).stripWhiteSpace();
175 if ( myWizard && !myOS.isEmpty() )
176 myWizard->setOS( myOS );
179 else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) {
180 if ( isBoolAttributeSet( attributes.value( "disable" ) ) )
183 QString install = attributes.value( "install" );
184 QStringList supported = QStringList::split( ",", attributes.value( "supported" ) );
185 QString script = attributes.value( "script" );
186 QStringList deps = QStringList();
187 if ( attributes.value( "dependancies" ) != "" )
188 deps = QStringList::split( ",", attributes.value( "dependancies" ), false );
189 element = myTree->addItem( attributes.value( "name" ), attributes.value( "version" ), install, supported, script );
190 QStringList diskspace = QStringList::split(",",attributes.value( "installdiskspace" ) );
191 QString descr = QString::null;
192 if ( attributes.value( "description" ) != "" )
193 descr = attributes.value( "description" ).stripWhiteSpace();
194 QString ctx = QString::null;
195 if ( attributes.value( "context" ) != "" )
196 ctx = attributes.value( "context" ).stripWhiteSpace().lower();
197 bool pickUp = isBoolAttributeSet( attributes.value( "pickupenv" ) );
198 myWizard->setDependancies( element,
199 Dependancies( attributes.value( "name" ),
201 ( diskspace.count() > 0 ? diskspace[ 0 ].toInt() : 0 ),
202 ( diskspace.count() > 1 ? diskspace[1].toInt() : ( diskspace.count() > 0 ? diskspace[0].toInt() : 0 ) ),
203 attributes.value( "temporarydiskspace" ).toInt(),
209 else if (( qName == "path" ) && ( attributes.length() > 0 ) && myWizard ) {
211 myTargetDir->setText( substituteVars( attributes.value( "targetdir" ) ) );
214 if ( !attributes.value( "tempdir" ).stripWhiteSpace().isEmpty() )
215 myTempDir->setText( substituteVars( attributes.value( "tempdir" ) ) );
220 // ================================================================
222 * StructureParser::endElement
223 * Finishes parsing of the xml dom-element
225 // ================================================================
226 bool StructureParser::endElement( const QString&,