From: Frank Reininghaus Date: Mon, 18 Feb 2013 22:58:26 +0000 (+0100) Subject: Fix crash when clicking an action in context menu for a removed device X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/518b53feb43325d5c194fa15118e80ab0729b620?ds=inline Fix crash when clicking an action in context menu for a removed device Devices can be added and removed while the context menu is open. Sfter an action has clicked that needs to access a device, we therefore have to check if its position in the model has changed, and more importantly, if it is still there at all in order to prevent a crash. BUG: 315298 FIXED-IN: 4.10.1 REVIEW: 108989 --- diff --git a/src/panels/places/placespanel.cpp b/src/panels/places/placespanel.cpp index 919f2ed45..56042d856 100644 --- a/src/panels/places/placespanel.cpp +++ b/src/panels/places/placespanel.cpp @@ -262,23 +262,34 @@ void PlacesPanel::slotItemContextMenuRequested(int index, const QPointF& pos) emptyTrash(); } else if (action == addAction) { addEntry(); - } else if (action == editAction) { - editEntry(index); - } else if (action == removeAction) { - m_model->removeItem(index); - } else if (action == hideAction) { - item->setHidden(hideAction->isChecked()); - } else if (action == openInNewTabAction) { - const KUrl url = m_model->item(index)->dataValue("url").value(); - emit placeMiddleClicked(url); } else if (action == showAllAction) { m_model->setHiddenItemsShown(showAllAction->isChecked()); - } else if (action == teardownAction) { - m_model->requestTeardown(index); - } else if (action == ejectAction) { - m_model->requestEject(index); } else if (iconSizeActionMap.contains(action)) { m_view->setIconSize(iconSizeActionMap.value(action)); + } else { + // The index might have changed if devices were added/removed while + // the context menu was open. + index = m_model->index(item); + if (index < 0) { + // The item is not in the model any more, probably because it was an + // external device that has been removed while the context menu was open. + return; + } + + if (action == editAction) { + editEntry(index); + } else if (action == removeAction) { + m_model->removeItem(index); + } else if (action == hideAction) { + item->setHidden(hideAction->isChecked()); + } else if (action == openInNewTabAction) { + const KUrl url = m_model->item(index)->dataValue("url").value(); + emit placeMiddleClicked(url); + } else if (action == teardownAction) { + m_model->requestTeardown(index); + } else if (action == ejectAction) { + m_model->requestEject(index); + } } }