File indexing completed on 2024-06-23 11:14:50

0001 /*
0002     SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #ifndef PULSEOBJECT_P_H
0007 #define PULSEOBJECT_P_H
0008 
0009 #include "debug.h"
0010 
0011 #include <QVariantMap>
0012 
0013 #include <pulse/introspect.h>
0014 
0015 #include "context.h"
0016 
0017 namespace PulseAudioQt
0018 {
0019 class PulseObjectPrivate
0020 {
0021 public:
0022     explicit PulseObjectPrivate(PulseObject *q);
0023     virtual ~PulseObjectPrivate();
0024 
0025     PulseObject *q;
0026     QVariantMap m_properties;
0027     QString m_name;
0028 
0029     template<typename PAInfo>
0030     void updatePulseObject(PAInfo *info)
0031     {
0032         if (m_name != QString::fromUtf8(info->name)) {
0033             m_name = QString::fromUtf8(info->name);
0034             Q_EMIT q->nameChanged();
0035         }
0036     }
0037 
0038     template<typename PAInfo>
0039     void updateProperties(PAInfo *info)
0040     {
0041         m_properties.clear();
0042         void *it = nullptr;
0043         while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
0044             Q_ASSERT(key);
0045             const char *value = pa_proplist_gets(info->proplist, key);
0046             if (!value) {
0047                 qCDebug(PULSEAUDIOQT) << "property" << key << "not a string";
0048                 continue;
0049             }
0050             Q_ASSERT(value);
0051             m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
0052         }
0053         Q_EMIT q->propertiesChanged();
0054     }
0055 };
0056 }
0057 #endif