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.
| 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.
| 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.