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