From 45ff9bba9908b520e5bf40db17c64604d240e346 Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 16 Dec 2019 18:05:09 -0400 Subject: [PATCH] EventFile now downloadable --- TODO.md | 4 +++ src/qml/Chat/Timeline/EventFile.qml | 36 ++++++++++++++-------- src/qml/Chat/Timeline/EventImage.qml | 15 +++------ src/qml/Chat/Timeline/EventMediaLoader.qml | 8 ++--- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/TODO.md b/TODO.md index 1318a17d..fc644007 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,9 @@ # TODO +- strip file:// from copy path +- sentinel func to report path if already cached without having to click +- verify eventfile height + - Make dark bar extend down pane - Verify default size diff --git a/src/qml/Chat/Timeline/EventFile.qml b/src/qml/Chat/Timeline/EventFile.qml index 92fdba14..605741d6 100644 --- a/src/qml/Chat/Timeline/EventFile.qml +++ b/src/qml/Chat/Timeline/EventFile.qml @@ -1,32 +1,42 @@ import QtQuick 2.12 import QtQuick.Layouts 1.12 import "../../Base" +import "../../utils.js" as Utils HTile { + id: file width: Math.max( Math.min(eventContent.messageBodyWidth, theme.chat.message.fileMinWidth), Math.min(eventContent.messageBodyWidth, implicitWidth), ) - onLeftClicked: Qt.openUrlExternally(loader.mediaUrl) - onRightClicked: eventDelegate.openContextMenu() - - // TODO: have the right URL, not mxc - onHoveredChanged: - eventDelegate.hoveredMediaTypeUrl = - hovered ? [EventDelegate.Media.File, loader.mediaUrl] : [] - - - property EventMediaLoader loader - - title.text: loader.singleMediaInfo.media_title || qsTr("Untitled file") title.elide: Text.ElideMiddle - subtitle.text: CppUtils.formattedBytes(loader.singleMediaInfo.media_size) image: HIcon { svgName: "download" } + + onLeftClicked: download(Qt.openUrlExternally) + onRightClicked: eventDelegate.openContextMenu() + + onHoveredChanged: { + if (! hovered) { + eventDelegate.hoveredMediaTypeUrl = [] + return + } + + eventDelegate.hoveredMediaTypeUrl = [ + EventDelegate.Media.File, + loader.downloadedPath || loader.mediaUrl + ] + } + + + property EventMediaLoader loader + + readonly property bool cryptDict: loader.singleMediaInfo.media_crypt_dict + readonly property bool isEncrypted: ! Utils.isEmptyObject(cryptDict) } diff --git a/src/qml/Chat/Timeline/EventImage.qml b/src/qml/Chat/Timeline/EventImage.qml index aba9c4c2..74034011 100644 --- a/src/qml/Chat/Timeline/EventImage.qml +++ b/src/qml/Chat/Timeline/EventImage.qml @@ -88,17 +88,10 @@ HMxcImage { return } - if (image.isEncrypted && ! loader.downloaded) { - eventDelegate.hoveredMediaTypeUrl = - [EventDelegate.Media.Image, loader.mediaUrl] - - return - } - - getOpenUrl(url => { - eventDelegate.hoveredMediaTypeUrl = - [EventDelegate.Media.Image, url] - }) + eventDelegate.hoveredMediaTypeUrl = [ + EventDelegate.Media.Image, + loader.downloadedPath || loader.mediaUrl + ] } } diff --git a/src/qml/Chat/Timeline/EventMediaLoader.qml b/src/qml/Chat/Timeline/EventMediaLoader.qml index 41e98577..d54e6858 100644 --- a/src/qml/Chat/Timeline/EventMediaLoader.qml +++ b/src/qml/Chat/Timeline/EventMediaLoader.qml @@ -25,7 +25,7 @@ HLoader { property string showDate: "" property string showLocalEcho: "" - property bool downloaded: false + property string downloadedPath: "" readonly property var imageExtensions: [ "bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm", @@ -71,13 +71,13 @@ HLoader { function download(callback) { - if (! downloaded) print("Downloading " + loader.mediaUrl + " ...") + if (! downloadedPath) print("Downloading " + loader.mediaUrl + " ...") const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict] py.callCoro("media_cache.get_media", args, path => { - if (! downloaded) print("Done: " + path) - downloaded = true + if (! downloadedPath) print("Done: " + path) + downloadedPath = path callback(path) }) }