1
/*  This file is part of the KDE project
2
    Copyright (C) 2005-2007 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
#include "effect.h"
23
#include "effect_p.h"
24
#include "effectparameter.h"
25
#include "effectinterface.h"
26
#include "factory_p.h"
27
28
#define PHONON_INTERFACENAME EffectInterface
29
30
QT_BEGIN_NAMESPACE
31
32
#ifndef QT_NO_PHONON_EFFECT
33
34
namespace Phonon
35
{
36
Effect::~Effect()
37
{
38
}
39
40
Effect::Effect(const EffectDescription &description, QObject *parent)
41
    : QObject(parent), MediaNode(*new EffectPrivate)
42
{
43
    K_D(Effect);
44
    d->description = description;
45
    d->createBackendObject();
46
}
47
48
Effect::Effect(EffectPrivate &dd, QObject *parent)
49
    : QObject(parent), MediaNode(dd)
50
{
51
}
52
53
void EffectPrivate::createBackendObject()
54
{
55
    if (m_backendObject)
56
        return;
57
    Q_Q(Effect);
58
    m_backendObject = Factory::createEffect(description.index(), q);
59
    if (m_backendObject) {
60
        setupBackendObject();
61
    }
62
}
63
64
//X Effect::Type Effect::type() const
65
//X {
66
//X     K_D(const Effect);
67
//X     return d->type;
68
//X }
69
//X 
70
EffectDescription Effect::description() const
71
{
72
    K_D(const Effect);
73
    return d->description;
74
}
75
76
QList<EffectParameter> Effect::parameters() const
77
{
78
    K_D(const Effect);
79
    // there should be an iface object, but better be safe for those backend
80
    // switching corner-cases: when the backend switches the new backend might
81
    // not support this effect -> no iface object
82
    if (d->m_backendObject) {
83
        return INTERFACE_CALL(parameters());
84
    }
85
    return QList<EffectParameter>();
86
}
87
88
QVariant Effect::parameterValue(const EffectParameter &param) const
89
{
90
    K_D(const Effect);
91
    if (!d->m_backendObject) {
92
        return d->parameterValues[param];
93
    }
94
    return INTERFACE_CALL(parameterValue(param));
95
}
96
97
void Effect::setParameterValue(const EffectParameter &param, const QVariant &newValue)
98
{
99
    K_D(Effect);
100
    d->parameterValues[param] = newValue;
101
    if (d->backendObject()) {
102
        INTERFACE_CALL(setParameterValue(param, newValue));
103
    }
104
}
105
106
bool EffectPrivate::aboutToDeleteBackendObject()
107
{
108
    if (m_backendObject) {
109
        const QList<EffectParameter> parameters = pINTERFACE_CALL(parameters());
110
        for (int i = 0; i < parameters.count(); ++i) {
111
            const EffectParameter &p = parameters.at(i);
112
            parameterValues[p] = pINTERFACE_CALL(parameterValue(p));
113
        }
114
    }
115
    return true;
116
}
117
118
void EffectPrivate::setupBackendObject()
119
{
120
    Q_ASSERT(m_backendObject);
121
122
    // set up attributes
123
    const QList<EffectParameter> parameters = pINTERFACE_CALL(parameters());
124
    for (int i = 0; i < parameters.count(); ++i) {
125
        const EffectParameter &p = parameters.at(i);
126
        pINTERFACE_CALL(setParameterValue(p, parameterValues[p]));
127
    }
128
}
129
130
} //namespace Phonon
131
132
#endif //QT_NO_PHONON_EFFECT
133
134
QT_END_NAMESPACE
135
136
#include "moc_effect.cpp"
137
138
// vim: sw=4 ts=4 tw=80