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
23 #include "amarokconfig.h"
24 #include "Collection.h"
26 #include "QueryMaker.h"
31 #include <KStandardDirs>
35 Meta::Observer::~Observer()
41 Meta::Observer::metadataChanged( Track
*track
)
47 Meta::Observer::metadataChanged( Artist
*artist
)
53 Meta::Observer::metadataChanged( Album
*album
)
59 Meta::Observer::metadataChanged( Composer
*composer
)
65 Meta::Observer::metadataChanged( Genre
*genre
)
71 Meta::Observer::metadataChanged( Year
*year
)
79 Meta::MetaBase::subscribe( Observer
*observer
)
82 m_observers
.insert( observer
);
86 Meta::MetaBase::unsubscribe( Observer
*observer
)
88 m_observers
.remove( observer
);
93 Meta::MetaBase::hasCapabilityInterface( Meta::Capability::Type type
) const
100 Meta::MetaBase::asCapabilityInterface( Meta::Capability::Type type
)
110 Meta::Track::inCollection() const
116 Meta::Track::collection() const
122 Meta::Track::cachedLyrics() const
128 Meta::Track::setCachedLyrics( const QString
&lyrics
)
134 Meta::Track::addMatchTo( QueryMaker
*qm
)
136 qm
->addMatch( TrackPtr( this ) );
140 Meta::Track::finishedPlaying( double playedFraction
)
142 Q_UNUSED( playedFraction
)
146 Meta::Track::notifyObservers() const
148 foreach( Observer
*observer
, m_observers
)
149 observer
->metadataChanged( const_cast<Meta::Track
*>( this ) );
153 Meta::Track::firstPlayed() const
159 Meta::Track::operator==( const Meta::Track
&track
) const
161 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &track
);
167 Meta::Artist::addMatchTo( QueryMaker
*qm
)
169 qm
->addMatch( ArtistPtr( this ) );
173 Meta::Artist::notifyObservers() const
175 foreach( Observer
*observer
, m_observers
)
176 observer
->metadataChanged( const_cast<Meta::Artist
*>( this ) );
180 Meta::Artist::operator==( const Meta::Artist
&artist
) const
182 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &artist
);
188 Meta::Album::addMatchTo( QueryMaker
*qm
)
190 qm
->addMatch( AlbumPtr( this ) );
194 Meta::Album::notifyObservers() const
196 foreach( Observer
*observer
, m_observers
)
197 observer
->metadataChanged( const_cast<Meta::Album
*>( this ) );
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/" ) );
208 size
= AmarokConfig::coverPreviewSize();
209 QString sizeKey
= QString::number( size
) + '@';
212 if( cacheCoverDir
.exists( sizeKey
+ "nocover.png" ) )
213 img
= QImage( cacheCoverDir
.filePath( sizeKey
+ "nocover.png" ) );
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" );
223 //s = makeShadowedImage( s );
225 return QPixmap::fromImage( img
);
229 Meta::Album::operator==( const Meta::Album
&album
) const
231 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &album
);
237 Meta::Genre::addMatchTo( QueryMaker
*qm
)
239 qm
->addMatch( GenrePtr( this ) );
243 Meta::Genre::notifyObservers() const
245 foreach( Observer
*observer
, m_observers
)
246 observer
->metadataChanged( const_cast<Meta::Genre
*>( this ) );
250 Meta::Genre::operator==( const Meta::Genre
&genre
) const
252 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &genre
);
258 Meta::Composer::addMatchTo( QueryMaker
*qm
)
260 qm
->addMatch( ComposerPtr( this ) );
264 Meta::Composer::notifyObservers() const
266 foreach( Observer
*observer
, m_observers
)
267 observer
->metadataChanged( const_cast<Meta::Composer
*>( this ) );
271 Meta::Composer::operator==( const Meta::Composer
&composer
) const
273 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &composer
);
279 Meta::Year::addMatchTo( QueryMaker
*qm
)
281 qm
->addMatch( YearPtr( this ) );
285 Meta::Year::notifyObservers() const
287 foreach( Observer
*observer
, m_observers
)
288 observer
->metadataChanged( const_cast<Meta::Year
*>( this ) );
292 Meta::Year::operator==( const Meta::Year
&year
) const
294 return dynamic_cast<const void*>( this ) == dynamic_cast<const void*>( &year
);