foreach takes a copy, use a mutable iterator. prevents crashes. also make a few more sanity checks in places to be ++sure about the health when executing those methods.

BUG:235851
BUG:240996

svn path=/trunk/KDE/kdelibs/; revision=1136808
This commit is contained in:
Aaron J. Seigo 2010-06-10 20:10:49 +00:00
parent 6ef91dbdce
commit 1cca6c7d02

View File

@ -110,10 +110,13 @@ Extender::Extender(Applet *applet)
Extender::~Extender()
{
d->destroying = true;
foreach (ExtenderItem *item, d->attachedExtenderItems) {
disconnect(item, 0, this, 0);
QMutableListIterator<ExtenderItem *> it(d->attachedExtenderItems);
while (it.hasNext()) {
ExtenderItem *item = it.next();
item->disconnect(this);
delete item;
}
d->attachedExtenderItems.clear();
delete d;
}
@ -211,6 +214,7 @@ ExtenderItem *Extender::item(const QString &name) const
if (!d->applet) {
return 0;
}
Containment *containment = d->applet.data()->containment();
if (!containment) {
return 0;
@ -231,6 +235,10 @@ ExtenderItem *Extender::item(const QString &name) const
continue;
}
if (!applet->d->extender) {
continue;
}
foreach (ExtenderItem *item, applet->d->extender.data()->attachedItems()) {
if (item->d->sourceApplet == d->applet.data() && item->name() == name) {
return item;
@ -597,7 +605,7 @@ void ExtenderPrivate::removeExtenderItem(ExtenderItem *item)
attachedExtenderItems.removeAll(item);
//collapse the popupapplet if the last item is removed.
if (!q->attachedItems().count()) {
if (attachedExtenderItems.isEmpty()) {
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(applet.data());
if (popupApplet) {
popupApplet->hidePopup();