Warning, /plasma/plasma-bigscreen/containments/homescreen/package/contents/ui/indicators/Volume.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Aditya Mehra <Aix.m@outlook.com> 0003 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 import QtQuick 2.14 0009 import QtQuick.Layouts 1.14 0010 import org.kde.plasma.core 2.0 as PlasmaCore 0011 import org.kde.plasma.private.volume 0012 import org.kde.kirigami 2.12 as Kirigami 0013 import org.kde.plasma.private.nanoshell as NanoShell 0014 import "code/icon.js" as Icon 0015 0016 AbstractIndicator { 0017 id: paIcon 0018 0019 property bool volumeFeedback: true 0020 property int maxVolumeValue: Math.round(100 * PulseAudio.NormalVolume / 100.0) 0021 property int currentMaxVolumePercent: 100 0022 property int volumeStep: Math.round(5 * PulseAudio.NormalVolume / 100.0) 0023 readonly property string dummyOutputName: "auto_null" 0024 icon.name: paSinkModel.preferredSink && !isDummyOutput(paSinkModel.preferredSink) ? Icon.name(paSinkModel.preferredSink.volume, paSinkModel.preferredSink.muted) 0025 : Icon.name(0, true) 0026 0027 function isDummyOutput(output) { 0028 return output && output.name === dummyOutputName; 0029 } 0030 0031 function boundVolume(volume) { 0032 return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue)); 0033 } 0034 0035 function volumePercent(volume, max){ 0036 if(!max) { 0037 max = PulseAudio.NormalVolume; 0038 } 0039 return Math.round(volume / max * 100.0); 0040 } 0041 0042 function playFeedback(sinkIndex) { 0043 if(!volumeFeedback){ 0044 return; 0045 } 0046 if(sinkIndex == undefined) { 0047 sinkIndex = paSinkModel.preferredSink.index; 0048 } 0049 feedback.play(sinkIndex) 0050 } 0051 0052 function increaseVolume() { 0053 if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { 0054 return; 0055 } 0056 0057 var volume = boundVolume(paSinkModel.preferredSink.volume + volumeStep); 0058 var percent = volumePercent(volume, maxVolumeValue); 0059 paSinkModel.preferredSink.muted = percent == 0; 0060 paSinkModel.preferredSink.volume = volume; 0061 osd.show(percent, currentMaxVolumePercent); 0062 playFeedback(); 0063 0064 } 0065 0066 function decreaseVolume() { 0067 if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { 0068 return; 0069 } 0070 0071 var volume = boundVolume(paSinkModel.preferredSink.volume - volumeStep); 0072 var percent = volumePercent(volume, maxVolumeValue); 0073 paSinkModel.preferredSink.muted = percent == 0; 0074 paSinkModel.preferredSink.volume = volume; 0075 osd.show(percent, currentMaxVolumePercent); 0076 playFeedback(); 0077 } 0078 0079 0080 0081 function muteVolume() { 0082 if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { 0083 return; 0084 } 0085 0086 var toMute = !paSinkModel.preferredSink.muted; 0087 paSinkModel.preferredSink.muted = toMute; 0088 osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, maxVolumeValue)); 0089 if (!toMute) { 0090 playFeedback(); 0091 } 0092 } 0093 0094 SinkModel { 0095 id: paSinkModel 0096 } 0097 0098 VolumeOSD { 0099 id: osd 0100 } 0101 0102 VolumeFeedback { 0103 id: feedback 0104 } 0105 0106 GlobalActionCollection { 0107 // KGlobalAccel cannot transition from kmix to something else, so if 0108 // the user had a custom shortcut set for kmix those would get lost. 0109 // To avoid this we hijack kmix name and actions. Entirely mental but 0110 // best we can do to not cause annoyance for the user. 0111 // The display name actually is updated to whatever registered last 0112 // though, so as far as user visible strings go we should be fine. 0113 // As of 2015-07-21: 0114 // componentName: kmix 0115 // actions: increase_volume, decrease_volume, mute 0116 name: "kmix" 0117 0118 GlobalAction { 0119 objectName: "increase_volume" 0120 text: i18n("Increase Volume") 0121 shortcut: Qt.Key_VolumeUp 0122 onTriggered: increaseVolume() 0123 } 0124 0125 GlobalAction { 0126 objectName: "decrease_volume" 0127 text: i18n("Decrease Volume") 0128 shortcut: Qt.Key_VolumeDown 0129 onTriggered: decreaseVolume() 0130 } 0131 0132 GlobalAction { 0133 objectName: "mute" 0134 text: i18n("Mute") 0135 shortcut: Qt.Key_VolumeMute 0136 onTriggered: muteVolume() 0137 } 0138 0139 } 0140 0141 onClicked: { 0142 NanoShell.StartupFeedback.open( 0143 "headphone", 0144 i18n("Audio Device chooser"), 0145 paIcon.Kirigami.ScenePosition.x + paIcon.width/2, 0146 paIcon.Kirigami.ScenePosition.y + paIcon.height/2, 0147 Math.min(paIcon.width, paIcon.height)); 0148 Plasmoid.executeCommand("plasma-settings -s -m kcm_mediacenter_audiodevice") 0149 } 0150 }