small hack to allow saving of defaults in ConfigLoader; used by Service, so put into the private impl for ConfigLoader and used that way.

based on a patch by Alain Boyer

CCMAIL:aainboyer@gmail.com

svn path=/trunk/KDE/kdelibs/; revision=887072
This commit is contained in:
Aaron J. Seigo 2008-11-21 01:26:43 +00:00
parent 47dcbf47b9
commit c6f32b32f9
3 changed files with 21 additions and 169 deletions

View File

@ -18,6 +18,7 @@
*/
#include "configloader.h"
#include "private/configloader_p.h"
#include <QColor>
#include <QFont>
@ -31,174 +32,6 @@
namespace Plasma
{
class ConfigLoaderPrivate
{
public:
~ConfigLoaderPrivate()
{
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;
}
KUrl *newUrl()
{
KUrl *v = new KUrl;
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;
}
KUrl::List *newUrlList()
{
KUrl::List *v = new KUrl::List;
urllists.append(v);
return v;
}
void parse(ConfigLoader *loader, QIODevice *xml);
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;
QString baseGroup;
QStringList groups;
QHash<QString, QString> keysToNames;
};
class ConfigLoaderHandler : public QXmlDefaultHandler
{
public:
@ -564,4 +397,15 @@ QStringList ConfigLoader::groupList() const
return d->groups;
}
void 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(), "");
}
}
}
} // Plasma namespace

View File

@ -128,7 +128,14 @@ public:
*/
QStringList groupList() const;
protected:
/**
* Hack used to force writing when no default exists in config file.
*/
void usrWriteConfig();
private:
friend class Service;
ConfigLoaderPrivate * const d;
};

View File

@ -31,8 +31,8 @@
#include <ktemporaryfile.h>
#include "configloader.h"
#include "version.h"
#include "private/configloader_p.h"
namespace Plasma
{
@ -264,6 +264,7 @@ void Service::setOperationsScheme(QIODevice *xml)
KSharedConfigPtr c = KSharedConfig::openConfig(d->tempFile->fileName(), KConfig::NoGlobals);
d->config = new ConfigLoader(c, xml, this);
d->config->d->setWriteDefaults(true);
emit operationsChanged();