EventFile now downloadable
This commit is contained in:
parent
8215d127c8
commit
45ff9bba99
4
TODO.md
4
TODO.md
|
@ -1,5 +1,9 @@
|
||||||
# TODO
|
# 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
|
- Make dark bar extend down pane
|
||||||
- Verify default size
|
- Verify default size
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,42 @@
|
||||||
import QtQuick 2.12
|
import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
import "../../Base"
|
import "../../Base"
|
||||||
|
import "../../utils.js" as Utils
|
||||||
|
|
||||||
HTile {
|
HTile {
|
||||||
|
id: file
|
||||||
width: Math.max(
|
width: Math.max(
|
||||||
Math.min(eventContent.messageBodyWidth,
|
Math.min(eventContent.messageBodyWidth,
|
||||||
theme.chat.message.fileMinWidth),
|
theme.chat.message.fileMinWidth),
|
||||||
Math.min(eventContent.messageBodyWidth, implicitWidth),
|
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.text: loader.singleMediaInfo.media_title || qsTr("Untitled file")
|
||||||
title.elide: Text.ElideMiddle
|
title.elide: Text.ElideMiddle
|
||||||
|
|
||||||
subtitle.text: CppUtils.formattedBytes(loader.singleMediaInfo.media_size)
|
subtitle.text: CppUtils.formattedBytes(loader.singleMediaInfo.media_size)
|
||||||
|
|
||||||
image: HIcon {
|
image: HIcon {
|
||||||
svgName: "download"
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image.isEncrypted && ! loader.downloaded) {
|
eventDelegate.hoveredMediaTypeUrl = [
|
||||||
eventDelegate.hoveredMediaTypeUrl =
|
EventDelegate.Media.Image,
|
||||||
[EventDelegate.Media.Image, loader.mediaUrl]
|
loader.downloadedPath || loader.mediaUrl
|
||||||
|
]
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
getOpenUrl(url => {
|
|
||||||
eventDelegate.hoveredMediaTypeUrl =
|
|
||||||
[EventDelegate.Media.Image, url]
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ HLoader {
|
||||||
property string showDate: ""
|
property string showDate: ""
|
||||||
property string showLocalEcho: ""
|
property string showLocalEcho: ""
|
||||||
|
|
||||||
property bool downloaded: false
|
property string downloadedPath: ""
|
||||||
|
|
||||||
readonly property var imageExtensions: [
|
readonly property var imageExtensions: [
|
||||||
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
||||||
|
@ -71,13 +71,13 @@ HLoader {
|
||||||
|
|
||||||
|
|
||||||
function download(callback) {
|
function download(callback) {
|
||||||
if (! downloaded) print("Downloading " + loader.mediaUrl + " ...")
|
if (! downloadedPath) print("Downloading " + loader.mediaUrl + " ...")
|
||||||
|
|
||||||
const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict]
|
const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict]
|
||||||
|
|
||||||
py.callCoro("media_cache.get_media", args, path => {
|
py.callCoro("media_cache.get_media", args, path => {
|
||||||
if (! downloaded) print("Done: " + path)
|
if (! downloadedPath) print("Done: " + path)
|
||||||
downloaded = true
|
downloadedPath = path
|
||||||
callback(path)
|
callback(path)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user