Always perform fallback document size discovery in fileprovideritemmetadata

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-01-03 21:21:10 +08:00
parent 3b179cc1a1
commit 1d01f67790
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 11 additions and 13 deletions

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

View file

@ -103,20 +103,8 @@ 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 {};
}