diff --git a/extender.cpp b/extender.cpp index 82ff544a0..bf0ccfe77 100644 --- a/extender.cpp +++ b/extender.cpp @@ -101,7 +101,7 @@ QList Extender::items() const foreach (Applet *applet, c->applets()) { if (applet->d->extender) { foreach (ExtenderItem *item, applet->d->extender->attachedItems()) { - if (item->sourceAppletId() == d->applet->id()) { + if (item->d->sourceApplet == d->applet) { result.append(item); } } diff --git a/extenderitem.cpp b/extenderitem.cpp index 3a5c487d5..01333fb7b 100644 --- a/extenderitem.cpp +++ b/extenderitem.cpp @@ -66,30 +66,27 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId) d->extenderItemId = ++ExtenderItemPrivate::s_maxExtenderItemId; } - //TODO: make sourceApplet a function so stuff doesn't break when the source applet has been - //removed. - d->sourceApplet = hostExtender->d->applet; - //create items's configgroup KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems"); KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId)); + uint sourceAppletId = dg.readEntry("sourceAppletId", 0); + //TODO: automatically load title and icon. - if (!dg.readEntry("sourceAppletId", 0)) { + if (!sourceAppletId) { //The item is new dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName()); dg.writeEntry("sourceAppletId", hostExtender->d->applet->id()); - d->sourceAppletId = hostExtender->d->applet->id(); d->sourceApplet = hostExtender->d->applet; } else { //The item already exists. d->name = dg.readEntry("extenderItemName", ""); - d->sourceAppletId = dg.readEntry("sourceAppletId", 0); - //Set the sourceapplet. + + //Find the sourceapplet. Corona *corona = hostExtender->d->applet->containment()->corona(); foreach (Containment *containment, corona->containments()) { foreach (Applet *applet, containment->applets()) { - if (applet->id() == d->sourceAppletId && + if (applet->id() == sourceAppletId && applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) { d->sourceApplet = applet; } @@ -97,6 +94,10 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId) } } + //make sure we keep monitoring if the source applet still exists, so the return to source icon + //can be hidden if it is removed. + connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved())); + //create the toolbox. d->toolbox = new QGraphicsWidget(this); d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox); @@ -109,6 +110,9 @@ ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId) //set the extender we want to move to. setExtender(hostExtender); + //show or hide the return to source icon. + d->updateToolBox(); + //set the image paths, image sizes and collapseIcon position. d->themeChanged(); @@ -283,7 +287,7 @@ bool ExtenderItem::autoExpireDelay() const bool ExtenderItem::isDetached() const { if (d->hostApplet()) { - return (sourceAppletId() != d->hostApplet()->id()); + return (d->sourceApplet != d->hostApplet()); } else { return false; } @@ -307,11 +311,6 @@ QAction *ExtenderItem::action(const QString &name) const } } -uint ExtenderItem::sourceAppletId() const -{ - return d->sourceAppletId; -} - void ExtenderItem::destroy() { if (d->mousePressed) { @@ -725,11 +724,11 @@ ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *h toplevel(0), previousTargetExtender(0), extender(hostExtender), + sourceApplet(0), dragger(new PanelSvg(extenderItem)), background(new PanelSvg(extenderItem)), collapseIcon(0), title(QString()), - sourceAppletId(hostExtender->d->applet->id()), mousePressed(false), mouseOver(false), expirationTimer(0) @@ -951,6 +950,14 @@ void ExtenderItemPrivate::themeChanged() q->update(); } +void ExtenderItemPrivate::sourceAppletRemoved() +{ + //the original source applet is removed, set the pointer to 0 and no longer show the return to + //source icon. + sourceApplet = 0; + updateToolBox(); +} + uint ExtenderItemPrivate::s_maxExtenderItemId = 0; } // namespace Plasma diff --git a/extenderitem.h b/extenderitem.h index fc9a2d456..712ddb40e 100644 --- a/extenderitem.h +++ b/extenderitem.h @@ -171,11 +171,6 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget */ QAction *action(const QString &name) const; - /** - * @return the id of the applet this item is created by. - */ - uint sourceAppletId() const; - public Q_SLOTS: /** * Destroys the extender item. As opposed to calling delete on this class, destroy also @@ -210,6 +205,7 @@ class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget Q_PRIVATE_SLOT(d, void toggleCollapse()) Q_PRIVATE_SLOT(d, void updateToolBox()) Q_PRIVATE_SLOT(d, void themeChanged()) + Q_PRIVATE_SLOT(d, void sourceAppletRemoved()) ExtenderItemPrivate * const d; diff --git a/private/extenderitem_p.h b/private/extenderitem_p.h index b563bcf98..7dac0fba1 100644 --- a/private/extenderitem_p.h +++ b/private/extenderitem_p.h @@ -55,6 +55,7 @@ class ExtenderItemPrivate QPointF scenePosFromScreenPos(const QPoint &pos) const; Applet *hostApplet() const; void themeChanged(); + void sourceAppletRemoved(); ExtenderItem *q; @@ -79,7 +80,6 @@ class ExtenderItemPrivate QString title; QString name; - uint sourceAppletId; uint extenderItemId; qreal dragLeft, dragTop, dragRight, dragBottom;