1 //-----------------------------------------------------------------------------
3 // KDE xscreensaver configuration dialog
5 // Copyright (c) Martin R. Jones <mjones@kde.org> 2002
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.
23 #include "kxscontrol.h"
30 KXSXml::KXSXml( QWidget
*p
)
31 : parent(p
), handler(0)
35 bool KXSXml::parse( const QString
&filename
)
37 QFile
file( filename
);
38 handler
= new KXSXmlHandler( parent
);
39 QXmlInputSource
source( &file
);
40 QXmlSimpleReader reader
;
41 reader
.setContentHandler( handler
);
42 if ( !reader
.parse( &source
, false ) )
48 QList
<KXSConfigItem
*> KXSXml::items() const
51 return handler
->items();
52 return QList
<KXSConfigItem
*>();
55 QString
KXSXml::description() const
58 return handler
->description();
62 //===========================================================================
64 KXSXmlHandler::KXSXmlHandler( QWidget
*p
)
65 : QXmlDefaultHandler(), parent(p
), selItem(0), inDesc(false)
67 mParentStack
.push( p
);
70 bool KXSXmlHandler::startDocument()
75 bool KXSXmlHandler::startElement( const QString
&, const QString
&,
77 const QXmlAttributes
&atts
)
80 QString id
= atts
.value("id");
81 if ( qName
== "number" ) {
82 QString sLow
= atts
.value( "low" );
83 QString sHigh
= atts
.value( "high" );
84 if ( sLow
.contains( '.' ) || sHigh
.contains( '.' ) ) {
86 i
= new KXSDoubleRangeControl( parent
, id
, atts
);
88 i
= new KXSDoubleRangeItem( id
, atts
);
91 i
= new KXSRangeControl( parent
, id
, atts
);
93 i
= new KXSRangeItem( id
, atts
);
95 } else if ( qName
== "boolean" ) {
97 i
= new KXSCheckBoxControl( parent
, id
, atts
);
99 i
= new KXSBoolItem( id
, atts
);
100 } else if ( qName
== "string" ) {
102 i
= new KXSLineEditControl( parent
, id
, atts
);
104 i
= new KXSStringItem( id
, atts
);
105 } else if ( qName
== "file" ) {
107 i
= new KXSFileControl( parent
, id
, atts
);
109 i
= new KXSStringItem( id
, atts
);
110 } else if ( qName
== "_description" ) {
112 } else if ( qName
== "select" ) {
114 selItem
= new KXSDropListControl( parent
, id
, atts
);
116 selItem
= new KXSSelectItem( id
, atts
);
118 } else if ( qName
== "option" && selItem
) {
119 selItem
->addOption( atts
);
120 } else if ( qName
== "hgroup" && parent
) {
121 KHBox
*hb
= new KHBox( parent
);
122 mParentStack
.push( hb
);
124 } else if ( qName
== "vgroup" && parent
) {
125 KVBox
*vb
= new KVBox( parent
);
126 mParentStack
.push( vb
);
131 mConfigItemList
.append( i
);
136 bool KXSXmlHandler::endElement( const QString
&, const QString
&, const QString
&qName
)
138 if ( qName
== "select" ) {
140 } else if ( qName
== "_description" ) {
142 } else if ( (qName
== "hgroup" || qName
== "vgroup") && parent
) {
143 if ( mParentStack
.count() > 1 ) {
145 parent
= mParentStack
.top();
151 bool KXSXmlHandler::characters( const QString
&ch
)