diff --git a/package/contents/config/main.xml b/package/contents/config/main.xml index 4d78be8..f25ac46 100644 --- a/package/contents/config/main.xml +++ b/package/contents/config/main.xml @@ -6,7 +6,21 @@ <kcfgfile name=""/> <group name="General"> - <entry name="showIconsOnly" type="Bool"> + <entry name="labeling" type="Enum"> + <choices> + <choice name="iconWithDescription"> + <label>Icon with description</label> + </choice> + <choice name="descriptionOnly"> + <label>Description only</label> + </choice> + <choice name="iconOnly"> + <label>Icon only</label> + </choice> + <default>iconWithDescription</default> + </choices> + </entry> + <entry name="usePortDescription" type="Bool"> <default>false</default> </entry> <entry name="useVerticalLayout" type="Bool"> diff --git a/package/contents/ui/ConfigGeneral.qml b/package/contents/ui/ConfigGeneral.qml index 133143f..43fbc64 100644 --- a/package/contents/ui/ConfigGeneral.qml +++ b/package/contents/ui/ConfigGeneral.qml @@ -23,27 +23,61 @@ import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 Item { - property alias cfg_showIconsOnly: showIconsOnly.checked + property int cfg_labeling: 0 + property alias cfg_usePortDescription: usePortDescription.checked + property alias cfg_useVerticalLayout: useVerticalLayout.checked - property alias cfg_defaultIconName: defaultIconName.currentText + + property string cfg_defaultIconName: null ColumnLayout { Layout.fillWidth: true + + ColumnLayout { + id: labeling + ExclusiveGroup { id: labelingGroup } + Repeater { + id: buttonRepeater + model: [ + i18n("Show icon with description"), + i18n("Show description only"), + i18n("Show icon only") + ] + RadioButton { + text: modelData + checked: index === cfg_labeling + exclusiveGroup: labelingGroup + onClicked: { + cfg_labeling = index + } + } + } + } + CheckBox { - id: showIconsOnly - text: i18n("Show icons only") + id: usePortDescription + enabled: cfg_labeling != 2 // "Icon only" + text: i18n("Use the audio sink's port description rather than the sink description") } + CheckBox { id: useVerticalLayout text: i18n("Use vertical layout") } + Label { text: i18n("Default icon") topPadding: 25 } ComboBox { id: defaultIconName - model: ["audio-speakers-symbolic", "audio-headphones", "audio-card"] + model: ListModel { + id: cbItems + ListElement { text: "Speakers"; value: "audio-speakers-symbolic" } + ListElement { text: "Headphones"; value: "audio-headphones" } + ListElement { text: "Audio card"; value: "audio-card" } + } + onCurrentIndexChanged: cfg_defaultIconName = cbItems.get(currentIndex).value } } } diff --git a/package/contents/ui/main.qml b/package/contents/ui/main.qml index 34c8ad8..10897e9 100644 --- a/package/contents/ui/main.qml +++ b/package/contents/ui/main.qml @@ -36,33 +36,54 @@ Item { Layout.minimumHeight: gridLayout.implicitHeight Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation - property bool showIconsOnly: plasmoid.configuration.showIconsOnly + property int labeling: plasmoid.configuration.labeling + property bool usePortDescription: plasmoid.configuration.usePortDescription + property bool useVerticalLayout: plasmoid.configuration.useVerticalLayout + property string defaultIconName: plasmoid.configuration.defaultIconName - // from plasma-volume-control applet - function iconNameFromPort(port, fallback) { - if (port) { - if (port.name.indexOf("speaker") !== -1) { + // see https://github.com/KDE/plasma-pa/blob/master/applet/contents/code/icon.js + function formFactorIcon(formFactor, fallback) { + + // return fallback; + + switch(formFactor) { + case "internal": + return "audio-card"; + case "speaker": return "audio-speakers-symbolic"; - } else if (port.name.indexOf("headphones") !== -1) { - return "audio-headphones"; - } else if (port.name.indexOf("headset") !== -1) { - return "audio-headset"; - } else if (port.name.indexOf("hdmi") !== -1) { + case "phone": + return "phone"; + case "handset": + return "phone"; + case "tv": return "video-television"; - } else if (port.name.indexOf("mic") !== -1) { + case "webcam": + return "camera-web"; + case "microphone": return "audio-input-microphone"; - } else if (port.name.indexOf("phone") !== -1) { - return "phone"; - } + case "headset": + return "audio-headset"; + case "headphone": + return "audio-headphones"; + case "hands-free": + return "hands-free"; + case "car": + return "car"; + case "hifi": + return "hifi"; + case "computer": + return "computer"; + case "portable": + return "portable"; } - return fallback; + return fallback || "audio-card"; // fallback } GridLayout { id: gridLayout - flow: useVerticalLayout == true ? GridLayout.TopToBottom : GridLayout.LeftToRight + flow: useVerticalLayout? GridLayout.TopToBottom : GridLayout.LeftToRight anchors.fill: parent QtControls.ExclusiveGroup { @@ -77,19 +98,21 @@ Item { id: tab enabled: currentPort !== null - text: showIconsOnly ? "" : currentDescription - iconName: showIconsOnly ? iconNameFromPort(currentPort, defaultIconName) : "" + text: labeling != 2 ? currentDescription : "" + iconName: labeling != 1 ? formFactorIcon(sink.formFactor, defaultIconName) : "" checkable: true exclusiveGroup: buttonGroup tooltip: currentDescription + // Layout.fillHeight: true Layout.fillWidth: true - Layout.preferredWidth: showIconsOnly ? -1 : units.gridUnit * 10 + Layout.preferredWidth: -1 + readonly property var sink: model.PulseObject readonly property var currentPort: model.Ports[ActivePortIndex] - readonly property string currentDescription: currentPort ? currentPort.description : model.Description + readonly property string currentDescription: usePortDescription ? currentPort ? currentPort.description : model.Description : model.Description Binding { target: tab diff --git a/package/metadata.desktop b/package/metadata.desktop index 892770b..1051a0f 100644 --- a/package/metadata.desktop +++ b/package/metadata.desktop @@ -1,5 +1,5 @@ [Desktop Entry] -Name=Audio Device Switcher +Name=Audio Device Switcher Enhanced Comment=Simple widget to change the default audio output device/sink Icon=org.kde.plasma.volume @@ -9,11 +9,11 @@ X-KDE-ServiceTypes=Plasma/Applet X-Plasma-API=declarativeappletscript X-Plasma-MainScript=ui/main.qml -X-KDE-PluginInfo-Name=org.kde.plasma.audiodeviceswitcher +X-KDE-PluginInfo-Name=org.kde.plasma.audiodeviceswitcherenhanced X-KDE-PluginInfo-Category=Multimedia -X-KDE-PluginInfo-Author=Andreas Krutzler -X-KDE-PluginInfo-Email=andreas.krutzler@gmx.net -X-KDE-PluginInfo-Version=0.3.0 +X-KDE-PluginInfo-Author=Jules Luzy-Riopel (inspired by Andreas Krutzler original version https://github.com/akrutzler/plasma-audio-device-switcher) +X-KDE-PluginInfo-Email=jules@lafabriquevirtuelle.com +X-KDE-PluginInfo-Version=0.4.0 X-KDE-PluginInfo-Website=https://github.com/akrutzler/plasma-audio-device-switcher X-KDE-PluginInfo-License=GPL X-KDE-PluginInfo-EnabledByDefault=true