Display file sizes as nicely formatted string in file provider file delegate

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-11-01 16:48:32 +08:00
parent 643d30a3d5
commit f22bf9e527
No known key found for this signature in database
GPG key ID: C839200C384636B0
3 changed files with 13 additions and 7 deletions

View file

@ -98,8 +98,10 @@ QVariant FileProviderMaterialisedItemsModel::data(const QModelIndex &index, int
return item.sharedByCurrentUser();
case UserVisiblePathRole:
return item.userVisiblePath();
case FileTypeRole:
case FileTypeStringRole:
return item.fileTypeString();
case FileSizeStringRole:
return _locale.formattedDataSize(item.documentSize());
}
return {};
}
@ -138,7 +140,8 @@ QHash<int, QByteArray> FileProviderMaterialisedItemsModel::roleNames() const
{ SharedRole, "shared" },
{ SharedByCurrentUserRole, "sharedByCurrentUser" },
{ UserVisiblePathRole, "userVisiblePath" },
{ FileTypeRole, "fileType" },
{ FileTypeStringRole, "fileTypeString" },
{ FileSizeStringRole, "fileSizeString" },
});
return roleNames;
}

View file

@ -15,6 +15,7 @@
#pragma once
#include <QAbstractListModel>
#include <QLocale>
#include "gui/macOS/fileprovideritemmetadata.h"
@ -60,7 +61,8 @@ public:
SharedRole,
SharedByCurrentUserRole,
UserVisiblePathRole,
FileTypeRole,
FileTypeStringRole,
FileSizeStringRole,
};
Q_ENUM(Roles)
@ -80,6 +82,7 @@ public slots:
private:
QVector<FileProviderItemMetadata> _items;
QLocale _locale;
};
} // namespace Mac

View file

@ -32,9 +32,9 @@ Item {
required property string domainIdentifier
required property string fileName
required property string userVisiblePath
required property string fileType
required property string fileTypeString
required property size documentSize
required property string fileSizeString
RowLayout {
id: internalLayout
@ -73,12 +73,12 @@ Item {
EnforcedPlainTextLabel {
id: fileSizeLabel
text: root.documentSize
text: root.fileSizeString
}
EnforcedPlainTextLabel {
id: fileTypeLabel
text: root.fileType
text: root.fileTypeString
color: Style.ncSecondaryTextColor
}
}