From 7ffa66f77789f754a4c35a5c4d0ecbfc0a0ae1e7 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Sat, 24 Aug 2013 20:22:56 +0200 Subject: [PATCH] Make determining the mime type faster for folders KFileItem::determineMimeType() not only determines the mime type, but also the icon. For folders, it looks for a .directory file inside the folder, where a custom icon might be stored. This can take quite a bit of time and cause the problem that some folder's type still appears to be "unknown" when the view is shown. We can work around this problem by caching the folder mime type in a static QString and applying to to all folders, which can be identified easily with KFileItem::isDir(), BUG: 321710 FIXED-IN: 4.11.1 REVIEW: 111830 --- src/kitemviews/kfileitemmodel.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 58a135cd1..7bbc1d17f 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -1381,6 +1381,9 @@ QHash KFileItemModel::retrieveData(const KFileItem& item, if (m_requestRole[TypeRole]) { data.insert(sharedValue("type"), item.mimeComment()); } + } else if (m_requestRole[TypeRole] && isDir) { + static const QString folderMimeType = item.mimeComment(); + data.insert(sharedValue("type"), folderMimeType); } return data; @@ -1987,7 +1990,15 @@ void KFileItemModel::determineMimeTypes(const KFileItemList& items, int timeout) QElapsedTimer timer; timer.start(); foreach (const KFileItem& item, items) { // krazy:exclude=foreach - item.determineMimeType(); + // Only determine mime types for files here. For directories, + // KFileItem::determineMimeType() reads the .directory file inside to + // load the icon, but this is not necessary at all if we just need the + // type. Some special code for setting the correct mime type for + // directories is in retrieveData(). + if (!item.isDir()) { + item.determineMimeType(); + } + if (timer.elapsed() > timeout) { // Don't block the user interface, let the remaining items // be resolved asynchronously. -- 2.47.3