]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix issue with duplicate items in details view
authorPeter Penz <peter.penz19@gmail.com>
Fri, 9 Dec 2011 20:49:59 +0000 (21:49 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 9 Dec 2011 20:52:31 +0000 (21:52 +0100)
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

src/kitemviews/kfileitemmodel.cpp

index 8eb47f5ec7cafcc5124b18cdd80ce49a5d227de4..00a856e2569511e68c2e7bb3086bc9143c05ac41 100644 (file)
@@ -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 {