Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/main.qml
Show All 29 Lines | |||||
30 | import org.kde.plasma.private.volume 0.1 | 30 | import org.kde.plasma.private.volume 0.1 | ||
31 | 31 | | |||
32 | import "../code/icon.js" as Icon | 32 | import "../code/icon.js" as Icon | ||
33 | 33 | | |||
34 | Item { | 34 | Item { | ||
35 | id: main | 35 | id: main | ||
36 | 36 | | |||
37 | property bool volumeFeedback: Plasmoid.configuration.volumeFeedback | 37 | property bool volumeFeedback: Plasmoid.configuration.volumeFeedback | ||
38 | property bool globalMute: Plasmoid.configuration.globalMute | ||||
38 | property int raiseMaxVolumeValue: 150 | 39 | property int raiseMaxVolumeValue: 150 | ||
39 | property int maxVolumeValue: Math.round(raiseMaxVolumeValue * PulseAudio.NormalVolume / 100.0) | 40 | property int maxVolumeValue: Math.round(raiseMaxVolumeValue * PulseAudio.NormalVolume / 100.0) | ||
40 | property int currentMaxVolumeValue: plasmoid.configuration.raiseMaximumVolume ? maxVolumeValue : PulseAudio.NormalVolume | 41 | property int currentMaxVolumeValue: plasmoid.configuration.raiseMaximumVolume ? maxVolumeValue : PulseAudio.NormalVolume | ||
41 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | 42 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | ||
42 | property string displayName: i18n("Audio Volume") | 43 | property string displayName: i18n("Audio Volume") | ||
43 | property QtObject draggedStream: null | 44 | property QtObject draggedStream: null | ||
44 | 45 | | |||
45 | // DEFAULT_SINK_NAME in module-always-sink.c | 46 | // DEFAULT_SINK_NAME in module-always-sink.c | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 108 | function decreaseVolume() { | |||
116 | playFeedback(); | 117 | playFeedback(); | ||
117 | } | 118 | } | ||
118 | 119 | | |||
119 | function muteVolume() { | 120 | function muteVolume() { | ||
120 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | 121 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | ||
121 | return; | 122 | return; | ||
122 | } | 123 | } | ||
123 | var toMute = !paSinkModel.preferredSink.muted; | 124 | var toMute = !paSinkModel.preferredSink.muted; | ||
125 | if (toMute) { | ||||
126 | enableGlobalMute(); | ||||
127 | osd.show(0); | ||||
128 | } else { | ||||
129 | if (globalMute) { | ||||
130 | disableGlobalMute(); | ||||
131 | } | ||||
124 | paSinkModel.preferredSink.muted = toMute; | 132 | paSinkModel.preferredSink.muted = toMute; | ||
125 | osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue)); | 133 | osd.show(volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue)); | ||
126 | if (!toMute) { | | |||
127 | playFeedback(); | 134 | playFeedback(); | ||
128 | } | 135 | } | ||
129 | } | 136 | } | ||
130 | 137 | | |||
131 | function increaseMicrophoneVolume() { | 138 | function increaseMicrophoneVolume() { | ||
132 | if (!paSourceModel.defaultSource) { | 139 | if (!paSourceModel.defaultSource) { | ||
133 | return; | 140 | return; | ||
134 | } | 141 | } | ||
Show All 29 Lines | 170 | if (!volumeFeedback) { | |||
164 | return; | 171 | return; | ||
165 | } | 172 | } | ||
166 | if (sinkIndex == undefined) { | 173 | if (sinkIndex == undefined) { | ||
167 | sinkIndex = paSinkModel.preferredSink.index; | 174 | sinkIndex = paSinkModel.preferredSink.index; | ||
168 | } | 175 | } | ||
169 | feedback.play(sinkIndex); | 176 | feedback.play(sinkIndex); | ||
170 | } | 177 | } | ||
171 | 178 | | |||
179 | function enableGlobalMute() { | ||||
180 | var role = paSinkModel.role("Muted"); | ||||
181 | var rowCount = paSinkModel.rowCount(); | ||||
182 | // List for devices that are already muted. Will use to keep muted after disable GlobalMute. | ||||
183 | var globalMuteDevices = []; | ||||
184 | | ||||
185 | for (var i = 0; i < rowCount; i++) { | ||||
186 | var idx = paSinkModel.index(i, 0); | ||||
187 | var name = paSinkModel.data(idx, paSinkModel.role("Name")); | ||||
188 | if (paSinkModel.data(idx, role) === false) { | ||||
189 | paSinkModel.setData(idx, true, role); | ||||
190 | } else { | ||||
191 | globalMuteDevices.push(name + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex"))); | ||||
192 | } | ||||
193 | } | ||||
194 | // If all the devices were muted, will unmute them all with disable GlobalMute. | ||||
195 | plasmoid.configuration.globalMuteDevices = globalMuteDevices.length < rowCount ? globalMuteDevices : []; | ||||
196 | plasmoid.configuration.globalMute = true; | ||||
197 | globalMute = true; | ||||
198 | } | ||||
199 | | ||||
200 | function disableGlobalMute() { | ||||
201 | var role = paSinkModel.role("Muted"); | ||||
202 | for (var i = 0; i < paSinkModel.rowCount(); i++) { | ||||
203 | var idx = paSinkModel.index(i, 0); | ||||
204 | var name = paSinkModel.data(idx, paSinkModel.role("Name")) + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex")); | ||||
205 | if (plasmoid.configuration.globalMuteDevices.indexOf(name) === -1) { | ||||
206 | paSinkModel.setData(idx, false, role); | ||||
207 | } | ||||
208 | } | ||||
209 | plasmoid.configuration.globalMuteDevices = []; | ||||
210 | plasmoid.configuration.globalMute = false; | ||||
211 | globalMute = false; | ||||
212 | } | ||||
213 | | ||||
172 | SinkModel { | 214 | SinkModel { | ||
173 | id: paSinkModel | 215 | id: paSinkModel | ||
174 | 216 | | |||
175 | property bool initalDefaultSinkIsSet: false | 217 | property bool initalDefaultSinkIsSet: false | ||
176 | 218 | | |||
177 | onDefaultSinkChanged: { | 219 | onDefaultSinkChanged: { | ||
178 | if (!defaultSink || !plasmoid.configuration.outputChangeOsd) { | 220 | if (!defaultSink || !plasmoid.configuration.outputChangeOsd) { | ||
179 | return; | 221 | return; | ||
Show All 18 Lines | 236 | if (!icon) { | |||
198 | } | 240 | } | ||
199 | } | 241 | } | ||
200 | 242 | | |||
201 | if (!icon) { | 243 | if (!icon) { | ||
202 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | 244 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | ||
203 | } | 245 | } | ||
204 | osd.showText(icon, description); | 246 | osd.showText(icon, description); | ||
205 | } | 247 | } | ||
248 | | ||||
249 | onRowsInserted: { | ||||
250 | if (globalMute) { | ||||
251 | var role = paSinkModel.role("Muted"); | ||||
252 | for (var i = 0; i < paSinkModel.rowCount(); i++) { | ||||
253 | var idx = paSinkModel.index(i, 0); | ||||
254 | if (paSinkModel.data(idx, role) === false) { | ||||
255 | paSinkModel.setData(idx, true, role); | ||||
256 | } | ||||
257 | } | ||||
258 | } | ||||
259 | } | ||||
206 | } | 260 | } | ||
207 | 261 | | |||
208 | SourceModel { | 262 | SourceModel { | ||
209 | id: paSourceModel | 263 | id: paSourceModel | ||
210 | } | 264 | } | ||
211 | 265 | | |||
212 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | 266 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | ||
213 | source: plasmoid.icon | 267 | source: plasmoid.icon | ||
▲ Show 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | 595 | PlasmaComponents3.CheckBox { | |||
559 | enabled: false // Intentionally disabled, see D26256 | 613 | enabled: false // Intentionally disabled, see D26256 | ||
560 | } | 614 | } | ||
561 | 615 | | |||
562 | Item { | 616 | Item { | ||
563 | Layout.fillWidth: true | 617 | Layout.fillWidth: true | ||
564 | } | 618 | } | ||
565 | 619 | | |||
566 | PlasmaComponents.ToolButton { | 620 | PlasmaComponents.ToolButton { | ||
621 | id: globalMuteCheckbox | ||||
622 | iconName: "audio-volume-muted" | ||||
623 | onClicked: { | ||||
624 | if (!globalMute) { | ||||
625 | enableGlobalMute(); | ||||
626 | } else { | ||||
627 | disableGlobalMute(); | ||||
628 | } | ||||
629 | } | ||||
630 | checked: globalMute | ||||
631 | tooltip: i18n("Force mute all playback devices") | ||||
632 | } | ||||
633 | | ||||
634 | PlasmaComponents.ToolButton { | ||||
567 | tooltip: plasmoid.action("configure").text | 635 | tooltip: plasmoid.action("configure").text | ||
568 | iconName: "configure" | 636 | iconName: "configure" | ||
569 | Accessible.name: tooltip | 637 | Accessible.name: tooltip | ||
570 | onClicked: plasmoid.action("configure").trigger() | 638 | onClicked: plasmoid.action("configure").trigger() | ||
571 | } | 639 | } | ||
572 | } | 640 | } | ||
573 | } | 641 | } | ||
574 | 642 | | |||
575 | Component.onCompleted: { | 643 | Component.onCompleted: { | ||
ngraham: This makes me nervous. How do we know it will have initialized after 200 ms? Is there an… | |||||
576 | MicrophoneIndicator.init(); | 644 | MicrophoneIndicator.init(); | ||
577 | } | 645 | } | ||
578 | } | 646 | } |
This makes me nervous. How do we know it will have initialized after 200 ms? Is there an onFinished signal we can listen for or something? Could we make one?