diff --git a/applet/contents/ui/ListItemBase.qml b/applet/contents/ui/ListItemBase.qml index 5082ac0..22977ad 100644 --- a/applet/contents/ui/ListItemBase.qml +++ b/applet/contents/ui/ListItemBase.qml @@ -1,394 +1,396 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.4 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 3.0 as PlasmaComponents3 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.draganddrop 2.0 as DragAndDrop import org.kde.plasma.private.volume 0.1 import "../code/icon.js" as Icon PlasmaComponents.ListItem { id: item property alias label: textLabel.text property alias labelOpacity: textLabel.opacity property alias draggable: dragArea.enabled property alias icon: clientIcon.source property alias iconUsesPlasmaTheme: clientIcon.usesPlasmaTheme property string type checked: dropArea.containsDrag opacity: (draggedStream && draggedStream.deviceIndex == Index) ? 0.3 : 1.0 ListView.delayRemove: dragArea.dragActive Item { width: parent.width height: rowLayout.height RowLayout { id: rowLayout anchors.left: parent.left anchors.right: parent.right anchors.rightMargin: LayoutMirroring.enabled ? 0 : units.smallSpacing anchors.leftMargin: LayoutMirroring.enabled ? units.smallSpacing : 0 spacing: units.smallSpacing PlasmaCore.IconItem { id: clientIcon Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter Layout.preferredHeight: column.height * 0.75 Layout.preferredWidth: Layout.preferredHeight source: "unknown" onSourceChanged: { if (!valid && source != "unknown") { source = "unknown"; } } DragAndDrop.DragArea { id: dragArea anchors.fill: parent delegate: parent mimeData { source: item } onDragStarted: { draggedStream = PulseObject; beginMoveStream(type == "sink-input" ? "sink" : "source"); } onDrop: { draggedStream = null; endMoveStream(); } MouseArea { anchors.fill: parent cursorShape: dragArea.enabled ? (pressed && pressedButtons === Qt.LeftButton ? Qt.ClosedHandCursor : Qt.OpenHandCursor) : undefined acceptedButtons: Qt.LeftButton | Qt.MiddleButton onClicked: { if (mouse.button === Qt.MiddleButton) { Muted = !Muted; } } } } } ColumnLayout { id: column spacing: 1 RowLayout { Layout.fillWidth: true PlasmaExtras.Heading { id: textLabel Layout.fillWidth: true height: undefined level: 5 opacity: 0.6 wrapMode: Text.NoWrap elide: Text.ElideRight } SmallToolButton { id: contextMenuButton icon: "application-menu" checkable: true onClicked: contextMenu.show() tooltip: i18n("Show additional options for %1", textLabel.text) } } RowLayout { SmallToolButton { readonly property bool isPlayback: type.substring(0, 4) == "sink" icon: Icon.name(Volume, Muted, isPlayback ? "audio-volume" : "microphone-sensitivity") onClicked: Muted = !Muted + checked: Muted tooltip: i18n("Mute %1", textLabel.text) } PlasmaComponents.Slider { id: slider // Helper properties to allow async slider updates. // While we are sliding we must not react to value updates // as otherwise we can easily end up in a loop where value // changes trigger volume changes trigger value changes. property int volume: Volume property bool ignoreValueChange: true property bool forceRaiseMaxVolume: false readonly property bool raiseMaxVolume: forceRaiseMaxVolume || volume >= PulseAudio.NormalVolume * 1.01 Layout.fillWidth: true minimumValue: PulseAudio.MinimalVolume maximumValue: raiseMaxVolume ? PulseAudio.MaximalVolume : PulseAudio.NormalVolume stepSize: maximumValue / (maximumValue / PulseAudio.NormalVolume * 100.0) visible: HasVolume enabled: VolumeWritable opacity: Muted ? 0.5 : 1 Accessible.name: i18nc("Accessibility data on volume slider", "Adjust volume for %1", textLabel.text) Component.onCompleted: { ignoreValueChange = false; } onVolumeChanged: { var oldIgnoreValueChange = ignoreValueChange; ignoreValueChange = true; value = Volume; ignoreValueChange = oldIgnoreValueChange; } onValueChanged: { if (!ignoreValueChange) { Volume = value; Muted = value == 0; if (!pressed) { updateTimer.restart(); } } } onPressedChanged: { if (!pressed) { // Make sure to sync the volume once the button was // released. // Otherwise it might be that the slider is at v10 // whereas PA rejected the volume change and is // still at v15 (e.g.). updateTimer.restart(); if (type == "sink") { playFeedback(Index); } } } Timer { id: updateTimer interval: 200 onTriggered: slider.value = Volume } } PlasmaComponents.Label { id: percentText readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value Layout.alignment: Qt.AlignHCenter Layout.minimumWidth: percentMetrics.advanceWidth horizontalAlignment: Qt.AlignRight text: i18nc("volume percentage", "%1%", Math.round(value / PulseAudio.NormalVolume * 100.0)) } TextMetrics { id: percentMetrics font: percentText.font text: i18nc("only used for sizing, should be widest possible string", "100%") } } RowLayout { Layout.fillWidth: true Item { Layout.fillWidth: true } PlasmaComponents3.Button { id: defaultButton text: i18n("Default Device") icon.name: "favorite" checkable: true checked: PulseObject.default visible: (type == "sink" && sinkView.model.count > 1) || (type == "source" && sourceView.model.count > 1) onClicked: PulseObject.default = true; } } } } DragAndDrop.DropArea { id: dropArea anchors.fill: parent enabled: draggedStream onDragEnter: { if (draggedStream.deviceIndex == Index) { event.ignore(); } } onDrop: { draggedStream.deviceIndex = Index; } } MouseArea { anchors { fill: parent leftMargin: clientIcon.width } acceptedButtons: Qt.MiddleButton onClicked: Muted = !Muted } } PlasmaComponents.ContextMenu { id: contextMenu visualParent: contextMenuButton placement: PlasmaCore.Types.BottomPosedLeftAlignedPopup 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(); // Raise max volume menuItem = newMenuItem(); menuItem.text = i18n("Raise maximum volume"); menuItem.checkable = true; menuItem.checked = slider.forceRaiseMaxVolume; menuItem.clicked.connect(function() { slider.forceRaiseMaxVolume = !slider.forceRaiseMaxVolume; if (!slider.forceRaiseMaxVolume && Volume > PulseAudio.NormalVolume) { Volume = PulseAudio.NormalVolume; } }); contextMenu.addMenuItem(menuItem); // Switch all streams of the relevant kind to this device if (type == "source") { 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") { menuItem = newMenuItem(); menuItem.text = i18n("Play all audio via this device"); menuItem.icon = "audio-on" // or "audio-ready" // or "audio-speakers-symbolic" menuItem.clicked.connect(function() { PulseObject.switchStreams(); }); 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.section = true; contextMenu.addMenuItem(menuItem); for (var i = 0; i < PulseObject.ports.length; i++) { var port = PulseObject.ports[i]; var menuItem = newMenuItem(); menuItem.text = port.description; if (port.availability == Port.Unavailable) { if (port.name == "analog-output-speaker" || port.name == "analog-input-microphone-internal") { menuItem.text += i18nc("Port is unavailable", " (unavailable)"); } else { menuItem.text += i18nc("Port is unplugged", " (unplugged)"); } } 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); } } // Choose output / input device // By choice only shown when there are at least two options if ((type == "sink-input" && sinkView.model.count > 1) || (type == "source-input" && sourceView.model.count > 1)) { contextMenu.addMenuItem(newSeperator()); var menuItem = newMenuItem(); if (type == "sink-input") { menuItem.text = i18nc("Heading for a list of possible output devices (speakers, headphones, ...) to choose", "Play audio using"); } else { menuItem.text = i18nc("Heading for a list of possible input devices (built-in microphone, headset, ...) to choose", "Record audio using"); } menuItem.section = true; contextMenu.addMenuItem(menuItem); var sModel = type == "sink-input" ? sinkView.model : sourceView.model; for (var i = 0; i < sModel.count; ++i) { var data = sModel.get(i); var menuItem = newMenuItem(); menuItem.text = data.Description; menuItem.enabled = true; menuItem.checkable = true; menuItem.checked = data.Index === PulseObject.deviceIndex; var setActiveSink = function(sinkIndex) { return function() { PulseObject.deviceIndex = sinkIndex; }; }; menuItem.clicked.connect(setActiveSink(data.Index)); contextMenu.addMenuItem(menuItem); } } } function show() { loadDynamicActions(); openRelative(); } } } diff --git a/src/kcm/package/contents/code/icon.js b/src/kcm/package/contents/code/icon.js new file mode 100644 index 0000000..55324a1 --- /dev/null +++ b/src/kcm/package/contents/code/icon.js @@ -0,0 +1,38 @@ +/* + Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) version 3, or any + later version accepted by the membership of KDE e.V. (or its + successor approved by the membership of KDE e.V.), which shall + act as a proxy defined in Section 6 of version 3 of the license. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +function name(volume, muted, prefix) { + if (!prefix) { + prefix = "audio-volume"; + } + var icon = null; + var percent = volume / maxVolumeValue; + if (percent <= 0.0 || muted) { + icon = prefix + "-muted"; + } else if (percent <= 0.25) { + icon = prefix + "-low"; + } else if (percent <= 0.75) { + icon = prefix + "-medium"; + } else { + icon = prefix + "-high"; + } + return icon; +} diff --git a/src/kcm/package/contents/ui/Applications.qml b/src/kcm/package/contents/ui/Applications.qml index 2c77707..d3bf711 100644 --- a/src/kcm/package/contents/ui/Applications.qml +++ b/src/kcm/package/contents/ui/Applications.qml @@ -1,108 +1,112 @@ /* Copyright 2014-2015 Harald Sitter Copyright 2016 David Rosca + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.2 import org.kde.plasma.private.volume 0.1 ScrollView { id: scrollView contentWidth: contentLayout.width contentHeight: contentLayout.height clip: true ColumnLayout { id: contentLayout Component.onCompleted: { // Normal binding causes binding loops width = Qt.binding(function() { return scrollView.width; }); } Header { Layout.fillWidth: true enabled: eventStreamView.count || sinkInputView.count - text: i18nd("kcm_pulseaudio", "Playback") + text: i18nd("kcm_pulseaudio", "Playback Streams") disabledText: i18ndc("kcm_pulseaudio", "@label", "No Applications Playing Audio") } ListView { id: eventStreamView Layout.fillWidth: true Layout.preferredHeight: contentHeight Layout.margins: units.gridUnit / 2 interactive: false spacing: units.largeSpacing model: PulseObjectFilterModel { filters: [ { role: "Name", value: "sink-input-by-media-role:event" } ] sourceModel: StreamRestoreModel {} } delegate: StreamListItem { deviceModel: sinkModel + isPlayback: true } } ListView { id: sinkInputView Layout.fillWidth: true Layout.preferredHeight: contentHeight Layout.margins: units.gridUnit / 2 interactive: false spacing: units.largeSpacing model: PulseObjectFilterModel { filters: [ { role: "VirtualStream", value: false } ] sourceModel: SinkInputModel {} } delegate: StreamListItem { deviceModel: sinkModel + isPlayback: true } } Header { Layout.fillWidth: true enabled: sourceOutputView.count > 0 - text: i18nd("kcm_pulseaudio", "Recording") + text: i18nd("kcm_pulseaudio", "Recording Streams") disabledText: i18ndc("kcm_pulseaudio", "@label", "No Applications Recording Audio") } ListView { id: sourceOutputView Layout.fillWidth: true Layout.preferredHeight: contentHeight Layout.margins: units.gridUnit / 2 interactive: false spacing: units.largeSpacing model: PulseObjectFilterModel { filters: [ { role: "VirtualStream", value: false } ] sourceModel: SourceOutputModel {} } delegate: StreamListItem { deviceModel: sourceModel + isPlayback: false } } } } diff --git a/src/kcm/package/contents/ui/DeviceListItem.qml b/src/kcm/package/contents/ui/DeviceListItem.qml index 30d5a29..4e05724 100644 --- a/src/kcm/package/contents/ui/DeviceListItem.qml +++ b/src/kcm/package/contents/ui/DeviceListItem.qml @@ -1,103 +1,111 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import org.kde.kirigami 2.5 as Kirigami import org.kde.plasma.private.volume 0.1 ColumnLayout { id: delegate width: parent.width + property bool isPlayback: type.substring(0, 4) == "sink" + + readonly property var currentPort: Ports[ActivePortIndex] + RowLayout { Kirigami.Icon { Layout.alignment: Qt.AlignHCenter - width: height - height: inputText.height + Layout.preferredHeight: delegateColumn.height * 0.75 + Layout.preferredWidth: Layout.preferredHeight source: IconName || "audio-card" } - Label { - id: inputText + ColumnLayout { + id: delegateColumn Layout.fillWidth: true - elide: Text.ElideRight - text: Description - } - - Button { - text: i18n("Default device") - icon.name: "favorite" - visible: delegate.ListView.view.count > 1 - checkable: true - checked: Default - onClicked: Default = true; - } - MuteButton { - muted: Muted - onCheckedChanged: Muted = checked - } - } - - ColumnLayout { - width: parent.width - - RowLayout { - visible: portbox.count > 1 + RowLayout { + Label { + id: inputText + Layout.fillWidth: true + elide: Text.ElideRight + text: !currentPort ? Description : i18ndc("kcm_pulseaudio", "label of device items", "%1 (%2)", currentPort.description, Description) + } - Label { - text: i18nd("kcm_pulseaudio", "Port") - } + Label { + visible: portbox.count > 1 + text: i18nd("kcm_pulseaudio", "Port:") + } - ComboBox { - id: portbox - readonly property var ports: Ports - Layout.fillWidth: true - onModelChanged: currentIndex = ActivePortIndex - currentIndex: ActivePortIndex - onActivated: ActivePortIndex = index - - onPortsChanged: { - var items = []; - for (var i = 0; i < ports.length; ++i) { - var port = ports[i]; - var text = port.description; - if (port.availability == Port.Unavailable) { - if (port.name == "analog-output-speaker" || port.name == "analog-input-microphone-internal") { - text += i18ndc("kcm_pulseaudio", "Port is unavailable", " (unavailable)"); - } else { - text += i18ndc("kcm_pulseaudio", "Port is unplugged", " (unplugged)"); + ComboBox { + id: portbox + visible: portbox.count > 1 + readonly property var ports: Ports + onModelChanged: currentIndex = ActivePortIndex + currentIndex: ActivePortIndex + onActivated: ActivePortIndex = index + + onPortsChanged: { + var items = []; + for (var i = 0; i < ports.length; ++i) { + var port = ports[i]; + var text = port.description; + if (port.availability == Port.Unavailable) { + if (port.name == "analog-output-speaker" || port.name == "analog-input-microphone-internal") { + text += i18ndc("kcm_pulseaudio", "Port is unavailable", " (unavailable)"); + } else { + text += i18ndc("kcm_pulseaudio", "Port is unplugged", " (unplugged)"); + } } + items.push(text); } - items.push(text); + model = items; } - model = items; + } + + Button { + text: i18n("Default Device") + icon.name: "favorite" + visible: delegate.ListView.view.count > 1 + checkable: true + checked: Default + onClicked: Default = true; } } - } - VolumeSlider {} + RowLayout { + MuteButton { + Layout.topMargin: -(height - icon.height) / 2 + muted: Muted + onCheckedChanged: Muted = checked + } + + VolumeSlider {} + } + } } ListItemSeperator { view: delegate.ListView.view } } diff --git a/src/kcm/package/contents/ui/Devices.qml b/src/kcm/package/contents/ui/Devices.qml index 7fbc5a2..7f2f159 100644 --- a/src/kcm/package/contents/ui/Devices.qml +++ b/src/kcm/package/contents/ui/Devices.qml @@ -1,77 +1,82 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.3 ScrollView { id: scrollView contentWidth: contentLayout.width contentHeight: contentLayout.height clip: true ColumnLayout { id: contentLayout Component.onCompleted: { // Normal binding causes binding loops width = Qt.binding(function() { return scrollView.width; }); } Header { Layout.fillWidth: true enabled: sinks.count > 0 - text: i18nd("kcm_pulseaudio", "Outputs") - disabledText: i18ndc("kcm_pulseaudio", "@label", "No Output Devices Available") + text: i18nd("kcm_pulseaudio", "Playback Devices") + disabledText: i18ndc("kcm_pulseaudio", "@label", "No Playback Devices Available") } ListView { id: sinks Layout.fillWidth: true Layout.preferredHeight: contentHeight Layout.margins: units.gridUnit / 2 interactive: false spacing: units.smallSpacing * 2 model: sinkModel - delegate: DeviceListItem {} + delegate: DeviceListItem { + isPlayback: true + } } Header { Layout.fillWidth: true enabled: sources.count > 0 - text: i18nd("kcm_pulseaudio", "Inputs") - disabledText: i18ndc("kcm_pulseaudio", "@label", "No Input Devices Available") + text: i18nd("kcm_pulseaudio", "Recording Devices") + disabledText: i18ndc("kcm_pulseaudio", "@label", "No Recording Devices Available") } ListView { id: sources Layout.fillWidth: true Layout.preferredHeight: contentHeight Layout.margins: units.gridUnit / 2 interactive: false model: sourceModel - delegate: DeviceListItem {} + delegate: DeviceListItem { + isPlayback: false + } } } } diff --git a/src/kcm/package/contents/ui/MuteButton.qml b/src/kcm/package/contents/ui/MuteButton.qml index 3109f0f..f73a3dd 100644 --- a/src/kcm/package/contents/ui/MuteButton.qml +++ b/src/kcm/package/contents/ui/MuteButton.qml @@ -1,32 +1,37 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.0 -import QtQuick.Controls 1.0 +import QtQuick.Controls 2.5 as QQC2 +import "../code/icon.js" as Icon -Button { +QQC2.ToolButton { property bool muted: true - iconName: 'audio-volume-muted' - tooltip: i18nd("kcm_pulseaudio", "Mute audio") + icon.name: Icon.name(Volume, Muted, isPlayback ? "audio-volume" : "microphone-sensitivity") checkable: true checked: muted onMutedChanged: checked = muted + + QQC2.ToolTip { + text: i18ndc("kcm_pulseaudio", "Mute audio stream", "Mute %1", inputText.text) // a little hacky + } } diff --git a/src/kcm/package/contents/ui/StreamListItem.qml b/src/kcm/package/contents/ui/StreamListItem.qml index 42f9c92..5862445 100644 --- a/src/kcm/package/contents/ui/StreamListItem.qml +++ b/src/kcm/package/contents/ui/StreamListItem.qml @@ -1,96 +1,100 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.0 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 import org.kde.kirigami 2.5 as Kirigami import org.kde.plasma.private.volume 0.1 ColumnLayout { id: delegate property alias deviceModel: deviceComboBox.model readonly property bool isEventStream: Name == "sink-input-by-media-role:event" + property bool isPlayback: type.substring(0, 4) == "sink" width: parent.width RowLayout { Layout.fillWidth: true spacing: units.smallSpacing * 2 Kirigami.Icon { Layout.alignment: Qt.AlignHCenter - Layout.preferredHeight: delegateColumn.height * 0.60 + Layout.preferredHeight: delegateColumn.height * 0.75 Layout.preferredWidth: Layout.preferredHeight source: IconName || "unknown" } ColumnLayout { id: delegateColumn Layout.fillWidth: true RowLayout { Label { id: inputText Layout.fillWidth: true text: { if (isEventStream) { return i18nd("kcm_pulseaudio", "Notification Sounds"); } else if (Client) { return i18ndc("kcm_pulseaudio", "label of stream items", "%1: %2", Client.name, Name); } else { return Name; } } elide: Text.ElideRight } DeviceComboBox { id: deviceComboBox Layout.leftMargin: units.smallSpacing Layout.rightMargin: units.smallSpacing Layout.preferredWidth: delegate.width / 3 visible: !isEventStream && count > 1 } + } + RowLayout { MuteButton { muted: Muted onCheckedChanged: Muted = checked } - } - VolumeSlider {} + VolumeSlider {} + } } } ListItemSeperator { view: delegate.ListView.view Component.onCompleted: { if (isEventStream) { visible = Qt.binding(function() { return sinkInputView.count > 0; }); } } } } diff --git a/src/kcm/package/contents/ui/VolumeSlider.qml b/src/kcm/package/contents/ui/VolumeSlider.qml index 98a0709..4439de1 100644 --- a/src/kcm/package/contents/ui/VolumeSlider.qml +++ b/src/kcm/package/contents/ui/VolumeSlider.qml @@ -1,112 +1,115 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.4 import QtQuick.Layouts 1.0 -import QtQuick.Controls 2.0 +import QtQuick.Controls 2.5 as QQC2 import org.kde.plasma.private.volume 0.1 RowLayout { Layout.bottomMargin: hundredPercentLabel.height - Slider { + QQC2.Slider { id: slider // Helper properties to allow async slider updates. // While we are sliding we must not react to value updates // as otherwise we can easily end up in a loop where value // changes trigger volume changes trigger value changes. property int volume: Volume property bool ignoreValueChange: true Layout.fillWidth: true from: PulseAudio.MinimalVolume to: PulseAudio.MaximalVolume + // TODO: implement a way to hide tickmarks + // stepSize: to / (PulseAudio.MaximalVolume / PulseAudio.NormalVolume * 100.0) visible: HasVolume enabled: VolumeWritable opacity: Muted ? 0.5 : 1 Component.onCompleted: { ignoreValueChange = false; } onVolumeChanged: { var oldIgnoreValueChange = ignoreValueChange; ignoreValueChange = true; value = Volume; ignoreValueChange = oldIgnoreValueChange; } onValueChanged: { if (!ignoreValueChange) { Volume = value; Muted = value == 0; if (!pressed) { updateTimer.restart(); } } } onPressedChanged: { if (!pressed) { // Make sure to sync the volume once the button was // released. // Otherwise it might be that the slider is at v10 // whereas PA rejected the volume change and is // still at v15 (e.g.). updateTimer.restart(); } } - Label { + QQC2.Label { id: hundredPercentLabel - readonly property real hundredPos: (slider.width / slider.maximumValue) * PulseAudio.NormalVolume + readonly property real hundredPos: (slider.width / slider.to) * PulseAudio.NormalVolume z: slider.z - 1 x: (Qt.application.layoutDirection == Qt.RightToLeft ? slider.width - hundredPos : hundredPos) - width / 2 - y: slider.height / 1.2 + y: slider.height opacity: 0.5 font.pixelSize: slider.height / 2.2 text: i18nd("kcm_pulseaudio", "100%") } Timer { id: updateTimer interval: 200 onTriggered: slider.value = Volume } } - Label { + QQC2.Label { id: percentText readonly property real value: PulseObject.volume > slider.maximumValue ? PulseObject.volume : slider.value Layout.alignment: Qt.AlignHCenter Layout.minimumWidth: percentMetrics.advanceWidth horizontalAlignment: Qt.AlignRight text: i18ndc("kcm_pulseaudio", "volume percentage", "%1%", Math.round(value / PulseAudio.NormalVolume * 100.0)) } TextMetrics { id: percentMetrics font: percentText.font text: i18ndc("kcm_pulseaudio", "only used for sizing, should be widest possible string", "100%") } } diff --git a/src/kcm/package/contents/ui/main.qml b/src/kcm/package/contents/ui/main.qml index d58d513..69eefc7 100644 --- a/src/kcm/package/contents/ui/main.qml +++ b/src/kcm/package/contents/ui/main.qml @@ -1,86 +1,88 @@ /* Copyright 2014-2015 Harald Sitter + Copyright 2019 Sefa Eyeoglu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ import QtQuick 2.7 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.0 import org.kde.kcm 1.0 import org.kde.plasma.core 2.0 as PlasmaCore /* for units.gridUnit */ import org.kde.kirigami 2.5 as Kirigami import org.kde.plasma.private.volume 0.1 Kirigami.Page { title: kcm.name property QtObject sinkModel: SinkModel { } property QtObject sourceModel: SourceModel { } + property int maxVolumeValue: PulseAudio.NormalVolume // the applet supports changing this value. We will just assume 65536 (100%) ConfigModule.quickHelp: i18nd("kcm_pulseaudio", "This module allows configuring the Pulseaudio sound subsystem.") implicitHeight: Kirigami.Units.gridUnit * 28 // TODO: replace this TabBar-plus-Frame-in-a-ColumnLayout with whatever shakes // out of https://bugs.kde.org/show_bug.cgi?id=394296 ColumnLayout { anchors.fill: parent spacing: 0 TabBar { id: tabView // Tab styles generally assume that they're touching the inner layout, // not the frame, so we need to move the tab bar down a pixel and make // sure it's drawn on top of the frame Layout.bottomMargin: -1 z: 1 TabButton { text: i18ndc("kcm_pulseaudio", "@title:tab", "Devices") } TabButton { text: i18ndc("kcm_pulseaudio", "@title:tab", "Applications") } TabButton { text: i18ndc("kcm_pulseaudio", "@title:tab", "Advanced") } } Frame { Layout.fillWidth: true Layout.fillHeight: true StackLayout { anchors.fill: parent currentIndex: tabView.currentIndex Devices { Layout.fillWidth: true Layout.fillHeight: true } Applications { Layout.fillWidth: true Layout.fillHeight: true } Advanced { Layout.fillWidth: true Layout.fillHeight: true } } } } }