Changeset View
Changeset View
Standalone View
Standalone View
plugins/systemvolume/pulseobject.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2014-2015 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef PULSEOBJECT_H | ||||
22 | #define PULSEOBJECT_H | ||||
23 | | ||||
24 | #include "debug.h" | ||||
25 | #include <QObject> | ||||
26 | | ||||
27 | #include <pulse/introspect.h> | ||||
28 | | ||||
29 | namespace QPulseAudio | ||||
30 | { | ||||
31 | | ||||
32 | class Context; | ||||
33 | | ||||
34 | class PulseObject : public QObject | ||||
35 | { | ||||
36 | Q_OBJECT | ||||
37 | Q_PROPERTY(quint32 index READ index CONSTANT) | ||||
38 | Q_PROPERTY(QString iconName READ iconName CONSTANT) | ||||
39 | Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged) | ||||
40 | public: | ||||
41 | template <typename PAInfo> | ||||
42 | void updatePulseObject(PAInfo *info) | ||||
43 | { | ||||
44 | m_index = info->index; | ||||
45 | | ||||
46 | m_properties.clear(); | ||||
47 | void *it = nullptr; | ||||
48 | while (const char *key = pa_proplist_iterate(info->proplist, &it)) { | ||||
49 | Q_ASSERT(key); | ||||
50 | const char *value = pa_proplist_gets(info->proplist, key); | ||||
51 | if (!value) { | ||||
52 | qCDebug(PLASMAPA) << "property" << key << "not a string"; | ||||
53 | continue; | ||||
54 | } | ||||
55 | Q_ASSERT(value); | ||||
56 | m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); | ||||
57 | } | ||||
58 | emit propertiesChanged(); | ||||
59 | } | ||||
60 | | ||||
61 | quint32 index() const; | ||||
62 | QString iconName() const; | ||||
63 | QVariantMap properties() const; | ||||
64 | | ||||
65 | signals: | ||||
66 | void propertiesChanged(); | ||||
67 | | ||||
68 | protected: | ||||
69 | PulseObject(QObject *parent); | ||||
70 | virtual ~PulseObject(); | ||||
71 | | ||||
72 | Context *context() const; | ||||
73 | quint32 m_index; | ||||
74 | QVariantMap m_properties; | ||||
75 | | ||||
76 | private: | ||||
77 | // Ensure that we get properly parented. | ||||
78 | PulseObject(); | ||||
79 | }; | ||||
80 | | ||||
81 | } // QPulseAudio | ||||
82 | | ||||
83 | #endif // PULSEOBJECT_H |