]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodelrolesupdater.cpp
"Group by" exists, group sorting rule is separate from sorting rule. Very WIP and...
[dolphin.git] / src / kitemviews / kfileitemmodelrolesupdater.cpp
index 06500b45dd168f9a2ddee88a5af07a3fe626f807..0ff431ac99a5366120d6fafb568ee52d12209438 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <KConfig>
 #include <KConfigGroup>
+#include <KIO/ListJob>
 #include <KIO/PreviewJob>
 #include <KIconLoader>
 #include <KJobWidgets>
@@ -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);
@@ -1306,8 +1307,6 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite
             url = QUrl::fromLocalFile(item.localPath());
         }
 
-        data.insert("isExpandable", false);
-        data.insert("count", 0);
         data.insert("size", -2); // invalid size, -1 means size unknown
 
         disconnect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
@@ -1315,7 +1314,11 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite
         connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged);
 
         auto listJob = KIO::listDir(url, KIO::HideProgressInfo);
-        QObject::connect(listJob, &KIO::ListJob::entries, this, [this, index](const KJob * /*job*/, const KIO::UDSEntryList &list) {
+        QObject::connect(listJob, &KIO::ListJob::entries, this, [this, item](const KJob * /*job*/, const KIO::UDSEntryList &list) {
+            int index = m_model->index(item);
+            if (index < 0) {
+                return;
+            }
             auto data = m_model->data(index);
             int origCount = data.value("count").toInt();
             int entryCount = origCount;
@@ -1335,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);
             }
         });