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
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtGraphicalEffects 1.12
|
|
|
|
import org.kde.kirigami 2.13 as Kirigami
|
|
|
|
import QtMultimedia 5.12
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
property int partID
|
|
|
|
property string mimeType
|
|
|
|
property string uniqueIdentifier
|
2020-08-13 19:23:02 +01:00
|
|
|
property string sourcePath: ""
|
2020-08-09 20:00:57 +01:00
|
|
|
|
|
|
|
readonly property int elementWidth: 100
|
|
|
|
readonly property int elementHeight: 100
|
|
|
|
|
|
|
|
width: thumbnailElement.visible ? thumbnailElement.width : elementWidth
|
|
|
|
height: thumbnailElement.visible ? thumbnailElement.height : elementHeight
|
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
Component {
|
|
|
|
id: attachmentViewer
|
|
|
|
|
|
|
|
AttachmentViewer {
|
|
|
|
filePath: root.sourcePath
|
|
|
|
mimeType: root.mimeType
|
|
|
|
title: uniqueIdentifier
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
Image {
|
|
|
|
id: thumbnailElement
|
|
|
|
visible: mimeType.match("image") || mimeType.match("video")
|
|
|
|
source: visible ? "image://thumbnailsProvider/" + root.uniqueIdentifier : ""
|
|
|
|
|
|
|
|
property bool rounded: true
|
|
|
|
property bool adapt: true
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
|
layer.enabled: rounded
|
|
|
|
layer.effect: OpacityMask {
|
|
|
|
maskSource: Item {
|
|
|
|
width: thumbnailElement.width
|
|
|
|
height: thumbnailElement.height
|
|
|
|
Rectangle {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: thumbnailElement.adapt ? thumbnailElement.width : Math.min(thumbnailElement.width, thumbnailElement.height)
|
|
|
|
height: thumbnailElement.adapt ? thumbnailElement.height : width
|
|
|
|
radius: messageBox.radius
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
|
|
if (root.sourcePath == "") {
|
|
|
|
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")
|
|
|
|
anchors.horizontalCenter: thumbnailElement.horizontalCenter
|
|
|
|
anchors.verticalCenter: thumbnailElement.verticalCenter
|
2020-08-13 19:23:02 +01:00
|
|
|
onClicked: {
|
|
|
|
if (root.sourcePath == "") {
|
|
|
|
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"
|
|
|
|
|
2020-08-13 19:23:02 +01:00
|
|
|
Audio {
|
|
|
|
id: audioPlayer
|
|
|
|
source: root.sourcePath
|
|
|
|
|
|
|
|
onStopped: {
|
|
|
|
audioPlayButton.icon.name = "media-playback-start"
|
|
|
|
}
|
|
|
|
|
|
|
|
onPlaying: {
|
|
|
|
audioPlayButton.icon.name = "media-playback-stop"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-09 20:00:57 +01:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
spacing: Kirigami.Units.largeSpacing
|
|
|
|
|
|
|
|
Button {
|
|
|
|
id : audioPlayButton
|
|
|
|
icon.name: "media-playback-start"
|
|
|
|
Layout.alignment: Qt.AlignCenter
|
2020-08-13 19:23:02 +01:00
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (root.sourcePath != "") {
|
|
|
|
if (icon.name == "media-playback-start") {
|
|
|
|
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
|
2022-09-20 23:14:37 +01:00
|
|
|
function onFilePathReceived() {
|
2020-08-13 19:23:02 +01:00
|
|
|
if (root.uniqueIdentifier == fileName && root.sourcePath == "") {
|
|
|
|
root.sourcePath = "file:" + filePath
|
|
|
|
|
|
|
|
if (root.mimeType.match("audio")) {
|
|
|
|
audioPlayer.source = root.sourcePath
|
|
|
|
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
|
|
|
}
|