File indexing completed on 2025-02-09 05:31:50
0001 /* This file is part of the KDE project 0002 Copyright (C) 2006-2008 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #include "objectdescription.h" 0024 #include "objectdescription_p.h" 0025 0026 #include <QObject> 0027 #include <QSet> 0028 #include <QStringList> 0029 #include "factory_p.h" 0030 #include "backendinterface.h" 0031 #include "platformplugin.h" 0032 #include "pulsesupport.h" 0033 0034 namespace Phonon 0035 { 0036 0037 ObjectDescriptionData::ObjectDescriptionData(int index, const QHash<QByteArray, QVariant> &properties) 0038 : d(new ObjectDescriptionPrivate(index, properties)) 0039 { 0040 } 0041 0042 ObjectDescriptionData::ObjectDescriptionData(ObjectDescriptionPrivate *dd) 0043 : d(dd) 0044 { 0045 } 0046 0047 ObjectDescriptionData::~ObjectDescriptionData() 0048 { 0049 delete d; 0050 } 0051 0052 bool ObjectDescriptionData::operator==(const ObjectDescriptionData &otherDescription) const 0053 { 0054 if (!isValid()) { 0055 return !otherDescription.isValid(); 0056 } 0057 if (!otherDescription.isValid()) { 0058 return false; 0059 } 0060 return *d == *otherDescription.d; 0061 } 0062 0063 int ObjectDescriptionData::index() const 0064 { 0065 if (!isValid()) { 0066 return -1; 0067 } 0068 return d->index; 0069 } 0070 0071 QString ObjectDescriptionData::name() const 0072 { 0073 if (!isValid()) { 0074 return QString(); 0075 } 0076 return d->name; 0077 } 0078 0079 QString ObjectDescriptionData::description() const 0080 { 0081 if (!isValid()) { 0082 return QString(); 0083 } 0084 return d->description; 0085 } 0086 0087 QVariant ObjectDescriptionData::property(const char *name) const 0088 { 0089 if (!isValid()) { 0090 return QVariant(); 0091 } 0092 return d->properties.value(name); 0093 } 0094 0095 QList<QByteArray> ObjectDescriptionData::propertyNames() const 0096 { 0097 if (!isValid()) { 0098 return QList<QByteArray>(); 0099 } 0100 return d->properties.keys(); 0101 } 0102 0103 bool ObjectDescriptionData::isValid() const 0104 { 0105 return d != nullptr; 0106 } 0107 0108 ObjectDescriptionData *ObjectDescriptionData::fromIndex(ObjectDescriptionType type, int index) 0109 { 0110 bool is_audio_device = (AudioOutputDeviceType == type || AudioCaptureDeviceType == type); 0111 0112 PulseSupport *pulse = PulseSupport::getInstance(); 0113 if (is_audio_device && pulse->isUsed()) { 0114 QList<int> indexes = pulse->objectDescriptionIndexes(type); 0115 if (indexes.contains(index)) { 0116 QHash<QByteArray, QVariant> properties = pulse->objectDescriptionProperties(type, index); 0117 return new ObjectDescriptionData(index, properties); 0118 } 0119 0120 // When Pulse is enabled, only try from the platform plugin or backend if it is about audio capture 0121 if (type != AudioCaptureDeviceType) 0122 return new ObjectDescriptionData(nullptr); // invalid 0123 } 0124 0125 #ifndef QT_NO_PHONON_PLATFORMPLUGIN 0126 // prefer to get the ObjectDescriptionData from the platform plugin 0127 PlatformPlugin *platformPlugin = Factory::platformPlugin(); 0128 if (platformPlugin) { 0129 QList<int> indexes = platformPlugin->objectDescriptionIndexes(type); 0130 if (indexes.contains(index)) { 0131 QHash<QByteArray, QVariant> properties = platformPlugin->objectDescriptionProperties(type, index); 0132 return new ObjectDescriptionData(index, properties); 0133 } 0134 } 0135 #endif //QT_NO_PHONON_PLATFORMPLUGIN 0136 0137 BackendInterface *iface = qobject_cast<BackendInterface *>(Factory::backend()); 0138 if (iface) { 0139 QList<int> indexes = iface->objectDescriptionIndexes(type); 0140 if (indexes.contains(index)) { 0141 QHash<QByteArray, QVariant> properties = iface->objectDescriptionProperties(type, index); 0142 return new ObjectDescriptionData(index, properties); 0143 } 0144 } 0145 0146 return new ObjectDescriptionData(nullptr); // invalid 0147 } 0148 0149 } //namespace Phonon 0150 0151 0152 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0153 void Phonon::registerMetaTypes() 0154 { 0155 // Deprecated, does nothing 0156 } 0157 #endif 0158 0159 // vim: sw=4 ts=4