From 25d9f455833c9687348a4d63de45e1e88df10f3e Mon Sep 17 00:00:00 2001 From: Chani Armitage Date: Mon, 27 Sep 2010 18:16:43 +0000 Subject: [PATCH] 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 --- corona.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++----- corona.h | 23 ++++++++++++++++++++++- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/corona.cpp b/corona.cpp index 3e8fe5864..5bb2db67d 100644 --- a/corona.cpp +++ b/corona.cpp @@ -337,6 +337,39 @@ void Corona::saveLayout(const QString &configName) const d->saveLayout(c); } +void Corona::exportLayout(KConfigGroup &config, QList 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 Corona::importLayout(const KConfigGroup &conf) +{ + return d->importLayout(conf, true); +} + QList Corona::importLayout(const KConfigBase &conf) +{ + return d->importLayout(conf, true); +} + +QList CoronaPrivate::importLayout(const KConfigBase &conf, bool mergeConfig) { if (const KConfigGroup *group = dynamic_cast(&conf)) { if (!group->isValid()) { @@ -467,11 +510,6 @@ QList Corona::importLayout(const KConfigBase &conf) } } - return d->importLayout(conf, true); -} - -QList CoronaPrivate::importLayout(const KConfigBase &conf, bool mergeConfig) -{ QList newContainments; QSet containmentsIds; diff --git a/corona.h b/corona.h index 4b030ad03..ff7f09416 100644 --- a/corona.h +++ b/corona.h @@ -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 importLayout(const KConfigBase &config); + KDE_DEPRECATED QList 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 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 containments); + public Q_SLOTS: /** * Initializes the layout from a config file. This will first clear any existing