2019-09-14 14:36:19 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import "../../Base"
|
|
|
|
import "../../utils.js" as Utils
|
|
|
|
|
|
|
|
HLoader {
|
|
|
|
id: loader
|
2019-09-15 07:48:53 +10:00
|
|
|
x: eventContent.spacing
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
|
|
|
|
property QtObject info
|
|
|
|
property url mediaUrl
|
|
|
|
|
|
|
|
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: {
|
|
|
|
let main_type = info.media_mime.split("/")[0].toLowerCase()
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
if (main_type === "image") return EventDelegate.Media.Image
|
|
|
|
if (main_type === "video") return EventDelegate.Media.Video
|
|
|
|
if (main_type === "audio") return EventDelegate.Media.Audio
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
if (info.event_type === "RoomMessageFile")
|
2019-09-15 08:33:32 +10:00
|
|
|
return EventDelegate.Media.File
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
let ext = Utils.urlExtension(mediaUrl)
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
readonly property url previewUrl: (
|
2019-09-15 08:33:32 +10:00
|
|
|
type === EventDelegate.Media.File ||
|
|
|
|
type === EventDelegate.Media.Image ?
|
2019-09-14 14:36:19 +10:00
|
|
|
info.thumbnail_url : ""
|
|
|
|
) || mediaUrl
|
|
|
|
|
|
|
|
|
|
|
|
onPreviewUrlChanged: {
|
2019-10-30 20:47:22 +11:00
|
|
|
print( mediaUrl)
|
2019-09-15 08:33:32 +10:00
|
|
|
if (type === EventDelegate.Media.Image) {
|
2019-09-14 14:36:19 +10:00
|
|
|
var file = "EventImage.qml"
|
2019-09-14 15:03:56 +10:00
|
|
|
var props = { source: previewUrl, fullSource: mediaUrl }
|
2019-09-15 07:48:53 +10:00
|
|
|
|
2019-10-28 03:10:07 +11:00
|
|
|
// } else if (type === EventDelegate.Media.File) {
|
|
|
|
// var file = "EventFile.qml"
|
|
|
|
// var props = {
|
|
|
|
// thumbnailUrl: previewUrl,
|
|
|
|
// fileUrl: mediaUrl,
|
|
|
|
// fileTitle: info.media_title,
|
|
|
|
// fileSize: info.media_size,
|
|
|
|
// }
|
|
|
|
|
|
|
|
// } else if (type === EventDelegate.Media.Video) {
|
|
|
|
// var file = "EventVideo.qml"
|
|
|
|
// var props = { source: mediaUrl }
|
|
|
|
|
|
|
|
// } else if (type === EventDelegate.Media.Audio) {
|
|
|
|
// var file = "EventAudio.qml"
|
|
|
|
// var props = { source: mediaUrl }
|
2019-09-18 13:23:47 +10:00
|
|
|
|
2019-09-15 07:48:53 +10:00
|
|
|
} else { return }
|
2019-09-14 14:36:19 +10:00
|
|
|
|
|
|
|
loader.setSource(file, props)
|
|
|
|
}
|
|
|
|
}
|