File indexing completed on 2024-04-21 16:20:32

0001 /*
0002     SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef STREAM_H
0008 #define STREAM_H
0009 
0010 #include <QString>
0011 
0012 #include <pulse/volume.h>
0013 
0014 #include "pulseobject.h"
0015 #include "volumeobject.h"
0016 
0017 #include "context.h"
0018 // Properties need fully qualified classes even with pointers.
0019 #include "client.h"
0020 
0021 namespace QPulseAudio
0022 {
0023 class Stream : public VolumeObject
0024 {
0025     Q_OBJECT
0026     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0027     Q_PROPERTY(QPulseAudio::Client *client READ client NOTIFY clientChanged)
0028     Q_PROPERTY(bool virtualStream READ isVirtualStream NOTIFY virtualStreamChanged)
0029     Q_PROPERTY(quint32 deviceIndex READ deviceIndex WRITE setDeviceIndex NOTIFY deviceIndexChanged)
0030     Q_PROPERTY(bool corked READ isCorked NOTIFY corkedChanged)
0031 public:
0032     template<typename PAInfo>
0033     void updateStream(const PAInfo *info)
0034     {
0035         updateVolumeObject(info);
0036 
0037         if (m_name != QString::fromUtf8(info->name)) {
0038             m_name = QString::fromUtf8(info->name);
0039             Q_EMIT nameChanged();
0040         }
0041         if (m_hasVolume != info->has_volume) {
0042             m_hasVolume = info->has_volume;
0043             Q_EMIT hasVolumeChanged();
0044         }
0045         if (m_volumeWritable != info->volume_writable) {
0046             m_volumeWritable = info->volume_writable;
0047             Q_EMIT isVolumeWritableChanged();
0048         }
0049         if (m_clientIndex != info->client) {
0050             m_clientIndex = info->client;
0051             Q_EMIT clientChanged();
0052         }
0053         if (m_virtualStream != (info->client == PA_INVALID_INDEX)) {
0054             m_virtualStream = info->client == PA_INVALID_INDEX;
0055             Q_EMIT virtualStreamChanged();
0056         }
0057         if (m_corked != info->corked) {
0058             m_corked = info->corked;
0059             Q_EMIT corkedChanged();
0060         }
0061     }
0062 
0063     QString name() const;
0064     Client *client() const;
0065     bool isVirtualStream() const;
0066     quint32 deviceIndex() const;
0067     bool isCorked() const;
0068 
0069     virtual void setDeviceIndex(quint32 deviceIndex) = 0;
0070 
0071 Q_SIGNALS:
0072     void nameChanged();
0073     void clientChanged();
0074     void virtualStreamChanged();
0075     void deviceIndexChanged();
0076     void corkedChanged();
0077 
0078 protected:
0079     explicit Stream(QObject *parent);
0080     ~Stream() override;
0081 
0082     quint32 m_deviceIndex;
0083 
0084 private:
0085     QString m_name;
0086     quint32 m_clientIndex;
0087     bool m_virtualStream = false;
0088     bool m_corked = false;
0089 };
0090 
0091 } // QPulseAudio
0092 
0093 #endif // STREAM_H