summaryrefslogtreecommitdiffstats
path: root/src/PulseAudioQt/pulseobject_p.h
blob: 946b66c72c69446e57b57fb8b2f3cef7261a25d6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
    SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>

    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef PULSEOBJECT_P_H
#define PULSEOBJECT_P_H

#include "debug.h"

#include <QVariantMap>

#include <pulse/introspect.h>

#include "context.h"

namespace PulseAudioQt
{
class PulseObjectPrivate
{
public:
    explicit PulseObjectPrivate(PulseObject *q);
    virtual ~PulseObjectPrivate();

    PulseObject *q;
    QVariantMap m_properties;
    QString m_name;

    template<typename PAInfo>
    void updatePulseObject(PAInfo *info)
    {
        if (m_name != QString::fromUtf8(info->name)) {
            m_name = QString::fromUtf8(info->name);
            Q_EMIT q->nameChanged();
        }
    }

    template<typename PAInfo>
    void updateProperties(PAInfo *info)
    {
        m_properties.clear();
        void *it = nullptr;
        while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
            Q_ASSERT(key);
            const char *value = pa_proplist_gets(info->proplist, key);
            if (!value) {
                qDebug() << "property" << key << "not a string";
                continue;
            }
            Q_ASSERT(value);
            m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
        }
        Q_EMIT q->propertiesChanged();
    }
};
}
#endif