Warning, /libraries/kirigami-addons/src/sounds/SoundsPicker.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
0003  * SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 import QtQuick
0009 import QtQuick.Controls as Controls2
0010 import org.kde.kirigami as Kirigami
0011 import QtQuick.Layouts
0012 import QtMultimedia
0013 import org.kde.kirigamiaddons.sounds
0014 import org.kde.kirigamiaddons.delegates as Delegates
0015 
0016 /**
0017  * A sound picker component for picking ringtones and notifications.
0018  * \inherits QtQuick.ListView
0019  */
0020 ListView {
0021     id: listView
0022 
0023     /**
0024      * This property holds the selected audio url.
0025      */
0026     property string selectedUrl: soundsModel.initialSourceUrl(listView.currentIndex)
0027 
0028     /**
0029      * This property controls the sound type (ringtone or notification).
0030      * \property bool notification
0031      */
0032     property bool notification: true
0033 
0034     /**
0035      * This property lets you choose sound theme, default to "plasma-mobile"
0036      * \property string theme
0037      */
0038     property alias theme: soundsModel.theme
0039 
0040     /**
0041      * This property is the internal Audio qml type used for play sound
0042      * \property QtMultimedia.Audio playMusic
0043      */
0044     property alias audioPlayer: playMusic
0045 
0046     model: SoundsModel {
0047         id: soundsModel
0048         notification: listView.notification
0049         theme: 'freedesktop'
0050     }
0051 
0052     delegate: Delegates.RoundedItemDelegate {
0053         required property string ringtoneName
0054         required property url sourceUrl
0055         required property int index
0056 
0057         text: ringtoneName
0058 
0059         icon.name: ListView.isCurrentItem ? "object-select-symbolic" : ""
0060         onClicked: {
0061             selectedUrl = sourceUrl;
0062             if (playMusic.playbackState === MediaPlayer.PlayingState) {
0063                 playMusic.pause();
0064             } else {
0065                 playMusic.play();
0066             }
0067         }
0068     }
0069 
0070     MediaPlayer {
0071         id: playMusic
0072         source: selectedUrl
0073         audioOutput: AudioOutput {}
0074     }
0075 }