From 7a83ad338ae43a30dc74075ee3d40182aabdeb8c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 1 Nov 2023 16:53:19 +0800 Subject: [PATCH] Have backup for 0 value in itemmetadata documentsize in materialised items model Signed-off-by: Claudio Cambra --- .../macOS/fileprovidermaterialiseditemsmodel.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp b/src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp index a4c0729910be..b8b4fa8f602c 100644 --- a/src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp +++ b/src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp @@ -14,6 +14,8 @@ #include "fileprovidermaterialiseditemsmodel.h" +#include + 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 {}; }