Skip to content

Commit

Permalink
Have backup for 0 value in itemmetadata documentsize in materialised …
Browse files Browse the repository at this point in the history
…items model

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Nov 1, 2023
1 parent 9719446 commit 7a83ad3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/gui/macOS/fileprovidermaterialiseditemsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "fileprovidermaterialiseditemsmodel.h"

#include <QFileInfo>

namespace OCC {

namespace Mac {
Expand Down Expand Up @@ -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 {};
}
Expand Down

0 comments on commit 7a83ad3

Please sign in to comment.