summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Gilg <[email protected]>2017-02-27 22:53:12 +0100
committerRoman Gilg <[email protected]>2017-02-27 22:53:12 +0100
commitf063ff829928b16d9ae2d76f6c71c93f67354eee (patch)
tree14dcc8f09227a51dab8e26b8986a12b7c2f708b5
parent817af4b68f6b199d91d8ff3d3900e7f2dbc95268 (diff)
[Applet] Context Menu per device/stream to offer additional functionality
Adds a button in the applet to open a context menu, currently offering: * Mute/unmute device/stream * Set device as new default * Change active port of device Reviewers: drosca Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4751
-rw-r--r--applet/contents/ui/ListItemBase.qml99
1 files changed, 93 insertions, 6 deletions
diff --git a/applet/contents/ui/ListItemBase.qml b/applet/contents/ui/ListItemBase.qml
index e6b9baa..60b17da 100644
--- a/applet/contents/ui/ListItemBase.qml
+++ b/applet/contents/ui/ListItemBase.qml
@@ -95,13 +95,25 @@ PlasmaComponents.ListItem {
ColumnLayout {
id: column
- PlasmaExtras.Heading {
- id :textLabel
+ RowLayout {
Layout.fillWidth: true
- level: 5
- opacity: 0.6
- wrapMode: Text.NoWrap
- elide: Text.ElideRight
+
+ PlasmaExtras.Heading {
+ id: textLabel
+ Layout.fillWidth: true
+ level: 5
+ opacity: 0.6
+ wrapMode: Text.NoWrap
+ elide: Text.ElideRight
+ }
+ PlasmaComponents.ToolButton {
+ id: contextMenuButton
+ Layout.preferredHeight: slider.height
+ Layout.preferredWidth: Layout.preferredHeight
+ checkable: true
+ iconName: "application-menu"
+ onClicked: contextMenu.show(x, y + height)
+ }
}
RowLayout {
@@ -218,4 +230,79 @@ PlasmaComponents.ListItem {
onClicked: Muted = !Muted
}
}
+
+ PlasmaComponents.ContextMenu {
+ id: contextMenu
+
+ onStatusChanged: {
+ if (status == PlasmaComponents.DialogStatus.Closed) {
+ contextMenuButton.checked = false;
+ }
+ }
+
+ function newSeperator() {
+ return Qt.createQmlObject("import org.kde.plasma.components 2.0 as PlasmaComponents; PlasmaComponents.MenuItem { separator: true }", contextMenu);
+ }
+ function newMenuItem() {
+ return Qt.createQmlObject("import org.kde.plasma.components 2.0 as PlasmaComponents; PlasmaComponents.MenuItem {}", contextMenu);
+ }
+
+ function loadDynamicActions() {
+ contextMenu.clearMenuItems();
+
+ // Mute
+ var menuItem = newMenuItem();
+ menuItem.text = i18nc("Checkable switch for (un-)muting sound output.", "Mute");
+ menuItem.checkable = true;
+ menuItem.checked = Muted;
+ menuItem.clicked.connect(function() {
+ Muted = !Muted
+ });
+ contextMenu.addMenuItem(menuItem);
+
+ // Default
+ if (typeof PulseObject.default === "boolean") {
+ var menuItem = newMenuItem();
+ menuItem.text = i18nc("Checkable switch to change the current default output.", "Default");
+ menuItem.checkable = true;
+ menuItem.checked = PulseObject.default
+ menuItem.clicked.connect(function() {
+ PulseObject.default = true
+ });
+ contextMenu.addMenuItem(menuItem);
+ }
+
+ // Ports
+ if (PulseObject.ports && PulseObject.ports.length > 0) {
+ contextMenu.addMenuItem(newSeperator());
+
+ var isMultiplePorts = (1 < PulseObject.ports.length);
+ var menuItem = newMenuItem();
+ menuItem.text = i18nc("Heading for a list of ports of a device (for example built-in laptop speakers or a plug for headphones)", "Ports");
+ menuItem.enabled = false;
+ contextMenu.addMenuItem(menuItem);
+
+ for (var i = 0; i < PulseObject.ports.length; i++) {
+ var port = PulseObject.ports[i];
+ var menuItem = newMenuItem();
+ menuItem.text = port.description;
+ menuItem.enabled = isMultiplePorts;
+ menuItem.checkable = true;
+ menuItem.checked = i === PulseObject.activePortIndex;
+ var setActivePort = function(portIndex) {
+ return function() {
+ PulseObject.activePortIndex = portIndex;
+ };
+ };
+ menuItem.clicked.connect(setActivePort(i));
+ contextMenu.addMenuItem(menuItem);
+ }
+ }
+ }
+
+ function show(x, y) {
+ loadDynamicActions();
+ open(x, y);
+ }
+ }
}