]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Load unknown icons for items just before showing items in the view
authorFrank Reininghaus <frank78ac@googlemail.com>
Fri, 12 Jul 2013 06:27:04 +0000 (08:27 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Fri, 12 Jul 2013 06:27:05 +0000 (08:27 +0200)
Rather than loading many icons (without full mime type determination)
in advance, we make sure that an item has an icon just before it is
shown in the view. This makes sure that no "unknown" icons are shown
unnecessarily, and saves some resources.

REVIEW: 111396

src/kitemviews/kfileitemlistview.cpp
src/kitemviews/kfileitemlistview.h
src/kitemviews/kfileitemmodelrolesupdater.cpp
src/kitemviews/kfileitemmodelrolesupdater.h

index 70ce11b1fbaad3ad9c749533945f423aef425f35..2da238d7a1f7cca8de3ab05dec36007cf110f0c1 100644 (file)
@@ -190,6 +190,22 @@ KItemListWidgetCreatorBase* KFileItemListView::defaultWidgetCreator() const
     return new KItemListWidgetCreator<KFileItemListWidget>();
 }
 
+void KFileItemListView::initializeItemListWidget(KItemListWidget* item)
+{
+    KStandardItemListView::initializeItemListWidget(item);
+
+    // Make sure that the item has an icon.
+    QHash<QByteArray, QVariant> data = item->data();
+    if (!data.contains("iconName") && data["iconPixmap"].value<QPixmap>().isNull()) {
+        Q_ASSERT(qobject_cast<KFileItemModel*>(model()));
+        KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(model());
+
+        const KFileItem fileItem = fileItemModel->fileItem(item->index());
+        data.insert("iconName", fileItem.iconName());
+        item->setData(data, QSet<QByteArray>() << "iconName");
+    }
+}
+
 void KFileItemListView::onPreviewsShownChanged(bool shown)
 {
     Q_UNUSED(shown);
index d795c96b5eacc78aa3d1db55e8217722248cd1e4..49ff77318cff99b283f88eb02c8d530736dbeb61 100644 (file)
@@ -77,6 +77,7 @@ public:
 
 protected:
     virtual KItemListWidgetCreatorBase* defaultWidgetCreator() const;
+    virtual void initializeItemListWidget(KItemListWidget* item);
     virtual void onPreviewsShownChanged(bool shown);
     virtual void onItemLayoutChanged(ItemLayout current, ItemLayout previous);
     virtual void onModelChanged(KItemModelBase* current, KItemModelBase* previous);
index eaaab6bc0529f1f72a2bc81ea3b1cd3729f8280b..317a7a352279b167388b359b84ee752ab0b5a5b0 100644 (file)
@@ -89,8 +89,6 @@ KFileItemModelRolesUpdater::KFileItemModelRolesUpdater(KFileItemModel* model, QO
     m_resolvableRoles(),
     m_enabledPlugins(),
     m_pendingSortRoleItems(),
-    m_hasUnknownIcons(false),
-    m_firstIndexWithoutIcon(0),
     m_pendingIndexes(),
     m_pendingPreviewItems(),
     m_previewJob(),
@@ -333,10 +331,6 @@ void KFileItemModelRolesUpdater::slotItemsInserted(const KItemRangeList& itemRan
     QElapsedTimer timer;
     timer.start();
 
-    const int firstInsertedIndex = itemRanges.first().index;
-    m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstInsertedIndex);
-    m_hasUnknownIcons = true;
-
     // Determine the sort role synchronously for as many items as possible.
     if (m_resolvableRoles.contains(m_model->sortRole())) {
         int insertedCount = 0;
@@ -373,11 +367,6 @@ void KFileItemModelRolesUpdater::slotItemsRemoved(const KItemRangeList& itemRang
 
     const bool allItemsRemoved = (m_model->count() == 0);
 
-    if (m_hasUnknownIcons) {
-        const int firstRemovedIndex = itemRanges.first().index;
-        m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstRemovedIndex);
-    }
-
     if (!m_watchedDirs.isEmpty()) {
         // Don't let KDirWatch watch for removed items
         if (allItemsRemoved) {
@@ -459,11 +448,6 @@ void KFileItemModelRolesUpdater::slotItemsMoved(const KItemRange& itemRange, QLi
     Q_UNUSED(itemRange);
     Q_UNUSED(movedToIndexes);
 
-    if (m_hasUnknownIcons) {
-        const int firstMovedIndex = itemRange.index;
-        m_firstIndexWithoutIcon = qMin(m_firstIndexWithoutIcon, firstMovedIndex);
-    }
-
     // The visible items might have changed.
     startUpdating();
 }
@@ -829,13 +813,6 @@ void KFileItemModelRolesUpdater::startUpdating()
     // Determine the icons for the visible items synchronously.
     updateVisibleIcons();
 
-    // Try to do at least a fast icon loading (without determining the
-    // mime type) for all items, to reduce the risk that the user sees
-    // "unknown" icons when scrolling.
-    if (m_hasUnknownIcons) {
-        updateAllIconsFast(MaxBlockTimeout - timer.elapsed());
-    }
-
     // A detailed update of the items in and near the visible area
     // only makes sense if sorting is finished.
     if (m_state == ResolvingSortRole) {
@@ -887,58 +864,9 @@ void KFileItemModelRolesUpdater::updateVisibleIcons()
         applyResolvedRoles(item, ResolveFast);
     }
 
-    if (index > lastVisibleIndex) {
-        return;
-    }
-
-    // If this didn't work before MaxBlockTimeout was reached, at least
-    // prevent that the user sees 'unknown' icons.
-    disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
-               this,    SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
-
-    while (index <= lastVisibleIndex) {
-        if (!m_model->data(index).contains("iconName")) {
-            const KFileItem item = m_model->fileItem(index);
-            QHash<QByteArray, QVariant> data;
-            data.insert("iconName", item.iconName());
-            m_model->setData(index, data);
-        }
-        ++index;
-    }
-
-    connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
-            this,    SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
-}
-
-void KFileItemModelRolesUpdater::updateAllIconsFast(int timeout)
-{
-    if (timeout <= 0) {
-        return;
-    }
-
-    QElapsedTimer timer;
-    timer.start();
-
-    disconnect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
-               this,    SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
-
-    const int count = m_model->count();
-    while (m_firstIndexWithoutIcon < count && timer.elapsed() < timeout) {
-        if (!m_model->data(m_firstIndexWithoutIcon).contains("iconName")) {
-            const KFileItem item = m_model->fileItem(m_firstIndexWithoutIcon);
-            QHash<QByteArray, QVariant> data;
-            data.insert("iconName", item.iconName());
-            m_model->setData(m_firstIndexWithoutIcon, data);
-        }
-        ++m_firstIndexWithoutIcon;
-    }
-
-    if (m_firstIndexWithoutIcon == count) {
-        m_hasUnknownIcons = false;
-    }
-
-    connect(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)),
-            this,    SLOT(slotItemsChanged(KItemRangeList,QSet<QByteArray>)));
+    // KFileItemListView::initializeItemListWidget(KItemListWidget*) will load
+    // preliminary icons (i.e., without mime type determination) for the
+    // remaining items.
 }
 
 void KFileItemModelRolesUpdater::startPreviewJob()
index 20ce21cfa4093f0500e5ad36cbd96c3d01f4fdb3..605c36f81af3943d5a7ffb22c739c5c03063e910 100644 (file)
@@ -232,12 +232,6 @@ private:
      */
     void updateVisibleIcons();
 
-    /**
-     * Tries to load at least preliminary icons (without determining the
-     * mime type) for all items for \a timeout milliseconds.
-     */
-    void updateAllIconsFast(int timeout);
-
     /**
      * Creates previews for the items starting from the first item in
      * m_pendingPreviewItems.
@@ -326,11 +320,6 @@ private:
     // Items for which the sort role still has to be determined.
     QSet<KFileItem> m_pendingSortRoleItems;
 
-    // Determines if the next call of startUpdating() will try to do a fast
-    // icon loading (i.e., without determining the mime type) for all items.
-    bool m_hasUnknownIcons;
-    int m_firstIndexWithoutIcon;
-
     // Indexes of items which still have to be handled by
     // resolveNextPendingRoles().
     QList<int> m_pendingIndexes;