diff --git a/corona.cpp b/corona.cpp index 3717ba381..07ea03591 100644 --- a/corona.cpp +++ b/corona.cpp @@ -261,6 +261,7 @@ public: } void offscreenWidgetDestroyed(QObject *); + QList importLayout(const KConfigBase &conf, bool mergeConfig); static bool s_positioningContainments; @@ -437,83 +438,87 @@ void Corona::layoutContainments() void Corona::loadLayout(const QString &configName) { - KSharedConfigPtr c; - bool mergeConfig = false; + KSharedConfigPtr conf; if (configName.isEmpty() || configName == d->configName) { - c = config(); + conf = config(); } else { - c = KSharedConfig::openConfig(configName); - mergeConfig = true; + conf = KSharedConfig::openConfig(configName); } - QList containmentsIds; + d->importLayout(*conf, conf != config()); +} - if (mergeConfig) { - foreach (Plasma::Containment *cont, d->containments) { - containmentsIds.append(cont->id()); +QList Corona::importLayout(const KConfigBase &conf) +{ + if (const KConfigGroup *group = dynamic_cast(&conf)) { + if (!group->isValid()) { + return QList(); } } - KConfigGroup containments(c, "Containments"); + return d->importLayout(conf, true); +} - foreach (const QString &group, containments.groupList()) { - KConfigGroup containmentConfig(&containments, group); +QList CoronaPrivate::importLayout(const KConfigBase &conf, bool mergeConfig) +{ + QList newContainments; + QSet containmentsIds; + + foreach (Containment *containment, containments) { + containmentsIds.insert(containment->id()); + } + + KConfigGroup containmentsGroup(&conf, "Containments"); + + foreach (const QString &group, containmentsGroup.groupList()) { + KConfigGroup containmentConfig(&containmentsGroup, group); if (containmentConfig.entryMap().isEmpty()) { continue; } uint cid = group.toUInt(); + if (containmentsIds.contains(cid)) { + cid = ++AppletPrivate::s_maxAppletId; + } else if (cid > AppletPrivate::s_maxAppletId) { + AppletPrivate::s_maxAppletId = cid; + } + if (mergeConfig) { - if (containmentsIds.contains(cid)) { - cid = 0; - } else if (cid > AppletPrivate::s_maxAppletId) { - AppletPrivate::s_maxAppletId = cid; - } + KConfigGroup realConf(q->config(), "Containments"); + realConf = KConfigGroup(&realConf, QString::number(cid)); + containmentConfig.copyTo(&realConf); } //kDebug() << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group; - Containment *c = d->addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), - cid, true); + Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, true); if (!c) { continue; } - if (mergeConfig) { - containmentsIds.append(c->id()); - } + newContainments.append(c); + containmentsIds.insert(c->id()); c->init(); c->restore(containmentConfig); } - foreach (Containment *containment, d->containments) { - QString cid = QString::number(containment->id()); - KConfigGroup *appletsConfigGroup = 0; - if (mergeConfig) { - KConfigGroup containmentConfig(&containments, cid); - appletsConfigGroup = new KConfigGroup(&containmentConfig, "Applets"); - } - + foreach (Containment *containment, newContainments) { foreach (Applet *applet, containment->applets()) { - if (mergeConfig) { - KConfigGroup externalAppletConfig(appletsConfigGroup, QString::number(applet->id())); - externalAppletConfig.copyTo(applet->d->mainConfigGroup()); - } - applet->init(); // We have to flush the applet constraints manually applet->flushPendingConstraintsEvents(); kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Applet" << applet->name(); } - delete appletsConfigGroup; containment->updateConstraints(Plasma::StartupCompletedConstraint); containment->flushPendingConstraintsEvents(); - emit containmentAdded(containment); + emit q->containmentAdded(containment); kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Containment" << containment->name(); } + + return newContainments; } Containment *Corona::containmentForScreen(int screen, int desktop) const diff --git a/corona.h b/corona.h index 9c847cf8c..cc54d3b85 100644 --- a/corona.h +++ b/corona.h @@ -251,6 +251,17 @@ public: */ AbstractDialogManager *dialogManager(); + /** + * 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.5 + */ + QList importLayout(const KConfigBase &config); + public Q_SLOTS: /** * Initializes the layout from a config file. This will first clear any existing