Move EventImage.download() to EventMediaLoader

This commit is contained in:
miruka 2019-12-16 17:48:07 -04:00
parent 011b870d0b
commit 8215d127c8
2 changed files with 24 additions and 23 deletions

View File

@ -20,7 +20,6 @@ HMxcImage {
property EventMediaLoader loader property EventMediaLoader loader
property bool downloaded: false
readonly property bool isEncrypted: ! Utils.isEmptyObject(cryptDict) readonly property bool isEncrypted: ! Utils.isEmptyObject(cryptDict)
@ -56,21 +55,9 @@ HMxcImage {
) )
function download(callback) {
if (! downloaded) 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
callback(path)
})
}
function getOpenUrl(callback) { function getOpenUrl(callback) {
if (image.isEncrypted && loader.mediaUrl) { if (image.isEncrypted && loader.mediaUrl) {
download(callback) loader.download(callback)
return return
} }
@ -101,7 +88,7 @@ HMxcImage {
return return
} }
if (image.isEncrypted && ! downloaded) { if (image.isEncrypted && ! loader.downloaded) {
eventDelegate.hoveredMediaTypeUrl = eventDelegate.hoveredMediaTypeUrl =
[EventDelegate.Media.Image, loader.mediaUrl] [EventDelegate.Media.Image, loader.mediaUrl]

View File

@ -6,6 +6,18 @@ HLoader {
id: loader id: loader
x: eventContent.spacing x: eventContent.spacing
onTypeChanged: {
if (type === EventDelegate.Media.Image) {
var file = "EventImage.qml"
} else if (type === EventDelegate.Media.File) {
var file = "EventFile.qml"
} else { return }
loader.setSource(file, {loader})
}
property QtObject singleMediaInfo property QtObject singleMediaInfo
property string mediaUrl property string mediaUrl
@ -13,6 +25,8 @@ HLoader {
property string showDate: "" property string showDate: ""
property string showLocalEcho: "" property string showLocalEcho: ""
property bool downloaded: false
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",
"tiff", "webp", "svg", "tiff", "webp", "svg",
@ -56,15 +70,15 @@ HLoader {
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
onTypeChanged: { function download(callback) {
if (type === EventDelegate.Media.Image) { if (! downloaded) print("Downloading " + loader.mediaUrl + " ...")
var file = "EventImage.qml"
} else if (type === EventDelegate.Media.File) { const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict]
var file = "EventFile.qml"
} else { return } py.callCoro("media_cache.get_media", args, path => {
if (! downloaded) print("Done: " + path)
loader.setSource(file, {loader}) downloaded = true
callback(path)
})
} }
} }