Commit 10ab204a authored by George Vogiatzis's avatar George Vogiatzis Committed by Nate Graham

[Applet]Hide hamburger menu when empty

Summary:
Don't show devices/applications hamburger menu when there are no options.
Hide "Record/Play all audio via this device" if there is only 1 device.
Prevent unavailable ports be active.

Last is a workaround to prevent locking a device to an unavailable port.
This can happen cause of the lack of a call from pulseaudio for a port
availability change.

Depends on D26418

Test Plan:
Lock can happen when an unused and available port becomes unavailable.
Until data refresh, a user can select the unavailable port. After the
switch if there is only 1 available port, UI will hide port selection,
locking user to an unavailable port.

2 vs 1 output devices
{F7876434}

{F7876435}

Reviewers: #vdg, #plasma, drosca, ngraham

Reviewed By: #vdg, ngraham

Subscribers: ngraham, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26574
parent 681e1c8f
......@@ -20,12 +20,15 @@
import QtQuick 2.0
import org.kde.plasma.private.volume 0.1
import "../code/icon.js" as Icon
ListItemBase {
readonly property var currentPort: Ports[ActivePortIndex]
readonly property var currentActivePortIndex: ActivePortIndex
readonly property var currentMuted: Muted
readonly property var activePortIndex: ActivePortIndex
draggable: false
label: {
......@@ -63,4 +66,17 @@ ListItemBase {
globalMute = false;
}
}
// Prevent an unavailable port selection. UI allows selection of an unavailable port, until it gets refresh,
// because there is no call from pulseaudio for availability change.
onActivePortIndexChanged: {
if (currentPort.availability === Port.Unavailable) {
for (var i = 0; i < Ports.length; i++) {
if (Ports[i].availability === Port.Available) {
ActivePortIndex = i;
return
}
}
}
}
}
......@@ -137,6 +137,24 @@ PlasmaComponents.ListItem {
checkable: true
onClicked: contextMenu.show()
tooltip: i18n("Show additional options for %1", defaultButton.text)
visible: {
if (((type == "sink-input" || type == "sink") && sinkView.model.count > 1)
|| ((type == "source-input" || type == "source") && sourceView.model.count > 1)) {
return true;
} else if (PulseObject.ports) {
var foundFirstAvailablePort = false;
for (var i = 0; i < PulseObject.ports.length; i++) {
if (PulseObject.ports[i].availability != Port.Unavailable) {
if (foundFirstAvailablePort) {
return true;
} else {
foundFirstAvailablePort = true;
}
}
}
}
return false;
}
}
}
......@@ -282,7 +300,7 @@ PlasmaComponents.ListItem {
contextMenu.clearMenuItems();
// Switch all streams of the relevant kind to this device
if (type == "source") {
if (type == "source" && sourceView.model.count > 1) {
menuItem = newMenuItem();
menuItem.text = i18n("Record all audio via this device");
menuItem.icon = "mic-on" // or "mic-ready" // or "audio-input-microphone-symbolic"
......@@ -290,7 +308,7 @@ PlasmaComponents.ListItem {
PulseObject.switchStreams();
});
contextMenu.addMenuItem(menuItem);
} else if (type == "sink") {
} else if (type == "sink" && sinkView.model.count > 1) {
menuItem = newMenuItem();
menuItem.text = i18n("Play all audio via this device");
menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment