2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-09-14 00:36:19 -04:00
|
|
|
import QtQuick 2.12
|
2019-12-18 04:53:08 -04:00
|
|
|
import "../../../Base"
|
2019-09-14 00:36:19 -04:00
|
|
|
|
|
|
|
HLoader {
|
|
|
|
id: loader
|
2020-05-10 18:30:20 -04:00
|
|
|
visible: Boolean(item)
|
2019-09-14 17:48:53 -04:00
|
|
|
x: eventContent.spacing
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
onTypeChanged: {
|
|
|
|
if (type === EventDelegate.Media.Image) {
|
|
|
|
var file = "EventImage.qml"
|
|
|
|
|
2019-12-16 18:19:06 -04:00
|
|
|
} else if (type !== EventDelegate.Media.Page) {
|
2019-12-16 17:48:07 -04:00
|
|
|
var file = "EventFile.qml"
|
|
|
|
|
|
|
|
} else { return }
|
|
|
|
|
|
|
|
loader.setSource(file, {loader})
|
|
|
|
}
|
|
|
|
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-10-30 06:47:59 -04:00
|
|
|
property QtObject singleMediaInfo
|
2019-11-04 07:00:28 -04:00
|
|
|
property string mediaUrl
|
2019-10-30 09:21:58 -04:00
|
|
|
property string showSender: ""
|
|
|
|
property string showDate: ""
|
2019-11-06 09:48:27 -04:00
|
|
|
property string showLocalEcho: ""
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 18:05:09 -04:00
|
|
|
property string downloadedPath: ""
|
2019-12-16 17:48:07 -04:00
|
|
|
|
2020-03-09 11:08:07 -04:00
|
|
|
readonly property string title:
|
|
|
|
singleMediaInfo.media_title || utils.urlFileName(mediaUrl)
|
|
|
|
|
2020-03-09 12:06:58 -04:00
|
|
|
readonly property string thumbnailTitle:
|
|
|
|
singleMediaInfo.media_title.replace(
|
|
|
|
/\.[^\.]+$/,
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/jpeg" ? ".jpg" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/png" ? ".png" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/gif" ? ".gif" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/tiff" ? ".tiff" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/svg+xml" ? ".svg" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/webp" ? ".webp" :
|
|
|
|
singleMediaInfo.thumbnail_mime === "image/bmp" ? ".bmp" :
|
|
|
|
".thumbnail"
|
|
|
|
) || utils.urlFileName(mediaUrl)
|
|
|
|
|
2019-09-14 00:36:19 -04:00
|
|
|
readonly property var imageExtensions: [
|
|
|
|
"bmp", "gif", "jpg", "jpeg", "png", "pbm", "pgm", "ppm", "xbm", "xpm",
|
|
|
|
"tiff", "webp", "svg",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var videoExtensions: [
|
|
|
|
"3gp", "avi", "flv", "m4p", "m4v", "mkv", "mov", "mp4",
|
|
|
|
"mpeg", "mpg", "ogv", "qt", "vob", "webm", "wmv", "yuv",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var audioExtensions: [
|
|
|
|
"pcm", "wav", "raw", "aiff", "flac", "m4a", "tta", "aac", "mp3",
|
|
|
|
"ogg", "oga", "opus",
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property int type: {
|
2019-12-09 11:35:50 -04:00
|
|
|
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
2019-11-27 06:18:06 -04:00
|
|
|
return EventDelegate.Media.Image
|
|
|
|
|
2020-03-08 04:46:20 -04:00
|
|
|
const mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-11-11 05:26:32 -04:00
|
|
|
if (mainType === "image") return EventDelegate.Media.Image
|
|
|
|
if (mainType === "video") return EventDelegate.Media.Video
|
|
|
|
if (mainType === "audio") return EventDelegate.Media.Audio
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2020-03-08 04:46:20 -04:00
|
|
|
const fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
2019-11-11 05:26:32 -04:00
|
|
|
|
|
|
|
if (fileEvents.includes(singleMediaInfo.event_type))
|
2019-09-14 18:33:32 -04:00
|
|
|
return EventDelegate.Media.File
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-10-30 06:47:59 -04:00
|
|
|
// If this is a preview for a link in a normal message
|
2020-03-09 11:00:48 -04:00
|
|
|
const ext = utils.urlExtension(mediaUrl).toLowerCase()
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
|
|
|
|
if (videoExtensions.includes(ext)) return EventDelegate.Media.Video
|
|
|
|
if (audioExtensions.includes(ext)) return EventDelegate.Media.Audio
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-09-14 18:33:32 -04:00
|
|
|
return EventDelegate.Media.Page
|
2019-09-14 00:36:19 -04:00
|
|
|
}
|
|
|
|
|
2019-11-04 07:00:28 -04:00
|
|
|
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
|
2019-09-14 00:36:19 -04:00
|
|
|
|
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
function download(callback) {
|
2019-12-16 18:19:06 -04:00
|
|
|
if (! loader.mediaUrl.startsWith("mxc://")) {
|
|
|
|
downloadedPath = loader.mediaUrl
|
|
|
|
callback(loader.mediaUrl)
|
2019-12-16 18:22:25 -04:00
|
|
|
return
|
2019-12-16 18:19:06 -04:00
|
|
|
}
|
|
|
|
|
2019-12-16 18:05:09 -04:00
|
|
|
if (! downloadedPath) print("Downloading " + loader.mediaUrl + " ...")
|
2019-09-17 23:23:47 -04:00
|
|
|
|
2020-02-12 13:04:46 -04:00
|
|
|
const args = [
|
|
|
|
loader.mediaUrl,
|
2020-03-09 11:46:08 -04:00
|
|
|
loader.title,
|
2020-02-12 13:04:46 -04:00
|
|
|
JSON.parse(loader.singleMediaInfo.media_crypt_dict)
|
|
|
|
]
|
2019-09-14 00:36:19 -04:00
|
|
|
|
2019-12-16 17:48:07 -04:00
|
|
|
py.callCoro("media_cache.get_media", args, path => {
|
2019-12-16 18:05:09 -04:00
|
|
|
if (! downloadedPath) print("Done: " + path)
|
|
|
|
downloadedPath = path
|
2019-12-16 17:48:07 -04:00
|
|
|
callback(path)
|
|
|
|
})
|
2019-09-14 00:36:19 -04:00
|
|
|
}
|
|
|
|
}
|