dataproviders: declare AudioInfo as singleton

This commit is contained in:
Yari Polla 2023-10-19 19:39:03 +02:00
parent 0070848cfb
commit 73e020e448
7 changed files with 24 additions and 38 deletions

View file

@ -60,7 +60,7 @@ void MobileShellPlugin::registerTypes(const char *uri)
qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator"); qmlRegisterType(resolvePath("components/VelocityCalculator.qml"), uri, 1, 0, "VelocityCalculator");
// /dataproviders // /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/BatteryInfo.qml"), uri, 1, 0, "BatteryInfo");
qmlRegisterType(resolvePath("dataproviders/BluetoothInfo.qml"), uri, 1, 0, "BluetoothInfo"); qmlRegisterType(resolvePath("dataproviders/BluetoothInfo.qml"), uri, 1, 0, "BluetoothInfo");
qmlRegisterType(resolvePath("dataproviders/SignalStrengthInfo.qml"), uri, 1, 0, "SignalStrengthInfo"); qmlRegisterType(resolvePath("dataproviders/SignalStrengthInfo.qml"), uri, 1, 0, "SignalStrengthInfo");

View file

@ -1,6 +1,8 @@
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
pragma Singleton
import QtQuick import QtQuick
import org.kde.plasma.private.volume import org.kde.plasma.private.volume

View file

@ -12,13 +12,12 @@ import QtQuick.Layouts
import org.kde.plasma.private.volume 0.1 import org.kde.plasma.private.volume 0.1
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import "../../dataproviders" as DataProviders import org.kde.plasma.private.mobileshell 1.0 as MobileShell
Kirigami.Icon { Kirigami.Icon {
id: paIcon id: paIcon
readonly property var provider: DataProviders.AudioInfo {}
source: provider.icon source: MobileShell.AudioInfo.icon
visible: provider.isVisible visible: MobileShell.AudioInfo.isVisible
} }

View file

@ -13,23 +13,20 @@ import QtQuick.Controls as Controls
import org.kde.kirigami 2.20 as Kirigami import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.components 3.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents
import org.kde.kquickcontrolsaddons as KQCAddons import org.kde.kquickcontrolsaddons as KQCAddons
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import org.kde.plasma.private.volume import org.kde.plasma.private.volume
import "../dataproviders" as DataProviders
// capture presses on the audio applet so it doesn't close the overlay // capture presses on the audio applet so it doesn't close the overlay
ColumnLayout { ColumnLayout {
spacing: 0 spacing: 0
required property DataProviders.AudioInfo audioInfo
PulseObjectFilterModel { PulseObjectFilterModel {
id: paSinkFilterModel id: paSinkFilterModel
sortRoleName: "SortByDefault" sortRoleName: "SortByDefault"
sortOrder: Qt.DescendingOrder sortOrder: Qt.DescendingOrder
filterOutInactiveDevices: true filterOutInactiveDevices: true
sourceModel: audioInfo.paSinkModel sourceModel: MobileShell.AudioInfo.paSinkModel
} }
SourceModel { SourceModel {

View file

@ -22,8 +22,6 @@ import "../dataproviders" as DataProviders
NanoShell.FullScreenOverlay { NanoShell.FullScreenOverlay {
id: window id: window
required property var audioInfo
// used by context menus opened in the applet to not autoclose the osd // used by context menus opened in the applet to not autoclose the osd
property bool suppressActiveClose: false property bool suppressActiveClose: false
@ -104,8 +102,8 @@ NanoShell.FullScreenOverlay {
anchors.rightMargin: Kirigami.Units.smallSpacing anchors.rightMargin: Kirigami.Units.smallSpacing
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
icon.name: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high" icon.name: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high"
text: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute") text: !MobileShell.AudioInfo.paSinkModel.preferredSink || MobileShell.AudioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute")
display: Controls.AbstractButton.IconOnly display: Controls.AbstractButton.IconOnly
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: Kirigami.Units.iconSizes.medium Layout.preferredWidth: Kirigami.Units.iconSizes.medium
@ -119,9 +117,9 @@ NanoShell.FullScreenOverlay {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: Kirigami.Units.smallSpacing * 2 Layout.rightMargin: Kirigami.Units.smallSpacing * 2
value: window.audioInfo.volumeValue value: MobileShell.AudioInfo.volumeValue
from: 0 from: 0
to: window.audioInfo.maxVolumePercent to: MobileShell.AudioInfo.maxVolumePercent
Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } } Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } }
} }
@ -139,7 +137,7 @@ NanoShell.FullScreenOverlay {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: Kirigami.Units.smallSpacing Layout.rightMargin: Kirigami.Units.smallSpacing
level: 3 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 // Display a subtle visual indication that the volume might be
// dangerously high // dangerously high
@ -147,9 +145,9 @@ NanoShell.FullScreenOverlay {
// Keep this in sync with the copies in plasma-pa:ListItemBase.qml // Keep this in sync with the copies in plasma-pa:ListItemBase.qml
// and plasma-pa:VolumeSlider.qml // and plasma-pa:VolumeSlider.qml
color: { color: {
if (window.audioInfo.volumeValue <= 100) { if (MobileShell.AudioInfo.volumeValue <= 100) {
return Kirigami.Theme.textColor 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 return Kirigami.Theme.neutralTextColor
} else { } else {
return Kirigami.Theme.negativeTextColor return Kirigami.Theme.negativeTextColor
@ -203,9 +201,6 @@ NanoShell.FullScreenOverlay {
Layout.topMargin: Kirigami.Units.gridUnit Layout.topMargin: Kirigami.Units.gridUnit
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: cards.width Layout.preferredWidth: cards.width
audioInfo: window.audioInfo
opacity: window.showFullApplet ? 1 : 0 opacity: window.showFullApplet ? 1 : 0
visible: opacity !== 0 visible: opacity !== 0
transform: Translate { transform: Translate {

View file

@ -11,8 +11,7 @@ import QtQuick.Layouts
import org.kde.plasma.private.volume 0.1 as VolumeLib import org.kde.plasma.private.volume 0.1 as VolumeLib
import org.kde.plasma.private.mobileshell.state as MobileShellState import org.kde.plasma.private.mobileshell.state as MobileShellState
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
import "../dataproviders" as DataProviders
/** /**
* This imports the volume OSD and also sets up keyboard/hardware button bindings. * This imports the volume OSD and also sets up keyboard/hardware button bindings.
@ -24,10 +23,8 @@ QtObject {
osd.showOverlay(); osd.showOverlay();
} }
property var audioInfo: DataProviders.AudioInfo { Component.onCompleted: {
onVolumeChanged: { MobileShell.AudioInfo.volumeChanged.connect(showVolumeOverlay);
component.osd.showOverlay();
}
} }
property var apiListener: Connections { property var apiListener: Connections {
@ -38,9 +35,7 @@ QtObject {
} }
} }
property var osd: VolumeOSD { property var osd: VolumeOSD {}
audioInfo: component.audioInfo
}
property var actionCollection: VolumeLib.GlobalActionCollection { property var actionCollection: VolumeLib.GlobalActionCollection {
name: "kmix" name: "kmix"
@ -50,21 +45,21 @@ QtObject {
objectName: "increase_volume" objectName: "increase_volume"
text: i18n("Increase Volume") text: i18n("Increase Volume")
shortcut: Qt.Key_VolumeUp shortcut: Qt.Key_VolumeUp
onTriggered: component.audioInfo.increaseVolume() onTriggered: MobileShell.AudioInfo.increaseVolume()
} }
VolumeLib.GlobalAction { VolumeLib.GlobalAction {
objectName: "decrease_volume" objectName: "decrease_volume"
text: i18n("Decrease Volume") text: i18n("Decrease Volume")
shortcut: Qt.Key_VolumeDown shortcut: Qt.Key_VolumeDown
onTriggered: component.audioInfo.decreaseVolume() onTriggered: MobileShell.AudioInfo.decreaseVolume()
} }
VolumeLib.GlobalAction { VolumeLib.GlobalAction {
objectName: "mute" objectName: "mute"
text: i18n("Mute") text: i18n("Mute")
shortcut: Qt.Key_VolumeMute shortcut: Qt.Key_VolumeMute
onTriggered: component.audioInfo.muteVolume() onTriggered: MobileShell.AudioInfo.muteVolume()
} }
} }
} }

View file

@ -10,12 +10,10 @@ import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
QS.QuickSetting { QS.QuickSetting {
text: i18n("Sound") text: i18n("Sound")
icon: "audio-speakers-symbolic" icon: "audio-speakers-symbolic"
status: i18n("%1%", audioInfo.volumeValue) status: i18n("%1%", MobileShell.AudioInfo.volumeValue)
enabled: false enabled: false
settingsCommand: "plasma-open-settings kcm_pulseaudio" settingsCommand: "plasma-open-settings kcm_pulseaudio"
property var audioInfo: MobileShell.AudioInfo {}
function toggle() { function toggle() {
MobileShellState.ShellDBusClient.showVolumeOSD() MobileShellState.ShellDBusClient.showVolumeOSD()
} }