Salome HOME
Fix a bug of config file for RedHat 9 - correct binaries distribution path
[tools/install.git] / src / SALOME_XmlHandler.cxx
1 //  File      : SALOME_XmlHandler.cxx
2 //  Created   : Thu Dec 18 12:01:00 2002
3 //  Author    : Vadim SANDLER
4 //  Project   : SALOME
5 //  Module    : Installation Wizard
6 //  Copyright : 2004-2005 CEA
7
8 #include "globals.h"
9
10 #include "SALOME_XmlHandler.hxx"
11 #include "SALOME_ProductsView.hxx"
12 #include "SALOME_InstallWizard.hxx"
13
14 #include <qlineedit.h>
15
16 bool isBoolAttributeSet( const QString& attr ) {
17   return ( attr == "true" || attr == "yes" || attr == "ok" || ( !attr.stripWhiteSpace().isEmpty() && attr.toInt() != 0 ) );
18 }
19
20 // ================================================================
21 /*!
22  *  StructureParser::StructureParser
23  *  Constructor
24  */
25 // ================================================================
26 StructureParser::StructureParser( SALOME_InstallWizard* wizard )
27      : QXmlDefaultHandler(), 
28        myWizard( wizard ), 
29        myTree( 0 ), 
30        myTargetDir( 0 ), 
31        myTempDir( 0 )
32 {
33 }
34 // ================================================================
35 /*!
36  *  StructureParser::setProductsList
37  *  Sets products list view
38  */
39 // ================================================================
40 void StructureParser::setProductsList( ProductsView* tree )
41 {
42   myTree = tree;
43 }
44 // ================================================================
45 /*!
46  *  StructureParser::setTargetDir
47  *  Sets target directory widget
48  */
49 // ================================================================
50 void StructureParser::setTargetDir( QLineEdit* dir )
51 {
52   myTargetDir = dir;
53 }
54 // ================================================================
55 /*!
56  *  StructureParser::setTempDir
57  *  Sets temp directory widget
58  */
59 // ================================================================
60 void StructureParser::setTempDir( QLineEdit* dir )
61 {
62   myTempDir = dir;
63 }
64 // ================================================================
65 /*!
66  *  StructureParser::startElement
67  *  Begins parsing of the xml dom-element
68  */  
69 // ================================================================
70 bool StructureParser::startElement( const QString&        /*namespaceURI*/,
71                                     const QString&        /*localName*/,
72                                     const QString&        qName,
73                                     const QXmlAttributes& attributes)
74 {
75   ___MESSAGE___( qName );
76   ___MESSAGE___( attributes.length() );
77   QCheckListItem* element;
78   if (( qName == "config" ) && ( attributes.length() > 0 ) ) {
79     QString myVersion, myCaption, myCopyright, myLicense, myOS;
80     if ( attributes.value( "version" ) ) {
81       myVersion = attributes.value( "version" ).stripWhiteSpace();
82       if ( myWizard && !myVersion.isEmpty() ) 
83         myWizard->setVersion( myVersion );
84     }
85     if ( attributes.value( "caption" ) ) {
86       myCaption = attributes.value( "caption" ).arg( myVersion ).stripWhiteSpace();
87       if ( myWizard && !myCaption.isEmpty() ) 
88         myWizard->setCaption( myCaption );
89     }
90     if ( attributes.value( "copyright" ) ) {
91       myCopyright = attributes.value( "copyright" ).stripWhiteSpace();
92       if ( myWizard && !myCopyright.isEmpty() ) 
93         myWizard->setCopyright( myCopyright );
94     }
95     if ( attributes.value( "license" ) ) {
96       myLicense = attributes.value( "license" ).stripWhiteSpace();
97       if ( myWizard && !myLicense.isEmpty() ) 
98         myWizard->setLicense( myLicense );
99     }
100     if ( attributes.value( "os" ) ) {
101       myOS = attributes.value( "os" ).stripWhiteSpace();
102       if ( myWizard && !myOS.isEmpty() ) 
103         myWizard->setOS( myOS );
104     }
105   } 
106   else if (( qName == "product" ) && ( attributes.length() > 0 ) && myTree && myWizard ) {
107     if ( isBoolAttributeSet( attributes.value( "disable" ) ) )
108       return true;
109     
110     QString install = attributes.value( "install" );
111     QStringList supported = QStringList::split( ",", attributes.value( "supported" ) );
112     QString script = attributes.value( "script" );
113     QStringList deps = QStringList();
114     if ( attributes.value( "dependancies" ) != "" )
115       deps = QStringList::split( ",", attributes.value( "dependancies" ), false );
116     element = myTree->addItem( attributes.value( "name" ), attributes.value( "version" ), install, supported, script );
117     QStringList diskspace = QStringList::split(",",attributes.value( "installdiskspace" ) );
118     QString descr = QString::null;
119     if ( attributes.value( "description" ) != "" )
120       descr = attributes.value( "description" ).stripWhiteSpace();
121     bool pickUp = isBoolAttributeSet( attributes.value( "pickupenv" ) );
122     myWizard->setDependancies( element, 
123                                Dependancies( attributes.value( "name" ), 
124                                              deps,
125                                              ( diskspace.count() > 0 ? diskspace[ 0 ].toInt() : 0 ), 
126                                              ( diskspace.count() > 1 ? diskspace[1].toInt() : ( diskspace.count() > 0 ? diskspace[0].toInt() : 0 ) ), 
127                                              attributes.value( "temporarydiskspace" ).toInt(),
128                                              install,
129                                              descr,
130                                              pickUp ) );
131   }
132   else if (( qName == "path" ) && ( attributes.length() > 0 ) && myWizard ) {
133     if ( myTargetDir )
134       myTargetDir->setText( attributes.value( "targetdir" ) );
135
136     if ( myTempDir ) {
137       if ( attributes.value( "tempdir" ) == "" )
138         myTempDir->setText( "/tmp" );
139       else
140         myTempDir->setText( attributes.value( "tempdir" ) );
141     }
142   }
143   return true;
144 }
145 // ================================================================
146 /*!
147  *  StructureParser::endElement
148  *  Finishes parsing of the xml dom-element
149  */
150 // ================================================================
151 bool StructureParser::endElement( const QString&, 
152                                   const QString&,
153                                   const QString& )
154 {
155   return true;
156 }
157