From 9832f380dc2f9f1ed44a7f84c8eb04e94b673851 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Sat, 5 Oct 2024 20:56:04 +0200 Subject: [PATCH] findthisdevice: Add audio playback Similar to the C++ kcm --- .../findthisdevice/findthisdevicehelper.cpp | 6 ++++++ plugins/findthisdevice/findthisdevicehelper.h | 1 + .../kdeconnect_findthisdevice_config.qml | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/findthisdevice/findthisdevicehelper.cpp b/plugins/findthisdevice/findthisdevicehelper.cpp index 7ab74ba28..4eca7e426 100644 --- a/plugins/findthisdevice/findthisdevicehelper.cpp +++ b/plugins/findthisdevice/findthisdevicehelper.cpp @@ -17,6 +17,7 @@ #endif #include +#include #include QString FindThisDeviceHelper::defaultSound() @@ -48,3 +49,8 @@ QString FindThisDeviceHelper::defaultSound() } return soundURL.toLocalFile(); } + +bool FindThisDeviceHelper::pathExists(const QString &path) +{ + return QFileInfo::exists(path); +} diff --git a/plugins/findthisdevice/findthisdevicehelper.h b/plugins/findthisdevice/findthisdevicehelper.h index c2e1bdb8e..14be8188f 100644 --- a/plugins/findthisdevice/findthisdevicehelper.h +++ b/plugins/findthisdevice/findthisdevicehelper.h @@ -17,4 +17,5 @@ class FindThisDeviceHelper : public QObject public: static Q_INVOKABLE QString defaultSound(); + bool pathExists(const QString &path); }; diff --git a/plugins/findthisdevice/kdeconnect_findthisdevice_config.qml b/plugins/findthisdevice/kdeconnect_findthisdevice_config.qml index dfea4685d..6b8cfa4c5 100644 --- a/plugins/findthisdevice/kdeconnect_findthisdevice_config.qml +++ b/plugins/findthisdevice/kdeconnect_findthisdevice_config.qml @@ -52,9 +52,25 @@ Kirigami.ScrollablePage { QQC2.Button { text: i18nc("@action:button", "Choose file") display: QQC2.Button.IconOnly - icon.name: "document-open" + 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 {} + } + } } } }