Revert previous commit, was incorrect
[amarok.git] / src / meta / Meta.cpp
blobf57bb692060d9353e4a21fdd8ac7d3af1dbfae3b
1 /* This file is part of the KDE project
2 Copyright (C) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>
3 Copyright (C) 2007 Ian Monroe <ian@monroe.nu>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "Meta.h"
22 #include "amarok.h"
23 #include "amarokconfig.h"
24 #include "Collection.h"
25 #include "debug.h"
26 #include "QueryMaker.h"
28 #include <QDir>
29 #include <QImage>
31 #include <KStandardDirs>
33 //Meta::Observer
35 Meta::Observer::~Observer()
37 //nothing to do
40 void
41 Meta::Observer::metadataChanged( Track *track )
43 Q_UNUSED( track );
46 void
47 Meta::Observer::metadataChanged( Artist *artist )
49 Q_UNUSED( artist );
52 void
53 Meta::Observer::metadataChanged( Album *album )
55 Q_UNUSED( album );
58 void
59 Meta::Observer::metadataChanged( Composer *composer )
61 Q_UNUSED( composer );
64 void
65 Meta::Observer::metadataChanged( Genre *genre )
67 Q_UNUSED( genre );
70 void
71 Meta::Observer::metadataChanged( Year *year )
73 Q_UNUSED( year );
76 //Meta::MetaBase
78 void
79 Meta::MetaBase::subscribe( Observer *observer )
81 if( observer )
82 m_observers.insert( observer );
85 void
86 Meta::MetaBase::unsubscribe( Observer *observer )
88 m_observers.remove( observer );
92 bool
93 Meta::MetaBase::hasCapabilityInterface( Meta::Capability::Type type ) const
95 Q_UNUSED( type );
96 return false;
99 Meta::Capability*
100 Meta::MetaBase::asCapabilityInterface( Meta::Capability::Type type )
102 Q_UNUSED( type );
103 return 0;
107 //Meta::Track
109 bool
110 Meta::Track::inCollection() const
112 return false;
115 Collection*
116 Meta::Track::collection() const
118 return 0;
121 QString
122 Meta::Track::cachedLyrics() const
124 return QString();
127 void
128 Meta::Track::setCachedLyrics( const QString &lyrics )
130 Q_UNUSED( lyrics )
133 void
134 Meta::Track::addMatchTo( QueryMaker *qm )
136 qm->addMatch( TrackPtr( this ) );
139 void
140 Meta::Track::finishedPlaying( double playedFraction )
142 Q_UNUSED( playedFraction )
145 void
146 Meta::Track::notifyObservers() const
148 foreach( Observer *observer, m_observers )
149 observer->metadataChanged( const_cast<Meta::Track*>( this ) );
152 uint
153 Meta::Track::firstPlayed() const
155 return 0;
158 bool
159 Meta::Track::operator==( const Meta::Track &track ) const
161 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &track );
164 //Meta::Artist
166 void
167 Meta::Artist::addMatchTo( QueryMaker *qm )
169 qm->addMatch( ArtistPtr( this ) );
172 void
173 Meta::Artist::notifyObservers() const
175 foreach( Observer *observer, m_observers )
176 observer->metadataChanged( const_cast<Meta::Artist*>( this ) );
179 bool
180 Meta::Artist::operator==( const Meta::Artist &artist ) const
182 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &artist );
185 //Meta::Album
187 void
188 Meta::Album::addMatchTo( QueryMaker *qm )
190 qm->addMatch( AlbumPtr( this ) );
193 void
194 Meta::Album::notifyObservers() const
196 foreach( Observer *observer, m_observers )
197 observer->metadataChanged( const_cast<Meta::Album*>( this ) );
200 QPixmap
201 Meta::Album::image( int size, bool withShadow )
203 Q_UNUSED( withShadow );
205 // Return "nocover" until it's fetched.
206 QDir cacheCoverDir = QDir( Amarok::saveLocation( "albumcovers/cache/" ) );
207 if ( size <= 1 )
208 size = AmarokConfig::coverPreviewSize();
209 QString sizeKey = QString::number( size ) + '@';
211 QImage img;
212 if( cacheCoverDir.exists( sizeKey + "nocover.png" ) )
213 img = QImage( cacheCoverDir.filePath( sizeKey + "nocover.png" ) );
214 else
216 QImage orgImage = QImage( KStandardDirs::locate( "data", "amarok/images/nocover.png" ) ); //optimise this!
217 //scaled() does not change the original image but returns a scaled copy
218 img = orgImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
219 img.save( cacheCoverDir.filePath( sizeKey + "nocover.png" ), "PNG" );
222 //if ( withShadow )
223 //s = makeShadowedImage( s );
225 return QPixmap::fromImage( img );
228 bool
229 Meta::Album::operator==( const Meta::Album &album ) const
231 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &album );
234 //Meta::Genre
236 void
237 Meta::Genre::addMatchTo( QueryMaker *qm )
239 qm->addMatch( GenrePtr( this ) );
242 void
243 Meta::Genre::notifyObservers() const
245 foreach( Observer *observer, m_observers )
246 observer->metadataChanged( const_cast<Meta::Genre*>( this ) );
249 bool
250 Meta::Genre::operator==( const Meta::Genre &genre ) const
252 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &genre );
255 //Meta::Composer
257 void
258 Meta::Composer::addMatchTo( QueryMaker *qm )
260 qm->addMatch( ComposerPtr( this ) );
263 void
264 Meta::Composer::notifyObservers() const
266 foreach( Observer *observer, m_observers )
267 observer->metadataChanged( const_cast<Meta::Composer*>( this ) );
270 bool
271 Meta::Composer::operator==( const Meta::Composer &composer ) const
273 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &composer );
276 //Meta::Year
278 void
279 Meta::Year::addMatchTo( QueryMaker *qm )
281 qm->addMatch( YearPtr( this ) );
284 void
285 Meta::Year::notifyObservers() const
287 foreach( Observer *observer, m_observers )
288 observer->metadataChanged( const_cast<Meta::Year*>( this ) );
291 bool
292 Meta::Year::operator==( const Meta::Year &year ) const
294 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &year );