Warning, /network/neochat/src/qml/AudioDelegate.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2022 Tobias Fella <tobias.fella@kde.org>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import QtMultimedia
0008 
0009 import org.kde.coreaddons
0010 import org.kde.kirigami as Kirigami
0011 
0012 import org.kde.neochat
0013 
0014 /**
0015  * @brief A timeline delegate for an audio message.
0016  *
0017  * @inherit MessageDelegate
0018  */
0019 MessageDelegate {
0020     id: root
0021 
0022     /**
0023      * @brief The media info for the event.
0024      *
0025      * This should consist of the following:
0026      *  - source - The mxc URL for the media.
0027      *  - mimeType - The MIME type of the media (should be audio/xxx for this delegate).
0028      *  - mimeIcon - The MIME icon name (should be audio-xxx).
0029      *  - size - The file size in bytes.
0030      *  - duration - The length in seconds of the audio media.
0031      */
0032     required property var mediaInfo
0033 
0034     /**
0035      * @brief Whether the media has been downloaded.
0036      */
0037     readonly property bool downloaded: root.progressInfo && root.progressInfo.completed
0038     onDownloadedChanged: audio.play()
0039 
0040     onOpenContextMenu: RoomManager.viewEventMenu(eventId, author, delegateType, plainText, "", "", mediaInfo.mimeType, progressInfo)
0041 
0042     bubbleContent: ColumnLayout {
0043         MediaPlayer {
0044             id: audio
0045             onErrorOccurred: (error, errorString) => console.warn("Audio playback error:" + error + errorString)
0046             audioOutput: AudioOutput {}
0047         }
0048 
0049         states: [
0050             State {
0051                 name: "notDownloaded"
0052                 when: !root.progressInfo.completed && !root.progressInfo.active
0053 
0054                 PropertyChanges {
0055                     target: playButton
0056                     icon.name: "media-playback-start"
0057                     onClicked: root.room.downloadFile(root.eventId)
0058                 }
0059             },
0060             State {
0061                 name: "downloading"
0062                 when: root.progressInfo.active && !root.progressInfo.completed
0063                 PropertyChanges {
0064                     target: downloadBar
0065                     visible: true
0066                 }
0067                 PropertyChanges {
0068                     target: playButton
0069                     icon.name: "media-playback-stop"
0070                     onClicked: {
0071                         root.room.cancelFileTransfer(root.eventId);
0072                     }
0073                 }
0074             },
0075             State {
0076                 name: "paused"
0077                 when: root.progressInfo.completed && (audio.playbackState === MediaPlayer.StoppedState || audio.playbackState === MediaPlayer.PausedState)
0078                 PropertyChanges {
0079                     target: playButton
0080                     icon.name: "media-playback-start"
0081                     onClicked: {
0082                         audio.source = root.progressInfo.localPath;
0083                         audio.play();
0084                     }
0085                 }
0086             },
0087             State {
0088                 name: "playing"
0089                 when: root.progressInfo.completed && audio.playbackState === MediaPlayer.PlayingState
0090 
0091                 PropertyChanges {
0092                     target: playButton
0093 
0094                     icon.name: "media-playback-pause"
0095 
0096                     onClicked: audio.pause()
0097                 }
0098             }
0099         ]
0100 
0101         RowLayout {
0102             QQC2.ToolButton {
0103                 id: playButton
0104             }
0105             QQC2.Label {
0106                 text: root.display
0107                 wrapMode: Text.Wrap
0108                 Layout.fillWidth: true
0109             }
0110         }
0111         QQC2.ProgressBar {
0112             id: downloadBar
0113             visible: false
0114             Layout.fillWidth: true
0115             from: 0
0116             to: root.mediaInfo.size
0117             value: root.progressInfo.progress
0118         }
0119         RowLayout {
0120             visible: audio.hasAudio
0121 
0122             QQC2.Slider {
0123                 Layout.fillWidth: true
0124                 from: 0
0125                 to: audio.duration
0126                 value: audio.position
0127                 onMoved: audio.seek(value)
0128             }
0129 
0130             QQC2.Label {
0131                 visible: root.contentMaxWidth > Kirigami.Units.gridUnit * 12
0132 
0133                 text: Format.formatDuration(audio.position) + "/" + Format.formatDuration(audio.duration)
0134             }
0135         }
0136         QQC2.Label {
0137             Layout.alignment: Qt.AlignRight
0138             Layout.rightMargin: Kirigami.Units.smallSpacing
0139             visible: audio.hasAudio && root.contentMaxWidth < Kirigami.Units.gridUnit * 12
0140 
0141             text: Format.formatDuration(audio.position) + "/" + Format.formatDuration(audio.duration)
0142         }
0143     }
0144 }