1
/*  This file is part of the KDE project
2
    Copyright (C) 2005-2006 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 "backendcapabilities.h"
24
#include "backendcapabilities_p.h"
25
26
#include "phonondefs_p.h"
27
#include "backendinterface.h"
28
#include "factory_p.h"
29
#include "globalconfig.h"
30
#include "globalstatic_p.h"
31
#include "objectdescription.h"
32
33
#include <QtCore/QList>
34
#include <QtCore/QSet>
35
#include <QtCore/QStringList>
36
37
QT_BEGIN_NAMESPACE
38
39
PHONON_GLOBAL_STATIC(Phonon::BackendCapabilitiesPrivate, globalBCPrivate)
40
41
namespace Phonon
42
{
43
44
BackendCapabilities::Notifier *BackendCapabilities::notifier()
45
{
46
    return globalBCPrivate;
47
}
48
49
QStringList BackendCapabilities::availableMimeTypes()
50
{
51
    if (BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend()))
52
        return backendIface->availableMimeTypes();
53
    else
54
        return QStringList();
55
}
56
57
bool BackendCapabilities::isMimeTypeAvailable(const QString &mimeType)
58
{
59
    QObject *m_backendObject = Factory::backend(false);
60
    if (!m_backendObject) {
61
        if (!Factory::isMimeTypeAvailable(mimeType)) {
62
            return false;
63
        }
64
        // without loading the backend we found out that the MIME type might be supported, now we
65
        // want to know for certain. For that we need to load the backend.
66
        m_backendObject = Factory::backend(true);
67
    }
68
    if (!m_backendObject) {
69
        // no backend == no MIME type supported at all
70
        return false;
71
    }
72
    return availableMimeTypes().contains(mimeType);
73
}
74
75
QList<AudioOutputDevice> BackendCapabilities::availableAudioOutputDevices()
76
{
77
    QList<AudioOutputDevice> ret;
78
#ifndef QT_NO_PHONON_SETTINGSGROUP
79
    const QList<int> deviceIndexes = GlobalConfig().audioOutputDeviceListFor(Phonon::NoCategory);
80
    for (int i = 0; i < deviceIndexes.count(); ++i) {
81
        ret.append(AudioOutputDevice::fromIndex(deviceIndexes.at(i)));
82
    }
83
#endif //QT_NO_PHONON_SETTINGSGROUP
84
    return ret;
85
}
86
87
88
#ifndef QT_NO_PHONON_AUDIOCAPTURE
89
QList<AudioCaptureDevice> BackendCapabilities::availableAudioCaptureDevices()
90
{
91
    QList<AudioCaptureDevice> ret;
92
    const QList<int> deviceIndexes = GlobalConfig().audioCaptureDeviceListFor(Phonon::NoCategory);
93
    for (int i = 0; i < deviceIndexes.count(); ++i) {
94
        ret.append(AudioCaptureDevice::fromIndex(deviceIndexes.at(i)));
95
    }
96
    return ret;
97
}
98
#endif //QT_NO_PHONON_AUDIOCAPTURE
99
100
#ifndef QT_NO_PHONON_EFFECT
101
QList<EffectDescription> BackendCapabilities::availableAudioEffects()
102
{
103
    BackendInterface *backendIface = qobject_cast<BackendInterface *>(Factory::backend());
104
    QList<EffectDescription> ret;
105
    if (backendIface) {
106
        const QList<int> deviceIndexes = backendIface->objectDescriptionIndexes(Phonon::EffectType);
107
        for (int i = 0; i < deviceIndexes.count(); ++i) {
108
            ret.append(EffectDescription::fromIndex(deviceIndexes.at(i)));
109
        }
110
    }
111
    return ret;
112
}
113
#endif //QT_NO_PHONON_EFFECT
114
115
} // namespace Phonon
116
117
QT_END_NAMESPACE
118
119
#include "moc_backendcapabilities.cpp"
120
121
// vim: sw=4 ts=4