kdeconnect-kde/plugins/findthisdevice/kdeconnect_findthisdevice_config.qml
Carl Schwan 9832f380dc findthisdevice: Add audio playback
Similar to the C++ kcm
2024-10-13 19:40:34 +00:00

76 lines
2.2 KiB
QML

/**
* SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
import QtQuick.Layouts 1.15
import QtQuick.Dialogs as Dialogs
import QtMultimedia
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kdeconnect 1.0
import org.kde.kdeconnect.private.findthisdevice as FindThisDevice
Kirigami.ScrollablePage {
id: root
property string device
actions: Kirigami.Action {
icon.name: "dialog-ok"
text: i18n("Apply")
onTriggered: config.set("ringtone", path.text)
}
Kirigami.FormLayout {
Dialogs.FileDialog {
id: fileDialog
currentFile: path.text
onAccepted: {
path.text = currentFile.toString().replace("file://", "")
}
KdeConnectPluginConfig {
id: config
deviceId: device
pluginName: "kdeconnect_findthisdevice"
onConfigChanged: {
path.text = getString("ringtone", FindThisDevice.FindThisDeviceHelper.defaultSound())
}
}
RowLayout {
Kirigami.FormData.label: i18n("Sound to play:")
QQC2.TextField {
id: path
}
QQC2.Button {
text: i18nc("@action:button", "Choose file")
display: QQC2.Button.IconOnly
icon.name: "document-open-symbolic"
onClicked: fileDialog.open()
}
QQC2.Button {
text: i18nc("@action:button", "Play")
display: QQC2.Button.IconOnly
icon.name: playMusic.playing ? "media-playback-stop-symbolic" : "media-playback-start-symbolic"
enabled: FindThisDevice.FindThisDeviceHelper.pathExists(path.text)
onClicked: {
playMusic.source = path.text;
playMusic.playing ? playMusic.stop() : playMusic.play();
}
MediaPlayer {
id: playMusic
audioOutput: AudioOutput {}
}
}
}
}
}