fix delayed loading of containments

This commit is contained in:
Marco Martin 2013-08-09 11:56:58 +02:00
parent 336055edc5
commit 0d9bc6d7be

View File

@ -46,11 +46,6 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent)
setAcceptedMouseButtons(Qt::RightButton);
qmlRegisterType<ContainmentInterface>();
}
void ContainmentInterface::init()
{
AppletInterface::init();
connect(containment(), &Plasma::Containment::appletRemoved,
this, &ContainmentInterface::appletRemovedForward);
@ -67,17 +62,26 @@ void ContainmentInterface::init()
connect(containment()->corona(), &Plasma::Corona::availableScreenRegionChanged,
this, &ContainmentInterface::availableScreenRegionChanged);
}
}
//HACK, why appletAddedForward doesn't get called?
foreach (Plasma::Applet *applet, containment()->applets()) {
appletAddedForward(applet);
}
foreach (QObject *appletObj, m_appletInterfaces) {
AppletInterface *applet = qobject_cast<AppletInterface *>(appletObj);
if (!applet->qmlObject()) {
applet->init();
}
}
void ContainmentInterface::init()
{
AppletInterface::init();
foreach (QObject *appletObj, m_appletInterfaces) {
AppletInterface *applet = qobject_cast<AppletInterface *>(appletObj);
if (applet) {
if (!applet->qmlObject()) {
applet->init();
}
m_appletInterfaces << applet;
emit appletAdded(applet);
}
}
if (!m_appletInterfaces.isEmpty()) {
emit appletsChanged();
}
}
QList <QObject *> ContainmentInterface::applets()
@ -142,17 +146,22 @@ QVariantList ContainmentInterface::availableScreenRegion(int id) const
void ContainmentInterface::appletAddedForward(Plasma::Applet *applet)
{
if (!applet) {
return;
}
QObject *appletGraphicObject = applet->property("graphicObject").value<QObject *>();
QObject *contGraphicObject = containment()->property("graphicObject").value<QObject *>();
qDebug() << "Applet added:" << applet << applet->title() << appletGraphicObject;
qDebug() << "Applet added on containment:" << containment()->title() << contGraphicObject
<< "Applet: " << applet << applet->title() << appletGraphicObject;
if (applet && contGraphicObject && appletGraphicObject) {
if (contGraphicObject && appletGraphicObject) {
appletGraphicObject->setProperty("visible", false);
appletGraphicObject->setProperty("parent", QVariant::fromValue(contGraphicObject));
//if an appletGraphicObject is not set, we have to display some error message
} else if (applet && contGraphicObject) {
} else if (contGraphicObject) {
QObject *errorUi = qmlObject()->createObjectFromSource(QUrl::fromLocalFile(containment()->corona()->package().filePath("appleterror")));
if (errorUi) {