Have backup for 0 value in itemmetadata documentsize in materialised items model

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-11-01 16:53:19 +08:00
parent 5c3cd69252
commit a204f114d2
No known key found for this signature in database
GPG Key ID: C839200C384636B0

View 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 {};
}