2007-07-18 11:26:24 +02:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
2007-07-18 11:26:24 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
2007-07-18 11:26:24 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
#include "configloader.h"
|
2007-07-18 11:26:24 +02:00
|
|
|
|
|
|
|
#include <QColor>
|
|
|
|
#include <QFont>
|
2008-08-04 10:45:41 +02:00
|
|
|
#include <QHash>
|
2007-07-18 11:26:24 +02:00
|
|
|
#include <QXmlContentHandler>
|
|
|
|
#include <QXmlInputSource>
|
|
|
|
#include <QXmlSimpleReader>
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KUrl>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
class ConfigLoaderPrivate
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-10-29 18:46:33 +01:00
|
|
|
~ConfigLoaderPrivate()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
qDeleteAll(bools);
|
|
|
|
qDeleteAll(strings);
|
|
|
|
qDeleteAll(stringlists);
|
|
|
|
qDeleteAll(colors);
|
|
|
|
qDeleteAll(fonts);
|
|
|
|
qDeleteAll(ints);
|
|
|
|
qDeleteAll(uints);
|
|
|
|
qDeleteAll(urls);
|
|
|
|
qDeleteAll(dateTimes);
|
2007-09-10 17:07:29 +02:00
|
|
|
qDeleteAll(doubles);
|
|
|
|
qDeleteAll(intlists);
|
|
|
|
qDeleteAll(longlongs);
|
|
|
|
qDeleteAll(points);
|
|
|
|
qDeleteAll(rects);
|
|
|
|
qDeleteAll(sizes);
|
|
|
|
qDeleteAll(ulonglongs);
|
|
|
|
qDeleteAll(urllists);
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
bool *newBool()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
bool *v = new bool;
|
2007-07-18 11:26:24 +02:00
|
|
|
bools.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QString *newString()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QString *v = new QString;
|
2007-07-18 11:26:24 +02:00
|
|
|
strings.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QStringList *newStringList()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QStringList *v = new QStringList;
|
2007-07-18 11:26:24 +02:00
|
|
|
stringlists.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QColor *newColor()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QColor *v = new QColor;
|
2007-07-18 11:26:24 +02:00
|
|
|
colors.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QFont *newFont()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QFont *v = new QFont;
|
2007-07-18 11:26:24 +02:00
|
|
|
fonts.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
qint32 *newInt()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
qint32 *v = new qint32;
|
2007-07-18 11:26:24 +02:00
|
|
|
ints.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
quint32 *newUint()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
quint32 *v = new quint32;
|
2007-07-18 11:26:24 +02:00
|
|
|
uints.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
KUrl *newUrl()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
KUrl *v = new KUrl;
|
2007-07-18 11:26:24 +02:00
|
|
|
urls.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QDateTime *newDateTime()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QDateTime *v = new QDateTime;
|
2007-07-18 11:26:24 +02:00
|
|
|
dateTimes.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
double *newDouble()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
double *v = new double;
|
2007-09-10 17:07:29 +02:00
|
|
|
doubles.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<qint32>* newIntList()
|
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QList<qint32> *v = new QList<qint32>;
|
2007-09-10 17:07:29 +02:00
|
|
|
intlists.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
qint64 *newLongLong()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
qint64 *v = new qint64;
|
2007-09-10 17:07:29 +02:00
|
|
|
longlongs.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QPoint *newPoint()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QPoint *v = new QPoint;
|
2007-09-10 17:07:29 +02:00
|
|
|
points.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QRect *newRect()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QRect *v = new QRect;
|
2007-09-10 17:07:29 +02:00
|
|
|
rects.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QSize *newSize()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
QSize *v = new QSize;
|
2007-09-10 17:07:29 +02:00
|
|
|
sizes.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
quint64 *newULongLong()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
quint64 *v = new quint64;
|
2007-09-10 17:07:29 +02:00
|
|
|
ulonglongs.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
KUrl::List *newUrlList()
|
2007-09-10 17:07:29 +02:00
|
|
|
{
|
2008-10-12 00:48:38 +02:00
|
|
|
KUrl::List *v = new KUrl::List;
|
2007-09-10 17:07:29 +02:00
|
|
|
urllists.append(v);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
void parse(ConfigLoader *loader, QIODevice *xml);
|
2007-11-25 01:14:27 +01:00
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
QList<bool *> bools;
|
|
|
|
QList<QString *> strings;
|
|
|
|
QList<QStringList *> stringlists;
|
|
|
|
QList<QColor *> colors;
|
|
|
|
QList<QFont *> fonts;
|
|
|
|
QList<qint32 *> ints;
|
|
|
|
QList<quint32 *> uints;
|
|
|
|
QList<KUrl *> urls;
|
|
|
|
QList<QDateTime *> dateTimes;
|
|
|
|
QList<double *> doubles;
|
|
|
|
QList<QList<qint32> *> intlists;
|
|
|
|
QList<qint64 *> longlongs;
|
|
|
|
QList<QPoint *> points;
|
|
|
|
QList<QRect *> rects;
|
|
|
|
QList<QSize *> sizes;
|
|
|
|
QList<quint64 *> ulonglongs;
|
|
|
|
QList<KUrl::List *> urllists;
|
2008-09-23 14:21:19 +02:00
|
|
|
QString baseGroup;
|
2008-09-04 00:28:10 +02:00
|
|
|
QStringList groups;
|
2008-08-04 09:59:32 +02:00
|
|
|
QHash<QString, QString> keysToNames;
|
2007-07-18 11:26:24 +02:00
|
|
|
};
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
class ConfigLoaderHandler : public QXmlDefaultHandler
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d);
|
2008-10-12 00:48:38 +02:00
|
|
|
bool startElement(const QString &namespaceURI, const QString &localName,
|
|
|
|
const QString &qName, const QXmlAttributes &atts);
|
|
|
|
bool endElement(const QString &namespaceURI, const QString &localName,
|
|
|
|
const QString &qName);
|
2007-07-18 11:26:24 +02:00
|
|
|
bool characters(const QString &ch);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void addItem();
|
|
|
|
void resetState();
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoader *m_config;
|
|
|
|
ConfigLoaderPrivate *d;
|
2007-07-18 11:26:24 +02:00
|
|
|
int m_min;
|
|
|
|
int m_max;
|
|
|
|
QString m_name;
|
|
|
|
QString m_key;
|
|
|
|
QString m_type;
|
|
|
|
QString m_label;
|
|
|
|
QString m_default;
|
|
|
|
QString m_cdata;
|
|
|
|
QString m_whatsThis;
|
|
|
|
KConfigSkeleton::ItemEnum::Choice m_choice;
|
|
|
|
QList<KConfigSkeleton::ItemEnum::Choice> m_enumChoices;
|
|
|
|
bool m_haveMin;
|
|
|
|
bool m_haveMax;
|
|
|
|
bool m_inChoice;
|
|
|
|
};
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
void ConfigLoaderPrivate::parse(ConfigLoader *loader, QIODevice *xml)
|
2007-11-25 01:14:27 +01:00
|
|
|
{
|
|
|
|
QXmlInputSource source(xml);
|
|
|
|
QXmlSimpleReader reader;
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoaderHandler handler(loader, this);
|
2007-11-25 01:14:27 +01:00
|
|
|
reader.setContentHandler(&handler);
|
|
|
|
reader.parse(&source, false);
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoaderHandler::ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d)
|
2007-07-18 11:26:24 +02:00
|
|
|
: QXmlDefaultHandler(),
|
|
|
|
m_config(config),
|
|
|
|
d(d)
|
|
|
|
{
|
|
|
|
resetState();
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
bool ConfigLoaderHandler::startElement(const QString &namespaceURI, const QString &localName,
|
2007-07-18 11:26:24 +02:00
|
|
|
const QString &qName, const QXmlAttributes &attrs)
|
|
|
|
{
|
|
|
|
Q_UNUSED(namespaceURI)
|
|
|
|
Q_UNUSED(qName)
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
// kDebug() << "ConfigLoaderHandler::startElement(" << localName << qName;
|
2007-07-18 11:26:24 +02:00
|
|
|
int numAttrs = attrs.count();
|
|
|
|
QString tag = localName.toLower();
|
|
|
|
if (tag == "group") {
|
2008-09-23 14:21:19 +02:00
|
|
|
QString group;
|
2007-07-18 11:26:24 +02:00
|
|
|
for (int i = 0; i < numAttrs; ++i) {
|
|
|
|
QString name = attrs.localName(i).toLower();
|
|
|
|
if (name == "name") {
|
2008-09-18 06:57:18 +02:00
|
|
|
//kDebug() << "set group to" << attrs.value(i);
|
2008-09-23 14:21:19 +02:00
|
|
|
group = attrs.value(i);
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
}
|
2008-09-23 14:21:19 +02:00
|
|
|
if (group.isEmpty()) {
|
|
|
|
group = d->baseGroup;
|
|
|
|
} else {
|
|
|
|
d->groups.append(group);
|
|
|
|
if (!d->baseGroup.isEmpty()) {
|
|
|
|
group = d->baseGroup + '\x1d' + group;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_config->setCurrentGroup(group);
|
2007-07-18 11:26:24 +02:00
|
|
|
} else if (tag == "entry") {
|
|
|
|
for (int i = 0; i < numAttrs; ++i) {
|
|
|
|
QString name = attrs.localName(i).toLower();
|
|
|
|
if (name == "name") {
|
|
|
|
m_name = attrs.value(i);
|
|
|
|
} else if (name == "type") {
|
|
|
|
m_type = attrs.value(i).toLower();
|
|
|
|
} else if (name == "key") {
|
|
|
|
m_key = attrs.value(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (tag == "choice") {
|
|
|
|
m_choice.name.clear();
|
|
|
|
m_choice.label.clear();
|
|
|
|
m_choice.whatsThis.clear();
|
|
|
|
for (int i = 0; i < numAttrs; ++i) {
|
|
|
|
QString name = attrs.localName(i).toLower();
|
|
|
|
if (name == "name") {
|
|
|
|
m_choice.name = attrs.value(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_inChoice = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
bool ConfigLoaderHandler::characters(const QString &ch)
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
m_cdata.append(ch);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
bool ConfigLoaderHandler::endElement(const QString &namespaceURI,
|
2008-10-12 00:48:38 +02:00
|
|
|
const QString &localName, const QString &qName)
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(namespaceURI)
|
|
|
|
Q_UNUSED(qName)
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
// kDebug() << "ConfigLoaderHandler::endElement(" << localName << qName;
|
2007-07-18 11:26:24 +02:00
|
|
|
QString tag = localName.toLower();
|
|
|
|
if (tag == "entry") {
|
|
|
|
addItem();
|
|
|
|
resetState();
|
|
|
|
} else if (tag == "label") {
|
|
|
|
if (m_inChoice) {
|
2008-09-04 01:33:57 +02:00
|
|
|
m_choice.label = m_cdata.trimmed();
|
2007-07-18 11:26:24 +02:00
|
|
|
} else {
|
2008-09-04 01:33:57 +02:00
|
|
|
m_label = m_cdata.trimmed();
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
} else if (tag == "whatsthis") {
|
|
|
|
if (m_inChoice) {
|
2008-09-04 01:33:57 +02:00
|
|
|
m_choice.whatsThis = m_cdata.trimmed();
|
2007-07-18 11:26:24 +02:00
|
|
|
} else {
|
2008-09-04 01:33:57 +02:00
|
|
|
m_whatsThis = m_cdata.trimmed();
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
} else if (tag == "default") {
|
2008-09-04 01:33:57 +02:00
|
|
|
m_default = m_cdata.trimmed();
|
2007-07-18 11:26:24 +02:00
|
|
|
} else if (tag == "min") {
|
|
|
|
m_min = m_cdata.toInt(&m_haveMin);
|
|
|
|
} else if (tag == "max") {
|
|
|
|
m_max = m_cdata.toInt(&m_haveMax);
|
|
|
|
} else if (tag == "choice") {
|
|
|
|
m_enumChoices.append(m_choice);
|
|
|
|
m_inChoice = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cdata.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
void ConfigLoaderHandler::addItem()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
if (m_name.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeletonItem *item = 0;
|
2007-07-18 11:26:24 +02:00
|
|
|
|
|
|
|
if (m_type == "bool") {
|
|
|
|
bool defaultValue = m_default.toLower() == "true";
|
|
|
|
item = m_config->addItemBool(m_name, *d->newBool(), defaultValue, m_key);
|
|
|
|
} else if (m_type == "color") {
|
|
|
|
item = m_config->addItemColor(m_name, *d->newColor(), QColor(m_default), m_key);
|
|
|
|
} else if (m_type == "datetime") {
|
|
|
|
item = m_config->addItemDateTime(m_name, *d->newDateTime(),
|
|
|
|
QDateTime::fromString(m_default), m_key);
|
|
|
|
} else if (m_type == "enum") {
|
2008-09-18 19:40:31 +02:00
|
|
|
m_key = (m_key.isEmpty()) ? m_name : m_key;
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemEnum *enumItem =
|
|
|
|
new KConfigSkeleton::ItemEnum(m_config->currentGroup(),
|
|
|
|
m_key, *d->newInt(),
|
|
|
|
m_enumChoices,
|
|
|
|
m_default.toUInt());
|
2007-07-18 11:26:24 +02:00
|
|
|
m_config->addItem(enumItem, m_name);
|
|
|
|
item = enumItem;
|
|
|
|
} else if (m_type == "font") {
|
|
|
|
item = m_config->addItemFont(m_name, *d->newFont(), QFont(m_default), m_key);
|
|
|
|
} else if (m_type == "int") {
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemInt *intItem = m_config->addItemInt(m_name, *d->newInt(),
|
2008-09-04 01:33:57 +02:00
|
|
|
m_default.toInt(), m_key);
|
|
|
|
|
2007-07-18 11:26:24 +02:00
|
|
|
if (m_haveMin) {
|
|
|
|
intItem->setMinValue(m_min);
|
|
|
|
}
|
2008-09-04 01:33:57 +02:00
|
|
|
|
2007-07-18 11:26:24 +02:00
|
|
|
if (m_haveMax) {
|
|
|
|
intItem->setMaxValue(m_max);
|
|
|
|
}
|
2008-09-04 01:33:57 +02:00
|
|
|
|
2007-07-18 11:26:24 +02:00
|
|
|
item = intItem;
|
|
|
|
} else if (m_type == "password") {
|
|
|
|
item = m_config->addItemPassword(m_name, *d->newString(), m_default, m_key);
|
|
|
|
} else if (m_type == "path") {
|
|
|
|
item = m_config->addItemPath(m_name, *d->newString(), m_default, m_key);
|
|
|
|
} else if (m_type == "string") {
|
|
|
|
item = m_config->addItemString(m_name, *d->newString(), m_default, m_key);
|
|
|
|
} else if (m_type == "stringlist") {
|
|
|
|
//FIXME: the split() is naive and will break on lists with ,'s in them
|
2008-10-12 00:48:38 +02:00
|
|
|
item = m_config->addItemStringList(m_name, *d->newStringList(),
|
2008-10-12 12:57:42 +02:00
|
|
|
m_default.split(','), m_key);
|
2007-07-18 11:26:24 +02:00
|
|
|
} else if (m_type == "uint") {
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemUInt *uintItem =
|
|
|
|
m_config->addItemUInt(m_name, *d->newUint(), m_default.toUInt(), m_key);
|
2007-07-18 11:26:24 +02:00
|
|
|
if (m_haveMin) {
|
|
|
|
uintItem->setMinValue(m_min);
|
|
|
|
}
|
|
|
|
if (m_haveMax) {
|
|
|
|
uintItem->setMaxValue(m_max);
|
|
|
|
}
|
|
|
|
item = uintItem;
|
|
|
|
} else if (m_type == "url") {
|
2008-09-18 19:40:31 +02:00
|
|
|
m_key = (m_key.isEmpty()) ? m_name : m_key;
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemUrl *urlItem =
|
|
|
|
new KConfigSkeleton::ItemUrl(m_config->currentGroup(),
|
|
|
|
m_key, *d->newUrl(),
|
|
|
|
m_default);
|
2007-07-18 11:26:24 +02:00
|
|
|
m_config->addItem(urlItem, m_name);
|
|
|
|
item = urlItem;
|
2007-09-10 17:07:29 +02:00
|
|
|
} else if (m_type == "double") {
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemDouble *doubleItem = m_config->addItemDouble(m_name,
|
2007-09-10 17:07:29 +02:00
|
|
|
*d->newDouble(), m_default.toDouble(), m_key);
|
|
|
|
if (m_haveMin) {
|
|
|
|
doubleItem->setMinValue(m_min);
|
|
|
|
}
|
|
|
|
if (m_haveMax) {
|
|
|
|
doubleItem->setMaxValue(m_max);
|
|
|
|
}
|
|
|
|
item = doubleItem;
|
|
|
|
} else if (m_type == "intlist") {
|
2008-10-12 12:57:42 +02:00
|
|
|
QStringList tmpList = m_default.split(',');
|
2007-09-10 17:07:29 +02:00
|
|
|
QList<qint32> defaultList;
|
2008-04-26 18:19:00 +02:00
|
|
|
foreach (const QString &tmp, tmpList) {
|
2007-09-10 17:07:29 +02:00
|
|
|
defaultList.append(tmp.toInt());
|
|
|
|
}
|
|
|
|
item = m_config->addItemIntList(m_name, *d->newIntList(), defaultList, m_key);
|
|
|
|
} else if (m_type == "longlong") {
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemLongLong *longlongItem = m_config->addItemLongLong(m_name,
|
2007-09-10 17:07:29 +02:00
|
|
|
*d->newLongLong(), m_default.toLongLong(), m_key);
|
|
|
|
if (m_haveMin) {
|
|
|
|
longlongItem->setMinValue(m_min);
|
|
|
|
}
|
|
|
|
if (m_haveMax) {
|
|
|
|
longlongItem->setMaxValue(m_max);
|
|
|
|
}
|
|
|
|
item = longlongItem;
|
|
|
|
/* No addItemPathList in KConfigSkeleton ?
|
|
|
|
} else if (m_type == "PathList") {
|
|
|
|
//FIXME: the split() is naive and will break on lists with ,'s in them
|
2008-10-12 00:48:38 +02:00
|
|
|
item = m_config->addItemPathList(m_name, *d->newStringList(), m_default.split(","), m_key);
|
|
|
|
*/
|
2007-09-10 17:07:29 +02:00
|
|
|
} else if (m_type == "point") {
|
|
|
|
QPoint defaultPoint;
|
2008-10-12 12:57:42 +02:00
|
|
|
QStringList tmpList = m_default.split(',');
|
2007-09-10 17:07:29 +02:00
|
|
|
while (tmpList.size() >= 2) {
|
|
|
|
defaultPoint.setX(tmpList[0].toInt());
|
|
|
|
defaultPoint.setY(tmpList[1].toInt());
|
|
|
|
}
|
|
|
|
item = m_config->addItemPoint(m_name, *d->newPoint(), defaultPoint, m_key);
|
|
|
|
} else if (m_type == "rect") {
|
|
|
|
QRect defaultRect;
|
2008-10-12 12:57:42 +02:00
|
|
|
QStringList tmpList = m_default.split(',');
|
2007-09-10 17:07:29 +02:00
|
|
|
while (tmpList.size() >= 4) {
|
|
|
|
defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(),
|
|
|
|
tmpList[2].toInt(), tmpList[3].toInt());
|
|
|
|
}
|
|
|
|
item = m_config->addItemRect(m_name, *d->newRect(), defaultRect, m_key);
|
|
|
|
} else if (m_type == "size") {
|
|
|
|
QSize defaultSize;
|
2008-10-12 12:57:42 +02:00
|
|
|
QStringList tmpList = m_default.split(',');
|
2007-09-10 17:07:29 +02:00
|
|
|
while (tmpList.size() >= 2) {
|
|
|
|
defaultSize.setWidth(tmpList[0].toInt());
|
|
|
|
defaultSize.setHeight(tmpList[1].toInt());
|
|
|
|
}
|
|
|
|
item = m_config->addItemSize(m_name, *d->newSize(), defaultSize, m_key);
|
|
|
|
} else if (m_type == "ulonglong") {
|
2008-10-12 00:48:38 +02:00
|
|
|
KConfigSkeleton::ItemULongLong *ulonglongItem =
|
|
|
|
m_config->addItemULongLong(m_name, *d->newULongLong(), m_default.toULongLong(), m_key);
|
2007-09-10 17:07:29 +02:00
|
|
|
if (m_haveMin) {
|
|
|
|
ulonglongItem->setMinValue(m_min);
|
|
|
|
}
|
|
|
|
if (m_haveMax) {
|
|
|
|
ulonglongItem->setMaxValue(m_max);
|
|
|
|
}
|
|
|
|
item = ulonglongItem;
|
|
|
|
/* No addItemUrlList in KConfigSkeleton ?
|
|
|
|
} else if (m_type == "urllist") {
|
|
|
|
//FIXME: the split() is naive and will break on lists with ,'s in them
|
|
|
|
QStringList tmpList = m_default.split(",");
|
|
|
|
KUrl::List defaultList;
|
2008-08-01 13:23:42 +02:00
|
|
|
foreach (const QString& tmp, tmpList) {
|
2007-09-10 17:07:29 +02:00
|
|
|
defaultList.append(KUrl(tmp));
|
|
|
|
}
|
|
|
|
item = m_config->addItemUrlList(m_name, *d->newUrlList(), defaultList, m_key);*/
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item) {
|
|
|
|
item->setLabel(m_label);
|
|
|
|
item->setWhatsThis(m_whatsThis);
|
2008-05-18 06:28:27 +02:00
|
|
|
d->keysToNames.insert(item->group() + item->key(), item->name());
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
void ConfigLoaderHandler::resetState()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
m_haveMin = false;
|
|
|
|
m_min = 0;
|
|
|
|
m_haveMax = false;
|
|
|
|
m_max = 0;
|
|
|
|
m_name.clear();
|
|
|
|
m_type.clear();
|
|
|
|
m_label.clear();
|
|
|
|
m_default.clear();
|
|
|
|
m_key.clear();
|
|
|
|
m_whatsThis.clear();
|
|
|
|
m_enumChoices.clear();
|
|
|
|
m_inChoice = false;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoader::ConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent)
|
2007-07-30 18:18:27 +02:00
|
|
|
: KConfigSkeleton(configFile, parent),
|
2008-10-29 18:46:33 +01:00
|
|
|
d(new ConfigLoaderPrivate)
|
2007-07-30 18:18:27 +02:00
|
|
|
{
|
2008-09-04 01:33:57 +02:00
|
|
|
d->parse(this, xml);
|
2007-07-30 18:18:27 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoader::ConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent)
|
2007-07-30 18:18:27 +02:00
|
|
|
: KConfigSkeleton(config, parent),
|
2008-10-29 18:46:33 +01:00
|
|
|
d(new ConfigLoaderPrivate)
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
2007-11-25 01:14:27 +01:00
|
|
|
d->parse(this, xml);
|
|
|
|
}
|
|
|
|
|
2008-09-18 19:40:31 +02:00
|
|
|
//FIXME: obviously this is broken and should be using the group as the root,
|
2007-11-25 01:14:27 +01:00
|
|
|
// but KConfigSkeleton does not currently support this. it will eventually though,
|
|
|
|
// at which point this can be addressed properly
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoader::ConfigLoader(const KConfigGroup *config, QIODevice *xml, QObject *parent)
|
2007-11-25 01:14:27 +01:00
|
|
|
: KConfigSkeleton(KSharedConfig::openConfig(config->config()->name()), parent),
|
2008-10-29 18:46:33 +01:00
|
|
|
d(new ConfigLoaderPrivate)
|
2007-11-25 01:14:27 +01:00
|
|
|
{
|
2008-09-23 14:21:19 +02:00
|
|
|
KConfigGroup group = config->parent();
|
|
|
|
d->baseGroup = config->name();
|
|
|
|
while (group.isValid() && group.name() != "<default>") {
|
|
|
|
d->baseGroup = group.name() + '\x1d' + d->baseGroup;
|
|
|
|
group = group.parent();
|
|
|
|
}
|
2007-11-25 01:14:27 +01:00
|
|
|
d->parse(this, xml);
|
2007-07-18 11:26:24 +02:00
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
ConfigLoader::~ConfigLoader()
|
2007-07-18 11:26:24 +02:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
KConfigSkeletonItem *ConfigLoader::findItem(const QString &group, const QString &key)
|
2008-05-18 06:28:27 +02:00
|
|
|
{
|
|
|
|
return KConfigSkeleton::findItem(d->keysToNames[group + key]);
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
bool ConfigLoader::hasGroup(const QString &group) const
|
2008-08-04 09:59:32 +02:00
|
|
|
{
|
2008-09-04 00:28:10 +02:00
|
|
|
return d->groups.contains(group);
|
|
|
|
}
|
|
|
|
|
2008-10-29 18:46:33 +01:00
|
|
|
QStringList ConfigLoader::groupList() const
|
2008-09-04 00:28:10 +02:00
|
|
|
{
|
|
|
|
return d->groups;
|
2008-08-04 09:59:32 +02:00
|
|
|
}
|
|
|
|
|
2007-07-18 17:15:14 +02:00
|
|
|
} // Plasma namespace
|