Try to fix it
[kdeartwork.git] / kscreensaver / kxsconfig / kxsxml.cpp
blob1892983c8fe7ac0ace649ba6f43a4f5aedb21bee
1 //-----------------------------------------------------------------------------
2 //
3 // KDE xscreensaver configuration dialog
4 //
5 // Copyright (c) Martin R. Jones <mjones@kde.org> 2002
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public
9 // License as published by the Free Software Foundation;
10 // version 2 of the License.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; see the file COPYING. If not, write to
19 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, USA.
22 #include "kxsxml.h"
23 #include "kxscontrol.h"
24 #include <qobject.h>
25 #include <qfile.h>
26 #include <q3vbox.h>
27 #include <q3hbox.h>
28 //Added by qt3to4:
29 #include <Q3PtrList>
30 #include <stdio.h>
32 KXSXml::KXSXml( QWidget *p )
33 : parent(p), handler(0)
37 bool KXSXml::parse( const QString &filename )
39 QFile file( filename );
40 handler = new KXSXmlHandler( parent );
41 QXmlInputSource source( &file );
42 QXmlSimpleReader reader;
43 reader.setContentHandler( handler );
44 if ( !reader.parse( &source, FALSE ) )
45 return FALSE;
47 return true;
50 const Q3PtrList<KXSConfigItem> *KXSXml::items() const
52 if ( handler )
53 return handler->items();
54 return 0;
57 QString KXSXml::description() const
59 if ( handler )
60 return handler->description();
61 return QString();
64 //===========================================================================
66 KXSXmlHandler::KXSXmlHandler( QWidget *p )
67 : QXmlDefaultHandler(), parent(p), selItem(0), inDesc(false)
69 mParentStack.push( p );
72 bool KXSXmlHandler::startDocument()
74 return true;
77 bool KXSXmlHandler::startElement( const QString&, const QString&,
78 const QString& qName,
79 const QXmlAttributes &atts )
81 KXSConfigItem *i = 0;
82 QString id = atts.value("id");
83 if ( qName == "number" ) {
84 QString sLow = atts.value( "low" );
85 QString sHigh = atts.value( "high" );
86 if ( sLow.contains( '.' ) || sHigh.contains( '.' ) ) {
87 if ( parent )
88 i = new KXSDoubleRangeControl( parent, id, atts );
89 else
90 i = new KXSDoubleRangeItem( id, atts );
91 } else {
92 if ( parent )
93 i = new KXSRangeControl( parent, id, atts );
94 else
95 i = new KXSRangeItem( id, atts );
97 } else if ( qName == "boolean" ) {
98 if ( parent )
99 i = new KXSCheckBoxControl( parent, id, atts );
100 else
101 i = new KXSBoolItem( id, atts );
102 } else if ( qName == "string" ) {
103 if ( parent )
104 i = new KXSLineEditControl( parent, id, atts );
105 else
106 i = new KXSStringItem( id, atts );
107 } else if ( qName == "file" ) {
108 if ( parent )
109 i = new KXSFileControl( parent, id, atts );
110 else
111 i = new KXSStringItem( id, atts );
112 } else if ( qName == "_description" ) {
113 inDesc = true;
114 } else if ( qName == "select" ) {
115 if ( parent )
116 selItem = new KXSDropListControl( parent, id, atts );
117 else
118 selItem = new KXSSelectItem( id, atts );
119 i = selItem;
120 } else if ( qName == "option" && selItem ) {
121 selItem->addOption( atts );
122 } else if ( qName == "hgroup" && parent ) {
123 Q3HBox *hb = new Q3HBox( parent );
124 mParentStack.push( hb );
125 parent = hb;
126 } else if ( qName == "vgroup" && parent ) {
127 Q3VBox *vb = new Q3VBox( parent );
128 mParentStack.push( vb );
129 parent = vb;
132 if ( i )
133 mConfigItemList.append( i );
135 return true;
138 bool KXSXmlHandler::endElement( const QString&, const QString&, const QString &qName )
140 if ( qName == "select" ) {
141 selItem = 0;
142 } else if ( qName == "_description" ) {
143 inDesc = false;
144 } else if ( (qName == "hgroup" || qName == "vgroup") && parent ) {
145 if ( mParentStack.count() > 1 ) {
146 mParentStack.pop();
147 parent = mParentStack.top();
150 return true;
153 bool KXSXmlHandler::characters( const QString &ch )
155 if ( inDesc )
156 desc += ch;
157 return true;