Example #1
0
ObjectDescriptionData *ObjectDescriptionData::fromIndex(ObjectDescriptionType type, int index)
{
    bool is_audio_device = (AudioOutputDeviceType == type || AudioCaptureDeviceType == type);

    PulseSupport *pulse = PulseSupport::getInstance();
    if (is_audio_device && pulse->isActive()) {
        QList<int> indexes = pulse->objectDescriptionIndexes(type);
        if (indexes.contains(index)) {
            QHash<QByteArray, QVariant> properties = pulse->objectDescriptionProperties(type, index);
            return new ObjectDescriptionData(index, properties);
        }
    } else {
        BackendInterface *iface = qobject_cast<BackendInterface *>(Factory::backend());

        // prefer to get the ObjectDescriptionData from the platform plugin for audio devices
#ifndef QT_NO_PHONON_PLATFORMPLUGIN
        if (is_audio_device) {
            PlatformPlugin *platformPlugin = Factory::platformPlugin();
            if (platformPlugin) {
                QList<int> indexes = platformPlugin->objectDescriptionIndexes(type);
                if (indexes.contains(index)) {
                    QHash<QByteArray, QVariant> properties = platformPlugin->objectDescriptionProperties(type, index);
                    return new ObjectDescriptionData(index, properties);
                }
            }
        }
#endif //QT_NO_PHONON_PLATFORMPLUGIN

        if (iface) {
            QList<int> indexes = iface->objectDescriptionIndexes(type);
            if (indexes.contains(index)) {
                QHash<QByteArray, QVariant> properties = iface->objectDescriptionProperties(type, index);
                return new ObjectDescriptionData(index, properties);
            }
        }
    }
    return new ObjectDescriptionData(0); // invalid
}