+void KFileItemModelRolesUpdater::updateVisibleIcons()
+{
+ int lastVisibleIndex = m_lastVisibleIndex;
+ if (lastVisibleIndex <= 0) {
+ // Guess a reasonable value for the last visible index if the view
+ // has not told us about the real value yet.
+ lastVisibleIndex = qMin(m_firstVisibleIndex + m_maximumVisibleItems, m_model->count() - 1);
+ if (lastVisibleIndex <= 0) {
+ lastVisibleIndex = qMin(200, m_model->count() - 1);
+ }
+ }
+
+ QElapsedTimer timer;
+ timer.start();
+
+ // Try to determine the final icons for all visible items.
+ int index;
+ for (index = m_firstVisibleIndex; index <= lastVisibleIndex && timer.elapsed() < MaxBlockTimeout; ++index) {
+ const KFileItem item = m_model->fileItem(index);
+ 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>)));
+}
+