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 69 Lines • ▼ Show 20 Line(s) | 107 | function decreaseVolume() { | |||
115 | playFeedback(); | 116 | playFeedback(); | ||
116 | } | 117 | } | ||
117 | 118 | | |||
118 | function muteVolume() { | 119 | function muteVolume() { | ||
119 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | 120 | if (!paSinkModel.preferredSink || isDummyOutput(paSinkModel.preferredSink)) { | ||
120 | return; | 121 | return; | ||
121 | } | 122 | } | ||
122 | var toMute = !paSinkModel.preferredSink.muted; | 123 | var toMute = !paSinkModel.preferredSink.muted; | ||
124 | if (toMute) { | ||||
125 | enableGlobalMute(); | ||||
126 | osd.show(0); | ||||
127 | } else { | ||||
128 | if (globalMute) { | ||||
129 | disableGlobalMute(); | ||||
130 | } | ||||
123 | paSinkModel.preferredSink.muted = toMute; | 131 | paSinkModel.preferredSink.muted = toMute; | ||
124 | osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue)); | 132 | osd.show(volumePercent(paSinkModel.preferredSink.volume, currentMaxVolumeValue)); | ||
125 | if (!toMute) { | | |||
126 | playFeedback(); | 133 | playFeedback(); | ||
127 | } | 134 | } | ||
128 | } | 135 | } | ||
129 | 136 | | |||
130 | function increaseMicrophoneVolume() { | 137 | function increaseMicrophoneVolume() { | ||
131 | if (!paSourceModel.defaultSource) { | 138 | if (!paSourceModel.defaultSource) { | ||
132 | return; | 139 | return; | ||
133 | } | 140 | } | ||
Show All 29 Lines | 169 | if (!volumeFeedback) { | |||
163 | return; | 170 | return; | ||
164 | } | 171 | } | ||
165 | if (sinkIndex == undefined) { | 172 | if (sinkIndex == undefined) { | ||
166 | sinkIndex = paSinkModel.preferredSink.index; | 173 | sinkIndex = paSinkModel.preferredSink.index; | ||
167 | } | 174 | } | ||
168 | feedback.play(sinkIndex); | 175 | feedback.play(sinkIndex); | ||
169 | } | 176 | } | ||
170 | 177 | | |||
178 | function enableGlobalMute() { | ||||
179 | var role = paSinkModel.role("Muted"); | ||||
180 | var rowCount = paSinkModel.rowCount(); | ||||
181 | // List for devices that are already muted. Will use to keep muted after disable GlobalMute. | ||||
182 | var globalMuteDevices = []; | ||||
183 | | ||||
184 | for (var i = 0; i < rowCount; i++) { | ||||
185 | var idx = paSinkModel.index(i, 0); | ||||
186 | var name = paSinkModel.data(idx, paSinkModel.role("Name")); | ||||
187 | if (paSinkModel.data(idx, role) === false) { | ||||
188 | paSinkModel.setData(idx, true, role); | ||||
189 | } else { | ||||
190 | globalMuteDevices.push(name + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex"))); | ||||
191 | } | ||||
192 | } | ||||
193 | // If all the devices were muted, will unmute them all with disable GlobalMute. | ||||
194 | plasmoid.configuration.globalMuteDevices = globalMuteDevices.length < rowCount ? globalMuteDevices : []; | ||||
195 | plasmoid.configuration.globalMute = true; | ||||
196 | globalMute = true; | ||||
197 | } | ||||
198 | | ||||
199 | function disableGlobalMute() { | ||||
200 | var role = paSinkModel.role("Muted"); | ||||
201 | for (var i = 0; i < paSinkModel.rowCount(); i++) { | ||||
202 | var idx = paSinkModel.index(i, 0); | ||||
203 | var name = paSinkModel.data(idx, paSinkModel.role("Name")) + "." + paSinkModel.data(idx, paSinkModel.role("ActivePortIndex")); | ||||
204 | if (plasmoid.configuration.globalMuteDevices.indexOf(name) === -1) { | ||||
205 | paSinkModel.setData(idx, false, role); | ||||
206 | } | ||||
207 | } | ||||
208 | plasmoid.configuration.globalMuteDevices = []; | ||||
209 | plasmoid.configuration.globalMute = false; | ||||
210 | globalMute = false; | ||||
211 | } | ||||
212 | | ||||
171 | SinkModel { | 213 | SinkModel { | ||
172 | id: paSinkModel | 214 | id: paSinkModel | ||
173 | 215 | | |||
174 | property bool initalDefaultSinkIsSet: false | 216 | property bool initalDefaultSinkIsSet: false | ||
175 | 217 | | |||
176 | onDefaultSinkChanged: { | 218 | onDefaultSinkChanged: { | ||
177 | if (!defaultSink || !plasmoid.configuration.outputChangeOsd) { | 219 | if (!defaultSink || !plasmoid.configuration.outputChangeOsd) { | ||
178 | return; | 220 | return; | ||
Show All 18 Lines | 235 | if (!icon) { | |||
197 | } | 239 | } | ||
198 | } | 240 | } | ||
199 | 241 | | |||
200 | if (!icon) { | 242 | if (!icon) { | ||
201 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | 243 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | ||
202 | } | 244 | } | ||
203 | osd.showText(icon, description); | 245 | osd.showText(icon, description); | ||
204 | } | 246 | } | ||
247 | | ||||
248 | onRowsInserted: { | ||||
249 | if (globalMute) { | ||||
250 | var role = paSinkModel.role("Muted"); | ||||
251 | for (var i = 0; i < paSinkModel.rowCount(); i++) { | ||||
252 | var idx = paSinkModel.index(i, 0); | ||||
253 | if (paSinkModel.data(idx, role) === false) { | ||||
254 | paSinkModel.setData(idx, true, role); | ||||
255 | } | ||||
256 | } | ||||
257 | } | ||||
258 | } | ||||
205 | } | 259 | } | ||
206 | 260 | | |||
207 | SourceModel { | 261 | SourceModel { | ||
208 | id: paSourceModel | 262 | id: paSourceModel | ||
209 | } | 263 | } | ||
210 | 264 | | |||
211 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | 265 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | ||
212 | source: plasmoid.icon | 266 | source: plasmoid.icon | ||
▲ Show 20 Lines • Show All 344 Lines • ▼ Show 20 Line(s) | 594 | PlasmaComponents3.CheckBox { | |||
557 | text: i18n("Raise maximum volume") | 611 | text: i18n("Raise maximum volume") | ||
558 | } | 612 | } | ||
559 | 613 | | |||
560 | Item { | 614 | Item { | ||
561 | Layout.fillWidth: true | 615 | Layout.fillWidth: true | ||
562 | } | 616 | } | ||
563 | 617 | | |||
564 | PlasmaComponents.ToolButton { | 618 | PlasmaComponents.ToolButton { | ||
619 | id: globalMuteCheckbox | ||||
620 | iconName: "audio-volume-muted" | ||||
621 | onClicked: { | ||||
622 | if (!globalMute) { | ||||
623 | enableGlobalMute(); | ||||
624 | } else { | ||||
625 | disableGlobalMute(); | ||||
626 | } | ||||
627 | } | ||||
628 | checked: globalMute | ||||
629 | tooltip: i18n("Force mute all playback devices") | ||||
630 | } | ||||
631 | | ||||
632 | PlasmaComponents.ToolButton { | ||||
565 | tooltip: plasmoid.action("configure").text | 633 | tooltip: plasmoid.action("configure").text | ||
566 | iconName: "configure" | 634 | iconName: "configure" | ||
567 | Accessible.name: tooltip | 635 | Accessible.name: tooltip | ||
568 | onClicked: plasmoid.action("configure").trigger() | 636 | onClicked: plasmoid.action("configure").trigger() | ||
569 | } | 637 | } | ||
570 | } | 638 | } | ||
571 | } | 639 | } | ||
572 | 640 | | |||
573 | Component.onCompleted: { | 641 | Component.onCompleted: { | ||
ngraham: This makes me nervous. How do we know it will have initialized after 200 ms? Is there an… | |||||
574 | MicrophoneIndicator.init(); | 642 | MicrophoneIndicator.init(); | ||
575 | } | 643 | } | ||
576 | } | 644 | } |
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?