From ee34edad4a821f2973447d6600347acd81945527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9nard?= Date: Wed, 28 Jan 2009 08:13:19 +0000 Subject: [PATCH] SVN commit 917619 Add an appletDestroyed signal instead of catching the destruction in containments with qobject destroyed signal. This fix errors because we give an invalid pointer to public appletRemoved signal. svn path=/branches/KDE/4.2/kdelibs/; revision=917622 --- applet.cpp | 3 +++ applet.h | 5 +++++ containment.cpp | 12 ++---------- containment.h | 2 +- private/containment_p.h | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/applet.cpp b/applet.cpp index 5cf0309f4..d4bf267a7 100644 --- a/applet.cpp +++ b/applet.cpp @@ -133,6 +133,9 @@ Applet::Applet(QObject *parentObject, const QVariantList &args) Applet::~Applet() { + //let people know that i will die + emit appletDestroyed(this); + if (d->transient) { d->resetConfigurationObject(); } else if (d->extender) { diff --git a/applet.h b/applet.h index c4b095531..5f5a21576 100644 --- a/applet.h +++ b/applet.h @@ -609,6 +609,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 c79736d98..055b4a684 100644 --- a/containment.cpp +++ b/containment.cpp @@ -742,7 +742,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*))); if (pos != QPointF(-1, -1)) { applet->setPos(pos); @@ -1709,16 +1709,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();