diff options
| author | Frank Reininghaus <[email protected]> | 2013-02-18 23:58:26 +0100 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2013-02-18 23:58:31 +0100 |
| commit | 518b53feb43325d5c194fa15118e80ab0729b620 (patch) | |
| tree | 1b56de1dd3282a7c544507aad84b89be0a8a9be7 | |
| parent | 6938241ebce940bc55aa4f0bb3e77361a1a0211a (diff) | |
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
| -rw-r--r-- | src/panels/places/placespanel.cpp | 37 |
1 files changed, 24 insertions, 13 deletions
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<KUrl>(); - 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<KUrl>(); + emit placeMiddleClicked(url); + } else if (action == teardownAction) { + m_model->requestTeardown(index); + } else if (action == ejectAction) { + m_model->requestEject(index); + } } } |
