From 0d9bc6d7beff69bc2d5270c9762f158a15602924 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Fri, 9 Aug 2013 11:56:58 +0200 Subject: [PATCH] fix delayed loading of containments --- .../qml/plasmoid/containmentinterface.cpp | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/scriptengines/qml/plasmoid/containmentinterface.cpp b/src/scriptengines/qml/plasmoid/containmentinterface.cpp index 586ca5b66..76810b054 100644 --- a/src/scriptengines/qml/plasmoid/containmentinterface.cpp +++ b/src/scriptengines/qml/plasmoid/containmentinterface.cpp @@ -46,11 +46,6 @@ ContainmentInterface::ContainmentInterface(DeclarativeAppletScript *parent) setAcceptedMouseButtons(Qt::RightButton); qmlRegisterType(); -} - -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(appletObj); - if (!applet->qmlObject()) { - applet->init(); - } - } +void ContainmentInterface::init() +{ + AppletInterface::init(); + + foreach (QObject *appletObj, m_appletInterfaces) { + AppletInterface *applet = qobject_cast(appletObj); + if (applet) { + if (!applet->qmlObject()) { + applet->init(); + } + m_appletInterfaces << applet; + emit appletAdded(applet); + } + } + + if (!m_appletInterfaces.isEmpty()) { + emit appletsChanged(); + } } QList 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 *contGraphicObject = containment()->property("graphicObject").value(); - 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) {