Skip to content

Commit

Permalink
Merging all unmerged pull requests from OG
Browse files Browse the repository at this point in the history
  • Loading branch information
lolcabanon committed Feb 28, 2023
1 parent 68f1f34 commit 2cda18a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 31 deletions.
16 changes: 15 additions & 1 deletion package/contents/config/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
44 changes: 39 additions & 5 deletions package/contents/ui/ConfigGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
63 changes: 43 additions & 20 deletions package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package/metadata.desktop
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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=[email protected]
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=[email protected]
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

0 comments on commit 2cda18a

Please sign in to comment.