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

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 CARD_H
0008 #define CARD_H
0009 
0010 #include <pulse/introspect.h>
0011 
0012 #include <QMap>
0013 #include <QVariant>
0014 
0015 #include "port.h"
0016 #include "profile.h"
0017 #include "pulseobject.h"
0018 
0019 namespace QPulseAudio
0020 {
0021 class CardPort : public Port
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged)
0025 public:
0026     explicit CardPort(QObject *parent = nullptr)
0027         : Port(parent)
0028     {
0029     }
0030     ~CardPort() override = default;
0031 
0032     //    int direction;                      /**< A #pa_direction enum, indicating the direction of this port. */
0033     //    uint32_t n_profiles;                /**< Number of entries in profile array */
0034     //    pa_card_profile_info** profiles;    /**< \deprecated Superseded by profiles2 */
0035     //    int64_t latency_offset;             /**< Latency offset of the port that gets added to the sink/source latency when the port is active. \since 3.0 */
0036     //    pa_card_profile_info2** profiles2;  /**< Array of pointers to available profiles, or NULL. Array is terminated by an entry set to NULL. \since 5.0 */
0037 
0038     void update(const pa_card_port_info *info)
0039     {
0040         setInfo(info);
0041 
0042         QVariantMap properties;
0043         void *it = nullptr;
0044         while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
0045             Q_ASSERT(key);
0046             const char *value = pa_proplist_gets(info->proplist, key);
0047             if (!value) {
0048                 qCDebug(PLASMAPA) << "property" << key << "not a string";
0049                 continue;
0050             }
0051             Q_ASSERT(value);
0052             properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
0053         }
0054 
0055         if (m_properties != properties) {
0056             m_properties = properties;
0057             Q_EMIT propertiesChanged();
0058         }
0059     }
0060 
0061     QVariantMap properties() const
0062     {
0063         return m_properties;
0064     }
0065 
0066 Q_SIGNALS:
0067     void propertiesChanged();
0068 
0069 private:
0070     QVariantMap m_properties;
0071 };
0072 
0073 class Card : public PulseObject
0074 {
0075     Q_OBJECT
0076     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0077     Q_PROPERTY(QList<QObject *> profiles READ profiles NOTIFY profilesChanged)
0078     Q_PROPERTY(quint32 activeProfileIndex READ activeProfileIndex WRITE setActiveProfileIndex NOTIFY activeProfileIndexChanged)
0079     Q_PROPERTY(QList<QObject *> ports READ ports NOTIFY portsChanged)
0080 public:
0081     explicit Card(QObject *parent);
0082 
0083     void update(const pa_card_info *info);
0084 
0085     QString name() const;
0086     QList<QObject *> profiles() const;
0087     quint32 activeProfileIndex() const;
0088     void setActiveProfileIndex(quint32 profileIndex);
0089     QList<QObject *> ports() const;
0090 
0091 Q_SIGNALS:
0092     void nameChanged();
0093     void profilesChanged();
0094     void activeProfileIndexChanged();
0095     void portsChanged();
0096 
0097 private:
0098     QString m_name;
0099     QList<QObject *> m_profiles;
0100     quint32 m_activeProfileIndex = -1;
0101     QList<QObject *> m_ports;
0102 };
0103 
0104 } // QPulseAudio
0105 
0106 #endif // CARD_H