Commit d0c753c1 authored by George Vogiatzis's avatar George Vogiatzis Committed by Nate Graham

[Applet] Make 'raise maximum volume' global

Summary:
Remove maximum volume control from configuration.
Remove individual maximum volume.
Add a checkbox in applet to enable raise maximum volume for all devices. (not applications)

Depends on D26271

Test Plan:
Before:
2 options exist to raise maximum volume.
One options controls the default output device(by setting the limit).
And a second one controls individual devices/applications.
After:
A checkbox in the applet will raise the max volume for all devices to 150%.

Reviewers: ngraham, #vdg, #plasma, drosca

Reviewed By: ngraham, #vdg

Subscribers: drosca, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26256
parent 8ada15ad
......@@ -23,7 +23,7 @@ function name(volume, muted, prefix) {
prefix = "audio-volume";
}
var icon = null;
var percent = volume / maxVolumeValue;
var percent = volume / currentMaxVolumeValue;
if (percent <= 0.0 || muted) {
icon = prefix + "-muted";
} else if (percent <= 0.25) {
......
......@@ -6,8 +6,8 @@
<kcfgfile name=""/>
<group name="General">
<entry name="maximumVolume" type="Int">
<default>100</default>
<entry name="raiseMaximumVolume" type="Bool">
<default>false</default>
</entry>
<entry name="volumeStep" type="Int">
<default>5</default>
......
......@@ -27,7 +27,6 @@ import org.kde.kirigami 2.5 as Kirigami
import org.kde.plasma.private.volume 0.1
Kirigami.FormLayout {
property alias cfg_maximumVolume: maximumVolume.value
property alias cfg_volumeStep: volumeStep.value
property alias cfg_volumeFeedback: volumeFeedback.checked
property alias cfg_outputChangeOsd: outputChangeOsd.checked
......@@ -37,23 +36,6 @@ Kirigami.FormLayout {
}
QQC2.SpinBox {
id: maximumVolume
Kirigami.FormData.label: i18n("Maximum volume:")
from: 10
to: 150
stepSize: 1
editable: true
textFromValue: function(value) {
return value + "%";
}
valueFromText: function(text) {
return parseInt(text);
}
}
QQC2.SpinBox {
id: volumeStep
implicitWidth: maximumVolume.width
......
......@@ -159,12 +159,12 @@ PlasmaComponents.ListItem {
// changes trigger volume changes trigger value changes.
property int volume: Volume
property bool ignoreValueChange: true
property bool forceRaiseMaxVolume: false
readonly property bool raiseMaxVolume: forceRaiseMaxVolume || volume >= PulseAudio.NormalVolume * 1.01
readonly property bool forceRaiseMaxVolume: (raiseMaximumVolumeCheckbox.checked && (type === "sink" || type === "source"))
|| volume >= PulseAudio.NormalVolume * 1.01
Layout.fillWidth: true
minimumValue: PulseAudio.MinimalVolume
maximumValue: raiseMaxVolume ? PulseAudio.MaximalVolume : PulseAudio.NormalVolume
maximumValue: forceRaiseMaxVolume ? PulseAudio.MaximalVolume : PulseAudio.NormalVolume
stepSize: maximumValue / (maximumValue / PulseAudio.NormalVolume * 100.0)
visible: HasVolume
enabled: VolumeWritable
......@@ -281,21 +281,8 @@ PlasmaComponents.ListItem {
function loadDynamicActions() {
contextMenu.clearMenuItems();
// Raise max volume
menuItem = newMenuItem();
menuItem.text = i18n("Raise maximum volume");
menuItem.checkable = true;
menuItem.checked = slider.forceRaiseMaxVolume;
menuItem.clicked.connect(function() {
slider.forceRaiseMaxVolume = !slider.forceRaiseMaxVolume;
if (!slider.forceRaiseMaxVolume && Volume > PulseAudio.NormalVolume) {
Volume = PulseAudio.NormalVolume;
}
});
contextMenu.addMenuItem(menuItem);
// Switch all streams of the relevant kind to this device
if (type == "source" && sourceView.model.count > 1) {
if (type == "source") {
menuItem = newMenuItem();
menuItem.text = i18n("Record all audio via this device");
menuItem.icon = "mic-on" // or "mic-ready" // or "audio-input-microphone-symbolic"
......@@ -303,7 +290,7 @@ PlasmaComponents.ListItem {
PulseObject.switchStreams();
});
contextMenu.addMenuItem(menuItem);
} else if (type == "sink" && sinkView.model.count > 1) {
} else if (type == "sink") {
menuItem = newMenuItem();
menuItem.text = i18n("Play all audio via this device");
menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic"
......
......@@ -35,7 +35,9 @@ Item {
id: main
property bool volumeFeedback: Plasmoid.configuration.volumeFeedback
property int maxVolumeValue: Math.round(Plasmoid.configuration.maximumVolume * PulseAudio.NormalVolume / 100.0)
property int raiseMaxVolumeValue: 150
property int maxVolumeValue: Math.round(raiseMaxVolumeValue * PulseAudio.NormalVolume / 100.0)
property int currentMaxVolumeValue: plasmoid.configuration.raiseMaximumVolume ? maxVolumeValue : PulseAudio.NormalVolume
property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0)
property string displayName: i18n("Audio Volume")
property QtObject draggedStream: null
......@@ -80,7 +82,7 @@ Item {
}
function boundVolume(volume) {
return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue));
return Math.max(PulseAudio.MinimalVolume, Math.min(volume, currentMaxVolumeValue));
}
function volumePercent(volume, max) {
......@@ -95,7 +97,7 @@ Item {
return;
}
var volume = boundVolume(paSinkModel.preferredSink.volume + volumeStep);
var percent = volumePercent(volume, maxVolumeValue);
var percent = volumePercent(volume, currentMaxVolumeValue);
paSinkModel.preferredSink.muted = percent == 0;
paSinkModel.preferredSink.volume = volume;
osd.show(percent);
......@@ -107,7 +109,7 @@ Item {
return;
}
var volume = boundVolume(paSinkModel.preferredSink.volume - volumeStep);
var percent = volumePercent(volume, maxVolumeValue);
var percent = volumePercent(volume, currentMaxVolumeValue);
paSinkModel.preferredSink.muted = percent == 0;
paSinkModel.preferredSink.volume = volume;
osd.show(percent);
......@@ -120,7 +122,7 @@ Item {
}
var toMute = !paSinkModel.preferredSink.muted;
paSinkModel.preferredSink.muted = toMute;
osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, maxVolumeValue));
osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue));
if (!toMute) {
playFeedback();
}
......@@ -536,6 +538,27 @@ Item {
RowLayout {
PlasmaComponents3.CheckBox {
id: raiseMaximumVolumeCheckbox
// Align center, with the devices mute icon. Calculating the size based on SmallToolButton.qml. '4' is margin in ListItem.
Layout.leftMargin: LayoutMirroring.enabled ? 0 : Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + 4
Layout.rightMargin: !LayoutMirroring.enabled ? 0 : Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + 4
spacing: Math.round((Math.ceil(units.iconSizes.small + units.smallSpacing * 2) - raiseMaximumVolumeCheckbox.indicator.width) / 2) + units.smallSpacing
checked: plasmoid.configuration.raiseMaximumVolume
onToggled: {
plasmoid.configuration.raiseMaximumVolume = checked
if (!checked) {
for (var i = 0; i < paSinkModel.rowCount(); i++) {
if (paSinkModel.data(paSinkModel.index(i, 0), paSinkModel.role("Volume")) > PulseAudio.NormalVolume) {
paSinkModel.setData(paSinkModel.index(i, 0), PulseAudio.NormalVolume, paSinkModel.role("Volume"));
}
}
}
}
text: i18n("Raise maximum volume")
enabled: false // Intentionally disabled, see D26256
}
Item {
Layout.fillWidth: true
}
......
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