exportLayout function to go with importLayout

also, deprecated the old importLayout in favour of one that only accepts
kconfiggroup.
CCBUG: 248386

svn path=/trunk/KDE/kdelibs/; revision=1180338
This commit is contained in:
Chani Armitage 2010-09-27 18:16:43 +00:00
parent 4369d1df2b
commit 25d9f45583
2 changed files with 65 additions and 6 deletions

View File

@ -337,6 +337,39 @@ void Corona::saveLayout(const QString &configName) const
d->saveLayout(c);
}
void Corona::exportLayout(KConfigGroup &config, QList<Containment*> containments)
{
foreach (const QString &group, config.groupList()) {
KConfigGroup cg(&config, group);
cg.deleteGroup();
}
//temporarily unlock so that removal works
ImmutabilityType oldImm = immutability();
d->immutability = Mutable;
KConfigGroup dest(&config, "Containments");
KConfigGroup dummy;
foreach (Plasma::Containment *c, containments) {
c->save(dummy);
c->config().reparent(&dest);
//ensure the containment is unlocked
//this is done directly because we have to bypass any SystemImmutable checks
c->Applet::d->immutability = Mutable;
foreach (Applet *a, c->applets()) {
a->d->immutability = Mutable;
}
c->destroy(false);
}
//restore immutability
d->immutability = oldImm;
config.sync();
}
void Corona::requestConfigSync()
{
// TODO: should we check into our immutability before doing this?
@ -459,7 +492,17 @@ void Corona::loadLayout(const QString &configName)
d->importLayout(*conf, false);
}
QList<Plasma::Containment *> Corona::importLayout(const KConfigGroup &conf)
{
return d->importLayout(conf, true);
}
QList<Plasma::Containment *> Corona::importLayout(const KConfigBase &conf)
{
return d->importLayout(conf, true);
}
QList<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigBase &conf, bool mergeConfig)
{
if (const KConfigGroup *group = dynamic_cast<const KConfigGroup *>(&conf)) {
if (!group->isValid()) {
@ -467,11 +510,6 @@ QList<Plasma::Containment *> Corona::importLayout(const KConfigBase &conf)
}
}
return d->importLayout(conf, true);
}
QList<Plasma::Containment *> CoronaPrivate::importLayout(const KConfigBase &conf, bool mergeConfig)
{
QList<Plasma::Containment *> newContainments;
QSet<uint> containmentsIds;

View File

@ -254,13 +254,14 @@ public:
/**
* Imports an applet layout from a config file. The results will be added to the
* current set of Containments.
* @deprecated Use the 4.6 version that takes a KConfigGroup
*
* @param config the name of the config file to load from,
* or the default config file if QString()
* @return the list of containments that were loaded
* @since 4.5
*/
QList<Plasma::Containment *> importLayout(const KConfigBase &config);
KDE_DEPRECATED QList<Plasma::Containment *> importLayout(const KConfigBase &config);
/**
* Returns the name of the preferred plugin to be used as containment toolboxes.
@ -271,6 +272,26 @@ public:
*/
QString preferredToolBoxPlugin(const Containment::Type type) const;
/**
* Imports an applet layout from a config file. The results will be added to the
* current set of Containments.
*
* @param config the name of the config file to load from,
* or the default config file if QString()
* @return the list of containments that were loaded
* @since 4.6
*/
QList<Plasma::Containment *> importLayout(const KConfigGroup &config);
/**
* Exports a set of containments to a config file.
*
* @param config the config group to save to
* @param containments the list of containments to save
* @since 4.6
*/
void exportLayout(KConfigGroup &config, QList<Containment*> containments);
public Q_SLOTS:
/**
* Initializes the layout from a config file. This will first clear any existing