File indexing completed on 2024-04-14 15:40:19

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
0003     SPDX-FileCopyrightText: 2016 David Rosca <nowrep@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef PULSEAUDIO_H
0009 #define PULSEAUDIO_H
0010 
0011 #include <QAbstractListModel>
0012 
0013 #include "maps.h"
0014 #include "sink.h"
0015 #include "source.h"
0016 
0017 namespace QPulseAudio
0018 {
0019 class Context;
0020 
0021 class AbstractModel : public QAbstractListModel
0022 {
0023     Q_OBJECT
0024 public:
0025     enum ItemRole {
0026         PulseObjectRole = Qt::UserRole + 1,
0027     };
0028     Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
0029 
0030     Q_ENUM(ItemRole)
0031 
0032     ~AbstractModel() override;
0033     QHash<int, QByteArray> roleNames() const final;
0034     int rowCount(const QModelIndex &parent = QModelIndex()) const final;
0035     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0036     bool setData(const QModelIndex &index, const QVariant &value, int role) final;
0037 
0038     Q_INVOKABLE int role(const QByteArray &roleName) const;
0039 
0040 Q_SIGNALS:
0041     void countChanged();
0042 
0043 protected:
0044     AbstractModel(const MapBaseQObject *map, QObject *parent);
0045     void initRoleNames(const QMetaObject &qobjectMetaObject);
0046     Context *context() const;
0047 
0048 private Q_SLOTS:
0049     void propertyChanged();
0050 
0051 private:
0052     void onDataAdded(int index);
0053     void onDataRemoved(int index);
0054     QMetaMethod propertyChangedMetaMethod() const;
0055 
0056     const MapBaseQObject *m_map;
0057     QHash<int, QByteArray> m_roles;
0058     QHash<int, int> m_objectProperties;
0059     QHash<int, int> m_signalIndexToProperties;
0060 
0061 private:
0062     // Prevent leaf-classes from default constructing as we want to enforce
0063     // them passing us a context or explicit nullptrs.
0064     AbstractModel() = default;
0065 };
0066 
0067 class CardModel : public AbstractModel
0068 {
0069     Q_OBJECT
0070 public:
0071     explicit CardModel(QObject *parent = nullptr);
0072 };
0073 
0074 class SinkModel : public AbstractModel
0075 {
0076     Q_OBJECT
0077     Q_PROPERTY(QPulseAudio::Sink *defaultSink READ defaultSink NOTIFY defaultSinkChanged)
0078     Q_PROPERTY(QPulseAudio::Sink *preferredSink READ preferredSink NOTIFY preferredSinkChanged)
0079 public:
0080     enum ItemRole {
0081         SortByDefaultRole = PulseObjectRole + 1,
0082     };
0083     Q_ENUM(ItemRole)
0084 
0085     explicit SinkModel(QObject *parent = nullptr);
0086     Sink *defaultSink() const;
0087     Sink *preferredSink() const;
0088     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0089 
0090 Q_SIGNALS:
0091     void defaultSinkChanged();
0092     void preferredSinkChanged();
0093 
0094 private:
0095     void sinkAdded(int index);
0096     void sinkRemoved(int index);
0097     void updatePreferredSink();
0098     Sink *findPreferredSink() const;
0099 
0100     Sink *m_preferredSink;
0101 };
0102 
0103 class SinkInputModel : public AbstractModel
0104 {
0105     Q_OBJECT
0106 public:
0107     explicit SinkInputModel(QObject *parent = nullptr);
0108 };
0109 
0110 class SourceModel : public AbstractModel
0111 {
0112     Q_OBJECT
0113     Q_PROPERTY(QPulseAudio::Source *defaultSource READ defaultSource NOTIFY defaultSourceChanged)
0114 public:
0115     enum ItemRole {
0116         SortByDefaultRole = PulseObjectRole + 1,
0117     };
0118     Q_ENUM(ItemRole)
0119 
0120     explicit SourceModel(QObject *parent = nullptr);
0121     Source *defaultSource() const;
0122     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0123 
0124 Q_SIGNALS:
0125     void defaultSourceChanged();
0126 };
0127 
0128 class SourceOutputModel : public AbstractModel
0129 {
0130     Q_OBJECT
0131 public:
0132     explicit SourceOutputModel(QObject *parent = nullptr);
0133 };
0134 
0135 class StreamRestoreModel : public AbstractModel
0136 {
0137     Q_OBJECT
0138 public:
0139     explicit StreamRestoreModel(QObject *parent = nullptr);
0140 };
0141 
0142 class ModuleModel : public AbstractModel
0143 {
0144     Q_OBJECT
0145 public:
0146     explicit ModuleModel(QObject *parent = nullptr);
0147 };
0148 
0149 } // QPulseAudio
0150 
0151 #endif // PULSEAUDIO_H