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 2.12
0009 import QtQuick.Controls 2.5 as Controls2
0010 import org.kde.kirigami 2.0 as Kirigami
0011 import QtQuick.Layouts 1.11
0012 import QtMultimedia 5.15
0013 import org.kde.kirigamiaddons.sounds 0.1
0014 
0015 /**
0016  * A sound picker component for picking ringtones and notifications.
0017  * \inherits QtQuick.ListView
0018  */
0019 ListView {
0020     id: listView
0021 
0022     /**
0023      * This property holds the selected audio url.
0024      */
0025     property string selectedUrl: soundsModel.initialSourceUrl(listView.currentIndex)
0026 
0027     /**
0028      * This property controls the sound type (ringtone or notification).
0029      * \property bool notification
0030      */
0031     property bool notification: true
0032 
0033     /**
0034      * This property lets you choose sound theme, default to "plasma-mobile"
0035      * \property string theme
0036      */
0037     property alias theme: soundsModel.theme
0038 
0039     /**
0040      * This property is the internal Audio qml type used for play sound
0041      * \property QtMultimedia.Audio playMusic
0042      */
0043     property alias audioPlayer: playMusic
0044 
0045     model: SoundsModel {
0046         id: soundsModel
0047         notification: listView.notification
0048     }
0049     
0050     delegate: Kirigami.BasicListItem {
0051         text: ringtoneName
0052         icon: ListView.isCurrentItem ? "object-select-symbolic" : ""
0053         onClicked: {
0054             selectedUrl = sourceUrl;
0055             if (playMusic.playbackState === MediaPlayer.PlayingState) {
0056                 playMusic.pause();
0057             } else {
0058                 playMusic.play();
0059             }
0060         }
0061     }
0062     
0063     Audio {
0064         id: playMusic
0065         source: selectedUrl
0066     }
0067 }