diff --git a/extender.cpp b/extender.cpp index e67fd0a33..57788d785 100644 --- a/extender.cpp +++ b/extender.cpp @@ -166,9 +166,17 @@ QList Extender::detachedItems() const { QList result; - foreach (ExtenderItem *item, items()) { - if (item->isDetached()) { - result.append(item); + //FIXME: a triple nested loop ... ew. there should be a more efficient way to do this + //iterate through all extenders we can find and check each extenders source applet. + foreach (Containment *c, d->applet->containment()->corona()->containments()) { + foreach (Applet *applet, c->applets()) { + if (applet->d->extender) { + foreach (ExtenderItem *item, applet->d->extender->attachedItems()) { + if (item->d->sourceApplet == d->applet && item->isDetached()) { + result.append(item); + } + } + } } } @@ -177,12 +185,33 @@ QList Extender::detachedItems() const ExtenderItem *Extender::item(const QString &name) const { - foreach (ExtenderItem *item, items()) { - if (item->name() == name) { + // chances are the item is in our own extender, so check there first + foreach (ExtenderItem *item, d->attachedExtenderItems) { + if (item->d->sourceApplet == d->applet && item->name() == name) { return item; } } + // maybe it's been moved elsewhere, so lets search through the entire tree of elements + //FIXME: a triple nested loop ... ew. there should be a more efficient way to do this + //iterate through all extenders we can find and check each extenders source applet. + foreach (Containment *c, d->applet->containment()->corona()->containments()) { + foreach (Applet *applet, c->applets()) { + if (applet->d->extender) { + if (applet->d->extender == this) { + // skip it, we checked it already + continue; + } + + foreach (ExtenderItem *item, applet->d->extender->attachedItems()) { + if (item->d->sourceApplet == d->applet && item->name() == name) { + return item; + } + } + } + } + } + return 0; }