diff --git a/applet.cpp b/applet.cpp index c4bfe0122..519a406f4 100644 --- a/applet.cpp +++ b/applet.cpp @@ -169,7 +169,8 @@ public: if (!xmlPath.isEmpty()) { QFile file(xmlPath); // FIXME: KConfigSkeleton doesn't play well with KConfigGroup =/ - //configXml = new ConfigXml(applet->config(), &file); + KConfigGroup config = applet->config(); + configXml = new ConfigXml(&config, &file); } if (!package->filePath("mainconfigui").isEmpty()) { diff --git a/configxml.cpp b/configxml.cpp index 4c55fe3fd..efe6b3f5d 100644 --- a/configxml.cpp +++ b/configxml.cpp @@ -174,6 +174,8 @@ class ConfigXml::Private return v; } + void parse(ConfigXml *configXml, QIODevice *xml); + QList bools; QList strings; QList stringlists; @@ -223,6 +225,16 @@ private: bool m_inChoice; }; +void ConfigXml::Private::parse(ConfigXml *configXml, QIODevice *xml) +{ + QXmlInputSource source(xml); + QXmlSimpleReader reader; + ConfigXmlHandler handler(configXml, this); + reader.setContentHandler(&handler); + reader.parse(&source, false); +} + +QList bools; ConfigXmlHandler::ConfigXmlHandler(ConfigXml* config, ConfigXml::Private* d) : QXmlDefaultHandler(), m_config(config), @@ -495,15 +507,21 @@ ConfigXml::ConfigXml(const QString &configFile, QIODevice *xml, QObject *parent) reader.parse(&source, false); } -ConfigXml::ConfigXml(KSharedConfig::Ptr config, QIODevice *xml, QObject *parent) +ConfigXml::ConfigXml(KSharedConfigPtr config, QIODevice *xml, QObject *parent) : KConfigSkeleton(config, parent), d(new Private) { - QXmlInputSource source(xml); - QXmlSimpleReader reader; - ConfigXmlHandler handler(this, d); - reader.setContentHandler(&handler); - reader.parse(&source, false); + d->parse(this, xml); +} + +//FIXME: obviously this is broken and should be using the group as the root, +// but KConfigSkeleton does not currently support this. it will eventually though, +// at which point this can be addressed properly +ConfigXml::ConfigXml(const KConfigGroup *config, QIODevice *xml, QObject *parent) + : KConfigSkeleton(KSharedConfig::openConfig(config->config()->name()), parent), + d(new Private) +{ + d->parse(this, xml); } ConfigXml::~ConfigXml() diff --git a/configxml.h b/configxml.h index c3c11c5c3..fde7a5066 100644 --- a/configxml.h +++ b/configxml.h @@ -20,8 +20,9 @@ #ifndef CONFIGXML_H #define CONFIGXML_H -#include -#include +#include +#include +#include #include @@ -84,11 +85,21 @@ public: * Creates a KConfigSkeleton populated using the definition found in * the XML data passed in. * - * @param configFile path to the configuration file to use + * @param config the configuration object to use * @param xml the xml data; must be valid KConfigXT data * @param parent optional QObject parent **/ - ConfigXml(KSharedConfig::Ptr config, QIODevice *xml, QObject *parent = 0); + ConfigXml(KSharedConfigPtr config, QIODevice *xml, QObject *parent = 0); + + /** + * Creates a KConfigSkeleton populated using the definition found in + * the XML data passed in. + * + * @param config the group to use as the root for configuration items + * @param xml the xml data; must be valid KConfigXT data + * @param parent optional QObject parent + **/ + ConfigXml(const KConfigGroup *config, QIODevice *xml, QObject *parent = 0); ~ConfigXml(); class Private;