23#include "globalconfig.h"
24#include "globalconfig_p.h"
27#include "phonondefs_p.h"
28#include "platformplugin.h"
29#include "backendinterface.h"
30#include "qsettingsgroup_p.h"
31#include "phononnamespace_p.h"
32#include "phononnamespace.h"
33#include "pulsesupport.h"
45GlobalConfig::GlobalConfig()
46 : k_ptr(new GlobalConfigPrivate)
50GlobalConfig::~GlobalConfig()
56 FilterAdvancedDevices = 1,
57 FilterHardwareDevices = 2,
58 FilterUnavailableDevices = 4
61static void filter(ObjectDescriptionType type, BackendInterface *backendIface,
QList<int> *list,
int whatToFilter)
64 while (it.hasNext()) {
67 properties = backendIface->objectDescriptionProperties(type, it.next());
69 properties = PulseSupport::getInstance()->objectDescriptionProperties(type, it.next());
71 if (whatToFilter & FilterAdvancedDevices) {
78 if (whatToFilter & FilterHardwareDevices) {
85 if (whatToFilter & FilterUnavailableDevices) {
95#ifndef QT_NO_PHONON_SETTINGSGROUP
96static QList<int> sortDevicesByCategoryPriority(
const GlobalConfig *config,
const QSettingsGroup *backendConfig, ObjectDescriptionType type, Category category,
QList<int> &defaultList)
98 Q_ASSERT(config); Q_UNUSED(config);
99 Q_ASSERT(backendConfig);
100 Q_ASSERT(type == AudioOutputDeviceType);
102 if (defaultList.
size() <= 1) {
109 while (it.hasNext()) {
119 PulseSupport *pulse = PulseSupport::getInstance();
120 if (pulse->isUsed()) {
121 deviceList = pulse->objectIndexesByCategory(type, category);
124 if (!backendConfig->hasKey(categoryKey)) {
127 if (!backendConfig->hasKey(categoryKey)) {
139 while (i.hasNext()) {
140 if (0 == defaultList.
removeAll(i.next())) {
146 deviceList += defaultList;
151static QList<int> sortDevicesByCategoryPriority(
const GlobalConfig *config,
const QSettingsGroup *backendConfig, ObjectDescriptionType type, CaptureCategory category,
QList<int> &defaultList)
153 Q_ASSERT(config); Q_UNUSED(config);
154 Q_ASSERT(backendConfig);
155 Q_ASSERT(type == AudioCaptureDeviceType || type == VideoCaptureDeviceType);
157 if (defaultList.
size() <= 1) {
164 while (it.hasNext()) {
174 PulseSupport *pulse = PulseSupport::getInstance();
175 if (pulse->isUsed()) {
176 deviceList = pulse->objectIndexesByCategory(type, category);
179 if (!backendConfig->hasKey(categoryKey)) {
182 if (!backendConfig->hasKey(categoryKey)) {
194 while (i.hasNext()) {
195 if (0 == defaultList.
removeAll(i.next())) {
201 deviceList += defaultList;
206bool GlobalConfig::hideAdvancedDevices()
const
208 P_D(
const GlobalConfig);
210 const QSettingsGroup generalGroup(&d->config,
QLatin1String(
"General"));
211 return generalGroup.value(
QLatin1String(
"HideAdvancedDevices"),
true);
214void GlobalConfig::setHideAdvancedDevices(
bool hide)
217 QSettingsGroup generalGroup(&d->config,
QLatin1String(
"General"));
218 generalGroup.setValue(
QLatin1String(
"HideAdvancedDevices"), hide);
222static bool isHiddenAudioOutputDevice(
const GlobalConfig *config,
int i)
226#ifndef QT_NO_PHONON_SETTINGSGROUP
227 if (!config->hideAdvancedDevices())
231 AudioOutputDevice ad = AudioOutputDevice::fromIndex(i);
232 const QVariant var = ad.property(
"isAdvanced");
236#ifndef PHONON_NO_AUDIOCAPTURE
237static bool isHiddenAudioCaptureDevice(
const GlobalConfig *config,
int i)
241#ifndef QT_NO_PHONON_SETTINGSGROUP
242 if (!config->hideAdvancedDevices())
246 AudioCaptureDevice ad = AudioCaptureDevice::fromIndex(i);
247 const QVariant var = ad.property(
"isAdvanced");
252#ifndef PHONON_NO_VIDEOCAPTURE
253static bool isHiddenVideoCaptureDevice(
const GlobalConfig *config,
int i)
257#ifndef QT_NO_PHONON_SETTINGSGROUP
258 if (!config->hideAdvancedDevices())
262 VideoCaptureDevice vd = VideoCaptureDevice::fromIndex(i);
263 const QVariant var = vd.property(
"isAdvanced");
268static QList<int> reindexList(
const GlobalConfig *config, ObjectDescriptionType type, Category category,
QList<int>newOrder)
271 Q_ASSERT(type == AudioOutputDeviceType);
284 int override = GlobalConfig::ShowUnavailableDevices | GlobalConfig::ShowAdvancedDevices;
285 QList<int> currentList = config->audioOutputDeviceListFor(category,
override);
290 foreach (
int i, newOrder) {
291 int found = currentList.
indexOf(i);
301 while (found < currentList.
size()) {
302 bool hidden = isHiddenAudioOutputDevice(config, currentList.
at(found));
311 if (currentList.
size() > 0)
312 newList += currentList;
321static QList<int> reindexList(
const GlobalConfig *config, ObjectDescriptionType type, CaptureCategory category,
QList<int>newOrder)
324 Q_ASSERT(type == AudioCaptureDeviceType || type == VideoCaptureDeviceType);
327 int override = GlobalConfig::ShowUnavailableDevices | GlobalConfig::ShowAdvancedDevices;
330#ifndef PHONON_NO_AUDIOCAPTURE
331 case AudioCaptureDeviceType:
332 currentList = config->audioCaptureDeviceListFor(category,
override);
336#ifndef PHONON_NO_VIDEOCAPTURE
337 case VideoCaptureDeviceType:
338 currentList = config->videoCaptureDeviceListFor(category,
override);
347 foreach (
int i, newOrder) {
348 int found = currentList.
indexOf(i);
358 while (found < currentList.
size()) {
362#ifndef PHONON_NO_AUDIOCAPTURE
363 case AudioCaptureDeviceType:
364 hidden = isHiddenAudioCaptureDevice(config, currentList.
at(found));
368#ifndef PHONON_NO_VIDEOCAPTURE
369 case VideoCaptureDeviceType:
370 hidden = isHiddenVideoCaptureDevice(config, currentList.
at(found));
385 if (currentList.
size() > 0)
386 newList += currentList;
391void GlobalConfig::setAudioOutputDeviceListFor(Category category,
QList<int> order)
393 PulseSupport *pulse = PulseSupport::getInstance();
394 if (pulse->isUsed()) {
395 pulse->setOutputDevicePriorityForCategory(category, order);
399#ifndef QT_NO_PHONON_SETTINGSGROUP
401 QSettingsGroup backendConfig(&d->config,
QLatin1String(
"AudioOutputDevice"));
403 order = reindexList(
this, AudioOutputDeviceType, category, order);
405 const QList<int> noCategoryOrder = audioOutputDeviceListFor(NoCategory, ShowUnavailableDevices|ShowAdvancedDevices);
406 if (category != NoCategory && order == noCategoryOrder) {
414QList<int> GlobalConfig::audioOutputDeviceListFor(Category category,
int override)
const
416 P_D(
const GlobalConfig);
418#ifndef QT_NO_PHONON_SETTINGSGROUP
419 const bool hide = ((
override & AdvancedDevicesFromSettings)
420 ? hideAdvancedDevices()
421 : static_cast<bool>(override & HideAdvancedDevices));
423 const bool hide = !((
override & AdvancedDevicesFromSettings) &&
static_cast<bool>(
override & HideAdvancedDevices));
428 PulseSupport *pulse = PulseSupport::getInstance();
429 if (pulse->isUsed()) {
430 defaultList = pulse->objectDescriptionIndexes(AudioOutputDeviceType);
431 if (hide || (
override & HideUnavailableDevices)) {
432 filter(AudioOutputDeviceType,
nullptr, &defaultList,
433 (hide ? FilterAdvancedDevices : 0)
434 | ((
override & HideUnavailableDevices) ? FilterUnavailableDevices : 0)
438 BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend());
440#ifndef QT_NO_PHONON_PLATFORMPLUGIN
441 if (PlatformPlugin *platformPlugin = Factory::platformPlugin()) {
444 defaultList = platformPlugin->objectDescriptionIndexes(AudioOutputDeviceType);
447 while (it.hasNext()) {
448 AudioOutputDevice objDesc = AudioOutputDevice::fromIndex(it.next());
449 const QVariant var = objDesc.property(
"isAdvanced");
461 QList<int> list = backendIface->objectDescriptionIndexes(AudioOutputDeviceType);
462 if (hide || !defaultList.
isEmpty() || (
override & HideUnavailableDevices)) {
463 filter(AudioOutputDeviceType, backendIface, &list,
464 (hide ? FilterAdvancedDevices : 0)
466 | (defaultList.
isEmpty() ? 0 : FilterHardwareDevices)
467 | ((
override & HideUnavailableDevices) ? FilterUnavailableDevices : 0)
474#ifndef QT_NO_PHONON_SETTINGSGROUP
475 const QSettingsGroup backendConfig(&d->config,
QLatin1String(
"AudioOutputDevice"));
476 return sortDevicesByCategoryPriority(
this, &backendConfig, AudioOutputDeviceType, category, defaultList);
483int GlobalConfig::audioOutputDeviceFor(Category category,
int override)
const
485#ifndef QT_NO_PHONON_SETTINGSGROUP
486 QList<int> ret = audioOutputDeviceListFor(category,
override);
495 return deviceProperties(AudioOutputDeviceType, index);
499#ifndef PHONON_NO_AUDIOCAPTURE
500void GlobalConfig::setAudioCaptureDeviceListFor(CaptureCategory category,
QList<int> order)
503 PulseSupport *pulse = PulseSupport::getInstance();
504 if (pulse->isUsed()) {
505 pulse->setCaptureDevicePriorityForCategory(category, order);
509#ifndef QT_NO_PHONON_SETTINGSGROUP
511 QSettingsGroup backendConfig(&d->config,
QLatin1String(
"AudioCaptureDevice"));
513 order = reindexList(
this, AudioCaptureDeviceType, category, order);
515 const QList<int> noCategoryOrder = audioCaptureDeviceListFor(NoCaptureCategory, ShowUnavailableDevices|ShowAdvancedDevices);
516 if (category != NoCaptureCategory && order == noCategoryOrder) {
524QList<int> GlobalConfig::audioCaptureDeviceListFor(CaptureCategory category,
int override)
const
526 P_D(
const GlobalConfig);
528#ifndef QT_NO_PHONON_SETTINGSGROUP
529 const bool hide = ((
override & AdvancedDevicesFromSettings)
530 ? hideAdvancedDevices()
531 : static_cast<bool>(override & HideAdvancedDevices));
533 const bool hide = !((
override & AdvancedDevicesFromSettings) &&
static_cast<bool>(
override & HideAdvancedDevices));
538 PulseSupport *pulse = PulseSupport::getInstance();
539 if (pulse->isUsed()) {
540 defaultList = pulse->objectDescriptionIndexes(AudioCaptureDeviceType);
541 if (hide || (
override & HideUnavailableDevices)) {
542 filter(AudioCaptureDeviceType,
nullptr, &defaultList,
543 (hide ? FilterAdvancedDevices : 0)
544 | ((
override & HideUnavailableDevices) ? FilterUnavailableDevices : 0)
548 BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend());
550#ifndef QT_NO_PHONON_PLATFORMPLUGIN
551 if (PlatformPlugin *platformPlugin = Factory::platformPlugin()) {
554 defaultList += platformPlugin->objectDescriptionIndexes(AudioCaptureDeviceType);
557 while (it.hasNext()) {
558 AudioCaptureDevice objDesc = AudioCaptureDevice::fromIndex(it.next());
559 const QVariant var = objDesc.property(
"isAdvanced");
571 QList<int> list = backendIface->objectDescriptionIndexes(AudioCaptureDeviceType);
572 if (hide || !defaultList.
isEmpty() || (
override & HideUnavailableDevices)) {
573 filter(AudioCaptureDeviceType, backendIface, &list,
574 (hide ? FilterAdvancedDevices : 0)
576 | (defaultList.
isEmpty() ? 0 : FilterHardwareDevices)
577 | ((
override & HideUnavailableDevices) ? FilterUnavailableDevices : 0)
584#ifndef QT_NO_PHONON_SETTINGSGROUP
585 const QSettingsGroup backendConfig(&d->config,
QLatin1String(
"AudioCaptureDevice"));
586 return sortDevicesByCategoryPriority(
this, &backendConfig, AudioCaptureDeviceType, category, defaultList);
588#ifndef QT_NO_PHONON_PLATFORMPLUGIN
596int GlobalConfig::audioCaptureDeviceFor(CaptureCategory category,
int override)
const
598 QList<int> ret = audioCaptureDeviceListFor(category,
override);
606 return deviceProperties(AudioCaptureDeviceType, index);
609void GlobalConfig::setAudioCaptureDeviceListFor(Category category,
QList<int> order)
611 CaptureCategory cat = categoryToCaptureCategory(category);
612 setAudioCaptureDeviceListFor(cat, order);
615QList<int> GlobalConfig::audioCaptureDeviceListFor(Category category,
int override)
const
617 CaptureCategory cat = categoryToCaptureCategory(category);
618 return audioCaptureDeviceListFor(cat,
override);
621int GlobalConfig::audioCaptureDeviceFor(Category category,
int override)
const
623 CaptureCategory cat = categoryToCaptureCategory(category);
624 return audioCaptureDeviceFor(cat,
override);
630#ifndef PHONON_NO_VIDEOCAPTURE
631void GlobalConfig::setVideoCaptureDeviceListFor(CaptureCategory category,
QList<int> order)
633#ifndef QT_NO_PHONON_SETTINGSGROUP
635 QSettingsGroup backendConfig(&d->config,
QLatin1String(
"VideoCaptureDevice"));
637 order = reindexList(
this, VideoCaptureDeviceType, category, order);
639 const QList<int> noCategoryOrder = videoCaptureDeviceListFor(NoCaptureCategory, ShowUnavailableDevices|ShowAdvancedDevices);
640 if (category != NoCaptureCategory && order == noCategoryOrder) {
648QList<int> GlobalConfig::videoCaptureDeviceListFor(CaptureCategory category,
int override)
const
650 P_D(
const GlobalConfig);
652#ifndef QT_NO_PHONON_SETTINGSGROUP
653 const bool hide = ((
override & AdvancedDevicesFromSettings)
654 ? hideAdvancedDevices()
655 : static_cast<bool>(override & HideAdvancedDevices));
657 const bool hide = !((
override & AdvancedDevicesFromSettings) &&
static_cast<bool>(
override & HideAdvancedDevices));
661 BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend());
667 QList<int> defaultList = backendIface->objectDescriptionIndexes(VideoCaptureDeviceType);
669#ifndef QT_NO_PHONON_PLATFORMPLUGIN
670 if (PlatformPlugin *platformPlugin = Factory::platformPlugin()) {
673 defaultList += platformPlugin->objectDescriptionIndexes(VideoCaptureDeviceType);
676 while (it.hasNext()) {
677 VideoCaptureDevice objDesc = VideoCaptureDevice::fromIndex(it.next());
678 const QVariant var = objDesc.property(
"isAdvanced");
687#ifndef QT_NO_PHONON_SETTINGSGROUP
688 if (hideAdvancedDevices() || (
override & HideUnavailableDevices)) {
689 filter(VideoCaptureDeviceType, backendIface, &defaultList,
690 (hideAdvancedDevices() ? FilterAdvancedDevices : 0) |
691 ((
override & HideUnavailableDevices) ? FilterUnavailableDevices : 0)
696 const QSettingsGroup backendConfig(&d->config,
QLatin1String(
"VideoCaptureDevice"));
697 return sortDevicesByCategoryPriority(
this, &backendConfig, VideoCaptureDeviceType, category, defaultList);
703int GlobalConfig::videoCaptureDeviceFor(CaptureCategory category,
int override)
const
705 QList<int> ret = videoCaptureDeviceListFor(category,
override);
713 return deviceProperties(VideoCaptureDeviceType, index);
716void GlobalConfig::setVideoCaptureDeviceListFor(Category category,
QList<int> order)
718 CaptureCategory cat = categoryToCaptureCategory(category);
719 setVideoCaptureDeviceListFor(cat, order);
722QList<int> GlobalConfig::videoCaptureDeviceListFor(Category category,
int override)
const
724 CaptureCategory cat = categoryToCaptureCategory(category);
725 return videoCaptureDeviceListFor(cat,
override);
728int GlobalConfig::videoCaptureDeviceFor(Category category,
int override)
const
730 CaptureCategory cat = categoryToCaptureCategory(category);
731 return videoCaptureDeviceFor(cat,
override);
742 PulseSupport *pulse = PulseSupport::getInstance();
743 if (pulse->isUsed()) {
745 indices = pulse->objectDescriptionIndexes(deviceType);
747 props = pulse->objectDescriptionProperties(deviceType, index);
752 #ifndef QT_NO_PHONON_PLATFORMPLUGIN
754 if (PlatformPlugin *platformPlugin = Factory::platformPlugin())
755 props = platformPlugin->objectDescriptionProperties(deviceType, index);
761 BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend());
763 props = backendIface->objectDescriptionProperties(deviceType, index);
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool isEmpty() const const
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
bool contains(const AT &value) const const
qsizetype indexOf(const AT &value, qsizetype from) const const
bool isEmpty() const const
qsizetype removeAll(const AT &t)
qsizetype size() const const
T value(qsizetype i) const const
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
QString number(double n, char format, int precision)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
bool isValid() const const
bool toBool() const const