This file is indexed.

/usr/share/plasma/plasmoids/org.kde.plasma.volume/contents/ui/main.qml is in plasma-pa 4:5.12.4-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
/*
    Copyright 2014-2015 Harald Sitter <sitter@kde.org>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of
    the License or (at your option) version 3 or any later version
    accepted by the membership of KDE e.V. (or its successor approved
    by the membership of KDE e.V.), which shall act as a proxy
    defined in Section 14 of version 3 of the license.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 2.2
import QtQuick.Layouts 1.0

import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.plasma.plasmoid 2.0

import org.kde.plasma.private.volume 0.1

import "../code/icon.js" as Icon

Item {
    id: main

    property bool volumeFeedback: Plasmoid.configuration.volumeFeedback
    property int maxVolumeValue: Math.round(Plasmoid.configuration.maximumVolume * PulseAudio.NormalVolume / 100.0)
    property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0)
    property string displayName: i18n("Audio Volume")
    property QtObject draggedStream: null

    Layout.minimumHeight: units.gridUnit * 12
    Layout.minimumWidth: units.gridUnit * 12
    Layout.preferredHeight: units.gridUnit * 20
    Layout.preferredWidth: units.gridUnit * 20

    Plasmoid.icon: paSinkModel.preferredSink ? Icon.name(paSinkModel.preferredSink.volume, paSinkModel.preferredSink.muted) : Icon.name(0, true)
    Plasmoid.switchWidth: units.gridUnit * 12
    Plasmoid.switchHeight: units.gridUnit * 12
    Plasmoid.toolTipMainText: {
        var sink = paSinkModel.preferredSink;
        if (!sink) {
            return displayName;
        }

        if (sink.muted) {
            return i18n("Audio Muted");
        } else {
            return i18n("Volume at %1%", volumePercent(sink.volume));
        }
    }
    Plasmoid.toolTipSubText: paSinkModel.preferredSink ? paSinkModel.preferredSink.description : ""

    function boundVolume(volume) {
        return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue));
    }

    function volumePercent(volume, max) {
        if (!max) {
            max = PulseAudio.NormalVolume;
        }
        return Math.round(volume / max * 100.0);
    }

    function increaseVolume() {
        if (!paSinkModel.preferredSink) {
            return;
        }
        var volume = boundVolume(paSinkModel.preferredSink.volume + volumeStep);
        var percent = volumePercent(volume, maxVolumeValue);
        paSinkModel.preferredSink.muted = percent == 0;
        paSinkModel.preferredSink.volume = volume;
        osd.show(percent);
        playFeedback();
    }

    function decreaseVolume() {
        if (!paSinkModel.preferredSink) {
            return;
        }
        var volume = boundVolume(paSinkModel.preferredSink.volume - volumeStep);
        var percent = volumePercent(volume, maxVolumeValue);
        paSinkModel.preferredSink.muted = percent == 0;
        paSinkModel.preferredSink.volume = volume;
        osd.show(percent);
        playFeedback();
    }

    function muteVolume() {
        if (!paSinkModel.preferredSink) {
            return;
        }
        var toMute = !paSinkModel.preferredSink.muted;
        paSinkModel.preferredSink.muted = toMute;
        osd.show(toMute ? 0 : volumePercent(paSinkModel.preferredSink.volume, maxVolumeValue));
        playFeedback();
    }

    function increaseMicrophoneVolume() {
        if (!paSourceModel.defaultSource) {
            return;
        }
        var volume = boundVolume(paSourceModel.defaultSource.volume + volumeStep);
        var percent = volumePercent(volume);
        paSourceModel.defaultSource.muted = percent == 0;
        paSourceModel.defaultSource.volume = volume;
        osd.showMicrophone(percent);
    }

    function decreaseMicrophoneVolume() {
        if (!paSourceModel.defaultSource) {
            return;
        }
        var volume = boundVolume(paSourceModel.defaultSource.volume - volumeStep);
        var percent = volumePercent(volume);
        paSourceModel.defaultSource.muted = percent == 0;
        paSourceModel.defaultSource.volume = volume;
        osd.showMicrophone(percent);
    }

    function muteMicrophone() {
        if (!paSourceModel.defaultSource) {
            return;
        }
        var toMute = !paSourceModel.defaultSource.muted;
        paSourceModel.defaultSource.muted = toMute;
        osd.showMicrophone(toMute? 0 : volumePercent(paSourceModel.defaultSource.volume));
    }

    function playFeedback(sinkIndex) {
        if (!volumeFeedback) {
            return;
        }
        if (sinkIndex == undefined) {
            sinkIndex = paSinkModel.preferredSink.index;
        }
        feedback.play(sinkIndex);
    }

    SinkModel {
        id: paSinkModel
    }

    SourceModel {
        id: paSourceModel
    }

    Plasmoid.compactRepresentation: PlasmaCore.IconItem {
        source: plasmoid.icon
        active: mouseArea.containsMouse
        colorGroup: PlasmaCore.ColorScope.colorGroup

        MouseArea {
            id: mouseArea

            property int wheelDelta: 0
            property bool wasExpanded: false

            anchors.fill: parent
            hoverEnabled: true
            acceptedButtons: Qt.LeftButton | Qt.MiddleButton
            onPressed: {
                if (mouse.button == Qt.LeftButton) {
                    wasExpanded = plasmoid.expanded;
                } else if (mouse.button == Qt.MiddleButton) {
                    muteVolume();
                }
            }
            onClicked: {
                if (mouse.button == Qt.LeftButton) {
                    plasmoid.expanded = !wasExpanded;
                }
            }
            onWheel: {
                var delta = wheel.angleDelta.y || wheel.angleDelta.x;
                wheelDelta += delta;
                // Magic number 120 for common "one click"
                // See: http://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop
                while (wheelDelta >= 120) {
                    wheelDelta -= 120;
                    increaseVolume();
                }
                while (wheelDelta <= -120) {
                    wheelDelta += 120;
                    decreaseVolume();
                }
            }
        }
    }

    GlobalActionCollection {
        // KGlobalAccel cannot transition from kmix to something else, so if
        // the user had a custom shortcut set for kmix those would get lost.
        // To avoid this we hijack kmix name and actions. Entirely mental but
        // best we can do to not cause annoyance for the user.
        // The display name actually is updated to whatever registered last
        // though, so as far as user visible strings go we should be fine.
        // As of 2015-07-21:
        //   componentName: kmix
        //   actions: increase_volume, decrease_volume, mute
        name: "kmix"
        displayName: main.displayName
        GlobalAction {
            objectName: "increase_volume"
            text: i18n("Increase Volume")
            shortcut: Qt.Key_VolumeUp
            onTriggered: increaseVolume()
        }
        GlobalAction {
            objectName: "decrease_volume"
            text: i18n("Decrease Volume")
            shortcut: Qt.Key_VolumeDown
            onTriggered: decreaseVolume()
        }
        GlobalAction {
            objectName: "mute"
            text: i18n("Mute")
            shortcut: Qt.Key_VolumeMute
            onTriggered: muteVolume()
        }
        GlobalAction {
            objectName: "increase_microphone_volume"
            text: i18n("Increase Microphone Volume")
            shortcut: Qt.Key_MicVolumeUp
            onTriggered: increaseMicrophoneVolume()
        }
        GlobalAction {
            objectName: "decrease_microphone_volume"
            text: i18n("Decrease Microphone Volume")
            shortcut: Qt.Key_MicVolumeDown
            onTriggered: decreaseMicrophoneVolume()
        }
        GlobalAction {
            objectName: "mic_mute"
            text: i18n("Mute Microphone")
            shortcut: Qt.Key_MicMute
            onTriggered: muteMicrophone()
        }
    }

    VolumeOSD {
        id: osd
    }

    VolumeFeedback {
        id: feedback
    }

    Plasmoid.fullRepresentation: ColumnLayout {
        spacing: units.smallSpacing

        function beginMoveStream(type, stream) {
            if (type == "sink") {
                sourceView.visible = false;
                sourceViewHeader.visible = false;
            } else if (type == "source") {
                sinkView.visible = false;
                sinkViewHeader.visible = false;
            }

            tabBar.currentTab = devicesTab;
        }

        function endMoveStream() {
            tabBar.currentTab = streamsTab;

            sourceView.visible = true;
            sourceViewHeader.visible = true;
            sinkView.visible = true;
            sinkViewHeader.visible = true;
        }

        RowLayout {
            spacing: units.smallSpacing
            Layout.fillWidth: true

            PlasmaComponents.TabBar {
                id: tabBar
                Layout.fillWidth: true
                activeFocusOnTab: true

                PlasmaComponents.TabButton {
                    id: devicesTab
                    text: i18n("Devices")
                }

                PlasmaComponents.TabButton {
                    id: streamsTab
                    text: i18n("Applications")
                }
            }

            PlasmaComponents.ToolButton {
                Layout.alignment: Qt.AlignBottom
                tooltip: plasmoid.action("configure").text
                iconName: "configure"
                Accessible.name: tooltip
                onClicked: {
                    plasmoid.action("configure").trigger();
                }
            }
        }

        PlasmaExtras.ScrollArea {
            id: scrollView;

            Layout.fillWidth: true
            Layout.fillHeight: true

            horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
            flickableItem.boundsBehavior: Flickable.StopAtBounds;

            //our scroll isn't a list of delegates, all internal items are tab focussable, making this redundant
            activeFocusOnTab: false

            Item {
                width: streamsView.visible ? streamsView.width : devicesView.width
                height: streamsView.visible ? streamsView.height : devicesView.height

                ColumnLayout {
                    id: streamsView
                    visible: tabBar.currentTab == streamsTab
                    property int maximumWidth: scrollView.viewport.width
                    width: maximumWidth
                    Layout.maximumWidth: maximumWidth

                    Header {
                        Layout.fillWidth: true
                        visible: sinkInputView.count > 0
                        text: i18n("Playback Streams")
                    }
                    ListView {
                        id: sinkInputView

                        Layout.fillWidth: true
                        Layout.minimumHeight: contentHeight
                        Layout.maximumHeight: contentHeight

                        model: PulseObjectFilterModel {
                            filters: [ { role: "VirtualStream", value: false } ]
                            sourceModel: SinkInputModel {}
                        }
                        boundsBehavior: Flickable.StopAtBounds;
                        delegate: StreamListItem {
                            type: "sink-input"
                            draggable: sinkView.count > 1
                        }
                    }

                    Header {
                        Layout.fillWidth: true
                        visible: sourceOutputView.count > 0
                        text: i18n("Capture Streams")
                    }
                    ListView {
                        id: sourceOutputView

                        Layout.fillWidth: true
                        Layout.minimumHeight: contentHeight
                        Layout.maximumHeight: contentHeight

                        model: PulseObjectFilterModel {
                            filters: [ { role: "VirtualStream", value: false } ]
                            sourceModel: SourceOutputModel {}
                        }
                        boundsBehavior: Flickable.StopAtBounds;
                        delegate: StreamListItem {
                            type: "source-input"
                            draggable: sourceView.count > 1
                        }
                    }
                }

                ColumnLayout {
                    id: devicesView
                    visible: tabBar.currentTab == devicesTab
                    property int maximumWidth: scrollView.viewport.width
                    width: maximumWidth
                    Layout.maximumWidth: maximumWidth

                    Header {
                        id: sinkViewHeader
                        Layout.fillWidth: true
                        visible: sinkView.count > 0
                        text: i18n("Playback Devices")
                    }
                    ListView {
                        id: sinkView

                        Layout.fillWidth: true
                        Layout.minimumHeight: contentHeight
                        Layout.maximumHeight: contentHeight

                        model: PulseObjectFilterModel {
                            sortRole: "SortByDefault"
                            sortOrder: Qt.DescendingOrder
                            sourceModel: paSinkModel
                        }
                        boundsBehavior: Flickable.StopAtBounds;
                        delegate: DeviceListItem {
                            type: "sink"
                        }
                    }

                    Header {
                        id: sourceViewHeader
                        Layout.fillWidth: true
                        visible: sourceView.count > 0
                        text: i18n("Capture Devices")
                    }
                    ListView {
                        id: sourceView

                        Layout.fillWidth: true
                        Layout.minimumHeight: contentHeight
                        Layout.maximumHeight: contentHeight

                        model: PulseObjectFilterModel {
                            sortRole: "SortByDefault"
                            sortOrder: Qt.DescendingOrder
                            sourceModel: paSourceModel
                        }
                        boundsBehavior: Flickable.StopAtBounds;
                        delegate: DeviceListItem {
                            type: "source"
                        }
                    }
                }

                PlasmaExtras.Heading {
                    level: 4
                    opacity: 0.8
                    width: parent.width
                    height: scrollView.height
                    visible: streamsView.visible && !sinkInputView.count && !sourceOutputView.count
                    text: i18n("No applications playing or recording audio")
                    wrapMode: Text.WordWrap
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                }

                PlasmaExtras.Heading {
                    level: 4
                    opacity: 0.8
                    width: parent.width
                    height: scrollView.height
                    visible: devicesView.visible && !sinkView.count && !sourceView.count
                    text: i18n("No output or input devices found")
                    wrapMode: Text.WordWrap
                    verticalAlignment: Text.AlignVCenter
                    horizontalAlignment: Text.AlignHCenter
                }
            }
        }
    }
}