Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorServicePipeWire::PwNodeModel Class Reference

Filtered view over a PipeWireConnection's registry-surfaced nodes, exposed as a QAbstractListModel for direct QML binding. More...

#include <PhosphorServicePipeWire/PwNodeModel.h>

Inheritance diagram for PhosphorServicePipeWire::PwNodeModel:
[legend]

Public Types

enum  Role {
  NodeRole = Qt::UserRole + 1 , IdRole = Qt::UserRole + 2 , NameRole = Qt::UserRole + 3 , NickRole = Qt::UserRole + 4 ,
  DescriptionRole = Qt::UserRole + 5 , MediaClassRole = Qt::UserRole + 6 , ChannelCountRole = Qt::UserRole + 7 , VolumesRole = Qt::UserRole + 8 ,
  MutedRole = Qt::UserRole + 9
}
 Row 0, or null when the model is empty. More...

Public Slots

void setConnection (PipeWireConnection *connection)
 Attach the model to a PipeWireConnection (or detach by passing nullptr).
void setMediaClasses (const QStringList &classes)
 Replace the media-class filter set.

Signals

void connectionChanged ()
void mediaClassesChanged ()
void countChanged ()
void firstNodeChanged ()

Public Member Functions

 PwNodeModel (QObject *parent=nullptr)
 ~PwNodeModel () override
PipeWireConnection * connection () const
QStringList mediaClasses () const
int rowCount (const QModelIndex &parent=QModelIndex()) const override
QVariant data (const QModelIndex &index, int role) const override
QHash< int, QByteArray > roleNames () const override
PwNode * firstNode () const
PwNode * nodeAt (int row) const
 The node at row, or null when row is out of range.

Detailed Description

Filtered view over a PipeWireConnection's registry-surfaced nodes, exposed as a QAbstractListModel for direct QML binding.

Construction is GUI-thread only. Set connection and mediaClasses, and the model populates itself from the connection's current snapshot plus stays live by listening to nodeAdded / nodeRemoved and to each node's infoChanged / propsChanged.

Roles (the int values are pinned by smoke tests so QML code keyed on the role-name strings stays stable across versions):

  • node (Qt::UserRole + 1) — the PwNode* itself; QML usually binds through this for nested access (model.node.volumes[0]).
  • id (Qt::UserRole + 2) — PipeWire global id (quint32).
  • name (Qt::UserRole + 3) — node.name.
  • nick (Qt::UserRole + 4) — node.nick.
  • description (Qt::UserRole + 5) — node.description.
  • mediaClass (Qt::UserRole + 6) — e.g. Audio/Sink.
  • channelCount(Qt::UserRole + 7) — channel count from SPA_PROP_channelVolumes.
  • volumes (Qt::UserRole + 8) — QList<qreal> linear amplitudes.
  • muted (Qt::UserRole + 9) — bool.
  • display (Qt::DisplayRole) — falls back through nick → description → name so plain model.display always has something usable.

mediaClasses is a list so a model can show e.g. both Audio/Sink and Audio/Source if needed; the convenience subclasses below pin a single class each for the common cases.

Member Enumeration Documentation

◆ Role

Row 0, or null when the model is empty.

Exists because "the first matching node" is a value QML wants to BIND to, and a nodeAt(0) call in a binding tracks no dependency so it would never re-evaluate. Pairing it with count is not a substitute: a rebuild that swaps every row for a different set of the SAME size (a connection swap, a media-class change) moves row 0 without moving the count, and the binding would stay pinned to a node that has since been destroyed.

Enumerator
NodeRole 
IdRole 
NameRole 
NickRole 
DescriptionRole 
MediaClassRole 
ChannelCountRole 
VolumesRole 
MutedRole 

Constructor & Destructor Documentation

◆ PwNodeModel()

PhosphorServicePipeWire::PwNodeModel::PwNodeModel ( QObject * parent = nullptr)
explicit

◆ ~PwNodeModel()

PhosphorServicePipeWire::PwNodeModel::~PwNodeModel ( )
override

Member Function Documentation

◆ connection()

PipeWireConnection * PhosphorServicePipeWire::PwNodeModel::connection ( ) const
nodiscard

◆ connectionChanged

void PhosphorServicePipeWire::PwNodeModel::connectionChanged ( )
signal

◆ countChanged

void PhosphorServicePipeWire::PwNodeModel::countChanged ( )
signal

◆ data()

QVariant PhosphorServicePipeWire::PwNodeModel::data ( const QModelIndex & index,
int role ) const
nodiscardoverride

◆ firstNode()

PwNode * PhosphorServicePipeWire::PwNodeModel::firstNode ( ) const
nodiscard

◆ firstNodeChanged

void PhosphorServicePipeWire::PwNodeModel::firstNodeChanged ( )
signal

◆ mediaClasses()

QStringList PhosphorServicePipeWire::PwNodeModel::mediaClasses ( ) const
nodiscard

◆ mediaClassesChanged

void PhosphorServicePipeWire::PwNodeModel::mediaClassesChanged ( )
signal

◆ nodeAt()

PwNode * PhosphorServicePipeWire::PwNodeModel::nodeAt ( int row) const
nodiscard

The node at row, or null when row is out of range.

For IMPERATIVE reads only — a click handler, a one-shot lookup. Do NOT call it from a binding: it is a plain function call, so the binding tracks no dependency on the model and will never re-evaluate. Pairing it with count does not rescue that, because a rebuild can replace every row with a different set of the same size. Bind firstNode when row 0 is what you want; anything else belongs in a delegate.

◆ roleNames()

QHash< int, QByteArray > PhosphorServicePipeWire::PwNodeModel::roleNames ( ) const
nodiscardoverride

◆ rowCount()

int PhosphorServicePipeWire::PwNodeModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
nodiscardoverride

◆ setConnection

void PhosphorServicePipeWire::PwNodeModel::setConnection ( PipeWireConnection * connection)
slot

Attach the model to a PipeWireConnection (or detach by passing nullptr).

Tears down every existing row, swaps the connection handle, then re-seeds from the new connection's current node snapshot — filtered through mediaClasses — and subscribes to nodeAdded / nodeRemoved so subsequent registry events keep the model live. Idempotent: passing the current connection pointer is a no-op (no signals fire, no rows churn), with one exception — when the previously-attached connection was destroyed externally (e.g. the caller deleted it without first calling setConnection(nullptr)), the internal QPointer clears and a subsequent setConnection(nullptr) triggers a one-shot beginResetModel to flush the now-dangling row caches. The connectionChanged notification is emitted AFTER the rebuild completes so any QML binding awakened by the signal observes a consistent state: connection() returns the new pointer AND the model's rows already describe it. This preserves the invariant that the model's rows always describe its current connection property — emitting before the rebuild would briefly expose "new connection but stale rows" to observers.

◆ setMediaClasses

void PhosphorServicePipeWire::PwNodeModel::setMediaClasses ( const QStringList & classes)
slot

Replace the media-class filter set.

Tears down every existing row and re-seeds from the current connection's snapshot through the new filter; if no connection is attached, just records the filter for the next setConnection(non-null) call. Idempotent on the current filter list (no signals, no rebuild). If the previously-attached connection was destroyed externally (the QPointer auto-nulled silently), this slot ALSO emits connectionChanged as a catch-up NOTIFY for the implicit non-null → null transition; bindings on the connection property therefore re-evaluate even when the user only meant to change the filter. The mediaClassesChanged notification is emitted AFTER the rebuild for the same row-invariant reason as setConnection — bindings awakened by the signal see mediaClasses() returning the new list AND the rows already filtered to match.


The documentation for this class was generated from the following file:
  • phosphor-service-pipewire/include/PhosphorServicePipeWire/PwNodeModel.h