Changeset View
Changeset View
Standalone View
Standalone View
plugins/systemvolume/card.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 CARD_H | ||||
22 | #define CARD_H | ||||
23 | | ||||
24 | #include <pulse/introspect.h> | ||||
25 | | ||||
26 | #include <QMap> | ||||
27 | #include <QVariant> | ||||
28 | | ||||
29 | #include "profile.h" | ||||
30 | #include "port.h" | ||||
31 | #include "pulseobject.h" | ||||
32 | | ||||
33 | namespace QPulseAudio | ||||
34 | { | ||||
35 | | ||||
36 | class CardPort : public Port | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | Q_PROPERTY(QVariantMap properties READ properties NOTIFY propertiesChanged) | ||||
40 | public: | ||||
41 | CardPort(QObject *parent = nullptr) : Port(parent) {} | ||||
42 | virtual ~CardPort() {} | ||||
43 | | ||||
44 | // int direction; /**< A #pa_direction enum, indicating the direction of this port. */ | ||||
45 | // uint32_t n_profiles; /**< Number of entries in profile array */ | ||||
46 | // pa_card_profile_info** profiles; /**< \deprecated Superseded by profiles2 */ | ||||
47 | // 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 */ | ||||
48 | // 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 */ | ||||
49 | | ||||
50 | void update(const pa_card_port_info *info) | ||||
51 | { | ||||
52 | setInfo(info); | ||||
53 | | ||||
54 | m_properties.clear(); | ||||
55 | void *it = nullptr; | ||||
56 | while (const char *key = pa_proplist_iterate(info->proplist, &it)) { | ||||
57 | Q_ASSERT(key); | ||||
58 | const char *value = pa_proplist_gets(info->proplist, key); | ||||
59 | if (!value) { | ||||
60 | qCDebug(PLASMAPA) << "property" << key << "not a string"; | ||||
61 | continue; | ||||
62 | } | ||||
63 | Q_ASSERT(value); | ||||
64 | m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value)); | ||||
65 | } | ||||
66 | emit propertiesChanged(); | ||||
67 | } | ||||
68 | | ||||
69 | QVariantMap properties() const { return m_properties; } | ||||
70 | | ||||
71 | signals: | ||||
72 | void propertiesChanged(); | ||||
73 | | ||||
74 | private: | ||||
75 | QVariantMap m_properties; | ||||
76 | }; | ||||
77 | | ||||
78 | class Card : public PulseObject | ||||
79 | { | ||||
80 | Q_OBJECT | ||||
81 | Q_PROPERTY(QString name READ name NOTIFY nameChanged) | ||||
82 | Q_PROPERTY(QList<QObject *> profiles READ profiles NOTIFY profilesChanged) | ||||
83 | Q_PROPERTY(quint32 activeProfileIndex READ activeProfileIndex WRITE setActiveProfileIndex NOTIFY activeProfileIndexChanged) | ||||
84 | Q_PROPERTY(QList<QObject *> ports READ ports NOTIFY portsChanged) | ||||
85 | public: | ||||
86 | Card(QObject *parent); | ||||
87 | | ||||
88 | void update(const pa_card_info *info); | ||||
89 | | ||||
90 | QString name() const; | ||||
91 | QList<QObject *> profiles() const; | ||||
92 | quint32 activeProfileIndex() const; | ||||
93 | void setActiveProfileIndex(quint32 profileIndex); | ||||
94 | QList<QObject *> ports() const; | ||||
95 | | ||||
96 | signals: | ||||
97 | void nameChanged(); | ||||
98 | void profilesChanged(); | ||||
99 | void activeProfileIndexChanged(); | ||||
100 | void portsChanged(); | ||||
101 | | ||||
102 | private: | ||||
103 | QString m_name; | ||||
104 | QList<QObject *> m_profiles; | ||||
105 | quint32 m_activeProfileIndex; | ||||
106 | QList<QObject *> m_ports; | ||||
107 | }; | ||||
108 | | ||||
109 | } // QPulseAudio | ||||
110 | | ||||
111 | #endif // CARD_H |