Skip to content

Commit

Permalink
Allow for http(s) images and videos to display in attachment widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Mar 6, 2024
1 parent 56b5baf commit 7dec619
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 9 additions & 3 deletions src/qml/editorwidgets/+Qt5/ExternalResource.qml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ EditorWidgetBase {
onCurrentValueChanged: {
if (currentValue != undefined && currentValue !== '')
{
const isHttp = value.startsWith('http://') || value.startsWith('https://');
var fullValue = isHttp ? value : prefixToRelativePath + value
isImage = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("image/")
isAudio = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("audio/")
isVideo = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("video/")

image.visible = isImage
geoTagBadge.visible = isImage
player.visible = isVideo
Expand All @@ -89,11 +95,11 @@ EditorWidgetBase {
image.hasImage = true
image.opacity = 1
image.anchors.topMargin = 0
image.source = 'file://' + prefixToRelativePath + value
geoTagBadge.hasGeoTag = ExifTools.hasGeoTag(prefixToRelativePath + value)
image.source = (!isHttp ? 'file://' : '') + fullValue
geoTagBadge.hasGeoTag = ExifTools.hasGeoTag(fullValue)
} else if (isAudio || isVideo) {
mediaFrame.height = 48
player.source = 'file://' + prefixToRelativePath + value
player.source = (!isHttp ? 'file://' : '') + fullValue
}
} else {
image.source = ''
Expand Down
16 changes: 9 additions & 7 deletions src/qml/editorwidgets/+Qt6/ExternalResource.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ EditorWidgetBase {
//to not break any binding of image.source
property var currentValue: value
onCurrentValueChanged: {
isImage = !config.UseLink && FileUtils.mimeTypeName(prefixToRelativePath + value ).startsWith("image/")
isAudio = !config.UseLink && FileUtils.mimeTypeName(prefixToRelativePath + value).startsWith("audio/")
isVideo = !config.UseLink && FileUtils.mimeTypeName(prefixToRelativePath + value).startsWith("video/")

if (currentValue != undefined && currentValue !== '') {
const isHttp = value.startsWith('http://') || value.startsWith('https://');
var fullValue = isHttp ? value : prefixToRelativePath + value
isImage = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("image/")
isAudio = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("audio/")
isVideo = !config.UseLink && FileUtils.mimeTypeName(fullValue).startsWith("video/")

image.visible = isImage
geoTagBadge.visible = isImage
if (isImage) {
Expand All @@ -90,11 +92,11 @@ EditorWidgetBase {
image.hasImage = true
image.opacity = 1
image.anchors.topMargin = 0
image.source = 'file://' + prefixToRelativePath + value
geoTagBadge.hasGeoTag = ExifTools.hasGeoTag(prefixToRelativePath + value)
image.source = (!isHttp ? 'file://' : '') + fullValue
geoTagBadge.hasGeoTag = ExifTools.hasGeoTag(fullValue)
} else if (isAudio || isVideo) {
player.firstFrameDrawn = false
player.sourceUrl = 'file://' + prefixToRelativePath + value
player.sourceUrl = (!isHttp ? 'file://' : '') + fullValue
}
} else {
image.source = ''
Expand Down

1 comment on commit 7dec619

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.