Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/main.qml
Show All 15 Lines | 1 | /* | |||
---|---|---|---|---|---|
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.2 | 21 | import QtQuick 2.2 | ||
22 | import QtQuick.Layouts 1.0 | 22 | import QtQuick.Layouts 1.0 | ||
23 | 23 | | |||
24 | import org.kde.plasma.core 2.0 as PlasmaCore | 24 | import org.kde.plasma.core 2.1 as PlasmaCore | ||
25 | import org.kde.plasma.components 2.0 as PlasmaComponents | 25 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | 26 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||
27 | import org.kde.plasma.plasmoid 2.0 | 27 | import org.kde.plasma.plasmoid 2.0 | ||
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 bool volumeFeedback: Plasmoid.configuration.volumeFeedback | 36 | property bool volumeFeedback: Plasmoid.configuration.volumeFeedback | ||
37 | property int maxVolumeValue: Math.round(Plasmoid.configuration.maximumVolume * PulseAudio.NormalVolume / 100.0) | 37 | property int maxVolumeValue: Math.round(Plasmoid.configuration.maximumVolume * PulseAudio.NormalVolume / 100.0) | ||
38 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | 38 | property int volumeStep: Math.round(Plasmoid.configuration.volumeStep * PulseAudio.NormalVolume / 100.0) | ||
39 | property string displayName: i18n("Audio Volume") | 39 | property string displayName: i18n("Audio Volume") | ||
40 | property QtObject draggedStream: null | 40 | property QtObject draggedStream: null | ||
41 | 41 | | |||
42 | // DEFAULT_SINK_NAME in module-always-sink.c | ||||
43 | readonly property string dummyOutputName: "auto_null" | ||||
44 | | ||||
42 | Layout.minimumHeight: units.gridUnit * 18 | 45 | Layout.minimumHeight: units.gridUnit * 18 | ||
43 | Layout.minimumWidth: units.gridUnit * 18 | 46 | Layout.minimumWidth: units.gridUnit * 18 | ||
44 | Layout.preferredHeight: units.gridUnit * 20 | 47 | Layout.preferredHeight: units.gridUnit * 20 | ||
45 | Layout.preferredWidth: units.gridUnit * 20 | 48 | Layout.preferredWidth: units.gridUnit * 20 | ||
46 | 49 | | |||
47 | Plasmoid.icon: paSinkModel.preferredSink && !isDummyOutput(paSinkModel.preferredSink) ? Icon.name(paSinkModel.preferredSink.volume, paSinkModel.preferredSink.muted) | 50 | Plasmoid.icon: paSinkModel.preferredSink && !isDummyOutput(paSinkModel.preferredSink) ? Icon.name(paSinkModel.preferredSink.volume, paSinkModel.preferredSink.muted) | ||
48 | : Icon.name(0, true) | 51 | : Icon.name(0, true) | ||
49 | Plasmoid.switchWidth: units.gridUnit * 18 | 52 | Plasmoid.switchWidth: units.gridUnit * 18 | ||
50 | Plasmoid.switchHeight: units.gridUnit * 18 | 53 | Plasmoid.switchHeight: units.gridUnit * 18 | ||
51 | Plasmoid.toolTipMainText: { | 54 | Plasmoid.toolTipMainText: { | ||
52 | var sink = paSinkModel.preferredSink; | 55 | var sink = paSinkModel.preferredSink; | ||
53 | if (!sink) { | 56 | if (!sink || isDummyOutput(sink)) { | ||
54 | return displayName; | 57 | return displayName; | ||
55 | } | 58 | } | ||
56 | 59 | | |||
57 | if (sink.muted) { | 60 | if (sink.muted) { | ||
58 | return i18n("Audio Muted"); | 61 | return i18n("Audio Muted"); | ||
59 | } else { | 62 | } else { | ||
60 | return i18n("Volume at %1%", volumePercent(sink.volume)); | 63 | return i18n("Volume at %1%", volumePercent(sink.volume)); | ||
61 | } | 64 | } | ||
62 | } | 65 | } | ||
63 | Plasmoid.toolTipSubText: paSinkModel.preferredSink ? paSinkModel.preferredSink.description : "" | 66 | Plasmoid.toolTipSubText: paSinkModel.preferredSink && !isDummyOutput(paSinkModel.preferredSink) ? paSinkModel.preferredSink.description : "" | ||
64 | 67 | | |||
65 | function isDummyOutput(output) { | 68 | function isDummyOutput(output) { | ||
66 | // DEFAULT_SINK_NAME in module-always-sink.c | 69 | return output && output.name === dummyOutputName; | ||
67 | return output && output.name === "auto_null" | | |||
68 | } | 70 | } | ||
69 | 71 | | |||
70 | function boundVolume(volume) { | 72 | function boundVolume(volume) { | ||
71 | return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue)); | 73 | return Math.max(PulseAudio.MinimalVolume, Math.min(volume, maxVolumeValue)); | ||
72 | } | 74 | } | ||
73 | 75 | | |||
74 | function volumePercent(volume, max) { | 76 | function volumePercent(volume, max) { | ||
75 | if (!max) { | 77 | if (!max) { | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 165 | onDefaultSinkChanged: { | |||
166 | } | 168 | } | ||
167 | 169 | | |||
168 | // avoid showing a OSD on startup | 170 | // avoid showing a OSD on startup | ||
169 | if (!initalDefaultSinkIsSet) { | 171 | if (!initalDefaultSinkIsSet) { | ||
170 | initalDefaultSinkIsSet = true; | 172 | initalDefaultSinkIsSet = true; | ||
171 | return; | 173 | return; | ||
172 | } | 174 | } | ||
173 | 175 | | |||
176 | var description = defaultSink.description; | ||||
177 | if (isDummyOutput(defaultSink)) { | ||||
178 | description = i18n("No output device"); | ||||
179 | } | ||||
180 | | ||||
174 | var icon = Icon.formFactorIcon(defaultSink.formFactor); | 181 | var icon = Icon.formFactorIcon(defaultSink.formFactor); | ||
175 | if (!icon) { | 182 | if (!icon) { | ||
176 | // Show "muted" icon for Dummy output | 183 | // Show "muted" icon for Dummy output | ||
177 | if (isDummyOutput(defaultSink)) { | 184 | if (isDummyOutput(defaultSink)) { | ||
178 | icon = "audio-volume-muted"; | 185 | icon = "audio-volume-muted"; | ||
179 | } | 186 | } | ||
180 | } | 187 | } | ||
181 | 188 | | |||
182 | if (!icon) { | 189 | if (!icon) { | ||
183 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | 190 | icon = Icon.name(defaultSink.volume, defaultSink.muted); | ||
184 | } | 191 | } | ||
185 | osd.showText(icon, defaultSink.description); | 192 | osd.showText(icon, description); | ||
186 | } | 193 | } | ||
187 | } | 194 | } | ||
188 | 195 | | |||
189 | SourceModel { | 196 | SourceModel { | ||
190 | id: paSourceModel | 197 | id: paSourceModel | ||
191 | } | 198 | } | ||
192 | 199 | | |||
193 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | 200 | Plasmoid.compactRepresentation: PlasmaCore.IconItem { | ||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 431 | ColumnLayout { | |||
437 | } | 444 | } | ||
438 | ListView { | 445 | ListView { | ||
439 | id: sinkView | 446 | id: sinkView | ||
440 | 447 | | |||
441 | Layout.fillWidth: true | 448 | Layout.fillWidth: true | ||
442 | Layout.minimumHeight: contentHeight | 449 | Layout.minimumHeight: contentHeight | ||
443 | Layout.maximumHeight: contentHeight | 450 | Layout.maximumHeight: contentHeight | ||
444 | 451 | | |||
445 | model: PulseObjectFilterModel { | 452 | model: PlasmaCore.SortFilterModel { | ||
446 | sortRole: "SortByDefault" | 453 | sortRole: "SortByDefault" | ||
447 | sortOrder: Qt.DescendingOrder | 454 | sortOrder: Qt.DescendingOrder | ||
448 | sourceModel: paSinkModel | 455 | sourceModel: paSinkModel | ||
456 | | ||||
457 | filterCallback: function (source_row, value) { | ||||
458 | var idx = sourceModel.index(source_row, 0); | ||||
459 | | ||||
460 | if (sourceModel.data(idx, sourceModel.role("Name")) === dummyOutputName) { | ||||
461 | return false; | ||||
462 | } | ||||
463 | | ||||
464 | return true; | ||||
465 | } | ||||
449 | } | 466 | } | ||
450 | boundsBehavior: Flickable.StopAtBounds; | 467 | boundsBehavior: Flickable.StopAtBounds; | ||
451 | delegate: DeviceListItem { | 468 | delegate: DeviceListItem { | ||
452 | type: "sink" | 469 | type: "sink" | ||
453 | onlyOne: devicesView.simpleMode | 470 | onlyOne: devicesView.simpleMode | ||
454 | } | 471 | } | ||
455 | } | 472 | } | ||
456 | 473 | | |||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |