static QList<int> sortDevicesByCategoryPriority(const GlobalConfig *config, const QSettingsGroup *backendConfig, ObjectDescriptionType type, Phonon::Category category, QList<int> &defaultList) { Q_ASSERT(config); Q_ASSERT(backendConfig); Q_ASSERT(type == AudioOutputDeviceType || type == AudioCaptureDeviceType); if (defaultList.size() <= 1) { // nothing to sort return defaultList; } else { // make entries unique QSet<int> seen; QMutableListIterator<int> it(defaultList); while (it.hasNext()) { if (seen.contains(it.next())) { it.remove(); } else { seen.insert(it.value()); } } } QList<int> deviceList; PulseSupport *pulse = PulseSupport::getInstance(); if (pulse->isActive()) { deviceList = pulse->objectIndexesByCategory(type, category); } else { QString categoryKey = QLatin1String("Category_") + QString::number(static_cast<int>(category)); if (!backendConfig->hasKey(categoryKey)) { // no list in config for the given category categoryKey = QLatin1String("Category_") + QString::number(static_cast<int>(Phonon::NoCategory)); if (!backendConfig->hasKey(categoryKey)) { // no list in config for NoCategory return defaultList; } } //Now the list from d->config deviceList = backendConfig->value(categoryKey, QList<int>()); } //if there are devices in d->config that the backend doesn't report, remove them from the list QMutableListIterator<int> i(deviceList); while (i.hasNext()) { if (0 == defaultList.removeAll(i.next())) { i.remove(); } } //if the backend reports more devices that are not in d->config append them to the list deviceList += defaultList; return deviceList; }
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 }