2020-08-09 20:00:57 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2020 Aniket Kumar <anikketkumar786@gmail.com>
|
2020-08-09 20:00:57 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2020-08-09 20:00:57 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-23 16:48:04 +00:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import QtQuick.Controls
|
|
|
|
import org.kde.kirigami as Kirigami
|
2023-09-21 18:23:06 +01:00
|
|
|
import QtMultimedia
|
2020-08-09 20:00:57 +01:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
property int partID
|
|
|
|
property string mimeType
|
|
|
|
property string uniqueIdentifier
|
2024-06-05 09:27:54 +01:00
|
|
|
property url source
|
2020-08-09 20:00:57 +01:00
|
|
|
|
|
|
|
readonly property int elementWidth: 100
|
|
|
|
readonly property int elementHeight: 100
|
|
|
|
|
2024-03-14 19:09:48 +00:00
|
|
|
width: thumbnailElement.width
|
|
|
|
height: thumbnailElement.height
|
2020-08-09 20:00:57 +01:00
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
Component {
|
|
|
|
id: attachmentViewer
|
|
|
|
|
|
|
|
AttachmentViewer {
|
2024-06-05 09:27:54 +01:00
|
|
|
fileUrl: root.source
|
2020-08-13 19:23:02 +01:00
|
|
|
mimeType: root.mimeType
|
|
|
|
title: uniqueIdentifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-14 19:09:48 +00:00
|
|
|
Kirigami.ShadowedImage {
|
2020-08-09 20:00:57 +01:00
|
|
|
id: thumbnailElement
|
|
|
|
visible: mimeType.match("image") || mimeType.match("video")
|
|
|
|
source: visible ? "image://thumbnailsProvider/" + root.uniqueIdentifier : ""
|
|
|
|
|
2024-03-14 19:09:48 +00:00
|
|
|
radius: 6
|
|
|
|
|
|
|
|
width: visible ? sourceSize.width : elementWidth
|
|
|
|
height: visible ? sourceSize.height : elementHeight
|
2020-08-09 20:00:57 +01:00
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
2024-06-05 09:27:54 +01:00
|
|
|
if (root.source.toString() === "") {
|
2020-08-13 19:23:02 +01:00
|
|
|
conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier)
|
|
|
|
} else {
|
|
|
|
openMedia();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
Button {
|
|
|
|
icon.name: "media-playback-start"
|
|
|
|
visible: root.mimeType.match("video")
|
2024-03-14 19:09:48 +00:00
|
|
|
anchors.centerIn: parent
|
2020-08-13 19:23:02 +01:00
|
|
|
onClicked: {
|
2024-06-05 09:27:54 +01:00
|
|
|
if (root.source.toString() === "") {
|
2020-08-13 19:23:02 +01:00
|
|
|
conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier)
|
|
|
|
} else {
|
|
|
|
openMedia();
|
|
|
|
}
|
|
|
|
}
|
2020-08-09 20:00:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: audioElement
|
|
|
|
visible: root.mimeType.match("audio")
|
|
|
|
anchors.fill: parent
|
|
|
|
radius: messageBox.radius
|
|
|
|
color: "lightgrey"
|
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
MediaPlayer {
|
2020-08-13 19:23:02 +01:00
|
|
|
id: audioPlayer
|
2024-06-05 09:27:54 +01:00
|
|
|
source: root.source
|
2020-08-13 19:23:02 +01:00
|
|
|
|
2023-09-21 18:23:06 +01:00
|
|
|
onPlaybackStateChanged: {
|
|
|
|
if (playbackState === MediaPlayer.PlayingState) {
|
|
|
|
audioPlayButton.icon.name = "media-playback-stop"
|
|
|
|
} else {
|
|
|
|
audioPlayButton.icon.name = "media-playback-start"
|
|
|
|
}
|
2020-08-13 19:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
ColumnLayout {
|
2024-03-14 19:09:48 +00:00
|
|
|
anchors.centerIn: parent
|
2020-08-09 20:00:57 +01:00
|
|
|
spacing: Kirigami.Units.largeSpacing
|
|
|
|
|
|
|
|
Button {
|
2024-06-05 09:27:54 +01:00
|
|
|
id: audioPlayButton
|
2020-08-09 20:00:57 +01:00
|
|
|
icon.name: "media-playback-start"
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
onClicked: {
|
2024-06-05 09:27:54 +01:00
|
|
|
if (root.source.toString() !== "") {
|
2024-03-14 19:09:48 +00:00
|
|
|
if (icon.name === "media-playback-start") {
|
2020-08-13 19:23:02 +01:00
|
|
|
audioPlayer.play()
|
|
|
|
} else {
|
|
|
|
audioPlayer.stop()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier)
|
|
|
|
}
|
|
|
|
}
|
2020-08-09 20:00:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
text: i18nd("kdeconnect-sms", "Audio clip")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: conversationModel
|
2023-10-03 09:17:41 +01:00
|
|
|
function onFilePathReceived(filePath, fileName) {
|
2024-06-05 09:27:54 +01:00
|
|
|
if (root.uniqueIdentifier === fileName && root.source.toString() === "") {
|
|
|
|
root.source = "file://" + filePath
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
if (root.mimeType.match("audio")) {
|
2024-06-05 09:27:54 +01:00
|
|
|
audioPlayer.source = root.source
|
2020-08-13 19:23:02 +01:00
|
|
|
audioPlayer.play()
|
|
|
|
} else if (root.mimeType.match("image") || root.mimeType.match("video")) {
|
|
|
|
openMedia();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openMedia() {
|
|
|
|
applicationWindow().pageStack.layers.push(attachmentViewer)
|
|
|
|
}
|
2020-08-09 20:00:57 +01:00
|
|
|
}
|