Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/main.qml
Show All 27 Lines | |||||
28 | 28 | | |||
29 | import org.kde.plasma.private.volume 0.1 | 29 | import org.kde.plasma.private.volume 0.1 | ||
30 | 30 | | |||
31 | import "../code/icon.js" as Icon | 31 | import "../code/icon.js" as Icon | ||
32 | 32 | | |||
33 | Item { | 33 | Item { | ||
34 | id: main | 34 | id: main | ||
35 | 35 | | |||
36 | property int volumeStep: 65536 / 15 | 36 | property int maxVolumePercent: 100 | ||
37 | property int maxVolumeValue: Math.round(maxVolumePercent * PulseAudio.NormalVolume / 100.0) | ||||
38 | property int volumeStep: PulseAudio.NormalVolume / 15 | ||||
37 | property string displayName: i18n("Audio Volume") | 39 | property string displayName: i18n("Audio Volume") | ||
38 | 40 | | |||
39 | Layout.minimumHeight: units.gridUnit * 12 | 41 | Layout.minimumHeight: units.gridUnit * 12 | ||
40 | Layout.minimumWidth: units.gridUnit * 12 | 42 | Layout.minimumWidth: units.gridUnit * 12 | ||
41 | Layout.preferredHeight: units.gridUnit * 20 | 43 | Layout.preferredHeight: units.gridUnit * 20 | ||
42 | Layout.preferredWidth: units.gridUnit * 20 | 44 | Layout.preferredWidth: units.gridUnit * 20 | ||
43 | 45 | | |||
44 | Plasmoid.icon: sinkModel.defaultSink ? Icon.name(sinkModel.defaultSink.volume, sinkModel.defaultSink.muted) : Icon.name(0, true) | 46 | Plasmoid.icon: sinkModel.defaultSink ? Icon.name(sinkModel.defaultSink.volume, sinkModel.defaultSink.muted) : Icon.name(0, true) | ||
45 | Plasmoid.switchWidth: units.gridUnit * 12 | 47 | Plasmoid.switchWidth: units.gridUnit * 12 | ||
46 | Plasmoid.switchHeight: units.gridUnit * 12 | 48 | Plasmoid.switchHeight: units.gridUnit * 12 | ||
47 | Plasmoid.toolTipMainText: displayName | 49 | Plasmoid.toolTipMainText: displayName | ||
48 | Plasmoid.toolTipSubText: sinkModel.defaultSink ? i18n("Volume at %1%\n%2", volumePercent(sinkModel.defaultSink.volume), sinkModel.defaultSink.description) : "" | 50 | Plasmoid.toolTipSubText: sinkModel.defaultSink ? i18n("Volume at %1%\n%2", volumePercent(sinkModel.defaultSink.volume), sinkModel.defaultSink.description) : "" | ||
49 | 51 | | |||
50 | function bound(value, min, max) { | 52 | function boundVolume(volume) { | ||
51 | return Math.max(min, Math.min(value, max)); | 53 | return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue)); | ||
52 | } | 54 | } | ||
53 | 55 | | |||
54 | function volumePercent(volume) { | 56 | function volumePercent(volume, max) { | ||
55 | return Math.round(100 * volume / 65536); | 57 | if (!max) { | ||
58 | max = PulseAudio.NormalVolume; | ||||
59 | } | ||||
60 | return Math.round(volume / max * 100.0); | ||||
56 | } | 61 | } | ||
57 | 62 | | |||
58 | function increaseVolume(showOsd) { | 63 | function increaseVolume(showOsd) { | ||
59 | if (!sinkModel.defaultSink) { | 64 | if (!sinkModel.defaultSink) { | ||
60 | return; | 65 | return; | ||
61 | } | 66 | } | ||
62 | var volume = bound(sinkModel.defaultSink.volume + volumeStep, 0, 65536); | 67 | var volume = boundVolume(sinkModel.defaultSink.volume + volumeStep); | ||
63 | sinkModel.defaultSink.volume = volume; | 68 | sinkModel.defaultSink.volume = volume; | ||
64 | if (showOsd) { | 69 | if (showOsd) { | ||
65 | osd.show(volumePercent(volume)); | 70 | osd.show(volumePercent(volume, maxVolumeValue)); | ||
66 | } | 71 | } | ||
67 | } | 72 | } | ||
68 | 73 | | |||
69 | function decreaseVolume(showOsd) { | 74 | function decreaseVolume(showOsd) { | ||
70 | if (!sinkModel.defaultSink) { | 75 | if (!sinkModel.defaultSink) { | ||
71 | return; | 76 | return; | ||
72 | } | 77 | } | ||
73 | var volume = bound(sinkModel.defaultSink.volume - volumeStep, 0, 65536); | 78 | var volume = boundVolume(sinkModel.defaultSink.volume - volumeStep); | ||
74 | sinkModel.defaultSink.volume = volume; | 79 | sinkModel.defaultSink.volume = volume; | ||
75 | if (showOsd) { | 80 | if (showOsd) { | ||
76 | osd.show(volumePercent(volume)); | 81 | osd.show(volumePercent(volume, maxVolumeValue)); | ||
77 | } | 82 | } | ||
78 | } | 83 | } | ||
79 | 84 | | |||
80 | function muteVolume(showOsd) { | 85 | function muteVolume(showOsd) { | ||
81 | if (!sinkModel.defaultSink) { | 86 | if (!sinkModel.defaultSink) { | ||
82 | return; | 87 | return; | ||
83 | } | 88 | } | ||
84 | var toMute = !sinkModel.defaultSink.muted; | 89 | var toMute = !sinkModel.defaultSink.muted; | ||
85 | sinkModel.defaultSink.muted = toMute; | 90 | sinkModel.defaultSink.muted = toMute; | ||
86 | if (showOsd) { | 91 | if (showOsd) { | ||
87 | osd.show(toMute ? 0 : volumePercent(sinkModel.defaultSink.volume)); | 92 | osd.show(toMute ? 0 : volumePercent(sinkModel.defaultSink.volume, maxVolumeValue)); | ||
88 | } | 93 | } | ||
89 | } | 94 | } | ||
90 | 95 | | |||
91 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | 96 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | ||
92 | source: plasmoid.icon | 97 | source: plasmoid.icon | ||
93 | active: mouseArea.containsMouse | 98 | active: mouseArea.containsMouse | ||
94 | colorGroup: PlasmaCore.ColorScope.colorGroup | 99 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
95 | 100 | | |||
▲ Show 20 Lines • Show All 206 Lines • Show Last 20 Lines |