2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-09-14 14:36:19 +10:00
|
|
|
import QtQuick 2.12
|
2019-12-18 19:53:08 +11:00
|
|
|
import "../../../Base"
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
HLoader {
|
|
|
|
id: loader
|
2020-05-11 08:30:20 +10:00
|
|
|
visible: Boolean(item)
|
2019-09-15 07:48:53 +10:00
|
|
|
x: eventContent.spacing
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-12-17 08:48:07 +11:00
|
|
|
onTypeChanged: {
|
|
|
|
if (type === EventDelegate.Media.Image) {
|
|
|
|
var file = "EventImage.qml"
|
|
|
|
|
2019-12-17 09:19:06 +11:00
|
|
|
} else if (type !== EventDelegate.Media.Page) {
|
2019-12-17 08:48:07 +11:00
|
|
|
var file = "EventFile.qml"
|
|
|
|
|
|
|
|
} else { return }
|
|
|
|
|
|
|
|
loader.setSource(file, {loader})
|
|
|
|
}
|
|
|
|
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-10-30 21:47:59 +11:00
|
|
|
property QtObject singleMediaInfo
|
2019-11-04 22:00:28 +11:00
|
|
|
property string mediaUrl
|
2019-10-31 00:21:58 +11:00
|
|
|
property string showSender: ""
|
|
|
|
property string showDate: ""
|
2019-11-07 00:48:27 +11:00
|
|
|
property string showLocalEcho: ""
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-12-17 09:05:09 +11:00
|
|
|
property string downloadedPath: ""
|
2019-12-17 08:48:07 +11:00
|
|
|
|
2020-03-10 02:08:07 +11:00
|
|
|
readonly property string title:
|
|
|
|
singleMediaInfo.media_title || utils.urlFileName(mediaUrl)
|
|
|
|
|
2020-03-10 03:06:58 +11: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 14:36:19 +10: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-10 02:35:50 +11:00
|
|
|
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
2019-11-27 21:18:06 +11:00
|
|
|
return EventDelegate.Media.Image
|
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
const mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-11-11 20:26:32 +11: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 14:36:19 +10:00
|
|
|
|
2020-03-08 19:46:20 +11:00
|
|
|
const fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
2019-11-11 20:26:32 +11:00
|
|
|
|
|
|
|
if (fileEvents.includes(singleMediaInfo.event_type))
|
2019-09-15 08:33:32 +10:00
|
|
|
return EventDelegate.Media.File
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-10-30 21:47:59 +11:00
|
|
|
// If this is a preview for a link in a normal message
|
2020-03-10 02:00:48 +11:00
|
|
|
const ext = utils.urlExtension(mediaUrl).toLowerCase()
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-09-15 08:33:32 +10: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 14:36:19 +10:00
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
return EventDelegate.Media.Page
|
2019-09-14 14:36:19 +10:00
|
|
|
}
|
|
|
|
|
2019-11-04 22:00:28 +11:00
|
|
|
readonly property string thumbnailMxc: singleMediaInfo.thumbnail_url
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
|
2019-12-17 08:48:07 +11:00
|
|
|
function download(callback) {
|
2019-12-17 09:19:06 +11:00
|
|
|
if (! loader.mediaUrl.startsWith("mxc://")) {
|
|
|
|
downloadedPath = loader.mediaUrl
|
|
|
|
callback(loader.mediaUrl)
|
2019-12-17 09:22:25 +11:00
|
|
|
return
|
2019-12-17 09:19:06 +11:00
|
|
|
}
|
|
|
|
|
2019-12-17 09:05:09 +11:00
|
|
|
if (! downloadedPath) print("Downloading " + loader.mediaUrl + " ...")
|
2019-09-18 13:23:47 +10:00
|
|
|
|
2020-02-13 04:04:46 +11:00
|
|
|
const args = [
|
|
|
|
loader.mediaUrl,
|
2020-03-10 02:46:08 +11:00
|
|
|
loader.title,
|
2020-02-13 04:04:46 +11:00
|
|
|
JSON.parse(loader.singleMediaInfo.media_crypt_dict)
|
|
|
|
]
|
2019-09-14 14:36:19 +10:00
|
|
|
|
2019-12-17 08:48:07 +11:00
|
|
|
py.callCoro("media_cache.get_media", args, path => {
|
2019-12-17 09:05:09 +11:00
|
|
|
if (! downloadedPath) print("Done: " + path)
|
|
|
|
downloadedPath = path
|
2019-12-17 08:48:07 +11:00
|
|
|
callback(path)
|
|
|
|
})
|
2019-09-14 14:36:19 +10:00
|
|
|
}
|
|
|
|
}
|