File indexing completed on 2025-02-09 05:31:46
0001 /* This file is part of the KDE project 0002 Copyright (C) 2005-2007 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 #include "effect.h" 0023 #include "effect_p.h" 0024 #include "effectparameter.h" 0025 #include "effectinterface.h" 0026 #include "factory_p.h" 0027 0028 #define PHONON_INTERFACENAME EffectInterface 0029 0030 #ifndef QT_NO_PHONON_EFFECT 0031 0032 namespace Phonon 0033 { 0034 Effect::~Effect() 0035 { 0036 } 0037 0038 Effect::Effect(const EffectDescription &description, QObject *parent) 0039 : QObject(parent), MediaNode(*new EffectPrivate) 0040 { 0041 P_D(Effect); 0042 d->description = description; 0043 d->createBackendObject(); 0044 } 0045 0046 Effect::Effect(EffectPrivate &dd, QObject *parent) 0047 : QObject(parent), MediaNode(dd) 0048 { 0049 } 0050 0051 void EffectPrivate::createBackendObject() 0052 { 0053 if (m_backendObject) 0054 return; 0055 P_Q(Effect); 0056 m_backendObject = Factory::createEffect(description.index(), q); 0057 if (m_backendObject) { 0058 setupBackendObject(); 0059 } 0060 } 0061 0062 //X Effect::Type Effect::type() const 0063 //X { 0064 //X P_D(const Effect); 0065 //X return d->type; 0066 //X } 0067 //X 0068 EffectDescription Effect::description() const 0069 { 0070 P_D(const Effect); 0071 return d->description; 0072 } 0073 0074 QList<EffectParameter> Effect::parameters() const 0075 { 0076 P_D(const Effect); 0077 // there should be an iface object, but better be safe for those backend 0078 // switching corner-cases: when the backend switches the new backend might 0079 // not support this effect -> no iface object 0080 if (d->m_backendObject) { 0081 return INTERFACE_CALL(parameters()); 0082 } 0083 return QList<EffectParameter>(); 0084 } 0085 0086 QVariant Effect::parameterValue(const EffectParameter ¶m) const 0087 { 0088 P_D(const Effect); 0089 if (!d->m_backendObject) { 0090 return d->parameterValues[param]; 0091 } 0092 return INTERFACE_CALL(parameterValue(param)); 0093 } 0094 0095 void Effect::setParameterValue(const EffectParameter ¶m, const QVariant &newValue) 0096 { 0097 P_D(Effect); 0098 d->parameterValues[param] = newValue; 0099 if (d->backendObject()) { 0100 INTERFACE_CALL(setParameterValue(param, newValue)); 0101 } 0102 } 0103 0104 bool EffectPrivate::aboutToDeleteBackendObject() 0105 { 0106 if (m_backendObject) { 0107 const QList<EffectParameter> parameters = pINTERFACE_CALL(parameters()); 0108 for (int i = 0; i < parameters.count(); ++i) { 0109 const EffectParameter &p = parameters.at(i); 0110 parameterValues[p] = pINTERFACE_CALL(parameterValue(p)); 0111 } 0112 } 0113 return true; 0114 } 0115 0116 void EffectPrivate::setupBackendObject() 0117 { 0118 Q_ASSERT(m_backendObject); 0119 0120 // set up attributes 0121 const QList<EffectParameter> parameters = pINTERFACE_CALL(parameters()); 0122 for (int i = 0; i < parameters.count(); ++i) { 0123 const EffectParameter &p = parameters.at(i); 0124 pINTERFACE_CALL(setParameterValue(p, parameterValues[p])); 0125 } 0126 } 0127 0128 } //namespace Phonon 0129 0130 #endif //QT_NO_PHONON_EFFECT 0131 0132 #include "moc_effect.cpp" 0133 0134 // vim: sw=4 ts=4 tw=80