wc/r18865/#8604/ contributed by Mitz Pettel <mitz@webkit.org>
[kdelibs.git] / phonon / videoeffect.cpp
blob60d981e420f320ae7cf6d00068bea78faedb1e80
1 /* This file is part of the KDE project
2 Copyright (C) 2005-2006 Matthias Kretz <kretz@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "videoeffect.h"
20 #include "videoeffect_p.h"
21 #include "effectparameter.h"
22 #include "factory.h"
24 namespace Phonon
27 VideoEffect::VideoEffect( const VideoEffectDescription& type, QObject* parent )
28 : QObject( parent )
29 , Base( *new VideoEffectPrivate )
31 K_D( VideoEffect );
32 d->type = type.index();
33 d->createIface();
36 VideoEffect::VideoEffect( VideoEffectPrivate& dd, QObject* parent, const VideoEffectDescription& type )
37 : QObject( parent )
38 , Base( dd )
40 K_D( VideoEffect );
41 d->type = type.index();
44 void VideoEffectPrivate::createIface()
46 if( backendObject )
47 return;
48 K_Q( VideoEffect );
49 backendObject = Factory::createVideoEffect(type, q);
50 if( backendObject )
51 q->setupIface();
54 VideoEffectDescription VideoEffect::type() const
56 K_D( const VideoEffect );
57 return VideoEffectDescription::fromIndex( d->type );
60 QList<EffectParameter> VideoEffect::parameterList() const
62 K_D( const VideoEffect );
63 QList<EffectParameter> ret;
64 // there should be an iface object, but better be safe for those backend
65 // switching corner-cases: when the backend switches the new backend might
66 // not support this effect -> no iface object
67 if( d->backendObject )
69 BACKEND_GET( QList<EffectParameter>, ret, "parameterList" );
70 for( int i = 0; i < ret.size(); ++i )
71 ret[ i ].setEffect( const_cast<VideoEffect*>( this ) );
73 return ret;
76 QVariant VideoEffect::value( int parameterId ) const
78 K_D( const VideoEffect );
79 if( !d->backendObject )
80 return d->parameterValues[ parameterId ];
81 QVariant ret;
82 BACKEND_GET1( QVariant, ret, "value", int, parameterId );
83 return ret;
86 void VideoEffect::setValue( int parameterId, QVariant newValue )
88 K_D( VideoEffect );
89 if( iface() )
90 BACKEND_CALL2( "setValue", int, parameterId, QVariant, newValue );
91 else
92 d->parameterValues[ parameterId ] = newValue;
95 bool VideoEffectPrivate::aboutToDeleteIface()
97 if( backendObject )
99 QList<EffectParameter> plist;
100 pBACKEND_GET( QList<EffectParameter>, plist, "parameterList" );
101 foreach( EffectParameter p, plist )
102 parameterValues[ p.id() ] = p.value();
104 return true;
107 void VideoEffect::setupIface()
109 K_D( VideoEffect );
110 Q_ASSERT( d->backendObject );
112 // set up attributes
113 QList<EffectParameter> plist;
114 BACKEND_GET( QList<EffectParameter>, plist, "parameterList" );
115 foreach( EffectParameter p, plist )
116 if( d->parameterValues.contains( p.id() ) )
117 p.setValue( d->parameterValues[ p.id() ] );
120 } //namespace Phonon
122 #include "videoeffect.moc"
124 // vim: sw=4 ts=4 tw=80