Have backup for 0 value in itemmetadata documentsize in materialised items model
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 1 Nov 2023 08:53:19 +0000 (16:53 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 19 Feb 2024 14:45:17 +0000 (22:45 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp

index a4c0729910be49a65d35ce30256439c51ff8b9ba..b8b4fa8f602c6c363e0b58db059827f25d8d8d02 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "fileprovidermaterialiseditemsmodel.h"
 
+#include <QFileInfo>
+
 namespace OCC {
 
 namespace Mac {
@@ -101,7 +103,19 @@ QVariant FileProviderMaterialisedItemsModel::data(const QModelIndex &index, int
     case FileTypeStringRole:
         return item.fileTypeString();
     case FileSizeStringRole:
-        return _locale.formattedDataSize(item.documentSize());
+    {
+        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 {};
 }