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