Warning, /network/kdeconnect-kde/smsapp/qml/MessageAttachments.qml is written in an unsupported language. File is not indexed.
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Aniket Kumar <anikketkumar786@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 import QtQuick 0008 import QtQuick.Layouts 0009 import QtQuick.Controls 0010 import Qt5Compat.GraphicalEffects 0011 import org.kde.kirigami as Kirigami 0012 import QtMultimedia 0013 0014 Item { 0015 id: root 0016 property int partID 0017 property string mimeType 0018 property string uniqueIdentifier 0019 property string sourcePath: "" 0020 0021 readonly property int elementWidth: 100 0022 readonly property int elementHeight: 100 0023 0024 width: thumbnailElement.visible ? thumbnailElement.width : elementWidth 0025 height: thumbnailElement.visible ? thumbnailElement.height : elementHeight 0026 0027 Component { 0028 id: attachmentViewer 0029 0030 AttachmentViewer { 0031 filePath: root.sourcePath 0032 mimeType: root.mimeType 0033 title: uniqueIdentifier 0034 } 0035 } 0036 0037 Image { 0038 id: thumbnailElement 0039 visible: mimeType.match("image") || mimeType.match("video") 0040 source: visible ? "image://thumbnailsProvider/" + root.uniqueIdentifier : "" 0041 0042 property bool rounded: true 0043 property bool adapt: true 0044 anchors.horizontalCenter: parent.horizontalCenter 0045 anchors.verticalCenter: parent.verticalCenter 0046 0047 layer.enabled: rounded 0048 layer.effect: OpacityMask { 0049 maskSource: Item { 0050 width: thumbnailElement.width 0051 height: thumbnailElement.height 0052 Rectangle { 0053 anchors.centerIn: parent 0054 width: thumbnailElement.adapt ? thumbnailElement.width : Math.min(thumbnailElement.width, thumbnailElement.height) 0055 height: thumbnailElement.adapt ? thumbnailElement.height : width 0056 radius: messageBox.radius 0057 } 0058 } 0059 } 0060 0061 MouseArea { 0062 anchors.fill: parent 0063 onClicked: { 0064 if (root.sourcePath == "") { 0065 conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier) 0066 } else { 0067 openMedia(); 0068 } 0069 } 0070 } 0071 0072 Button { 0073 icon.name: "media-playback-start" 0074 visible: root.mimeType.match("video") 0075 anchors.horizontalCenter: thumbnailElement.horizontalCenter 0076 anchors.verticalCenter: thumbnailElement.verticalCenter 0077 onClicked: { 0078 if (root.sourcePath == "") { 0079 conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier) 0080 } else { 0081 openMedia(); 0082 } 0083 } 0084 } 0085 } 0086 0087 Rectangle { 0088 id: audioElement 0089 visible: root.mimeType.match("audio") 0090 anchors.fill: parent 0091 radius: messageBox.radius 0092 color: "lightgrey" 0093 0094 MediaPlayer { 0095 id: audioPlayer 0096 source: root.sourcePath 0097 0098 onPlaybackStateChanged: { 0099 if (playbackState === MediaPlayer.PlayingState) { 0100 audioPlayButton.icon.name = "media-playback-stop" 0101 } else { 0102 audioPlayButton.icon.name = "media-playback-start" 0103 } 0104 } 0105 } 0106 0107 ColumnLayout { 0108 anchors.verticalCenter: parent.verticalCenter 0109 anchors.horizontalCenter: parent.horizontalCenter 0110 spacing: Kirigami.Units.largeSpacing 0111 0112 Button { 0113 id : audioPlayButton 0114 icon.name: "media-playback-start" 0115 Layout.alignment: Qt.AlignCenter 0116 0117 onClicked: { 0118 if (root.sourcePath != "") { 0119 if (icon.name == "media-playback-start") { 0120 audioPlayer.play() 0121 } else { 0122 audioPlayer.stop() 0123 } 0124 } else { 0125 conversationModel.requestAttachmentPath(root.partID, root.uniqueIdentifier) 0126 } 0127 } 0128 } 0129 0130 Label { 0131 text: i18nd("kdeconnect-sms", "Audio clip") 0132 } 0133 } 0134 } 0135 0136 Connections { 0137 target: conversationModel 0138 function onFilePathReceived(filePath, fileName) { 0139 if (root.uniqueIdentifier == fileName && root.sourcePath == "") { 0140 root.sourcePath = "file://" + filePath 0141 0142 if (root.mimeType.match("audio")) { 0143 audioPlayer.source = root.sourcePath 0144 audioPlayer.play() 0145 } else if (root.mimeType.match("image") || root.mimeType.match("video")) { 0146 openMedia(); 0147 } 0148 } 0149 } 0150 } 0151 0152 function openMedia() { 0153 applicationWindow().pageStack.layers.push(attachmentViewer) 0154 } 0155 }