diff --git a/applet/contents/ui/DeviceListItem.qml b/applet/contents/ui/DeviceListItem.qml --- a/applet/contents/ui/DeviceListItem.qml +++ b/applet/contents/ui/DeviceListItem.qml @@ -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 @@ 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 + } + } + } + } } diff --git a/applet/contents/ui/ListItemBase.qml b/applet/contents/ui/ListItemBase.qml --- a/applet/contents/ui/ListItemBase.qml +++ b/applet/contents/ui/ListItemBase.qml @@ -137,6 +137,24 @@ 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,15 +300,15 @@ 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" menuItem.clicked.connect(function() { 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"