Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PwNodeModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServicePipeWire/phosphorservicepipewire_export.h>
7// Full definitions for BOTH types this header's moc surface exposes: the
8// `connection` Q_PROPERTY carries PipeWireConnection*, and the `firstNode`
9// Q_PROPERTY plus the `nodeAt()` Q_INVOKABLE carry PwNode*. Qt6 moc
10// auto-registers property and invokable-return metatypes, and QMetaType
11// SFINAE-probes completeness — a forward declaration of either would
12// re-fire GCC's -Wsfinae-incomplete once moc aggregation order stops
13// shielding it. Same rationale as PipeWireHost.h.
16
17#include <QAbstractListModel>
18#include <QHash>
19#include <QList>
20#include <QStringList>
21
22#include <memory>
23
25
56class PHOSPHORSERVICEPIPEWIRE_EXPORT PwNodeModel : public QAbstractListModel
57{
58 Q_OBJECT
59 Q_DISABLE_COPY_MOVE(PwNodeModel)
62 Q_PROPERTY(QStringList mediaClasses READ mediaClasses WRITE setMediaClasses NOTIFY mediaClassesChanged)
63 Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
74
75public:
76 // DO NOT REORDER OR INSERT MID-LIST — smoke tests pin these values
77 // for QML wire stability. New roles must be appended at the end
78 // (`Qt::UserRole + 10`, ...) so the documented role-name → int
79 // mapping stays stable for QML consumers that key on the integers
80 // (Q_ENUM exposes them by name into QML, but the int values are
81 // also reachable via `Qt.UserRole + N` patterns).
82 enum Role {
83 NodeRole = Qt::UserRole + 1,
84 IdRole = Qt::UserRole + 2,
85 NameRole = Qt::UserRole + 3,
86 NickRole = Qt::UserRole + 4,
87 DescriptionRole = Qt::UserRole + 5,
88 MediaClassRole = Qt::UserRole + 6,
89 ChannelCountRole = Qt::UserRole + 7,
90 VolumesRole = Qt::UserRole + 8,
91 MutedRole = Qt::UserRole + 9,
92 };
93 Q_ENUM(Role)
94
95 explicit PwNodeModel(QObject* parent = nullptr);
96 ~PwNodeModel() override;
97
98 [[nodiscard]] PipeWireConnection* connection() const;
99 [[nodiscard]] QStringList mediaClasses() const;
100
101 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
102 [[nodiscard]] QVariant data(const QModelIndex& index, int role) const override;
103 [[nodiscard]] QHash<int, QByteArray> roleNames() const override;
104
105 [[nodiscard]] PwNode* firstNode() const;
106
116 [[nodiscard]] Q_INVOKABLE PwNode* nodeAt(int row) const;
117
118public Q_SLOTS:
154 void setMediaClasses(const QStringList& classes);
155
156Q_SIGNALS:
161
162private:
163 class Private;
164 // Private is befriended so it can drive the QAbstractListModel
165 // protected row-event machinery (`beginInsertRows` /
166 // `endInsertRows`, `beginRemoveRows` / `endRemoveRows`, `index()`)
167 // and emit our `countChanged` signal from inside the rebuild path,
168 // without forcing the rebuild logic to live on PwNodeModel itself.
169 friend class Private;
170 // Pinned subclasses (PwSinkModel / PwSourceModel / PwStreamModel)
171 // seed the media-class filter directly into `d` from their
172 // constructors rather than calling the public `setMediaClasses`
173 // slot. At construction the model is empty (no connection, no
174 // rows), so there's nothing for `setMediaClasses` to rebuild —
175 // and emitting `mediaClassesChanged` from a constructor would
176 // wake any binding before the subclass is fully constructed.
177 // Direct assignment via friendship keeps the seeding contained
178 // without exposing a public mutator that bypasses the rebuild.
179 friend class PwSinkModel;
180 friend class PwSourceModel;
181 friend class PwStreamModel;
182 std::unique_ptr<Private> d;
183};
184
203class PHOSPHORSERVICEPIPEWIRE_EXPORT PwSinkModel : public PwNodeModel
204{
205 Q_OBJECT
206
207public:
208 explicit PwSinkModel(QObject* parent = nullptr);
209};
210
215class PHOSPHORSERVICEPIPEWIRE_EXPORT PwSourceModel : public PwNodeModel
216{
217 Q_OBJECT
218
219public:
220 explicit PwSourceModel(QObject* parent = nullptr);
221};
222
229class PHOSPHORSERVICEPIPEWIRE_EXPORT PwStreamModel : public PwNodeModel
230{
231 Q_OBJECT
232
233public:
234 explicit PwStreamModel(QObject* parent = nullptr);
235};
236
237} // namespace PhosphorServicePipeWire
Owns the PipeWire main loop on a dedicated QThread and exposes connection state to the GUI thread via...
Definition PipeWireConnection.h:59
Role
Row 0, or null when the model is empty.
Definition PwNodeModel.h:82
@ IdRole
Definition PwNodeModel.h:84
@ MutedRole
Definition PwNodeModel.h:91
@ MediaClassRole
Definition PwNodeModel.h:88
@ DescriptionRole
Definition PwNodeModel.h:87
@ NodeRole
Definition PwNodeModel.h:83
@ NameRole
Definition PwNodeModel.h:85
@ ChannelCountRole
Definition PwNodeModel.h:89
@ VolumesRole
Definition PwNodeModel.h:90
@ NickRole
Definition PwNodeModel.h:86
PwNodeModel(QObject *parent=nullptr)
void setMediaClasses(const QStringList &classes)
Replace the media-class filter set.
PipeWireConnection * connection() const
PwNode * nodeAt(int row) const
The node at row, or null when row is out of range.
void setConnection(PipeWireConnection *connection)
Attach the model to a PipeWireConnection (or detach by passing nullptr).
QVariant data(const QModelIndex &index, int role) const override
friend class PwSinkModel
Definition PwNodeModel.h:179
QHash< int, QByteArray > roleNames() const override
friend class PwStreamModel
Definition PwNodeModel.h:181
int rowCount(const QModelIndex &parent=QModelIndex()) const override
friend class PwSourceModel
Definition PwNodeModel.h:180
friend class Private
Definition PwNodeModel.h:169
One PipeWire audio node — a sink, source, output stream, or input stream.
Definition PwNode.h:49
PwSinkModel(QObject *parent=nullptr)
PwSourceModel(QObject *parent=nullptr)
PwStreamModel(QObject *parent=nullptr)
Definition PipeWireConnection.h:20