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

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 PULSEOBJECT_H
0008 #define PULSEOBJECT_H
0009 
0010 #include "debug.h"
0011 #include <QObject>
0012 #include <QVariant>
0013 
0014 #include <pulse/introspect.h>
0015 
0016 namespace QPulseAudio
0017 {
0018 class Context;
0019 
0020 class PulseObject : public QObject
0021 {
0022     Q_OBJECT
0023     Q_PROPERTY(quint32 index READ index CONSTANT)
0024     Q_PROPERTY(QString iconName READ iconName CONSTANT)
0025     Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged)
0026 public:
0027     template<typename PAInfo>
0028     void updatePulseObject(PAInfo *info)
0029     {
0030         m_index = info->index;
0031 
0032         QVariantMap properties;
0033         void *it = nullptr;
0034         while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
0035             Q_ASSERT(key);
0036             const char *value = pa_proplist_gets(info->proplist, key);
0037             if (!value) {
0038                 qCDebug(PLASMAPA) << "property" << key << "not a string";
0039                 continue;
0040             }
0041             Q_ASSERT(value);
0042             properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
0043         }
0044 
0045         if (m_properties != properties) {
0046             m_properties = properties;
0047             Q_EMIT propertiesChanged();
0048         }
0049     }
0050 
0051     quint32 index() const;
0052     QString iconName() const;
0053     QVariantMap properties() const;
0054 
0055 Q_SIGNALS:
0056     void propertiesChanged();
0057 
0058 protected:
0059     explicit PulseObject(QObject *parent);
0060     ~PulseObject() override;
0061 
0062     Context *context() const;
0063     quint32 m_index;
0064     QVariantMap m_properties;
0065 
0066 private:
0067     // Ensure that we get properly parented.
0068     PulseObject();
0069 };
0070 
0071 } // QPulseAudio
0072 
0073 #endif // PULSEOBJECT_H