2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-11-04 04:48:12 +11:00
|
|
|
import QtQuick 2.12
|
|
|
|
|
|
|
|
HImage {
|
|
|
|
id: image
|
2019-12-16 04:02:40 +11:00
|
|
|
inderterminateProgressBar: isMxc
|
2019-11-04 04:48:12 +11:00
|
|
|
source: sourceOverride || (show ? cachedPath : "")
|
|
|
|
onWidthChanged: Qt.callLater(update)
|
|
|
|
onHeightChanged: Qt.callLater(update)
|
|
|
|
onVisibleChanged: Qt.callLater(update)
|
2019-11-16 23:06:56 +11:00
|
|
|
onMxcChanged: Qt.callLater(update)
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
property string mxc
|
|
|
|
property string sourceOverride: ""
|
2019-11-05 01:29:41 +11:00
|
|
|
property bool thumbnail: true
|
2019-11-05 05:37:25 +11:00
|
|
|
property var cryptDict: ({})
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
property bool show: false
|
|
|
|
property string cachedPath: ""
|
2019-11-07 06:47:18 +11:00
|
|
|
readonly property bool isMxc: mxc.startsWith("mxc://")
|
2019-11-04 04:48:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
function update() {
|
2020-03-08 19:27:51 +11:00
|
|
|
if (! py) return // component was destroyed
|
|
|
|
|
2019-11-04 04:48:12 +11:00
|
|
|
let w = sourceSize.width || width
|
|
|
|
let h = sourceSize.height || height
|
|
|
|
|
|
|
|
if (! image.mxc || w < 1 || h < 1 ) {
|
|
|
|
show = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-07 06:47:18 +11:00
|
|
|
if (! isMxc) {
|
2019-12-10 02:35:50 +11:00
|
|
|
if (source !== mxc) source = mxc
|
2019-11-06 00:19:48 +11:00
|
|
|
show = image.visible
|
2019-11-04 22:00:28 +11:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-05 01:29:41 +11:00
|
|
|
let method = image.thumbnail ? "get_thumbnail" : "get_media"
|
2019-11-05 05:37:25 +11:00
|
|
|
let args = image.thumbnail ?
|
|
|
|
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
2019-11-05 01:29:41 +11:00
|
|
|
|
2019-11-13 00:10:00 +11:00
|
|
|
py.callCoro("media_cache." + method, args, path => {
|
2019-11-04 22:00:28 +11:00
|
|
|
if (! image) return
|
2019-12-10 02:35:50 +11:00
|
|
|
if (image.cachedPath !== path) image.cachedPath = path
|
2019-11-13 00:10:00 +11:00
|
|
|
|
|
|
|
image.broken = false
|
|
|
|
image.show = image.visible
|
|
|
|
|
|
|
|
}, () => {
|
|
|
|
image.broken = true
|
|
|
|
},
|
2019-11-04 22:00:28 +11:00
|
|
|
)
|
2019-11-04 04:48:12 +11:00
|
|
|
}
|
|
|
|
}
|