Always perform fallback document size discovery in fileprovideritemmetadata
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 3 Jan 2024 13:21:10 +0000 (21:21 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Feb 2024 14:45:19 +0000 (22:45 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileprovideritemmetadata_mac.mm
src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp

index e356a0245895c6be5f4f14ea8a2e7df60ffeacb3..d8e64abb6883221ffbfedc909868f32430d97603 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "fileprovideritemmetadata.h"
 
+#include <QFileInfo>
 #include <QLoggingCategory>
 
 #import <Foundation/Foundation.h>
@@ -94,6 +95,15 @@ FileProviderItemMetadata FileProviderItemMetadata::fromNSFileProviderItem(const
     metadata._userVisiblePath = metadata.getUserVisiblePath();
     metadata._fileTypeString = QString::fromNSString(bridgedNsFileProviderItem.contentType.localizedDescription);
 
+    if (metadata._documentSize == 0) {
+        // If the document size is 0, we can try to get the size of the file
+        // directly from its path. These are all materialised files anyway
+        // so the size will be properly represented
+        const auto path = metadata.userVisiblePath();
+        const auto fileInfo = QFileInfo(path);
+        metadata._documentSize = fileInfo.size();
+    }
+
     return metadata;
 }
 
index b8b4fa8f602c6c363e0b58db059827f25d8d8d02..2e18666c39b67a76fc30c5dbb41d686ef294f6b9 100644 (file)
@@ -103,19 +103,7 @@ QVariant FileProviderMaterialisedItemsModel::data(const QModelIndex &index, int
     case FileTypeStringRole:
         return item.fileTypeString();
     case FileSizeStringRole:
-    {
-        const auto docSize = item.documentSize();
-        if (docSize > 0) {
-            return _locale.formattedDataSize(item.documentSize());
-        }
-
-        // If the document size is 0, we can try to get the size of the file
-        // directly from its path. These are all materialised files anyway
-        // so the size will be properly represented
-        const auto path = item.userVisiblePath();
-        const auto fileInfo = QFileInfo(path);
-        return _locale.formattedDataSize(fileInfo.size());
-    }
+        return _locale.formattedDataSize(item.documentSize());
     }
     return {};
 }