future proof the ConfigXml API a bit by pretending we actually know what to do with a KConfigGroup

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=741174
This commit is contained in:
Aaron J. Seigo 2007-11-25 00:14:27 +00:00
parent 9c31a55b06
commit f54dcc2cc1
3 changed files with 41 additions and 11 deletions

View File

@ -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()) {

View File

@ -174,6 +174,8 @@ class ConfigXml::Private
return v;
}
void parse(ConfigXml *configXml, QIODevice *xml);
QList<bool*> bools;
QList<QString*> strings;
QList<QStringList*> 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<bool*> 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()

View File

@ -20,8 +20,9 @@
#ifndef CONFIGXML_H
#define CONFIGXML_H
#include <kconfigskeleton.h>
#include <ksharedconfig.h>
#include <KConfigGroup>
#include <KConfigSkeleton>
#include <KSharedConfig>
#include <plasma/plasma_export.h>
@ -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;