SVN_SILENT made messages (.desktop file)
[kdeartwork.git] / kscreensaver / kxsconfig / kxsxml.cpp
blob9d7ad8500b0be8af838b3f875ad263999d66a7fe
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 <kvbox.h>
27 #include <khbox.h>
28 #include <stdio.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 ) )
43 return false;
45 return true;
48 QList<KXSConfigItem*> KXSXml::items() const
50 if ( handler )
51 return handler->items();
52 return QList<KXSConfigItem*>();
55 QString KXSXml::description() const
57 if ( handler )
58 return handler->description();
59 return QString();
62 //===========================================================================
64 KXSXmlHandler::KXSXmlHandler( QWidget *p )
65 : QXmlDefaultHandler(), parent(p), selItem(0), inDesc(false)
67 mParentStack.push( p );
70 bool KXSXmlHandler::startDocument()
72 return true;
75 bool KXSXmlHandler::startElement( const QString&, const QString&,
76 const QString& qName,
77 const QXmlAttributes &atts )
79 KXSConfigItem *i = 0;
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( '.' ) ) {
85 if ( parent )
86 i = new KXSDoubleRangeControl( parent, id, atts );
87 else
88 i = new KXSDoubleRangeItem( id, atts );
89 } else {
90 if ( parent )
91 i = new KXSRangeControl( parent, id, atts );
92 else
93 i = new KXSRangeItem( id, atts );
95 } else if ( qName == "boolean" ) {
96 if ( parent )
97 i = new KXSCheckBoxControl( parent, id, atts );
98 else
99 i = new KXSBoolItem( id, atts );
100 } else if ( qName == "string" ) {
101 if ( parent )
102 i = new KXSLineEditControl( parent, id, atts );
103 else
104 i = new KXSStringItem( id, atts );
105 } else if ( qName == "file" ) {
106 if ( parent )
107 i = new KXSFileControl( parent, id, atts );
108 else
109 i = new KXSStringItem( id, atts );
110 } else if ( qName == "_description" ) {
111 inDesc = true;
112 } else if ( qName == "select" ) {
113 if ( parent )
114 selItem = new KXSDropListControl( parent, id, atts );
115 else
116 selItem = new KXSSelectItem( id, atts );
117 i = selItem;
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 );
123 parent = hb;
124 } else if ( qName == "vgroup" && parent ) {
125 KVBox *vb = new KVBox( parent );
126 mParentStack.push( vb );
127 parent = vb;
130 if ( i )
131 mConfigItemList.append( i );
133 return true;
136 bool KXSXmlHandler::endElement( const QString&, const QString&, const QString &qName )
138 if ( qName == "select" ) {
139 selItem = 0;
140 } else if ( qName == "_description" ) {
141 inDesc = false;
142 } else if ( (qName == "hgroup" || qName == "vgroup") && parent ) {
143 if ( mParentStack.count() > 1 ) {
144 mParentStack.pop();
145 parent = mParentStack.top();
148 return true;
151 bool KXSXmlHandler::characters( const QString &ch )
153 if ( inDesc )
154 desc += ch;
155 return true;