PulseAudio Qt Bindings

models.h
1 /*
2  SPDX-FileCopyrightText: 2014-2015 Harald Sitter <[email protected]>
3  SPDX-FileCopyrightText: 2016 David Rosca <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 
8 #ifndef PULSEAUDIO_H
9 #define PULSEAUDIO_H
10 
11 #include <QAbstractListModel>
12 
13 #include "pulseaudioqt_export.h"
14 
15 namespace PulseAudioQt
16 {
17 class Context;
18 class MapBaseQObject;
19 class Sink;
20 class Source;
21 class AbstractModelPrivate;
22 class SinkModelPrivate;
23 
24 class PULSEAUDIOQT_EXPORT AbstractModel : public QAbstractListModel
25 {
26  Q_OBJECT
27 public:
28  enum ItemRole { PulseObjectRole = Qt::UserRole + 1 };
29 
30  Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
31 
32  ~AbstractModel() override;
33  QHash<int, QByteArray> roleNames() const final override;
34  int rowCount(const QModelIndex &parent = QModelIndex()) const final override;
35  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
36  bool setData(const QModelIndex &index, const QVariant &value, int role) final override;
37 
38  Q_INVOKABLE int role(const QByteArray &roleName) const;
39 
40 Q_SIGNALS:
41  void countChanged();
42 
43 protected:
44  AbstractModel(const MapBaseQObject *map, QObject *parent);
45  void initRoleNames(const QMetaObject &qobjectMetaObject);
46  Context *context() const;
47 
48 private Q_SLOTS:
49  void propertyChanged();
50 
51 private:
52  void onDataAdded(int index);
53  void onDataRemoved(int index);
54  QMetaMethod propertyChangedMetaMethod() const;
55 
56  AbstractModelPrivate *d;
57 
58  // Prevent leaf-classes from default constructing as we want to enforce
59  // them passing us a context or explicit nullptrs.
60  AbstractModel()
61  {
62  }
63 };
64 
65 class PULSEAUDIOQT_EXPORT CardModel : public AbstractModel
66 {
67  Q_OBJECT
68 public:
69  CardModel(QObject *parent = nullptr);
70 
71 private:
72  void *d;
73 };
74 
75 class PULSEAUDIOQT_EXPORT SinkModel : public AbstractModel
76 {
77  Q_OBJECT
78  Q_PROPERTY(PulseAudioQt::Sink *defaultSink READ defaultSink NOTIFY defaultSinkChanged)
79  Q_PROPERTY(PulseAudioQt::Sink *preferredSink READ preferredSink NOTIFY preferredSinkChanged)
80 public:
81  enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 };
82  Q_ENUM(ItemRole)
83 
84  SinkModel(QObject *parent = nullptr);
85  virtual ~SinkModel();
86  Sink *defaultSink() const;
87  Sink *preferredSink() const;
88  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
89 
90 Q_SIGNALS:
91  void defaultSinkChanged();
92  void preferredSinkChanged();
93 
94 private:
95  void sinkAdded(int index);
96  void sinkRemoved(int index);
97  void updatePreferredSink();
98  Sink *findPreferredSink() const;
99  SinkModelPrivate *d;
100 };
101 
102 class PULSEAUDIOQT_EXPORT SinkInputModel : public AbstractModel
103 {
104  Q_OBJECT
105 public:
106  SinkInputModel(QObject *parent = nullptr);
107 
108 private:
109  void *d;
110 };
111 
112 class PULSEAUDIOQT_EXPORT SourceModel : public AbstractModel
113 {
114  Q_OBJECT
115  Q_PROPERTY(PulseAudioQt::Source *defaultSource READ defaultSource NOTIFY defaultSourceChanged)
116 public:
117  enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 };
118  Q_ENUM(ItemRole)
119 
120  SourceModel(QObject *parent = nullptr);
121  Source *defaultSource() const;
122  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
123 
124 Q_SIGNALS:
125  void defaultSourceChanged();
126 
127 private:
128  void *d;
129 };
130 
131 class PULSEAUDIOQT_EXPORT SourceOutputModel : public AbstractModel
132 {
133  Q_OBJECT
134 public:
135  SourceOutputModel(QObject *parent = nullptr);
136 
137 private:
138  void *d;
139 };
140 
141 class PULSEAUDIOQT_EXPORT StreamRestoreModel : public AbstractModel
142 {
143  Q_OBJECT
144 public:
145  StreamRestoreModel(QObject *parent = nullptr);
146 
147 private:
148  void *d;
149 };
150 
151 class PULSEAUDIOQT_EXPORT ModuleModel : public AbstractModel
152 {
153  Q_OBJECT
154 public:
155  ModuleModel(QObject *parent = nullptr);
156 
157 private:
158  void *d;
159 };
160 
161 } // PulseAudioQt
162 
163 #endif // PULSEAUDIO_H
UserRole
The primary namespace of PulseAudioQt.
Definition: card.cpp:16
A PulseAudio source.
Definition: source.h:19
A PulseAudio sink.
Definition: sink.h:19
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:12:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.