File indexing completed on 2024-07-14 04:37:32

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 "pulseaudioqt_export.h"
0014 
0015 namespace PulseAudioQt
0016 {
0017 class Context;
0018 class MapBaseQObject;
0019 class Sink;
0020 class Source;
0021 class AbstractModelPrivate;
0022 class SinkModelPrivate;
0023 
0024 class PULSEAUDIOQT_EXPORT AbstractModel : public QAbstractListModel
0025 {
0026     Q_OBJECT
0027 public:
0028     enum ItemRole { PulseObjectRole = Qt::UserRole + 1 };
0029 
0030     Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
0031 
0032     ~AbstractModel() override;
0033     QHash<int, QByteArray> roleNames() const final override;
0034     int rowCount(const QModelIndex &parent = QModelIndex()) const final override;
0035     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0036     bool setData(const QModelIndex &index, const QVariant &value, int role) final override;
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     AbstractModelPrivate *d;
0057 
0058     // Prevent leaf-classes from default constructing as we want to enforce
0059     // them passing us a context or explicit nullptrs.
0060     AbstractModel()
0061     {
0062     }
0063 };
0064 
0065 class PULSEAUDIOQT_EXPORT CardModel : public AbstractModel
0066 {
0067     Q_OBJECT
0068 public:
0069     CardModel(QObject *parent = nullptr);
0070 
0071 private:
0072     void *d;
0073 };
0074 
0075 class PULSEAUDIOQT_EXPORT SinkModel : public AbstractModel
0076 {
0077     Q_OBJECT
0078     Q_PROPERTY(PulseAudioQt::Sink *defaultSink READ defaultSink NOTIFY defaultSinkChanged)
0079     Q_PROPERTY(PulseAudioQt::Sink *preferredSink READ preferredSink NOTIFY preferredSinkChanged)
0080 public:
0081     enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 };
0082     Q_ENUM(ItemRole)
0083 
0084     SinkModel(QObject *parent = nullptr);
0085     virtual ~SinkModel();
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     SinkModelPrivate *d;
0100 };
0101 
0102 class PULSEAUDIOQT_EXPORT SinkInputModel : public AbstractModel
0103 {
0104     Q_OBJECT
0105 public:
0106     SinkInputModel(QObject *parent = nullptr);
0107 
0108 private:
0109     void *d;
0110 };
0111 
0112 class PULSEAUDIOQT_EXPORT SourceModel : public AbstractModel
0113 {
0114     Q_OBJECT
0115     Q_PROPERTY(PulseAudioQt::Source *defaultSource READ defaultSource NOTIFY defaultSourceChanged)
0116 public:
0117     enum ItemRole { SortByDefaultRole = PulseObjectRole + 1 };
0118     Q_ENUM(ItemRole)
0119 
0120     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 private:
0128     void *d;
0129 };
0130 
0131 class PULSEAUDIOQT_EXPORT SourceOutputModel : public AbstractModel
0132 {
0133     Q_OBJECT
0134 public:
0135     SourceOutputModel(QObject *parent = nullptr);
0136 
0137 private:
0138     void *d;
0139 };
0140 
0141 class PULSEAUDIOQT_EXPORT StreamRestoreModel : public AbstractModel
0142 {
0143     Q_OBJECT
0144 public:
0145     StreamRestoreModel(QObject *parent = nullptr);
0146 
0147 private:
0148     void *d;
0149 };
0150 
0151 class PULSEAUDIOQT_EXPORT ModuleModel : public AbstractModel
0152 {
0153     Q_OBJECT
0154 public:
0155     ModuleModel(QObject *parent = nullptr);
0156 
0157 private:
0158     void *d;
0159 };
0160 
0161 } // PulseAudioQt
0162 
0163 #endif // PULSEAUDIO_H