move the tracking of uiReady into libplasma

doesn't still have nothing about ui, is completely bookkeeping, but is
easier to have it correct there
This commit is contained in:
Marco Martin 2013-08-09 21:51:13 +02:00
parent ebdfbb2e25
commit 8750d01f40
13 changed files with 66 additions and 44 deletions

View File

@ -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;

View File

@ -376,7 +376,6 @@ class PLASMA_EXPORT Applet : public QObject
*/
void configNeedsSaving();
//ACTIONS
/**
* Emitted when activation is requested due to, for example, a global

View File

@ -395,6 +395,12 @@ void Containment::addApplet(Applet *applet)
d->applets << applet;
if (!applet->d->uiReady) {
d->loadingApplets << applet;
static_cast<Applet *>(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<QString, ContainmentActions*> &Containment::containmentActions()
return d->localActionPlugins;
}
bool Containment::isUiReady() const
{
return static_cast<const Applet *>(this)->d->uiReady;
}
void Containment::setActivity(const QString &activityId)
{
if (activityId.isEmpty() || d->activityId == activityId) {

View File

@ -205,6 +205,11 @@ class PLASMA_EXPORT Containment : public Applet
QHash<QString, ContainmentActions*> &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

View File

@ -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)

View File

@ -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<Containment *>(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<Applet *>(q->containment())->d->uiReady = true;
emit q->containment()->uiReadyChanged(true);
}
}
}
uiReady = true;
}
void AppletPrivate::setIsContainment(bool nowIsContainment, bool forceUpdate)
{
if (isContainment == nowIsContainment && !forceUpdate) {

View File

@ -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

View File

@ -22,6 +22,7 @@
#define CONTAINMENT_P_H
#include <kactioncollection.h>
#include <QSet>
#include "plasma.h"
#include "applet.h"
@ -97,6 +98,8 @@ public:
Types::FormFactor formFactor;
Types::Location location;
QList<Applet *> applets;
//Applets still considered not ready
QSet <Applet *> loadingApplets;
QString wallpaper;
QHash<QString, ContainmentActions*> localActionPlugins;
int screen;

View File

@ -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:
/**

View File

@ -186,20 +186,7 @@ void AppletInterface::init()
geometryChanged(QRectF(), QRectF(x(), y(), width(), height()));
emit busyChanged();
if (!qobject_cast<Plasma::Containment *>(applet())) {
m_appletScriptEngine->setUiReady(true);
ContainmentInterface *containmentGraphicObject = qobject_cast<ContainmentInterface *>(applet()->containment()->property("graphicObject").value<QObject *>());
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

View File

@ -82,9 +82,6 @@ void ContainmentInterface::init()
if (!m_appletInterfaces.isEmpty()) {
emit appletsChanged();
}
if (m_appletScriptEngine->m_inProgressAppletInterfaces.isEmpty()) {
m_appletScriptEngine->setUiReady(true);
}
}
QList <QObject *> 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();
}

View File

@ -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<AppletInterface>();
qmlRegisterType<ConfigPropertyMap>();
@ -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

View File

@ -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<QObject *> m_inProgressAppletInterfaces;
friend class AppletInterface;
friend class ContainmentInterface;
};