diff --git a/src/qml/Component/Timeline/FileDelegate.qml b/src/qml/Component/Timeline/FileDelegate.qml index a6f0b1c86..cd0139a9f 100644 --- a/src/qml/Component/Timeline/FileDelegate.qml +++ b/src/qml/Component/Timeline/FileDelegate.qml @@ -41,9 +41,26 @@ TimelineContainer { spacing: Kirigami.Units.largeSpacing states: [ + State { + name: "downloadedInstant" + when: progressInfo.completed && autoOpenFile + + PropertyChanges { + target: openButton + icon.name: "document-open" + onClicked: openSavedFile() + } + + PropertyChanges { + target: downloadButton + icon.name: "download" + QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "Download") + onClicked: saveFileAs() + } + }, State { name: "downloaded" - when: progressInfo.completed + when: progressInfo.completed && !autoOpenFile PropertyChanges { target: openButton @@ -52,11 +69,8 @@ TimelineContainer { 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() } }, @@ -76,7 +90,6 @@ TimelineContainer { 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) } @@ -87,7 +100,6 @@ TimelineContainer { PropertyChanges { target: downloadButton - onClicked: fileDelegate.saveFileAs() } } @@ -148,7 +160,11 @@ TimelineContainer { FileDialog { fileMode: FileDialog.SaveFile folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation) - onAccepted: currentRoom.downloadFile(eventId, file) + onAccepted: if (openSavedFile) { + UrlHelper.copyTo(progressInfo.localPath, file) + } else { + currentRoom.downloadFile(eventId, file); + } } } } diff --git a/src/urlhelper.cpp b/src/urlhelper.cpp index 1f0168bd0..0a7e3ce6a 100644 --- a/src/urlhelper.cpp +++ b/src/urlhelper.cpp @@ -3,6 +3,7 @@ #include "urlhelper.h" +#include #include #ifdef Q_OS_ANDROID @@ -22,3 +23,9 @@ void UrlHelper::openUrl(const QUrl &url) job->start(); #endif } + +void UrlHelper::copyTo(const QUrl &origin, const QUrl &destination) +{ + QFile originFile(origin.toLocalFile()); + originFile.copy(destination.toLocalFile()); +} diff --git a/src/urlhelper.h b/src/urlhelper.h index 226e6d308..30e818ec1 100644 --- a/src/urlhelper.h +++ b/src/urlhelper.h @@ -10,4 +10,5 @@ class UrlHelper : public QObject Q_OBJECT public: Q_INVOKABLE void openUrl(const QUrl &url); + Q_INVOKABLE void copyTo(const QUrl &origin, const QUrl &destination); };