1
/*  This file is part of the KDE project
2
    Copyright (C) 2006-2008 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 "objectdescription.h"
24
#include "objectdescription_p.h"
25
26
#include <QtCore/QObject>
27
#include <QtCore/QSet>
28
#include "factory_p.h"
29
#include <QtCore/QStringList>
30
#include "backendinterface.h"
31
#include "platformplugin.h"
32
#include "pulsesupport.h"
33
34
QT_BEGIN_NAMESPACE
35
36
namespace Phonon
37
{
38
39
ObjectDescriptionData::ObjectDescriptionData(int index, const QHash<QByteArray, QVariant> &properties)
40
    : d(new ObjectDescriptionPrivate(index, properties))
41
{
42
}
43
44
ObjectDescriptionData::ObjectDescriptionData(ObjectDescriptionPrivate *dd)
45
    : d(dd)
46
{
47
}
48
49
ObjectDescriptionData::~ObjectDescriptionData()
50
{
51
    delete d;
52
}
53
54
bool ObjectDescriptionData::operator==(const ObjectDescriptionData &otherDescription) const
55
{
56
    if (!isValid()) {
57
        return !otherDescription.isValid();
58
    }
59
    if (!otherDescription.isValid()) {
60
        return false;
61
    }
62
    return *d == *otherDescription.d;
63
}
64
65
int ObjectDescriptionData::index() const
66
{
67
    if (!isValid()) {
68
        return -1;
69
    }
70
    return d->index;
71
}
72
73
QString ObjectDescriptionData::name() const
74
{
75
    if (!isValid()) {
76
        return QString();
77
    }
78
    return d->name;
79
}
80
81
QString ObjectDescriptionData::description() const
82
{
83
    if (!isValid()) {
84
        return QString();
85
    }
86
    return d->description;
87
}
88
89
QVariant ObjectDescriptionData::property(const char *name) const
90
{
91
    if (!isValid()) {
92
        return QVariant();
93
    }
94
    return d->properties.value(name);
95
}
96
97
QList<QByteArray> ObjectDescriptionData::propertyNames() const
98
{
99
    if (!isValid()) {
100
        return QList<QByteArray>();
101
    }
102
    return d->properties.keys();
103
}
104
105
bool ObjectDescriptionData::isValid() const
106
{
107
    return d != 0;
108
}
109
110
ObjectDescriptionData *ObjectDescriptionData::fromIndex(ObjectDescriptionType type, int index)
111
{
112
    bool is_audio_device = (AudioOutputDeviceType == type || AudioCaptureDeviceType == type);
113
114
    PulseSupport *pulse = PulseSupport::getInstance();
115
    if (is_audio_device && pulse->isActive()) {
116
        QList<int> indexes = pulse->objectDescriptionIndexes(type);
117
        if (indexes.contains(index)) {
118
            QHash<QByteArray, QVariant> properties = pulse->objectDescriptionProperties(type, index);
119
            return new ObjectDescriptionData(index, properties);
120
        }
121
    } else {
122
        BackendInterface *iface = qobject_cast<BackendInterface *>(Factory::backend());
123
124
        // prefer to get the ObjectDescriptionData from the platform plugin for audio devices
125
#ifndef QT_NO_PHONON_PLATFORMPLUGIN
126
        if (is_audio_device) {
127
            PlatformPlugin *platformPlugin = Factory::platformPlugin();
128
            if (platformPlugin) {
129
                QList<int> indexes = platformPlugin->objectDescriptionIndexes(type);
130
                if (indexes.contains(index)) {
131
                    QHash<QByteArray, QVariant> properties = platformPlugin->objectDescriptionProperties(type, index);
132
                    return new ObjectDescriptionData(index, properties);
133
                }
134
            }
135
        }
136
#endif //QT_NO_PHONON_PLATFORMPLUGIN
137
138
        if (iface) {
139
            QList<int> indexes = iface->objectDescriptionIndexes(type);
140
            if (indexes.contains(index)) {
141
                QHash<QByteArray, QVariant> properties = iface->objectDescriptionProperties(type, index);
142
                return new ObjectDescriptionData(index, properties);
143
            }
144
        }
145
    }
146
    return new ObjectDescriptionData(0); // invalid
147
}
148
149
} //namespace Phonon
150
151
QT_END_NAMESPACE
152
// vim: sw=4 ts=4