Commit 681e1c8f authored by George Vogiatzis's avatar George Vogiatzis Committed by Nate Graham

[Applet]Add global mute function

Summary:
Add a Mute icon that will force all playback devices to mute. Even if new
device/port connects, will automatically mute.
Does not work as an indicator. It is possible for all the devices to be
muted and the icon to be disabled. It acts as a force switch.
Is aware of devices that were muted before. So that will be able to unmute
only the devices that actually mute. With an exception if all the devices
were muted.
Gets disabled when manually unmute a device.
Stores values in config file, for reboot etc.

Part of T10470 layout changes.

Depends on D26256

BUG: 396835

Reviewers: #vdg, #plasma, drosca, ngraham

Reviewed By: #vdg, ngraham

Subscribers: ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26418
parent d0c753c1
......@@ -16,9 +16,15 @@
<default>true</default>
</entry>
<entry name="outputChangeOsd" type="Bool">
<label>Whether to show a popup when the default output device changes (e.g. plugging in a headset)</label>
<label>Whether to show a popup when the default output device changes (e.g. plugging in a headset)</label>
<default>true</default>
</entry>
<entry name="globalMute" type="Bool">
<default>false</default>
</entry>
<entry name="globalMuteDevices" type="StringList">
<label>Devices that were not muted with global mute, and will remain muted afterwards.</label>
</entry>
</group>
</kcfg>
......@@ -24,6 +24,8 @@ import "../code/icon.js" as Icon
ListItemBase {
readonly property var currentPort: Ports[ActivePortIndex]
readonly property var currentActivePortIndex: ActivePortIndex
readonly property var currentMuted: Muted
draggable: false
label: {
......@@ -47,4 +49,18 @@ ListItemBase {
return Description;
}
}
onCurrentActivePortIndexChanged: {
if (type === "sink" && globalMute && !Muted) {
Muted = true;
}
}
onCurrentMutedChanged: {
if (type === "sink" && globalMute && !Muted) {
plasmoid.configuration.globalMuteDevices = [];
plasmoid.configuration.globalMute = false;
globalMute = false;
}
}
}
......@@ -35,6 +35,7 @@ Item {
id: main
property bool volumeFeedback: Plasmoid.configuration.volumeFeedback
property bool globalMute: Plasmoid.configuration.globalMute
property int raiseMaxVolumeValue: 150
property int maxVolumeValue: Math.round(raiseMaxVolumeValue * PulseAudio.NormalVolume / 100.0)
property int currentMaxVolumeValue: plasmoid.configuration.raiseMaximumVolume ? maxVolumeValue : PulseAudio.NormalVolume
......@@ -121,9 +122,15 @@ Item {
return;
}
var toMute = !paSinkModel.preferredSink.muted;
paSinkModel.preferredSink.muted = toMute;
osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue));
if (!toMute) {
if (toMute) {
enableGlobalMute();
osd.show(0);
} else {
if (globalMute) {
disableGlobalMute();
}
paSinkModel.preferredSink.muted = toMute;
osd.show(volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue));
playFeedback();
}
}
......@@ -169,6 +176,41 @@ Item {
feedback.play(sinkIndex);
}
function enableGlobalMute() {
var role = paSinkModel.role("Muted");
var rowCount = paSinkModel.rowCount();
// List for devices that are already muted. Will use to keep muted after disable GlobalMute.
var globalMuteDevices = [];
for (var i = 0; i < rowCount; i++) {
var idx = paSinkModel.index(i, 0);
var name = paSinkModel.data(idx, paSinkModel.role("Name"));
if (paSinkModel.data(idx, role) === false) {
paSinkModel.setData(idx, true, role);
} else {
globalMuteDevices.push(name + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex")));
}
}
// If all the devices were muted, will unmute them all with disable GlobalMute.
plasmoid.configuration.globalMuteDevices = globalMuteDevices.length < rowCount ? globalMuteDevices : [];
plasmoid.configuration.globalMute = true;
globalMute = true;
}
function disableGlobalMute() {
var role = paSinkModel.role("Muted");
for (var i = 0; i < paSinkModel.rowCount(); i++) {
var idx = paSinkModel.index(i, 0);
var name = paSinkModel.data(idx, paSinkModel.role("Name")) + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex"));
if (plasmoid.configuration.globalMuteDevices.indexOf(name) === -1) {
paSinkModel.setData(idx, false, role);
}
}
plasmoid.configuration.globalMuteDevices = [];
plasmoid.configuration.globalMute = false;
globalMute = false;
}
SinkModel {
id: paSinkModel
......@@ -203,6 +245,18 @@ Item {
}
osd.showText(icon, description);
}
onRowsInserted: {
if (globalMute) {
var role = paSinkModel.role("Muted");
for (var i = 0; i < paSinkModel.rowCount(); i++) {
var idx = paSinkModel.index(i, 0);
if (paSinkModel.data(idx, role) === false) {
paSinkModel.setData(idx, true, role);
}
}
}
}
}
SourceModel {
......@@ -563,6 +617,20 @@ Item {
Layout.fillWidth: true
}
PlasmaComponents.ToolButton {
id: globalMuteCheckbox
iconName: "audio-volume-muted"
onClicked: {
if (!globalMute) {
enableGlobalMute();
} else {
disableGlobalMute();
}
}
checked: globalMute
tooltip: i18n("Force mute all playback devices")
}
PlasmaComponents.ToolButton {
tooltip: plasmoid.action("configure").text
iconName: "configure"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment