Port: Expose port availability to QML
ClosedPublic

Authored by drosca on Feb 23 2017, 10:06 AM.

Details

Summary

Replaces old available property, which is not used anywhere
and also was completely wrong.

Test Plan

Verified it is accessible from QML: port.availability == Port.Available

Diff Detail

Repository
R115 Plasma Audio Volume Applet
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
drosca created this revision.Feb 23 2017, 10:06 AM
Restricted Application added a project: Plasma. · View Herald TranscriptFeb 23 2017, 10:06 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik added inline comments.
src/port.h
37

Not needed, perhaps even

enum Availability {
    Unknown = -1,
    Unavailable,
    Available
};
drosca updated this revision to Diff 11669.Feb 23 2017, 10:27 AM

Don't set first enum value to 0

src/port.h
37

It matches the PA enum values (not that it is actually used though).

romangg added inline comments.
src/port.cpp
39

Better put the definition of this getter in the header.

src/port.h
66

Better put the definition of this long method in the cpp file.

drosca added inline comments.Feb 23 2017, 11:12 AM
src/port.cpp
39

I prefer function definitions always in cpp file.

src/port.h
66

This is templated function, so that's why the definition is in header.

romangg accepted this revision.Feb 23 2017, 11:57 AM

Tested it and it works fine. Only problem was that I couldn't use "Port.Available", but probably only because I didn't define it somewhere in the QML file. What worked in DeviceListItem.qml:
Ports[portbox.currentIndex].availability == 1
What do I need to add in this file to make the comparision with "Port.Available" instead?

Some higher level questions regarding the overall goals:

  • We now know which ports of which sink are currently connected, right? When I take a look at my audio sink directly on the mainboard, it has one port at the back (lineout) and one at the front (headphones). I can switch between them in the KCM, which only changes the volume, but not the direction. I.e. when I have connected headphones I cannot change here to the port on the back, the sound will still come via the front port and the back port is marked as not available. When I manually disconnect the headphone, it switches to the back again. So is there a way to change this behaviour?
  • To know if a device is currently "connected", we would need to loop over all its port and check if atleast one of them is connected, right? But what about the "State" property of a sink? It seems to also indicate, if the device is currently used. Should we use this one instead?
src/port.cpp
39

Ok

src/port.h
66

There is a way around it, but probably doesn't make sense here. So ok.

This revision is now accepted and ready to land.Feb 23 2017, 11:57 AM
What do I need to add in this file to make the comparision with "Port.Available" instead?

You probably forgot import org.kde.plasma.private.volume.

We now know which ports of which sink are currently connected, right? When I take a look at my audio sink directly on the mainboard, it has one port at the back (lineout) and one at the front (headphones). I can switch between them in the KCM, which only changes the volume, but not the direction. I.e. when I have connected headphones I cannot change here to the port on the back, the sound will still come via the front port and the back port is marked as not available. When I manually disconnect the headphone, it switches to the back again. So is there a way to change this behaviour?

You can probably change it, but only in pulseaudio configuration (most likely changing some modules properties or loading/unlading modules). You can't do that with plasma-pa.

To know if a device is currently "connected", we would need to loop over all its port and check if atleast one of them is connected, right? But what about the "State" property of a sink? It seems to also indicate, if the device is currently used. Should we use this one instead?

Correct, it indicates if you have "jack" connected in port. State property of Device is different thing, it indicates whether the device is currently playing any audio (if it has some streams, if the streams are currently playing or not).

This revision was automatically updated to reflect the committed changes.