Remove duplicated ConfigLoader

This moved to KConfigGui as KConfigLoader.

Use of private KConfig API in Service had to be ported to use only
public method.

REVIEW: 117784
This commit is contained in:
David Edmundson 2014-04-26 14:29:54 +02:00
parent 0addea76cb
commit 4ce14a1654
20 changed files with 35 additions and 1414 deletions

View File

@ -25,7 +25,6 @@ MACRO(PLASMA_UNIT_TESTS)
ENDMACRO(PLASMA_UNIT_TESTS)
PLASMA_UNIT_TESTS(
configloadertest
packagestructuretest
packageurlinterceptortest
pluginloadertest

View File

@ -1,210 +0,0 @@
/********************************************************************************
* Copyright 2010 by Martin Blumenstingl <darklight.xdarklight@googlemail.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*********************************************************************************/
#include <QtTestWidgets>
#include "configloadertest.h"
#include <kconfig.h>
#include <kconfiggroup.h>
#include <kconfigskeleton.h>
#include "plasma/configloader.h"
Q_DECLARE_METATYPE(QList<int>)
#define TEST_NAME QString::fromLatin1("configloadertest")
#define GET_CONFIG_ITEM_VALUE(type, configName) \
KConfigSkeletonItem* item = cl->findItem(TEST_NAME, configName); \
/* Check if we got back a valid item. */ \
QVERIFY(item != 0); \
/* Cast the item to the given type. */ \
type typeItem = dynamic_cast<type>(item); \
/* Make sure the cast was successful. */ \
QVERIFY(typeItem != 0);
void ConfigLoaderTest::init()
{
QString fileName = TEST_NAME + QString::fromLatin1(".xml");
configFile = new QFile(QFINDTESTDATA(QString::fromLatin1("/") + fileName));
cl = new Plasma::ConfigLoader(configFile->fileName(), configFile);
}
void ConfigLoaderTest::cleanup()
{
delete cl;
delete configFile;
}
void ConfigLoaderTest::boolDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemBool *, "DefaultBoolItem");
QVERIFY(typeItem->isEqual(true));
}
void ConfigLoaderTest::colorDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemColor *, "DefaultColorItem");
QVERIFY(typeItem->isEqual(QColor("#00FF00")));
}
void ConfigLoaderTest::dateTimeDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDateTime *, "DefaultDateTimeItem");
QVERIFY(typeItem->isEqual(QDateTime::fromString("Thu Sep 09 2010")));
}
void ConfigLoaderTest::enumDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemEnum *, "DefaultEnumItem");
QVERIFY(typeItem->isEqual(3));
}
void ConfigLoaderTest::fontDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemFont *, "DefaultFontItem");
QVERIFY(typeItem->isEqual(QFont("DejaVu Sans")));
}
void ConfigLoaderTest::intDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemInt *, "DefaultIntItem");
QVERIFY(typeItem->isEqual(27));
}
void ConfigLoaderTest::passwordDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPassword *, "DefaultPasswordItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("h4x.")));
}
void ConfigLoaderTest::pathDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemPath *, "DefaultPathItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("/dev/null")));
}
void ConfigLoaderTest::stringDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemString *, "DefaultStringItem");
QVERIFY(typeItem->isEqual(QString::fromLatin1("TestString")));
}
void ConfigLoaderTest::stringListDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KConfigSkeleton::ItemStringList *, "DefaultStringListItem");
// Create a string list with the expected values.
QStringList expected;
expected.append("One");
expected.append("Two");
expected.append("Three");
expected.append("Four");
expected.append("Five");
QVERIFY(typeItem->isEqual(expected));
}
void ConfigLoaderTest::uintDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUInt *, "DefaultUIntItem");
QVERIFY(typeItem->isEqual(7U));
}
void ConfigLoaderTest::urlDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemUrl *, "DefaultUrlItem");
QVERIFY(typeItem->isEqual(QUrl("http://kde.org")));
}
void ConfigLoaderTest::doubleDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemDouble *, "DefaultDoubleItem");
QVERIFY(typeItem->isEqual(13.37));
}
void ConfigLoaderTest::intListDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemIntList *, "DefaultIntListItem");
// Create a int list with the expected values.
QList<int> expected;
expected.append(1);
expected.append(1);
expected.append(2);
expected.append(3);
expected.append(5);
expected.append(8);
QVERIFY(typeItem->isEqual(qVariantFromValue(expected)));
}
void ConfigLoaderTest::longLongDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemLongLong *, "DefaultLongLongItem");
QVERIFY(typeItem->isEqual(Q_INT64_C(-9211372036854775808)));
}
void ConfigLoaderTest::pointDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemPoint *, "DefaultPointItem");
QVERIFY(typeItem->isEqual(QPoint(185, 857)));
}
void ConfigLoaderTest::rectDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemRect *, "DefaultRectItem");
// Create a new QRect with the expected value.
QRect expected;
expected.setCoords(3, 7, 951, 358);
QVERIFY(typeItem->isEqual(expected));
}
void ConfigLoaderTest::sizeDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemSize *, "DefaultSizeItem");
QVERIFY(typeItem->isEqual(QSize(640, 480)));
}
void ConfigLoaderTest::ulongLongDefaultValue()
{
GET_CONFIG_ITEM_VALUE(KCoreConfigSkeleton::ItemULongLong *, "DefaultULongLongItem");
QVERIFY(typeItem->isEqual(Q_UINT64_C(9223372036854775806)));
}
QTEST_MAIN(ConfigLoaderTest)

View File

@ -1,67 +0,0 @@
/********************************************************************************
* Copyright 2010 by Martin Blumenstingl <darklight.xdarklight@googlemail.com> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library 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 *
* Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public License *
* along with this library; see the file COPYING.LIB. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
*********************************************************************************/
#ifndef CONFIGLOADERTEST_H
#define CONFIGLOADERTEST_H
#include <QtTest/QtTest>
namespace Plasma
{
class ConfigLoader;
}
class QFile;
class ConfigLoaderTest : public QObject
{
Q_OBJECT
public Q_SLOTS:
void init();
void cleanup();
private Q_SLOTS:
void boolDefaultValue();
void colorDefaultValue();
void dateTimeDefaultValue();
void enumDefaultValue();
void fontDefaultValue();
void intDefaultValue();
void passwordDefaultValue();
void pathDefaultValue();
void stringDefaultValue();
void stringListDefaultValue();
void uintDefaultValue();
void urlDefaultValue();
void doubleDefaultValue();
void intListDefaultValue();
void longLongDefaultValue();
void pointDefaultValue();
void rectDefaultValue();
void sizeDefaultValue();
void ulongLongDefaultValue();
private:
Plasma::ConfigLoader *cl;
QFile *configFile;
};
#endif

View File

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="keystatusplasmoidrc"/>
<group name="configloadertest">
<entry name="DefaultBoolItem" type="Bool">
<default>true</default>
</entry>
<entry name="DefaultColorItem" type="Color">
<default>#00FF00</default>
</entry>
<entry name="DefaultDateTimeItem" type="DateTime">
<default>Thu Sep 09 2010</default>
</entry>
<entry name="DefaultEnumItem" type="Enum">
<default>3</default>
<choice name="One" value="1" />
<choice name="Two" value="2" />
<choice name="Three" value="3" />
<choice name="Four" value="4" />
</entry>
<entry name="DefaultFontItem" type="Font">
<default>DejaVu Sans</default>
</entry>
<entry name="DefaultIntItem" type="Int">
<default>27</default>
</entry>
<entry name="DefaultPasswordItem" type="Password">
<default>h4x.</default>
</entry>
<entry name="DefaultPathItem" type="Path">
<default>/dev/null</default>
</entry>
<entry name="DefaultStringItem" type="String">
<default>TestString</default>
</entry>
<entry name="DefaultStringListItem" type="StringList">
<default>One,Two,Three,Four,Five</default>
</entry>
<entry name="DefaultUIntItem" type="UInt">
<default>7</default>
</entry>
<entry name="DefaultUrlItem" type="Url">
<default>http://kde.org</default>
</entry>
<entry name="DefaultDoubleItem" type="Double">
<default>13.37</default>
</entry>
<entry name="DefaultIntListItem" type="IntList">
<default>1,1,2,3,5,8</default>
</entry>
<entry name="DefaultLongLongItem" type="LongLong">
<default>-9211372036854775808</default>
</entry>
<entry name="DefaultPointItem" type="Point">
<default>185,857</default>
</entry>
<entry name="DefaultRectItem" type="Rect">
<default>3,7,951,358</default>
</entry>
<entry name="DefaultSizeItem" type="Size">
<default>640,480</default>
</entry>
<entry name="DefaultULongLongItem" type="ULongLong">
<default>9223372036854775806</default>
</entry>
</group>
</kcfg>

View File

@ -44,7 +44,6 @@ set(Plasma_LIB_SRCS
#applets,containments,corona
applet.cpp
configloader.cpp
containment.cpp
containmentactions.cpp
corona.cpp
@ -151,7 +150,6 @@ generate_export_header(KF5Plasma
ecm_generate_headers(Plasma_CamelCase_HEADERS
HEADER_NAMES
Applet
ConfigLoader
Containment
ContainmentActions
Corona

View File

@ -43,9 +43,9 @@
#include <klocalizedstring.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <KConfigLoader>
#include <kwindowsystem.h>
#include "configloader.h"
#include "containment.h"
#include "corona.h"
#include "package.h"
@ -264,16 +264,16 @@ bool Applet::destroyed() const
return d->transient;
}
ConfigLoader *Applet::configScheme() const
KConfigLoader *Applet::configScheme() const
{
if (!d->configLoader) {
const QString xmlPath = d->package ? d->package->filePath("mainconfigxml") : QString();
KConfigGroup cfg = config();
if (xmlPath.isEmpty()) {
d->configLoader = new ConfigLoader(&cfg, 0);
d->configLoader = new KConfigLoader(cfg, 0);
} else {
QFile file(xmlPath);
d->configLoader = new ConfigLoader(&cfg, &file);
d->configLoader = new KConfigLoader(cfg, &file);
QObject::connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
}
}

View File

@ -30,7 +30,6 @@
#include <kconfiggroup.h>
#include <kplugininfo.h>
#include <plasma/configloader.h>
#include <plasma/plasma.h>
#include <plasma/version.h>
#include <plasma/framesvg.h>
@ -38,6 +37,7 @@
class QWidget;
class KActionCollection;
class KConfigLoader;
namespace Plasma
{
@ -178,7 +178,7 @@ public:
*
* @return config skeleton object, or 0 if none
**/
ConfigLoader *configScheme() const;
KConfigLoader *configScheme() const;
/**
* Saves state information about this applet that will

View File

@ -1,467 +0,0 @@
/*
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*/
#include "configloader.h"
#include "private/configloader_p.h"
#include "private/configloaderhandler_p.h"
#include <QColor>
#include <QFont>
#include <QHash>
#include <QXmlContentHandler>
#include <QXmlInputSource>
#include <QXmlSimpleReader>
#include <QUrl>
#include <QDebug>
namespace Plasma
{
void ConfigLoaderPrivate::parse(ConfigLoader *loader, QIODevice *xml)
{
clearData();
loader->clearItems();
if (xml) {
QXmlInputSource source(xml);
QXmlSimpleReader reader;
ConfigLoaderHandler handler(loader, this);
reader.setContentHandler(&handler);
reader.parse(&source, false);
}
}
ConfigLoaderHandler::ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d)
: QXmlDefaultHandler(),
m_config(config),
d(d)
{
resetState();
}
bool ConfigLoaderHandler::startElement(const QString &namespaceURI, const QString &localName,
const QString &qName, const QXmlAttributes &attrs)
{
Q_UNUSED(namespaceURI)
Q_UNUSED(qName)
// qDebug() << "ConfigLoaderHandler::startElement(" << localName << qName;
int numAttrs = attrs.count();
QString tag = localName.toLower();
if (tag == "group") {
QString group;
for (int i = 0; i < numAttrs; ++i) {
QString name = attrs.localName(i).toLower();
if (name == "name") {
//qDebug() << "set group to" << attrs.value(i);
group = attrs.value(i);
}
}
if (group.isEmpty()) {
group = d->baseGroup;
} else {
d->groups.append(group);
if (!d->baseGroup.isEmpty()) {
group = d->baseGroup + '\x1d' + group;
}
}
m_currentGroup = group;
if (m_config) {
m_config->setCurrentGroup(group);
}
} 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).trimmed();
} else if (name == "type") {
m_type = attrs.value(i).toLower();
} else if (name == "key") {
m_key = attrs.value(i).trimmed();
}
}
} 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;
}
bool ConfigLoaderHandler::characters(const QString &ch)
{
m_cdata.append(ch);
return true;
}
QString ConfigLoaderHandler::name() const
{
return m_name;
}
void ConfigLoaderHandler::setName(const QString &name)
{
m_name = name;
}
QString ConfigLoaderHandler::key() const
{
return m_key;
}
void ConfigLoaderHandler::setKey(const QString &key)
{
m_key = key;
}
QString ConfigLoaderHandler::type() const
{
return m_type;
}
QString ConfigLoaderHandler::currentGroup() const
{
return m_currentGroup;
}
QString ConfigLoaderHandler::defaultValue() const
{
return m_default;
}
bool ConfigLoaderHandler::endElement(const QString &namespaceURI,
const QString &localName, const QString &qName)
{
Q_UNUSED(namespaceURI)
Q_UNUSED(qName)
// qDebug() << "ConfigLoaderHandler::endElement(" << localName << qName;
const QString tag = localName.toLower();
if (tag == "group") {
m_name = "__operationName";
m_type = "string";
//m_default = currentGroup();
addItem();
resetState();
}
if (tag == "entry") {
addItem();
resetState();
} else if (tag == "label") {
if (m_inChoice) {
m_choice.label = m_cdata.trimmed();
} else {
m_label = m_cdata.trimmed();
}
} else if (tag == "whatsthis") {
if (m_inChoice) {
m_choice.whatsThis = m_cdata.trimmed();
} else {
m_whatsThis = m_cdata.trimmed();
}
} else if (tag == "default") {
m_default = m_cdata.trimmed();
} 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;
}
void ConfigLoaderHandler::addItem()
{
if (m_name.isEmpty()) {
if (m_key.isEmpty()) {
return;
}
m_name = m_key;
}
m_name.remove(' ');
KConfigSkeletonItem *item = 0;
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") {
m_key = (m_key.isEmpty()) ? m_name : m_key;
bool ok;
int value = m_default.toUInt(&ok);
//if is not an integer, try to find the string value among the registered choices
if (!ok) {
int i = 0;
foreach (const KConfigSkeleton::ItemEnum::Choice &choice, m_enumChoices) {
if (choice.name == m_default) {
value = i;
break;
}
++i;
}
}
KConfigSkeleton::ItemEnum *enumItem =
new KConfigSkeleton::ItemEnum(m_config->currentGroup(),
m_key, *d->newInt(),
m_enumChoices,
value);
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") {
KConfigSkeleton::ItemInt *intItem = m_config->addItemInt(m_name, *d->newInt(),
m_default.toInt(), m_key);
if (m_haveMin) {
intItem->setMinValue(m_min);
}
if (m_haveMax) {
intItem->setMaxValue(m_max);
}
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
item = m_config->addItemStringList(m_name, *d->newStringList(),
m_default.split(','), m_key);
} else if (m_type == "uint") {
KConfigSkeleton::ItemUInt *uintItem =
m_config->addItemUInt(m_name, *d->newUint(), m_default.toUInt(), m_key);
if (m_haveMin) {
uintItem->setMinValue(m_min);
}
if (m_haveMax) {
uintItem->setMaxValue(m_max);
}
item = uintItem;
} else if (m_type == "url") {
m_key = (m_key.isEmpty()) ? m_name : m_key;
KConfigSkeleton::ItemUrl *urlItem =
new KConfigSkeleton::ItemUrl(m_config->currentGroup(),
m_key, *d->newUrl(),
QUrl::fromUserInput(m_default));
m_config->addItem(urlItem, m_name);
item = urlItem;
} else if (m_type == "double") {
KConfigSkeleton::ItemDouble *doubleItem = m_config->addItemDouble(m_name,
*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") {
QStringList tmpList = m_default.split(',');
QList<int> defaultList;
foreach (const QString &tmp, tmpList) {
defaultList.append(tmp.toInt());
}
item = m_config->addItemIntList(m_name, *d->newIntList(), defaultList, m_key);
} else if (m_type == "longlong") {
KConfigSkeleton::ItemLongLong *longlongItem = m_config->addItemLongLong(m_name,
*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
item = m_config->addItemPathList(m_name, *d->newStringList(), m_default.split(","), m_key);
*/
} else if (m_type == "point") {
QPoint defaultPoint;
QStringList tmpList = m_default.split(',');
if (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;
QStringList tmpList = m_default.split(',');
if (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;
QStringList tmpList = m_default.split(',');
if (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") {
KConfigSkeleton::ItemULongLong *ulonglongItem =
m_config->addItemULongLong(m_name, *d->newULongLong(), m_default.toULongLong(), m_key);
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(",");
QList<QUrl> defaultList;
foreach (const QString& tmp, tmpList) {
defaultList.append(QUrl(tmp));
}
item = m_config->addItemUrlList(m_name, *d->newUrlList(), defaultList, m_key);*/
}
if (item) {
item->setLabel(m_label);
item->setWhatsThis(m_whatsThis);
d->keysToNames.insert(item->group() + item->key(), item->name());
}
}
void ConfigLoaderHandler::resetState()
{
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;
}
ConfigLoader::ConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent)
: KConfigSkeleton(configFile, parent),
d(new ConfigLoaderPrivate)
{
d->parse(this, xml);
}
ConfigLoader::ConfigLoader(KSharedConfigPtr config, QIODevice *xml, QObject *parent)
: KConfigSkeleton(config, parent),
d(new ConfigLoaderPrivate)
{
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
ConfigLoader::ConfigLoader(const KConfigGroup *config, QIODevice *xml, QObject *parent)
: KConfigSkeleton(KSharedConfig::openConfig(config->config()->name()), parent),
d(new ConfigLoaderPrivate)
{
KConfigGroup group = config->parent();
d->baseGroup = config->name();
while (group.isValid() && group.name() != "<default>") {
d->baseGroup = group.name() + '\x1d' + d->baseGroup;
group = group.parent();
}
d->parse(this, xml);
}
ConfigLoader::~ConfigLoader()
{
delete d;
}
KConfigSkeletonItem *ConfigLoader::findItem(const QString &group, const QString &key)
{
return KConfigSkeleton::findItem(d->keysToNames[group + key]);
}
KConfigSkeletonItem *ConfigLoader::findItemByName(const QString &name)
{
return KConfigSkeleton::findItem(name);
}
QVariant ConfigLoader::property(const QString &name)
{
KConfigSkeletonItem *item = KConfigSkeleton::findItem(name);
if (item) {
return item->property();
}
return QVariant();
}
bool ConfigLoader::hasGroup(const QString &group) const
{
return d->groups.contains(group);
}
QStringList ConfigLoader::groupList() const
{
return d->groups;
}
bool ConfigLoader::usrWriteConfig()
{
if (d->saveDefaults) {
KConfigSkeletonItem::List itemList = items();
for (int i = 0; i < itemList.size(); i++) {
KConfigGroup cg(config(), itemList.at(i)->group());
cg.writeEntry(itemList.at(i)->key(), "");
}
}
return true;
}
} // Plasma namespace

View File

@ -1,154 +0,0 @@
/*
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*/
#ifndef PLASMA_CONFIGLOADER_H
#define PLASMA_CONFIGLOADER_H
#include <kconfiggroup.h>
#include <kconfigskeleton.h>
#include <ksharedconfig.h>
#include <plasma/plasma_export.h>
/**
* @class ConfigLoader plasma/configloader.h <Plasma/ConfigLoader>
*
* @short A KConfigSkeleton that populates itself based on KConfigXT XML
*
* This class allows one to ship an XML file and reconstitute it into a
* KConfigSkeleton object at runtime. Common usage might look like this:
*
* \code
* QFile file(xmlFilePath);
* Plasma::ConfigLoader appletConfig(configFilePath, &file);
* \endcode
*
* Alternatively, any QIODevice may be used in place of QFile in the
* example above.
*
* Currently the following data types are supported:
*
* @li bools
* @li colors
* @li datetimes
* @li enumerations
* @li fonts
* @li ints
* @li passwords
* @li paths
* @li strings
* @li stringlists
* @li uints
* @li urls
* @li doubles
* @li int lists
* @li longlongs
* @li path lists
* @li points
* @li rects
* @li sizes
* @li ulonglongs
* @li url lists
**/
namespace Plasma
{
class ConfigLoaderPrivate;
class PLASMA_EXPORT ConfigLoader : public KConfigSkeleton
{
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 xml the xml data; must be valid KConfigXT data
* @param parent optional QObject parent
**/
ConfigLoader(const QString &configFile, QIODevice *xml, QObject *parent = 0);
/**
* Creates a KConfigSkeleton populated using the definition found in
* the XML data passed in.
*
* @param config the configuration object to use
* @param xml the xml data; must be valid KConfigXT data
* @param parent optional QObject parent
**/
ConfigLoader(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
**/
ConfigLoader(const KConfigGroup *config, QIODevice *xml, QObject *parent = 0);
~ConfigLoader();
/**
* Finds the item for the given group and key.
*
* @param group the group in the config file to look in
* @param key the configuration key to find
* @return the associated KConfigSkeletonItem, or 0 if none
*/
KConfigSkeletonItem *findItem(const QString &group, const QString &key);
/**
* Finds an item by its name
*/
KConfigSkeletonItem *findItemByName(const QString &name);
/**
* Returns the property (variantized value) of the named item
*/
QVariant property(const QString &name);
/**
* Check to see if a group exists
*
* @param group the name of the group to check for
* @return true if the group exists, or false if it does not
*/
bool hasGroup(const QString &group) const;
/**
* @return the list of groups defined by the XML
*/
QStringList groupList() const;
protected:
/**
* Hack used to force writing when no default exists in config file.
*/
bool usrWriteConfig();
private:
friend class Service;
ConfigLoaderPrivate *const d;
};
} // Plasma namespace
#endif //multiple inclusion guard

View File

@ -39,6 +39,8 @@
#include <kauthorized.h>
#include <klocalizedstring.h>
#include <kservicetypetrader.h>
#include <KConfigSkeleton>
#include <KConfigLoader>
#if !PLASMA_NO_KIO
#include "kio/jobclasses.h" // for KIO::JobFlags

View File

@ -29,6 +29,8 @@
#include <QVariant>
#include <QDebug>
#include <QStandardPaths>
#include <kplugininfo.h>
#include <kservice.h>
#include <kservicetypetrader.h>

View File

@ -34,6 +34,7 @@
#include <klocalizedstring.h>
#include <kkeysequencewidget.h>
#include <kglobalaccel.h>
#include <KConfigLoader>
#include "containment.h"
#include "corona.h"

View File

@ -92,7 +92,7 @@ public:
// sripting and package stuff
AppletScript *script;
Package *package;
ConfigLoader *configLoader;
KConfigLoader *configLoader;
// actions stuff; put activationAction into actions?
KActionCollection *actions;

View File

@ -1,227 +0,0 @@
/*
* Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*/
#ifndef PLASMA_CONFIGLOADER_P_H
#define PLASMA_CONFIGLOADER_P_H
#include <QUrl>
namespace Plasma
{
class ConfigLoaderPrivate
{
public:
ConfigLoaderPrivate()
: saveDefaults(false)
{
}
~ConfigLoaderPrivate()
{
clearData();
}
void clearData()
{
qDeleteAll(bools);
qDeleteAll(strings);
qDeleteAll(stringlists);
qDeleteAll(colors);
qDeleteAll(fonts);
qDeleteAll(ints);
qDeleteAll(uints);
qDeleteAll(urls);
qDeleteAll(dateTimes);
qDeleteAll(doubles);
qDeleteAll(intlists);
qDeleteAll(longlongs);
qDeleteAll(points);
qDeleteAll(rects);
qDeleteAll(sizes);
qDeleteAll(ulonglongs);
qDeleteAll(urllists);
}
bool *newBool()
{
bool *v = new bool;
bools.append(v);
return v;
}
QString *newString()
{
QString *v = new QString;
strings.append(v);
return v;
}
QStringList *newStringList()
{
QStringList *v = new QStringList;
stringlists.append(v);
return v;
}
QColor *newColor()
{
QColor *v = new QColor;
colors.append(v);
return v;
}
QFont *newFont()
{
QFont *v = new QFont;
fonts.append(v);
return v;
}
qint32 *newInt()
{
qint32 *v = new qint32;
ints.append(v);
return v;
}
quint32 *newUint()
{
quint32 *v = new quint32;
uints.append(v);
return v;
}
QUrl *newUrl()
{
QUrl *v = new QUrl;
urls.append(v);
return v;
}
QDateTime *newDateTime()
{
QDateTime *v = new QDateTime;
dateTimes.append(v);
return v;
}
double *newDouble()
{
double *v = new double;
doubles.append(v);
return v;
}
QList<qint32> *newIntList()
{
QList<qint32> *v = new QList<qint32>;
intlists.append(v);
return v;
}
qint64 *newLongLong()
{
qint64 *v = new qint64;
longlongs.append(v);
return v;
}
QPoint *newPoint()
{
QPoint *v = new QPoint;
points.append(v);
return v;
}
QRect *newRect()
{
QRect *v = new QRect;
rects.append(v);
return v;
}
QSize *newSize()
{
QSize *v = new QSize;
sizes.append(v);
return v;
}
quint64 *newULongLong()
{
quint64 *v = new quint64;
ulonglongs.append(v);
return v;
}
QList<QUrl> *newUrlList()
{
QList<QUrl> *v = new QList<QUrl>();
urllists.append(v);
return v;
}
void parse(ConfigLoader *loader, QIODevice *xml);
/**
* Whether or not to write out default values.
*
* @param writeDefaults true if defaults should be written out
*/
void setWriteDefaults(bool writeDefaults)
{
saveDefaults = writeDefaults;
}
/**
* @return true if default values will also be written out
*/
bool writeDefaults() const
{
return saveDefaults;
}
QList<bool *> bools;
QList<QString *> strings;
QList<QStringList *> stringlists;
QList<QColor *> colors;
QList<QFont *> fonts;
QList<qint32 *> ints;
QList<quint32 *> uints;
QList<QUrl *> 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<QList<QUrl> *> urllists;
QString baseGroup;
QStringList groups;
QHash<QString, QString> keysToNames;
bool saveDefaults;
};
} // namespace Plasma
#endif

View File

@ -1,73 +0,0 @@
/*
* Copyright 2007-2008 Aaron Seigo <aseigo@kde.org>
* Copyright 2013 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* 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.
*
* 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.
*/
#ifndef PLASMA_CONFIGLOADERHANDLER_P_H
#define PLASMA_CONFIGLOADERHANDLER_P_H
#include <QXmlDefaultHandler>
namespace Plasma
{
class ConfigLoaderHandler : public QXmlDefaultHandler
{
public:
ConfigLoaderHandler(ConfigLoader *config, ConfigLoaderPrivate *d);
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);
bool characters(const QString &ch);
QString name() const;
void setName(const QString &name);
QString key() const;
void setKey(const QString &name);
QString type() const;
QString currentGroup() const;
QString defaultValue() const;
private:
virtual void addItem();
void resetState();
ConfigLoader *m_config;
ConfigLoaderPrivate *d;
int m_min;
int m_max;
QString m_currentGroup;
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;
};
} // namespace Plasma
#endif

View File

@ -31,13 +31,9 @@
#include <kplugininfo.h>
#include <klocalizedstring.h>
#include "plasma/configloader.h"
namespace Plasma
{
class ConfigLoader;
class NullServiceJob : public ServiceJob
{
public:

View File

@ -30,126 +30,17 @@
#include <kservice.h>
#include <kservicetypetrader.h>
#include <ksharedconfig.h>
#include <KConfigLoader>
#include <KConfigSkeleton>
#include <qstandardpaths.h>
#include "configloader.h"
#include "version.h"
#include "private/configloader_p.h"
#include "private/configloaderhandler_p.h"
#include "pluginloader.h"
namespace Plasma
{
class ConfigLoaderHandlerMap : public ConfigLoaderHandler
{
public:
ConfigLoaderHandlerMap(ConfigLoader *config, ConfigLoaderPrivate *d)
: ConfigLoaderHandler(config, d)
{}
void addItem();
const QMap<QString, QVariantMap> &groupsMap() const;
private:
QMap<QString, QVariantMap> m_groupsMap;
};
void ConfigLoaderHandlerMap::addItem()
{
if (name().isEmpty()) {
if (key().isEmpty()) {
return;
}
setName(key());
} else if (key().isEmpty()) {
if (name().isEmpty()) {
return;
}
setKey(name());
}
if (!m_groupsMap.contains(currentGroup())) {
m_groupsMap[currentGroup()] = QVariantMap();
m_groupsMap[currentGroup()]["_name"] = currentGroup();
}
if (type() == "bool") {
bool defaultVal = defaultValue().toLower() == "true";
m_groupsMap[currentGroup()][key()] = defaultVal;
} else if (type() == "color") {
m_groupsMap[currentGroup()][key()] = QColor(defaultValue());
} else if (type() == "datetime") {
m_groupsMap[currentGroup()][key()] = QDateTime::fromString(defaultValue());
} else if (type() == "enum") {
key() = (key().isEmpty()) ? name() : key();
m_groupsMap[currentGroup()][key()] = defaultValue().toUInt();
} else if (type() == "font") {
m_groupsMap[currentGroup()][key()] = QFont(defaultValue());
} else if (type() == "int") {
m_groupsMap[currentGroup()][key()] = defaultValue().toInt();
} else if (type() == "password") {
m_groupsMap[currentGroup()][key()] = defaultValue();
} else if (type() == "path") {
m_groupsMap[currentGroup()][key()] = defaultValue();
} else if (type() == "string") {
m_groupsMap[currentGroup()][key()] = defaultValue();
} else if (type() == "stringlist") {
//FIXME: the split() is naive and will break on lists with ,'s in them
m_groupsMap[currentGroup()][key()] = defaultValue().split(',');
} else if (type() == "uint") {
m_groupsMap[currentGroup()][key()] = defaultValue().toUInt();
} else if (type() == "url") {
setKey((key().isEmpty()) ? name() : key());
m_groupsMap[currentGroup()][key()] = QUrl::fromUserInput(defaultValue());
} else if (type() == "double") {
m_groupsMap[currentGroup()][key()] = defaultValue().toDouble();
} else if (type() == "intlist") {
QStringList tmpList = defaultValue().split(',');
QList<int> defaultList;
foreach (const QString &tmp, tmpList) {
defaultList.append(tmp.toInt());
}
m_groupsMap[currentGroup()][key()] = QVariant::fromValue(defaultList);
} else if (type() == "longlong") {
m_groupsMap[currentGroup()][key()] = defaultValue().toLongLong();
} else if (type() == "point") {
QPoint defaultPoint;
QStringList tmpList = defaultValue().split(',');
if (tmpList.size() >= 2) {
defaultPoint.setX(tmpList[0].toInt());
defaultPoint.setY(tmpList[1].toInt());
}
m_groupsMap[currentGroup()][key()] = defaultPoint;
} else if (type() == "rect") {
QRect defaultRect;
QStringList tmpList = defaultValue().split(',');
if (tmpList.size() >= 4) {
defaultRect.setCoords(tmpList[0].toInt(), tmpList[1].toInt(),
tmpList[2].toInt(), tmpList[3].toInt());
}
m_groupsMap[currentGroup()][key()] = tmpList;
} else if (type() == "size") {
QSize defaultSize;
QStringList tmpList = defaultValue().split(',');
if (tmpList.size() >= 2) {
defaultSize.setWidth(tmpList[0].toInt());
defaultSize.setHeight(tmpList[1].toInt());
}
m_groupsMap[currentGroup()][key()] = tmpList;
} else if (type() == "ulonglong") {
m_groupsMap[currentGroup()][key()] = defaultValue().toULongLong();
}
}
const QMap<QString, QVariantMap> &ConfigLoaderHandlerMap::groupsMap() const
{
return m_groupsMap;
}
Service::Service(QObject *parent)
: QObject(parent),
d(new ServicePrivate(this))
@ -279,15 +170,19 @@ void Service::setOperationsScheme(QIODevice *xml)
{
d->operationsMap.clear();
ConfigLoaderPrivate *configLoaderPrivate = new ConfigLoaderPrivate;
configLoaderPrivate->setWriteDefaults(true);
ConfigLoaderHandlerMap configLoaderHandler(0, configLoaderPrivate);
QXmlInputSource source(xml);
QXmlSimpleReader reader;
reader.setContentHandler(&configLoaderHandler);
reader.parse(&source, false);
d->operationsMap = configLoaderHandler.groupsMap();
delete configLoaderPrivate;
// /dev/null is because I need to pass a filename argument to construct a
// KSharedConfig. We need a config object for the config loader even
// though we dont' actually want to use any config parts from it,
// we just want to share the KConfigLoader XML parsing.
KSharedConfigPtr config = KSharedConfig::openConfig("/dev/null");
KConfigLoader loader(config, xml);
foreach (const QString &group, loader.groupList()) {
d->operationsMap[group]["_name"] = group;
}
foreach (KConfigSkeletonItem *item, loader.items()) {
d->operationsMap[item->group()][item->key()] = item->property();
}
}
void Service::registerOperationsScheme()

View File

@ -37,6 +37,7 @@
#include <kservice.h>
#include <kservicetypetrader.h>
#include <klocalizedstring.h>
#include <KConfigLoader>
#include <Plasma/Plasma>
#include <Plasma/Applet>

View File

@ -26,6 +26,7 @@
#include <kactioncollection.h>
#include <kservicetypetrader.h>
#include <kdesktopfile.h>
#include <KConfigLoader>
#include <QDebug>
#include <QQmlExpression>
@ -33,7 +34,6 @@
#include <QQmlProperty>
#include <QSignalMapper>
#include <Plasma/ConfigLoader>
#include <Plasma/PluginLoader>
QHash<QObject *, WallpaperInterface *> WallpaperInterface::s_rootObjects = QHash<QObject *, WallpaperInterface *>();
@ -88,7 +88,7 @@ KDeclarative::ConfigPropertyMap *WallpaperInterface::configuration() const
return m_configuration;
}
Plasma::ConfigLoader *WallpaperInterface::configScheme()
KConfigLoader *WallpaperInterface::configScheme()
{
if (!m_configLoader) {
//FIXME: do we need "mainconfigxml" in wallpaper packagestructures?
@ -98,10 +98,10 @@ Plasma::ConfigLoader *WallpaperInterface::configScheme()
cfg = KConfigGroup(&cfg, "Wallpaper");
if (xmlPath.isEmpty()) {
m_configLoader = new Plasma::ConfigLoader(&cfg, 0);
m_configLoader = new KConfigLoader(cfg, 0);
} else {
QFile file(xmlPath);
m_configLoader = new Plasma::ConfigLoader(&cfg, &file);
m_configLoader = new KConfigLoader(cfg, &file);
}
}

View File

@ -25,11 +25,7 @@
#include <Plasma/Package>
namespace Plasma
{
class ConfigLoader;
}
class KConfigLoader;
class KActionCollection;
class ContainmentInterface;
@ -67,7 +63,7 @@ public:
KDeclarative::ConfigPropertyMap *configuration() const;
Plasma::ConfigLoader *configScheme();
KConfigLoader *configScheme();
QList<QAction *> contextualActions() const;
@ -107,7 +103,7 @@ private:
KDeclarative::QmlObject *m_qmlObject;
Plasma::Package m_pkg;
KDeclarative::ConfigPropertyMap *m_configuration;
Plasma::ConfigLoader *m_configLoader;
KConfigLoader *m_configLoader;
KActionCollection *m_actions;
QSignalMapper *m_actionSignals;