Improve the file delegate

- cleaner code
- supports stopping downloads
- utilises the mimetype in order to display an icon
- better size formatting
- tooltips
This commit is contained in:
Jan Blackquill
2021-08-19 13:23:52 -04:00
parent d7ce0b7468
commit 4955b1f7a0
4 changed files with 85 additions and 30 deletions

View File

@@ -610,7 +610,7 @@ void Controller::openOrCreateDirectChat(NeoChatUser *user)
QString Controller::formatByteSize(double size, int precision) const
{
return KFormat().formatByteSize(size, precision);
return QLocale().formattedDataSize(size, precision);
}
QString Controller::formatDuration(quint64 msecs, KFormat::DurationFormatOptions options) const

View File

@@ -37,6 +37,7 @@ QHash<int, QByteArray> MessageEventModel::roleNames() const
roles[HighlightRole] = "isHighlighted";
roles[SpecialMarksRole] = "marks";
roles[LongOperationRole] = "progressInfo";
roles[FileMimetypeIcon] = "fileMimetypeIcon";
roles[AnnotationRole] = "annotation";
roles[EventResolvedTypeRole] = "eventResolvedType";
roles[ReplyRole] = "reply";
@@ -536,6 +537,15 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return m_currentRoom->isEventHighlighted(&evt);
}
if (role == FileMimetypeIcon) {
auto e = eventCast<const RoomMessageEvent>(&evt);
if (!e || !e->hasFileContent()) {
return QVariant();
}
return e->content()->fileInfo()->mimeType.iconName();
}
if (role == SpecialMarksRole) {
if (isPending) {
return pendingIt->deliveryStatus();

View File

@@ -30,6 +30,8 @@ public:
UserMarkerRole,
FormattedBodyRole,
FileMimetypeIcon,
ReplyRole,
ShowAuthorRole,