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,10 +21,21 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
innerObject: RowLayout {
property bool openOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed 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 {
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumWidth: fileDelegate.bubbleMaxWidth Layout.maximumWidth: fileDelegate.bubbleMaxWidth
Layout.margins: Kirigami.Units.largeSpacing Layout.margins: Kirigami.Units.largeSpacing
@@ -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,9 +21,6 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
innerObject: Image {
id: img
property var content: model.content property var content: model.content
readonly property bool isAnimated: contentType === "image/gif" readonly property bool isAnimated: contentType === "image/gif"
@@ -35,6 +32,10 @@ TimelineContainer {
readonly property var info: content.info readonly property var info: content.info
readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId readonly property string mediaId: isThumbnail ? content.thumbnailMediaId : content.mediaId
innerObject: Image {
id: img
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,18 +23,11 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
innerObject: Video {
id: vid
property bool playOnFinished: false property bool playOnFinished: false
readonly property bool downloaded: progressInfo && progressInfo.completed readonly property bool downloaded: progressInfo && progressInfo.completed
property bool supportStreaming: true property bool supportStreaming: true
readonly property int maxWidth: 1000 // TODO messageListView.width
Layout.maximumWidth: videoDelegate.bubbleMaxWidth
Layout.fillWidth: true
Layout.maximumHeight: Kirigami.Units.gridUnit * 15
Layout.minimumHeight: Kirigami.Units.gridUnit * 5
onDownloadedChanged: { onDownloadedChanged: {
if (downloaded) { if (downloaded) {
@@ -47,10 +40,16 @@ TimelineContainer {
} }
} }
readonly property int maxWidth: 1000 // TODO messageListView.width innerObject: Video {
id: vid
Layout.preferredWidth: content.info.w > maxWidth ? maxWidth : content.info.w Layout.maximumWidth: videoDelegate.bubbleMaxWidth
Layout.preferredHeight: content.info.w > maxWidth ? (content.info.h / content.info.w * maxWidth) : content.info.h Layout.fillWidth: true
Layout.maximumHeight: Kirigami.Units.gridUnit * 15
Layout.minimumHeight: Kirigami.Units.gridUnit * 5
Layout.preferredWidth: (model.content.info.w === undefined || model.content.info.w > videoDelegate.maxWidth) ? videoDelegate.maxWidth : content.info.w
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)
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,6 +142,7 @@ 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) {
@@ -158,4 +158,3 @@ TimelineContainer {
vid.play() vid.play()
} }
} }
}