diff --git a/applet.cpp b/applet.cpp index ffaa3a4d8..b7e7b98e3 100644 --- a/applet.cpp +++ b/applet.cpp @@ -134,6 +134,9 @@ Applet::Applet(QObject *parentObject, const QVariantList &args) Applet::~Applet() { + //let people know that i will die + emit appletDestroyed(this); + if (!d->transient && d->extender) { //This would probably be nicer if it was located in extender. But in it's dtor, this won't //work since when that get's called, the applet's config() isn't accessible anymore. (same diff --git a/applet.h b/applet.h index 5f4ad714b..44ae39346 100644 --- a/applet.h +++ b/applet.h @@ -611,6 +611,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ void activate(); + /** + * Emitted when the applet is deleted + */ + void appletDestroyed(Plasma::Applet *applet); + public Q_SLOTS: /** * Sets the immutability type for this applet (not immutable, diff --git a/containment.cpp b/containment.cpp index a40b7156c..462e3e344 100644 --- a/containment.cpp +++ b/containment.cpp @@ -734,7 +734,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving())); connect(applet, SIGNAL(releaseVisualFocus()), this, SIGNAL(releaseVisualFocus())); - connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*))); + connect(applet, SIGNAL(appletDestroyed(Plasma::Applet*)), this, SLOT(appletDestroyed(Plasma::Applet*))); connect(applet, SIGNAL(activate()), this, SIGNAL(activate())); if (pos != QPointF(-1, -1)) { @@ -1697,16 +1697,8 @@ bool ContainmentPrivate::regionIsEmpty(const QRectF ®ion, Applet *ignoredAppl return true; } -void ContainmentPrivate::appletDestroyed(QObject *object) +void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet) { - // we do a static_cast here since it really isn't an Applet by this - // point anymore since we are in the qobject dtor. we don't actually - // try and do anything with it, we just need the value of the pointer - // so this unsafe looking code is actually just fine. - // - // NOTE: DO NOT USE THE applet VARIABLE FOR ANYTHING OTHER THAN COMPARING - // THE ADDRESS! ACTUALLY USING THE OBJECT WILL RESULT IN A CRASH!!! - Applet *applet = static_cast(object); applets.removeAll(applet); if (focusedApplet == applet) { focusedApplet = 0; diff --git a/containment.h b/containment.h index 354ccb751..e2343415a 100644 --- a/containment.h +++ b/containment.h @@ -507,7 +507,7 @@ class PLASMA_EXPORT Containment : public Applet const QGraphicsItem *toolBoxItem() const; private: - Q_PRIVATE_SLOT(d, void appletDestroyed(QObject*)) + Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)) Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) diff --git a/private/containment_p.h b/private/containment_p.h index 6fe21b7bf..0a91b981c 100644 --- a/private/containment_p.h +++ b/private/containment_p.h @@ -75,7 +75,7 @@ public: void positionContainments(); void setLockToolText(); void handleDisappeared(AppletHandle *handle); - void appletDestroyed(QObject*); + void appletDestroyed(Plasma::Applet*); void containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim); void zoomIn(); void zoomOut();