From 73e020e44823dc0df94f9704adb4c8d816d84cd5 Mon Sep 17 00:00:00 2001 From: Yari Polla Date: Thu, 19 Oct 2023 19:39:03 +0200 Subject: [PATCH] dataproviders: declare AudioInfo as singleton --- components/mobileshell/mobileshellplugin.cpp | 2 +- .../qml/dataproviders/AudioInfo.qml | 2 ++ .../statusbar/indicators/VolumeIndicator.qml | 7 +++---- .../mobileshell/qml/volumeosd/AudioApplet.qml | 9 +++------ .../mobileshell/qml/volumeosd/VolumeOSD.qml | 19 +++++++------------ .../qml/volumeosd/VolumeOSDProvider.qml | 19 +++++++------------ quicksettings/audio/contents/ui/main.qml | 4 +--- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/components/mobileshell/mobileshellplugin.cpp b/components/mobileshell/mobileshellplugin.cpp index 86068584..2cfd8923 100644 --- a/components/mobileshell/mobileshellplugin.cpp +++ b/components/mobileshell/mobileshellplugin.cpp @@ -60,7 +60,7 @@ void MobileShellPlugin::registerTypes(const char *uri) qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); // /dataproviders - qmlRegisterType(resolvePath("dataproviders/AudioInfo.qml"), uri, 1, 0, "AudioInfo"); + qmlRegisterSingletonType(resolvePath("dataproviders/AudioInfo.qml"), uri, 1, 0, "AudioInfo"); qmlRegisterType(resolvePath("dataproviders/BatteryInfo.qml"), uri, 1, 0, "BatteryInfo"); qmlRegisterType(resolvePath("dataproviders/BluetoothInfo.qml"), uri, 1, 0, "BluetoothInfo"); qmlRegisterType(resolvePath("dataproviders/SignalStrengthInfo.qml"), uri, 1, 0, "SignalStrengthInfo"); diff --git a/components/mobileshell/qml/dataproviders/AudioInfo.qml b/components/mobileshell/qml/dataproviders/AudioInfo.qml index 9afd1403..6453408b 100644 --- a/components/mobileshell/qml/dataproviders/AudioInfo.qml +++ b/components/mobileshell/qml/dataproviders/AudioInfo.qml @@ -1,6 +1,8 @@ // SPDX-FileCopyrightText: 2023 Devin Lin // SPDX-License-Identifier: GPL-2.0-or-later +pragma Singleton + import QtQuick import org.kde.plasma.private.volume diff --git a/components/mobileshell/qml/statusbar/indicators/VolumeIndicator.qml b/components/mobileshell/qml/statusbar/indicators/VolumeIndicator.qml index 3f20c6f0..04dad06f 100644 --- a/components/mobileshell/qml/statusbar/indicators/VolumeIndicator.qml +++ b/components/mobileshell/qml/statusbar/indicators/VolumeIndicator.qml @@ -12,13 +12,12 @@ import QtQuick.Layouts import org.kde.plasma.private.volume 0.1 import org.kde.kirigami as Kirigami -import "../../dataproviders" as DataProviders +import org.kde.plasma.private.mobileshell 1.0 as MobileShell Kirigami.Icon { id: paIcon - readonly property var provider: DataProviders.AudioInfo {} - source: provider.icon + source: MobileShell.AudioInfo.icon - visible: provider.isVisible + visible: MobileShell.AudioInfo.isVisible } diff --git a/components/mobileshell/qml/volumeosd/AudioApplet.qml b/components/mobileshell/qml/volumeosd/AudioApplet.qml index d8542bb6..cbae84c9 100644 --- a/components/mobileshell/qml/volumeosd/AudioApplet.qml +++ b/components/mobileshell/qml/volumeosd/AudioApplet.qml @@ -13,23 +13,20 @@ import QtQuick.Controls as Controls import org.kde.kirigami 2.20 as Kirigami import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.kquickcontrolsaddons as KQCAddons +import org.kde.plasma.private.mobileshell 1.0 as MobileShell import org.kde.plasma.private.volume -import "../dataproviders" as DataProviders - // capture presses on the audio applet so it doesn't close the overlay ColumnLayout { spacing: 0 - - required property DataProviders.AudioInfo audioInfo - + PulseObjectFilterModel { id: paSinkFilterModel sortRoleName: "SortByDefault" sortOrder: Qt.DescendingOrder filterOutInactiveDevices: true - sourceModel: audioInfo.paSinkModel + sourceModel: MobileShell.AudioInfo.paSinkModel } SourceModel { diff --git a/components/mobileshell/qml/volumeosd/VolumeOSD.qml b/components/mobileshell/qml/volumeosd/VolumeOSD.qml index ca9186c6..bd28f45a 100644 --- a/components/mobileshell/qml/volumeosd/VolumeOSD.qml +++ b/components/mobileshell/qml/volumeosd/VolumeOSD.qml @@ -22,8 +22,6 @@ import "../dataproviders" as DataProviders NanoShell.FullScreenOverlay { id: window - required property var audioInfo - // used by context menus opened in the applet to not autoclose the osd property bool suppressActiveClose: false @@ -104,8 +102,8 @@ NanoShell.FullScreenOverlay { anchors.rightMargin: Kirigami.Units.smallSpacing PlasmaComponents.ToolButton { - icon.name: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high" - text: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute") + icon.name: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high" + text: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute") display: Controls.AbstractButton.IconOnly Layout.alignment: Qt.AlignVCenter Layout.preferredWidth: Kirigami.Units.iconSizes.medium @@ -119,9 +117,9 @@ NanoShell.FullScreenOverlay { Layout.fillWidth: true Layout.alignment: Qt.AlignVCenter Layout.rightMargin: Kirigami.Units.smallSpacing * 2 - value: window.audioInfo.volumeValue + value: MobileShell.AudioInfo.volumeValue from: 0 - to: window.audioInfo.maxVolumePercent + to: MobileShell.AudioInfo.maxVolumePercent Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } } } @@ -139,7 +137,7 @@ NanoShell.FullScreenOverlay { Layout.alignment: Qt.AlignVCenter Layout.rightMargin: Kirigami.Units.smallSpacing level: 3 - text: i18nc("Percentage value", "%1%", window.audioInfo.volumeValue) + text: i18nc("Percentage value", "%1%", MobileShell.AudioInfo.volumeValue) // Display a subtle visual indication that the volume might be // dangerously high @@ -147,9 +145,9 @@ NanoShell.FullScreenOverlay { // Keep this in sync with the copies in plasma-pa:ListItemBase.qml // and plasma-pa:VolumeSlider.qml color: { - if (window.audioInfo.volumeValue <= 100) { + if (MobileShell.AudioInfo.volumeValue <= 100) { return Kirigami.Theme.textColor - } else if (window.audioInfo.volumeValue > 100 && window.audioInfo.volumeValue <= 125) { + } else if (MobileShell.AudioInfo.volumeValue > 100 && MobileShell.AudioInfo.volumeValue <= 125) { return Kirigami.Theme.neutralTextColor } else { return Kirigami.Theme.negativeTextColor @@ -203,9 +201,6 @@ NanoShell.FullScreenOverlay { Layout.topMargin: Kirigami.Units.gridUnit Layout.alignment: Qt.AlignHCenter Layout.preferredWidth: cards.width - - audioInfo: window.audioInfo - opacity: window.showFullApplet ? 1 : 0 visible: opacity !== 0 transform: Translate { diff --git a/components/mobileshell/qml/volumeosd/VolumeOSDProvider.qml b/components/mobileshell/qml/volumeosd/VolumeOSDProvider.qml index cf6b1103..12b3eff7 100644 --- a/components/mobileshell/qml/volumeosd/VolumeOSDProvider.qml +++ b/components/mobileshell/qml/volumeosd/VolumeOSDProvider.qml @@ -11,8 +11,7 @@ import QtQuick.Layouts import org.kde.plasma.private.volume 0.1 as VolumeLib import org.kde.plasma.private.mobileshell.state as MobileShellState - -import "../dataproviders" as DataProviders +import org.kde.plasma.private.mobileshell 1.0 as MobileShell /** * This imports the volume OSD and also sets up keyboard/hardware button bindings. @@ -24,10 +23,8 @@ QtObject { osd.showOverlay(); } - property var audioInfo: DataProviders.AudioInfo { - onVolumeChanged: { - component.osd.showOverlay(); - } + Component.onCompleted: { + MobileShell.AudioInfo.volumeChanged.connect(showVolumeOverlay); } property var apiListener: Connections { @@ -38,9 +35,7 @@ QtObject { } } - property var osd: VolumeOSD { - audioInfo: component.audioInfo - } + property var osd: VolumeOSD {} property var actionCollection: VolumeLib.GlobalActionCollection { name: "kmix" @@ -50,21 +45,21 @@ QtObject { objectName: "increase_volume" text: i18n("Increase Volume") shortcut: Qt.Key_VolumeUp - onTriggered: component.audioInfo.increaseVolume() + onTriggered: MobileShell.AudioInfo.increaseVolume() } VolumeLib.GlobalAction { objectName: "decrease_volume" text: i18n("Decrease Volume") shortcut: Qt.Key_VolumeDown - onTriggered: component.audioInfo.decreaseVolume() + onTriggered: MobileShell.AudioInfo.decreaseVolume() } VolumeLib.GlobalAction { objectName: "mute" text: i18n("Mute") shortcut: Qt.Key_VolumeMute - onTriggered: component.audioInfo.muteVolume() + onTriggered: MobileShell.AudioInfo.muteVolume() } } } diff --git a/quicksettings/audio/contents/ui/main.qml b/quicksettings/audio/contents/ui/main.qml index 7ac509a4..2be26304 100644 --- a/quicksettings/audio/contents/ui/main.qml +++ b/quicksettings/audio/contents/ui/main.qml @@ -10,12 +10,10 @@ import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS QS.QuickSetting { text: i18n("Sound") icon: "audio-speakers-symbolic" - status: i18n("%1%", audioInfo.volumeValue) + status: i18n("%1%", MobileShell.AudioInfo.volumeValue) enabled: false settingsCommand: "plasma-open-settings kcm_pulseaudio" - property var audioInfo: MobileShell.AudioInfo {} - function toggle() { MobileShellState.ShellDBusClient.showVolumeOSD() }