diff --git a/src/plasma/applet.cpp b/src/plasma/applet.cpp index f3b766bd3..7b201504f 100644 --- a/src/plasma/applet.cpp +++ b/src/plasma/applet.cpp @@ -434,6 +434,10 @@ void Applet::flushPendingConstraintsEvents() Plasma::Types::Constraints c = d->pendingConstraints; d->pendingConstraints = Types::NoConstraint; + if (c & Plasma::Types::UiReadyConstraint) { + d->setUiReady(); + } + if (c & Plasma::Types::StartupCompletedConstraint) { //common actions bool unlocked = immutability() == Types::Mutable; diff --git a/src/plasma/applet.h b/src/plasma/applet.h index 0b1e077ee..7282274c2 100644 --- a/src/plasma/applet.h +++ b/src/plasma/applet.h @@ -364,7 +364,7 @@ class PLASMA_EXPORT Applet : public QObject * @since 4.4 */ void statusChanged(Plasma::Types::ItemStatus status); - + //CONFIGURATION /** * Emitted when an applet has changed values in its configuration @@ -375,7 +375,6 @@ class PLASMA_EXPORT Applet : public QObject * applets. */ void configNeedsSaving(); - //ACTIONS /** diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index d81ffeac6..ac9da7538 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -395,6 +395,12 @@ void Containment::addApplet(Applet *applet) d->applets << applet; + if (!applet->d->uiReady) { + d->loadingApplets << applet; + static_cast(this)->d->uiReady = false; + emit uiReadyChanged(false); + } + connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving())); connect(applet, SIGNAL(appletDeleted(Plasma::Applet*)), this, SLOT(appletDeleted(Plasma::Applet*))); connect(applet, SIGNAL(statusChanged(Plasma::Types::ItemStatus)), this, SLOT(checkStatus(Plasma::Types::ItemStatus))); @@ -510,6 +516,11 @@ QHash &Containment::containmentActions() return d->localActionPlugins; } +bool Containment::isUiReady() const +{ + return static_cast(this)->d->uiReady; +} + void Containment::setActivity(const QString &activityId) { if (activityId.isEmpty() || d->activityId == activityId) { diff --git a/src/plasma/containment.h b/src/plasma/containment.h index f5b35a2ee..44134e10d 100644 --- a/src/plasma/containment.h +++ b/src/plasma/containment.h @@ -205,6 +205,11 @@ class PLASMA_EXPORT Containment : public Applet QHash &containmentActions(); + /** + * @returns true when the ui of this containment is fully loaded, as well the ui of every applet in it + */ + bool isUiReady() const; + Q_SIGNALS: /** * This signal is emitted when a new applet is created by the containment @@ -262,6 +267,12 @@ Q_SIGNALS: */ void formFactorChanged(Plasma::Types::FormFactor formFactor); + /** + * Emitted when the ui has been fully loaded and is fully working + * @param uiReady true when the ui of the containment is ready, as well the ui of each applet in it + */ + void uiReadyChanged(bool uiReady); + public Q_SLOTS: /** * Informs the Corona as to what position it is in. This is informational diff --git a/src/plasma/plasma.h b/src/plasma/plasma.h index 6c2014564..c7048e788 100644 --- a/src/plasma/plasma.h +++ b/src/plasma/plasma.h @@ -53,8 +53,9 @@ enum Constraint { ImmutableConstraint = 8, /**< the immutability (locked) nature of the applet changed */ StartupCompletedConstraint = 16, /**< application startup has completed */ ContextConstraint = 32, /**< the context (e.g. activity) has changed */ + UiReadyConstraint = 64, /** The ui has been completely loaded (FIXME: merged with StartupCompletedConstraint?) */ AllConstraints = FormFactorConstraint | LocationConstraint | ScreenConstraint | - ImmutableConstraint + ImmutableConstraint | UiReadyConstraint }; Q_ENUMS(Constraint) Q_DECLARE_FLAGS(Constraints, Constraint) diff --git a/src/plasma/private/applet_p.cpp b/src/plasma/private/applet_p.cpp index b7fe4e948..0e590aa45 100644 --- a/src/plasma/private/applet_p.cpp +++ b/src/plasma/private/applet_p.cpp @@ -67,7 +67,8 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int transient(false), needsConfig(false), started(false), - globalShortcutEnabled(false) + globalShortcutEnabled(false), + uiReady(false) { if (appletId == 0) { appletId = ++s_maxAppletId; @@ -270,6 +271,29 @@ void AppletPrivate::propagateConfigChanged() q->configChanged(); } +void AppletPrivate::setUiReady() +{ + //am i the containment? + Containment *c = qobject_cast(q); + if (c) { + //if we are the containment and there is still some uncomplete applet, we're still incomplete + if (!c->d->loadingApplets.isEmpty()) { + return; + } + } else { + c = q->containment(); + if (c) { + q->containment()->d->loadingApplets.remove(q); + if (q->containment()->d->loadingApplets.isEmpty()) { + static_cast(q->containment())->d->uiReady = true; + emit q->containment()->uiReadyChanged(true); + } + } + } + + uiReady = true; +} + void AppletPrivate::setIsContainment(bool nowIsContainment, bool forceUpdate) { if (isContainment == nowIsContainment && !forceUpdate) { diff --git a/src/plasma/private/applet_p.h b/src/plasma/private/applet_p.h index ab3cf1795..4c27f1bae 100644 --- a/src/plasma/private/applet_p.h +++ b/src/plasma/private/applet_p.h @@ -69,6 +69,7 @@ public: void updateShortcuts(); void globalShortcutChanged(); void propagateConfigChanged(); + void setUiReady(); static KActionCollection* defaultActions(QObject *parent); @@ -114,6 +115,7 @@ public: bool needsConfig : 1; bool started : 1; bool globalShortcutEnabled : 1; + bool uiReady : 1; }; } // Plasma namespace diff --git a/src/plasma/private/containment_p.h b/src/plasma/private/containment_p.h index 2a56c155e..ad0c8d6b3 100644 --- a/src/plasma/private/containment_p.h +++ b/src/plasma/private/containment_p.h @@ -22,6 +22,7 @@ #define CONTAINMENT_P_H #include +#include #include "plasma.h" #include "applet.h" @@ -97,6 +98,8 @@ public: Types::FormFactor formFactor; Types::Location location; QList applets; + //Applets still considered not ready + QSet loadingApplets; QString wallpaper; QHash localActionPlugins; int screen; diff --git a/src/plasma/scripting/appletscript.h b/src/plasma/scripting/appletscript.h index 435b13165..0bdd99645 100644 --- a/src/plasma/scripting/appletscript.h +++ b/src/plasma/scripting/appletscript.h @@ -157,6 +157,11 @@ Q_SIGNALS: */ void saveState(KConfigGroup &group) const; + /** + * @param uiReady true if the UI for this applet is ready + */ + void uiReadyChanged(bool uiReady); + public Q_SLOTS: /** diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp index 329a0c087..78f1c1e8b 100644 --- a/src/scriptengines/qml/plasmoid/appletinterface.cpp +++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp @@ -186,20 +186,7 @@ void AppletInterface::init() geometryChanged(QRectF(), QRectF(x(), y(), width(), height())); emit busyChanged(); - if (!qobject_cast(applet())) { - m_appletScriptEngine->setUiReady(true); - - ContainmentInterface *containmentGraphicObject = qobject_cast(applet()->containment()->property("graphicObject").value()); - - if (containmentGraphicObject) { - DeclarativeAppletScript *containmentScript = containmentGraphicObject->m_appletScriptEngine; - - containmentScript->m_inProgressAppletInterfaces.remove(this); - if (containmentScript->m_inProgressAppletInterfaces.isEmpty()) { - containmentScript->setUiReady(true); - } - } - } + applet()->updateConstraints(Plasma::Types::UiReadyConstraint); } Plasma::Types::FormFactor AppletInterface::formFactor() const diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 27b54773e..76810b054 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -82,9 +82,6 @@ void ContainmentInterface::init() if (!m_appletInterfaces.isEmpty()) { emit appletsChanged(); } - if (m_appletScriptEngine->m_inProgressAppletInterfaces.isEmpty()) { - m_appletScriptEngine->setUiReady(true); - } } QList ContainmentInterface::applets() @@ -176,7 +173,6 @@ void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) } m_appletInterfaces << appletGraphicObject; - m_appletScriptEngine->m_inProgressAppletInterfaces.insert(appletGraphicObject); emit appletAdded(appletGraphicObject); emit appletsChanged(); } diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp index dc9ac00aa..dc1242498 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.cpp @@ -56,8 +56,7 @@ K_EXPORT_PLASMA_APPLETSCRIPTENGINE(declarativeappletscript, DeclarativeAppletScr DeclarativeAppletScript::DeclarativeAppletScript(QObject *parent, const QVariantList &args) : Plasma::AppletScript(parent), - m_interface(0), - m_uiReady(false) + m_interface(0) { qmlRegisterType(); qmlRegisterType(); @@ -115,21 +114,6 @@ void DeclarativeAppletScript::constraintsEvent(Plasma::Types::Constraints constr } } -void DeclarativeAppletScript::setUiReady(bool ready) -{ - if (m_uiReady == ready) { - return; - } - - m_uiReady = ready; - emit uiReadyChanged(ready); -} - -bool DeclarativeAppletScript::isUiReady() const -{ - return m_uiReady; -} - void DeclarativeAppletScript::activate() { #if 0 diff --git a/src/scriptengines/qml/plasmoid/declarativeappletscript.h b/src/scriptengines/qml/plasmoid/declarativeappletscript.h index e03bb46a8..64a11045e 100644 --- a/src/scriptengines/qml/plasmoid/declarativeappletscript.h +++ b/src/scriptengines/qml/plasmoid/declarativeappletscript.h @@ -46,9 +46,6 @@ public: void constraintsEvent(Plasma::Types::Constraints constraints); - void setUiReady(bool ready); - bool isUiReady() const; - public Q_SLOTS: void executeAction(const QString &name); void activate(); @@ -64,8 +61,6 @@ Q_SIGNALS: private: AppletInterface *m_interface; - bool m_uiReady; - QSet m_inProgressAppletInterfaces; friend class AppletInterface; friend class ContainmentInterface; };