Move EventImage.download() to EventMediaLoader
This commit is contained in:
parent
011b870d0b
commit
8215d127c8
|
@ -20,7 +20,6 @@ HMxcImage {
|
|||
|
||||
|
||||
property EventMediaLoader loader
|
||||
property bool downloaded: false
|
||||
|
||||
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) {
|
||||
if (image.isEncrypted && loader.mediaUrl) {
|
||||
download(callback)
|
||||
loader.download(callback)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -101,7 +88,7 @@ HMxcImage {
|
|||
return
|
||||
}
|
||||
|
||||
if (image.isEncrypted && ! downloaded) {
|
||||
if (image.isEncrypted && ! loader.downloaded) {
|
||||
eventDelegate.hoveredMediaTypeUrl =
|
||||
[EventDelegate.Media.Image, loader.mediaUrl]
|
||||
|
||||
|
|
|
@ -6,6 +6,18 @@ HLoader {
|
|||
id: loader
|
||||
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 string mediaUrl
|
||||
|
@ -13,6 +25,8 @@ HLoader {
|
|||
property string showDate: ""
|
||||
property string showLocalEcho: ""
|
||||
|
||||
property bool downloaded: false
|
||||
|
||||
readonly property var imageExtensions: [
|
||||
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
||||
"tiff", "webp", "svg",
|
||||
|
@ -56,15 +70,15 @@ HLoader {
|
|||
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
|
||||
|
||||
|
||||
onTypeChanged: {
|
||||
if (type === EventDelegate.Media.Image) {
|
||||
var file = "EventImage.qml"
|
||||
function download(callback) {
|
||||
if (! downloaded) print("Downloading " + loader.mediaUrl + " ...")
|
||||
|
||||
} else if (type === EventDelegate.Media.File) {
|
||||
var file = "EventFile.qml"
|
||||
const args = [loader.mediaUrl, loader.singleMediaInfo.media_crypt_dict]
|
||||
|
||||
} else { return }
|
||||
|
||||
loader.setSource(file, {loader})
|
||||
py.callCoro("media_cache.get_media", args, path => {
|
||||
if (! downloaded) print("Done: " + path)
|
||||
downloaded = true
|
||||
callback(path)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user