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