Fix variable lookup in the timeline delegates

This fix issues with downloading and interacting with files
This commit is contained in:
Carl Schwan
2021-12-26 21:48:37 +01:00
parent 8a70e240e4
commit aa9dcc87cb
3 changed files with 63 additions and 65 deletions

View File

@@ -21,9 +21,20 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
readonly property bool downloaded: progressInfo && progressInfo.completed
function saveFileAs() {
const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
dialog.open()
dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId)
}
function openSavedFile() {
if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return;
}
innerObject: RowLayout { innerObject: RowLayout {
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumWidth: fileDelegate.bubbleMaxWidth Layout.maximumWidth: fileDelegate.bubbleMaxWidth
@@ -129,16 +140,5 @@ TimelineContainer {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent) onLongPressed: openFileContext(model, parent)
} }
function saveFileAs() {
var dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
dialog.open()
dialog.currentFile = dialog.folder + "/" + currentRoom.fileNameToDownload(eventId)
}
function openSavedFile() {
if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return;
}
} }
} }

View File

@@ -21,19 +21,20 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
property var content: model.content
readonly property bool isAnimated: contentType === "image/gif"
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
readonly property bool isThumbnail: !(content.info.thumbnail_info == null || content.thumbnailMediaId == null)
// readonly property var info: isThumbnail ? content.info.thumbnail_info : content.info
readonly property var info: content.info
readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId
innerObject: Image { innerObject: Image {
id: img id: img
property var content: model.content
readonly property bool isAnimated: contentType === "image/gif"
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
readonly property bool isThumbnail: !(content.info.thumbnail_info == null || content.thumbnailMediaId == null)
// readonly property var info: isThumbnail ? content.info.thumbnail_info : content.info
readonly property var info: content.info
readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId
Layout.maximumWidth: imageDelegate.bubbleMaxWidth Layout.maximumWidth: imageDelegate.bubbleMaxWidth
source: "image://mxc/" + mediaId source: "image://mxc/" + mediaId
@@ -108,18 +109,16 @@ TimelineContainer {
} }
} }
function downloadAndOpen() function downloadAndOpen() {
{ if (downloaded) {
if (downloaded) openSavedFile() openSavedFile()
else } else {
{
openOnFinished = true openOnFinished = true
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
} }
} }
function openSavedFile() function openSavedFile() {
{
if (Qt.openUrlExternally(progressInfo.localPath)) return; if (Qt.openUrlExternally(progressInfo.localPath)) return;
if (Qt.openUrlExternally(progressInfo.localDir)) return; if (Qt.openUrlExternally(progressInfo.localDir)) return;
} }

View File

@@ -23,34 +23,33 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
property bool playOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
property bool supportStreaming: true
readonly property int maxWidth: 1000 // TODO messageListView.width
onDownloadedChanged: {
if (downloaded) {
vid.source = progressInfo.localPath
}
if (downloaded && playOnFinished) {
playSavedFile()
playOnFinished = false
}
}
innerObject: Video { innerObject: Video {
id: vid id: vid
property bool playOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed
property bool supportStreaming: true
Layout.maximumWidth: videoDelegate.bubbleMaxWidth Layout.maximumWidth: videoDelegate.bubbleMaxWidth
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumHeight: Kirigami.Units.gridUnit * 15 Layout.maximumHeight: Kirigami.Units.gridUnit * 15
Layout.minimumHeight: Kirigami.Units.gridUnit * 5 Layout.minimumHeight: Kirigami.Units.gridUnit * 5
onDownloadedChanged: { Layout.preferredWidth: (model.content.info.w === undefined || model.content.info.w > videoDelegate.maxWidth) ? videoDelegate.maxWidth : content.info.w
if (downloaded) { Layout.preferredHeight: model.content.info.w === undefined ? (videoDelegate.maxWidth * 3 / 4) : (model.content.info.w > videoDelegate.maxWidth ? (model.content.info.h / model.content.info.w * videoDelegate.maxWidth) : model.content.info.h)
vid.source = progressInfo.localPath
}
if (downloaded && playOnFinished) {
playSavedFile()
playOnFinished = false
}
}
readonly property int maxWidth: 1000 // TODO messageListView.width
Layout.preferredWidth: content.info.w > maxWidth ? maxWidth : content.info.w
Layout.preferredHeight: content.info.w > maxWidth ? (content.info.h / content.info.w * maxWidth) : content.info.h
loops: MediaPlayer.Infinite loops: MediaPlayer.Infinite
@@ -81,7 +80,7 @@ TimelineContainer {
visible: vid.playbackState == MediaPlayer.StoppedState || vid.error != MediaPlayer.NoError visible: vid.playbackState == MediaPlayer.StoppedState || vid.error != MediaPlayer.NoError
source: "image://mxc/" + content.thumbnailMediaId source: model.content.thumbnailMediaId ? "image://mxc/" + model.content.thumbnailMediaId : ""
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
@@ -106,7 +105,7 @@ TimelineContainer {
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
visible: progressInfo.active && !vid.downloaded visible: progressInfo.active && !videoDelegate.downloaded
color: "#BB000000" color: "#BB000000"
@@ -130,7 +129,7 @@ TimelineContainer {
vid.play() vid.play()
} }
} else { } else {
vid.downloadAndPlay() videoDelegate.downloadAndPlay()
} }
} }
@@ -143,19 +142,19 @@ TimelineContainer {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent) onLongPressed: openFileContext(model, parent)
} }
}
function downloadAndPlay() { function downloadAndPlay() {
if (vid.downloaded) { if (vid.downloaded) {
playSavedFile() playSavedFile()
} else { } else {
playOnFinished = true playOnFinished = true
currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)) currentRoom.downloadFile(eventId, Platform.StandardPaths.writableLocation(Platform.StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
}
}
function playSavedFile() {
vid.stop()
vid.play()
} }
} }
function playSavedFile() {
vid.stop()
vid.play()
}
} }