Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/ListItemBase.qml
Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Line(s) | 111 | RowLayout { | |||
---|---|---|---|---|---|
139 | 139 | | |||
140 | SmallToolButton { | 140 | SmallToolButton { | ||
141 | id: contextMenuButton | 141 | id: contextMenuButton | ||
142 | icon: "application-menu" | 142 | icon: "application-menu" | ||
143 | checkable: true | 143 | checkable: true | ||
144 | onClicked: contextMenu.show() | 144 | onClicked: contextMenu.show() | ||
145 | tooltip: i18n("Show additional options for %1", defaultButton.text) | 145 | tooltip: i18n("Show additional options for %1", defaultButton.text) | ||
146 | visible: { | 146 | visible: { | ||
147 | // if it is a sink type and there are at least two sink devices. Same for source type. | ||||
147 | if (((type == "sink-input" || type == "sink") && sinkView.model.count > 1) | 148 | if (((type == "sink-input" || type == "sink") && sinkView.model.count > 1) | ||
148 | || ((type == "source-input" || type == "source") && sourceView.model.count > 1)) { | 149 | || ((type == "source-input" || type == "source") && sourceView.model.count > 1)) { | ||
149 | return true; | 150 | return true; | ||
150 | } else if (PulseObject.ports) { | 151 | } else if (PulseObject.ports && PulseObject.ports.length > 1) { | ||
152 | // In case an unavailable port is active. | ||||
153 | if (PulseObject.ports[PulseObject.activePortIndex].availability == Port.Unavailable) { | ||||
154 | return true; | ||||
155 | } | ||||
156 | // If there are at least two available ports. | ||||
151 | var foundFirstAvailablePort = false; | 157 | var foundFirstAvailablePort = false; | ||
152 | for (var i = 0; i < PulseObject.ports.length; i++) { | 158 | for (var i = 0; i < PulseObject.ports.length; i++) { | ||
153 | if (PulseObject.ports[i].availability != Port.Unavailable) { | 159 | if (PulseObject.ports[i].availability != Port.Unavailable) { | ||
154 | if (foundFirstAvailablePort) { | 160 | if (foundFirstAvailablePort) { | ||
155 | return true; | 161 | return true; | ||
156 | } else { | 162 | } else { | ||
157 | foundFirstAvailablePort = true; | 163 | foundFirstAvailablePort = true; | ||
158 | } | 164 | } | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 323 | } else if (type == "sink" && sinkView.model.count > 1) { | |||
320 | menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic" | 326 | menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic" | ||
321 | menuItem.clicked.connect(function() { | 327 | menuItem.clicked.connect(function() { | ||
322 | PulseObject.switchStreams(); | 328 | PulseObject.switchStreams(); | ||
323 | }); | 329 | }); | ||
324 | contextMenu.addMenuItem(menuItem); | 330 | contextMenu.addMenuItem(menuItem); | ||
325 | } | 331 | } | ||
326 | 332 | | |||
327 | // Ports | 333 | // Ports | ||
328 | // Intentionally only shown when there are at least two available ports. | 334 | // Intentionally only shown when there are at least two ports. | ||
329 | if (PulseObject.ports && PulseObject.ports.length > 1) { | 335 | if (PulseObject.ports && PulseObject.ports.length > 1) { | ||
330 | contextMenu.addMenuItem(newSeperator()); | 336 | contextMenu.addMenuItem(newSeperator()); | ||
331 | 337 | | |||
332 | var menuItem = newMenuItem(); | 338 | var menuItem = newMenuItem(); | ||
333 | menuItem.text = i18nc("Heading for a list of ports of a device (for example built-in laptop speakers or a plug for headphones)", "Ports"); | 339 | menuItem.text = i18nc("Heading for a list of ports of a device (for example built-in laptop speakers or a plug for headphones)", "Ports"); | ||
334 | menuItem.section = true; | 340 | menuItem.section = true; | ||
335 | contextMenu.addMenuItem(menuItem); | 341 | contextMenu.addMenuItem(menuItem); | ||
336 | menuItem.visible = false; | | |||
337 | 342 | | |||
343 | var setActivePort = function(portIndex) { | ||||
344 | return function() { | ||||
345 | PulseObject.activePortIndex = portIndex; | ||||
346 | }; | ||||
347 | }; | ||||
348 | | ||||
349 | // If an unavailable port is active, show all the ports. | ||||
350 | if (PulseObject.ports[PulseObject.activePortIndex].availability == Port.Unavailable) { | ||||
351 | for (var i = 0; i < PulseObject.ports.length; i++) { | ||||
352 | var port = PulseObject.ports[i]; | ||||
353 | var menuItem = newMenuItem(); | ||||
354 | if (port.availability == Port.Unavailable) { | ||||
355 | if (port.name == "analog-output-speaker" || port.name == "analog-input-microphone-internal") { | ||||
356 | menuItem.text = i18nc("Port is unavailable", "%1 (unavailable)", port.description); | ||||
357 | } else { | ||||
pino: please avoid i18n puzzles, and use placeholders instead; for example
```
i18nc("Port is… | |||||
I wanted to do this change, but this is old code from 5.17. I believe that translated history must exist, and will automatically be used. gvgeo: I wanted to do this change, but this is old code from 5.17. I believe that translated history… | |||||
ngraham: Better to change it now to avoid the string puzzle entirely IMO | |||||
358 | menuItem.text = i18nc("Port is unplugged", "%1 (unplugged)", port.description); | ||||
359 | } | ||||
pino: ditto | |||||
360 | } else { | ||||
361 | menuItem.text = port.description; | ||||
362 | } | ||||
363 | menuItem.checkable = true; | ||||
364 | menuItem.checked = i === PulseObject.activePortIndex; | ||||
365 | menuItem.clicked.connect(setActivePort(i)); | ||||
366 | contextMenu.addMenuItem(menuItem); | ||||
367 | } | ||||
368 | } else { // Hide ports that are unavailable and only show if there are at least two available | ||||
338 | var menuItemsPorts = []; | 369 | var menuItemsPorts = []; | ||
339 | var availablePorts = 0; | 370 | var availablePorts = 0; | ||
340 | for (var i = 0; i < PulseObject.ports.length; i++) { | 371 | for (var i = 0; i < PulseObject.ports.length; i++) { | ||
341 | var port = PulseObject.ports[i]; | 372 | var port = PulseObject.ports[i]; | ||
342 | if (port.availability != Port.Unavailable) { | 373 | if (port.availability != Port.Unavailable) { | ||
343 | menuItemsPorts[availablePorts] = newMenuItem(); | 374 | menuItemsPorts[availablePorts] = newMenuItem(); | ||
344 | menuItemsPorts[availablePorts].text = port.description; | 375 | menuItemsPorts[availablePorts].text = port.description; | ||
345 | menuItemsPorts[availablePorts].checkable = true; | 376 | menuItemsPorts[availablePorts].checkable = true; | ||
346 | menuItemsPorts[availablePorts].checked = i === PulseObject.activePortIndex; | 377 | menuItemsPorts[availablePorts].checked = i === PulseObject.activePortIndex; | ||
347 | var setActivePort = function(portIndex) { | | |||
348 | return function() { | | |||
349 | PulseObject.activePortIndex = portIndex; | | |||
350 | }; | | |||
351 | }; | | |||
352 | menuItemsPorts[availablePorts].clicked.connect(setActivePort(i)); | 378 | menuItemsPorts[availablePorts].clicked.connect(setActivePort(i)); | ||
353 | contextMenu.addMenuItem(menuItemsPorts[availablePorts]); | 379 | contextMenu.addMenuItem(menuItemsPorts[availablePorts]); | ||
354 | menuItemsPorts[availablePorts].visible = false; | | |||
355 | availablePorts++; | 380 | availablePorts++; | ||
356 | } | 381 | } | ||
357 | } | 382 | } | ||
358 | 383 | | |||
359 | if (1 < availablePorts){ | 384 | if (availablePorts <= 1){ | ||
360 | menuItem.visible = true; | 385 | menuItem.visible = false; | ||
361 | for (var i = 0; i < availablePorts; i++) { | 386 | for (var i = 0; i < availablePorts; i++) { | ||
362 | menuItemsPorts[i].visible = true; | 387 | menuItemsPorts[i].visible = false; | ||
388 | } | ||||
363 | } | 389 | } | ||
364 | } | 390 | } | ||
365 | } | 391 | } | ||
366 | 392 | | |||
367 | // Choose output / input device | 393 | // Choose output / input device | ||
368 | // Intentionally only shown when there are at least two options | 394 | // Intentionally only shown when there are at least two options | ||
369 | if ((type == "sink-input" && sinkView.model.count > 1) || (type == "source-input" && sourceView.model.count > 1)) { | 395 | if ((type == "sink-input" && sinkView.model.count > 1) || (type == "source-input" && sourceView.model.count > 1)) { | ||
370 | contextMenu.addMenuItem(newSeperator()); | 396 | contextMenu.addMenuItem(newSeperator()); | ||
Show All 34 Lines |
please avoid i18n puzzles, and use placeholders instead; for example