- KJob* job;
- if (items.count() <= MaxResolveItemsCount) {
- job = KIO::filePreview(items, cacheSize, &m_enabledPlugins);
- } else {
- KFileItemList itemsSubSet;
- for (int i = 0; i <= MaxResolveItemsCount; ++i) {
- itemsSubSet.append(items.at(i));
+ // KIO::filePreview() will request the MIME-type of all passed items, which (in the
+ // worst case) might block the application for several seconds. To prevent such
+ // a blocking the MIME-type of the items will determined until the MaxBlockTimeout
+ // has been reached and only those items will get passed. As soon as the MIME-type
+ // has been resolved once KIO::filePreview() can already access the resolved
+ // MIME-type in a fast way.
+ QElapsedTimer timer;
+ timer.start();
+ KFileItemList itemSubSet;
+ for (int i = 0; i < items.count(); ++i) {
+ KFileItem item = items.at(i);
+ item.determineMimeType();
+ itemSubSet.append(items.at(i));
+ if (timer.elapsed() > MaxBlockTimeout) {
+#ifdef KFILEITEMMODELROLESUPDATER_DEBUG
+ kDebug() << "Maximum time of" << MaxBlockTimeout << "ms exceeded, creating only previews for"
+ << (i + 1) << "items," << (items.count() - (i + 1)) << "will be resolved later";
+#endif
+ break;