diff --git a/imports/NeoChat/Component/Timeline/FileDelegate.qml b/imports/NeoChat/Component/Timeline/FileDelegate.qml index 23d8f818a..bcd9aa71e 100644 --- a/imports/NeoChat/Component/Timeline/FileDelegate.qml +++ b/imports/NeoChat/Component/Timeline/FileDelegate.qml @@ -2,7 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only import QtQuick 2.15 -import QtQuick.Controls 2.15 +import QtQuick.Controls 2.15 as QQC2 import QtQuick.Layouts 1.15 import QtGraphicalEffects 1.15 import Qt.labs.platform 1.1 @@ -23,29 +23,82 @@ RowLayout { spacing: Kirigami.Units.largeSpacing - onDownloadedChanged: if (downloaded && openOnFinished) { - openSavedFile(); - } + states: [ + State { + name: "downloaded" + when: progressInfo.completed - ToolButton { - icon.name: progressInfo.completed ? "document-open" : "document-save" - onClicked: progressInfo.completed ? openSavedFile() : saveFileAs() - } + PropertyChanges { + target: downloadButton + icon.name: "document-open" + + QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File") + + onClicked: openSavedFile() + } + }, + State { + name: "downloading" + when: progressInfo.active + + PropertyChanges { + target: sizeLabel + text: i18nc("file download progress", "%1 / %2", Controller.formatByteSize(progressInfo.progress), Controller.formatByteSize(progressInfo.total)) + } + PropertyChanges { + target: downloadButton + icon.name: "media-playback-stop" + + QQC2.ToolTip.text: i18nc("tooltip for a button on a message; stops downloading the message's file", "Stop Download") + onClicked: currentRoom.cancelFileTransfer(eventId) + } + }, + State { + name: "raw" + when: true + + PropertyChanges { + target: downloadButton + + onClicked: root.saveFileAs() + } + } + ] + + Kirigami.Icon { + id: ikon + source: model.fileMimetypeIcon + fallback: "unknown" + } ColumnLayout { - Kirigami.Heading { - Layout.fillWidth: true - level: 4 - text: model.display - wrapMode: Label.Wrap - } + Layout.alignment: Qt.AlignVCenter + Layout.fillWidth: true + + spacing: 0 + + QQC2.Label { + text: model.display + wrapMode: Text.Wrap - Label { Layout.fillWidth: true - text: !progressInfo.completed && progressInfo.active ? (Controller.formatByteSize(progressInfo.progress) + "/" + Controller.formatByteSize(progressInfo.total)) : Controller.formatByteSize(content.info ? content.info.size : 0) - color: Kirigami.Theme.disabledTextColor - wrapMode: Label.Wrap } + QQC2.Label { + id: sizeLabel + + text: Controller.formatByteSize(content.info ? content.info.size : 0) + opacity: 0.7 + + Layout.fillWidth: true + } + } + + QQC2.Button { + id: downloadButton + icon.name: "download" + + QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "Download") + QQC2.ToolTip.visible: hovered } Component { @@ -61,21 +114,11 @@ RowLayout { } function saveFileAs() { - var dialog = fileDialog.createObject(ApplicationWindow.overlay) + var dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay) dialog.open() dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId) } - function downloadAndOpen() { - if (downloaded) { - openSavedFile(); - } else { - openOnFinished = true; - currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" - + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)); - } - } - function openSavedFile() { if (Qt.openUrlExternally(progressInfo.localPath)) return; if (Qt.openUrlExternally(progressInfo.localDir)) return; diff --git a/src/controller.cpp b/src/controller.cpp index 724fbc1c2..4c1631176 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -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 diff --git a/src/messageeventmodel.cpp b/src/messageeventmodel.cpp index 8bbecc730..6aafe71c5 100644 --- a/src/messageeventmodel.cpp +++ b/src/messageeventmodel.cpp @@ -37,6 +37,7 @@ QHash 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(&evt); + if (!e || !e->hasFileContent()) { + return QVariant(); + } + + return e->content()->fileInfo()->mimeType.iconName(); + } + if (role == SpecialMarksRole) { if (isPending) { return pendingIt->deliveryStatus(); diff --git a/src/messageeventmodel.h b/src/messageeventmodel.h index 9f74d5bc9..59a00271d 100644 --- a/src/messageeventmodel.h +++ b/src/messageeventmodel.h @@ -30,6 +30,8 @@ public: UserMarkerRole, FormattedBodyRole, + FileMimetypeIcon, + ReplyRole, ShowAuthorRole,