Phonon

objectdescription.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006-2008 Matthias Kretz <kretz@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.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "objectdescription.h"
24#include "objectdescription_p.h"
25
26#include <QObject>
27#include <QSet>
28#include <QStringList>
29#include "factory_p.h"
30#include "backendinterface.h"
31#include "platformplugin.h"
32#include "pulsesupport.h"
33
34namespace Phonon
35{
36
37ObjectDescriptionData::ObjectDescriptionData(int index, const QHash<QByteArray, QVariant> &properties)
38 : d(new ObjectDescriptionPrivate(index, properties))
39{
40}
41
42ObjectDescriptionData::ObjectDescriptionData(ObjectDescriptionPrivate *dd)
43 : d(dd)
44{
45}
46
47ObjectDescriptionData::~ObjectDescriptionData()
48{
49 delete d;
50}
51
52bool ObjectDescriptionData::operator==(const ObjectDescriptionData &otherDescription) const
53{
54 if (!isValid()) {
55 return !otherDescription.isValid();
56 }
57 if (!otherDescription.isValid()) {
58 return false;
59 }
60 return *d == *otherDescription.d;
61}
62
63int ObjectDescriptionData::index() const
64{
65 if (!isValid()) {
66 return -1;
67 }
68 return d->index;
69}
70
71QString ObjectDescriptionData::name() const
72{
73 if (!isValid()) {
74 return QString();
75 }
76 return d->name;
77}
78
79QString ObjectDescriptionData::description() const
80{
81 if (!isValid()) {
82 return QString();
83 }
84 return d->description;
85}
86
87QVariant ObjectDescriptionData::property(const char *name) const
88{
89 if (!isValid()) {
90 return QVariant();
91 }
92 return d->properties.value(name);
93}
94
95QList<QByteArray> ObjectDescriptionData::propertyNames() const
96{
97 if (!isValid()) {
98 return QList<QByteArray>();
99 }
100 return d->properties.keys();
101}
102
103bool ObjectDescriptionData::isValid() const
104{
105 return d != nullptr;
106}
107
108ObjectDescriptionData *ObjectDescriptionData::fromIndex(ObjectDescriptionType type, int index)
109{
110 bool is_audio_device = (AudioOutputDeviceType == type || AudioCaptureDeviceType == type);
111
112 PulseSupport *pulse = PulseSupport::getInstance();
113 if (is_audio_device && pulse->isUsed()) {
114 QList<int> indexes = pulse->objectDescriptionIndexes(type);
115 if (indexes.contains(index)) {
116 QHash<QByteArray, QVariant> properties = pulse->objectDescriptionProperties(type, index);
117 return new ObjectDescriptionData(index, properties);
118 }
119
120 // When Pulse is enabled, only try from the platform plugin or backend if it is about audio capture
121 if (type != AudioCaptureDeviceType)
122 return new ObjectDescriptionData(nullptr); // invalid
123 }
124
125#ifndef QT_NO_PHONON_PLATFORMPLUGIN
126 // prefer to get the ObjectDescriptionData from the platform plugin
127 PlatformPlugin *platformPlugin = Factory::platformPlugin();
128 if (platformPlugin) {
129 QList<int> indexes = platformPlugin->objectDescriptionIndexes(type);
130 if (indexes.contains(index)) {
131 QHash<QByteArray, QVariant> properties = platformPlugin->objectDescriptionProperties(type, index);
132 return new ObjectDescriptionData(index, properties);
133 }
134 }
135#endif //QT_NO_PHONON_PLATFORMPLUGIN
136
137 BackendInterface *iface = qobject_cast<BackendInterface *>(Factory::backend());
138 if (iface) {
139 QList<int> indexes = iface->objectDescriptionIndexes(type);
140 if (indexes.contains(index)) {
141 QHash<QByteArray, QVariant> properties = iface->objectDescriptionProperties(type, index);
142 return new ObjectDescriptionData(index, properties);
143 }
144 }
145
146 return new ObjectDescriptionData(nullptr); // invalid
147}
148
149} //namespace Phonon
150
151
152#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
153void Phonon::registerMetaTypes()
154{
155 // Deprecated, does nothing
156}
157#endif
158
159// vim: sw=4 ts=4
Data class for objects describing devices or features of the backend.
bool isValid() const
Returns true if the Tuple is valid (index != -1); otherwise returns false.
KGuiItem properties()
bool contains(const AT &value) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.