From: Peter Penz Date: Fri, 9 Dec 2011 20:49:59 +0000 (+0100) Subject: Fix issue with duplicate items in details view X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/54745c440cc9361e32e82a3c1db50288805efcd6 Fix issue with duplicate items in details view When expanding an item, collapsing it and expanding it again before the items for the first expanding could be loaded, it was possible that items have been inserted twice into the model. BUG: 288521 FIXED-IN: 4.8.0 --- diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 8eb47f5ec..00a856e25 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -404,11 +404,11 @@ bool KFileItemModel::setExpanded(int index, bool expanded) return false; } + KDirLister* dirLister = m_dirLister.data(); const KUrl url = m_itemData.at(index)->item.url(); if (expanded) { m_expandedUrls.insert(url); - KDirLister* dirLister = m_dirLister.data(); if (dirLister) { dirLister->openUrl(url, KDirLister::Keep); return true; @@ -416,6 +416,10 @@ bool KFileItemModel::setExpanded(int index, bool expanded) } else { m_expandedUrls.remove(url); + if (dirLister) { + dirLister->stop(url); + } + KFileItemList itemsToRemove; const int expansionLevel = data(index)["expansionLevel"].toInt(); ++index; @@ -666,6 +670,22 @@ void KFileItemModel::slotCanceled() void KFileItemModel::slotNewItems(const KFileItemList& items) { + if (m_requestRole[ExpansionLevelRole] && m_rootExpansionLevel >= 0) { + // If the expanding of items is enabled in the model, it might be + // possible that the call dirLister->openUrl(url, KDirLister::Keep) in + // KFileItemModel::setExpanded() results in emitting of the same items + // twice due to the Keep-parameter. This case happens if an item gets + // expanded, collapsed and expanded again before the items could be loaded + // for the first expansion. + foreach (const KFileItem& item, items) { + const int index = m_items.value(item.url(), -1); + if (index >= 0) { + // The items are already part of the model. + return; + } + } + } + if (m_nameFilter.isEmpty()) { m_pendingItemsToInsert.append(items); } else {