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"
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
) )
50 const Q3PtrList
<KXSConfigItem
> *KXSXml::items() const
53 return handler
->items();
57 QString
KXSXml::description() const
60 return handler
->description();
64 //===========================================================================
66 KXSXmlHandler::KXSXmlHandler( QWidget
*p
)
67 : QXmlDefaultHandler(), parent(p
), selItem(0), inDesc(false)
69 mParentStack
.push( p
);
72 bool KXSXmlHandler::startDocument()
77 bool KXSXmlHandler::startElement( const QString
&, const QString
&,
79 const QXmlAttributes
&atts
)
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( '.' ) ) {
88 i
= new KXSDoubleRangeControl( parent
, id
, atts
);
90 i
= new KXSDoubleRangeItem( id
, atts
);
93 i
= new KXSRangeControl( parent
, id
, atts
);
95 i
= new KXSRangeItem( id
, atts
);
97 } else if ( qName
== "boolean" ) {
99 i
= new KXSCheckBoxControl( parent
, id
, atts
);
101 i
= new KXSBoolItem( id
, atts
);
102 } else if ( qName
== "string" ) {
104 i
= new KXSLineEditControl( parent
, id
, atts
);
106 i
= new KXSStringItem( id
, atts
);
107 } else if ( qName
== "file" ) {
109 i
= new KXSFileControl( parent
, id
, atts
);
111 i
= new KXSStringItem( id
, atts
);
112 } else if ( qName
== "_description" ) {
114 } else if ( qName
== "select" ) {
116 selItem
= new KXSDropListControl( parent
, id
, atts
);
118 selItem
= new KXSSelectItem( id
, atts
);
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
);
126 } else if ( qName
== "vgroup" && parent
) {
127 Q3VBox
*vb
= new Q3VBox( parent
);
128 mParentStack
.push( vb
);
133 mConfigItemList
.append( i
);
138 bool KXSXmlHandler::endElement( const QString
&, const QString
&, const QString
&qName
)
140 if ( qName
== "select" ) {
142 } else if ( qName
== "_description" ) {
144 } else if ( (qName
== "hgroup" || qName
== "vgroup") && parent
) {
145 if ( mParentStack
.count() > 1 ) {
147 parent
= mParentStack
.top();
153 bool KXSXmlHandler::characters( const QString
&ch
)