]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodelrolesupdater.cpp
dolphinview: Update thumbnail on filename change
[dolphin.git] / src / kitemviews / kfileitemmodelrolesupdater.cpp
index e2d32265ef726b0acf2712d9db6b92fa45c84fef..8811401b03e9401afdbc608ad0abcdb6a5b348af 100644 (file)
 
 #include <KConfig>
 #include <KConfigGroup>
+#include <KIO/ListJob>
 #include <KIO/PreviewJob>
 #include <KIconLoader>
+#include <KIconUtils>
 #include <KJobWidgets>
 #include <KOverlayIconPlugin>
 #include <KPluginMetaData>
@@ -556,15 +558,13 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem &item, const QPi
     const QStringList overlays = data["iconOverlays"].toStringList();
     // Strangely KFileItem::overlays() returns empty string-values, so
     // we need to check first whether an overlay must be drawn at all.
-    // It is more efficient to do it here, as KIconLoader::drawOverlays()
-    // assumes that an overlay will be drawn and has some additional
-    // setup time.
     if (!scaledPixmap.isNull()) {
         for (const QString &overlay : overlays) {
             if (!overlay.isEmpty()) {
                 // There is at least one overlay, draw all overlays above m_pixmap
                 // and cancel the check
-                KIconLoader::global()->drawOverlays(overlays, scaledPixmap, KIconLoader::Desktop);
+                const QSize size = scaledPixmap.size();
+                scaledPixmap = KIconUtils::addOverlays(scaledPixmap, overlays).pixmap(size);
                 break;
             }
         }
@@ -575,6 +575,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem &item, const QPi
     disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
     m_model->setData(index, data);
     connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
+    Q_EMIT previewJobFinished(); // For unit testing
 
     m_finishedItems.insert(item);
 }
@@ -1287,11 +1288,11 @@ bool KFileItemModelRolesUpdater::applyResolvedRoles(int index, ResolveHint hint)
 
 void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &item, int index)
 {
-    if (!item.isLocalFile()) {
+    if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::None || !item.isLocalFile()) {
         return;
     }
 
-    if (ContentDisplaySettings::directorySizeCount() || item.isSlow()) {
+    if (ContentDisplaySettings::directorySizeMode() == ContentDisplaySettings::EnumDirectorySizeMode::ContentCount || item.isSlow()) {
         // fastpath no recursion necessary
 
         auto data = m_model->data(index);
@@ -1337,14 +1338,21 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite
                 ++entryCount;
             }
 
-            // count has changed
-            if (origCount < entryCount) {
-                QHash<QByteArray, QVariant> data;
-                data.insert("isExpandable", entryCount > 0);
-                data.insert("count", entryCount);
+            QHash<QByteArray, QVariant> newData;
+            QVariant expandable = data.value("isExpandable");
+            if (expandable.isNull() || expandable.toBool() != (entryCount > 0)) {
+                // if expandable has changed
+                newData.insert("isExpandable", entryCount > 0);
+            }
+
+            if (origCount != entryCount) {
+                // count has changed
+                newData.insert("count", entryCount);
+            }
 
+            if (!newData.isEmpty()) {
                 disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
-                m_model->setData(index, data);
+                m_model->setData(index, newData);
                 connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
             }
         });