On Wednesday 10 June 2009, Aaron J. Seigo wrote:
> we should still catch such mistakes gracefully, however. does the attached
> patch help?

that patch could be hazardous to your health. try the attached one instead as 
it actually works.

i'm not sure i like adding that sort of overhead on every parent changed call, 
though.. not sure it's overhead that matters either, however. it shouldn't, 
really as that's not really a "hot path" and this does make things a bit more 
robust.

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Qt Software

Index: applet.cpp
===================================================================
--- applet.cpp	(revision 979854)
+++ applet.cpp	(working copy)
@@ -1972,6 +1972,24 @@
         }
     }
         break;
+    case ItemParentChange:
+        if (d->mainConfig && !d->isContainment &&
+            !containment() &&
+            dynamic_cast<Containment*>(value.value<QGraphicsItem *>())) {
+            // if this is an applet, and we've just been assigned to our first containment,
+            // but the applet did something stupid like ask for the config() object prior to
+            // this happening (e.g. inits ctor) then let's repair that situation for them.
+            kWarning() << "Configuration object was requested prior to init(), which is too early. "
+                          "Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
+                          << name();
+            KConfigGroup *old = d->mainConfig;
+            KConfigGroup appletConfig = dynamic_cast<Containment*>(value.value<QGraphicsItem *>())->config();
+            appletConfig = KConfigGroup(&appletConfig, "Applets");
+            d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
+            old->copyTo(d->mainConfig);
+            old->deleteGroup();
+            delete old;
+        }
     case ItemPositionChange:
         return (immutability() == Mutable || isContainment() || formFactor() == Horizontal || formFactor() == Vertical) ? value : pos();
         break;

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to