From d8731d7806942b7414a7958915f99e48b439de54 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 9 Apr 2014 22:15:02 +0200 Subject: [PATCH] re-add Corona::createContainmentDelayed() unfortunate, but necessary for on the fly containment plugin switch --- src/plasma/corona.cpp | 29 +++++++++++++------ src/plasma/corona.h | 20 +++++++++++++ src/plasma/private/corona_p.h | 2 +- .../qml/plasmoid/containmentinterface.cpp | 4 +++ .../qml/plasmoid/wallpaperinterface.cpp | 6 ++-- 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/plasma/corona.cpp b/src/plasma/corona.cpp index a5962d877..194df4972 100644 --- a/src/plasma/corona.cpp +++ b/src/plasma/corona.cpp @@ -198,6 +198,15 @@ Containment *Corona::createContainment(const QString &name, const QVariantList & return 0; } +Containment *Corona::createContainmentDelayed(const QString &name, const QVariantList &args) +{ + if (d->immutability == Types::Mutable) { + return d->addContainment(name, args, 0, true); + } + + return 0; +} + int Corona::screenForContainment(const Containment* containment) const { return -1; @@ -388,7 +397,7 @@ void CoronaPrivate::syncConfig() emit q->configSynced(); } -Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id) +Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit) { QString pluginName = name; Containment *containment = 0; @@ -448,14 +457,16 @@ Containment *CoronaPrivate::addContainment(const QString &name, const QVariantLi QObject::connect(containment, SIGNAL(screenChanged(int)), q, SIGNAL(screenOwnerChanged(int))); - containment->init(); - KConfigGroup cg = containment->config(); - containment->restore(cg); - containment->updateConstraints(Plasma::Types::StartupCompletedConstraint); - containment->save(cg); - q->requestConfigSync(); - containment->flushPendingConstraintsEvents(); - emit q->containmentAdded(containment); + if (!delayedInit) { + containment->init(); + KConfigGroup cg = containment->config(); + containment->restore(cg); + containment->updateConstraints(Plasma::Types::StartupCompletedConstraint); + containment->save(cg); + q->requestConfigSync(); + containment->flushPendingConstraintsEvents(); + emit q->containmentAdded(containment); + } return containment; } diff --git a/src/plasma/corona.h b/src/plasma/corona.h index 8b8918efc..06ebbb091 100644 --- a/src/plasma/corona.h +++ b/src/plasma/corona.h @@ -271,6 +271,26 @@ protected: **/ virtual void loadDefaultLayout(); + /** + * Loads a containment with delayed initialization, primarily useful + * for implementations of loadDefaultLayout. The caller is responsible + * for all initializating, saving and notification of a new containment. + * + * @param name the plugin name for the containment, as given by + * KPluginInfo::pluginName(). If an empty string is passed in, the defalt + * containment plugin will be used (usually DesktopContainment). If the + * string literal "null" is passed in, then no plugin will be loaded and + * a simple Containment object will be created instead. + * @param args argument list to pass to the containment + * + * @return a pointer to the containment on success, or 0 on failure. Failure can + * be caused by the Immutability type being too restrictive, as containments can't be added + * when widgets are locked, or if the requested containment plugin can not be located + * or successfully loaded. + * @see addContainment + **/ + Containment *createContainmentDelayed(const QString &name, + const QVariantList &args = QVariantList()); private: CoronaPrivate *const d; diff --git a/src/plasma/private/corona_p.h b/src/plasma/private/corona_p.h index de21808ea..3d10313b4 100644 --- a/src/plasma/private/corona_p.h +++ b/src/plasma/private/corona_p.h @@ -45,7 +45,7 @@ public: void updateContainmentImmutability(); void containmentDestroyed(QObject *obj); void syncConfig(); - Containment *addContainment(const QString &name, const QVariantList &args, uint id); + Containment *addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit = false); QList importLayout(const KConfigGroup &conf, bool mergeConfig); Corona *q; diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 91059982c..56ce9fbaf 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -148,6 +148,10 @@ void ContainmentInterface::init() QQmlProperty prop(qmlObject()->rootObject(), "anchors.fill"); prop.write(expr.evaluate()); } + + if (!containment()->wallpaper().isEmpty()) { + loadWallpaper(); + } } QList ContainmentInterface::applets() diff --git a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp index 90a6ce756..7177b033b 100644 --- a/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp +++ b/src/scriptengines/qml/plasmoid/wallpaperinterface.cpp @@ -110,12 +110,13 @@ Plasma::ConfigLoader *WallpaperInterface::configScheme() void WallpaperInterface::syncWallpaperPackage() { - if (m_wallpaperPlugin == m_containmentInterface->containment()->wallpaper()) { + if (m_wallpaperPlugin == m_containmentInterface->containment()->wallpaper() && + m_qmlObject->rootObject()) { return; } m_wallpaperPlugin = m_containmentInterface->containment()->wallpaper(); - + if (!m_qmlObject) { m_qmlObject = new KDeclarative::QmlObject(this); s_rootObjects[m_qmlObject->engine()] = this; @@ -138,7 +139,6 @@ void WallpaperInterface::syncWallpaperPackage() m_configuration = new KDeclarative::ConfigPropertyMap(configScheme(), this); } - m_qmlObject->setSource(QUrl::fromLocalFile(m_pkg.filePath("mainscript"))); m_qmlObject->engine()->rootContext()->setContextProperty("wallpaper", this); m_qmlObject->completeInitialization();