]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make determining the mime type faster for folders
authorFrank Reininghaus <frank78ac@googlemail.com>
Sat, 24 Aug 2013 18:22:56 +0000 (20:22 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sat, 24 Aug 2013 18:22:56 +0000 (20:22 +0200)
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

index 58a135cd178f6d2577dfbe43987c786503b2f12f..7bbc1d17f46d1736bc0aa4c48db80e63f8a7880f 100644 (file)
@@ -1381,6 +1381,9 @@ QHash<QByteArray, QVariant> 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.