EventFile now downloadable
This commit is contained in:
parent
8215d127c8
commit
45ff9bba99
4
TODO.md
4
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
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user