Fix scaling of covers in Meta::Album. QImage::scaled() does not change the original...
[amarok.git] / src / meta / meta.cpp
blob32f4ffda5cc2a8cc8fec055bdb3455aa4b8614ff
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 "querymaker.h"
27 #include <QDir>
28 #include <QImage>
30 #include <KStandardDirs>
32 //Meta::Observer
34 Meta::Observer::~Observer()
36 //nothing to do
39 void
40 Meta::Observer::metadataChanged( Track *track )
42 Q_UNUSED( track );
45 void
46 Meta::Observer::metadataChanged( Artist *artist )
48 Q_UNUSED( artist );
51 void
52 Meta::Observer::metadataChanged( Album *album )
54 Q_UNUSED( album );
57 void
58 Meta::Observer::metadataChanged( Composer *composer )
60 Q_UNUSED( composer );
63 void
64 Meta::Observer::metadataChanged( Genre *genre )
66 Q_UNUSED( genre );
69 void
70 Meta::Observer::metadataChanged( Year *year )
72 Q_UNUSED( year );
75 //Meta::MetaBase
77 void
78 Meta::MetaBase::subscribe( Observer *observer )
80 if( observer )
81 m_observers.insert( observer );
84 void
85 Meta::MetaBase::unsubscribe( Observer *observer )
87 m_observers.remove( observer );
90 //Meta::Track
92 bool
93 Meta::Track::inCollection() const
95 return false;
98 Collection*
99 Meta::Track::collection() const
101 return 0;
104 QString
105 Meta::Track::cachedLyrics() const
107 return QString();
110 void
111 Meta::Track::setCachedLyrics( const QString &lyrics )
113 Q_UNUSED( lyrics )
116 void
117 Meta::Track::addMatchTo( QueryMaker *qm )
119 qm->addMatch( TrackPtr( this ) );
122 void
123 Meta::Track::finishedPlaying( double playedFraction )
125 Q_UNUSED( playedFraction )
128 void
129 Meta::Track::notifyObservers() const
131 foreach( Observer *observer, m_observers )
132 observer->metadataChanged( const_cast<Meta::Track*>( this ) );
135 //Meta::Artist
137 void
138 Meta::Artist::addMatchTo( QueryMaker *qm )
140 qm->addMatch( ArtistPtr( this ) );
143 void
144 Meta::Artist::notifyObservers() const
146 foreach( Observer *observer, m_observers )
147 observer->metadataChanged( const_cast<Meta::Artist*>( this ) );
150 //Meta::Album
152 void
153 Meta::Album::addMatchTo( QueryMaker *qm )
155 qm->addMatch( AlbumPtr( this ) );
158 void
159 Meta::Album::notifyObservers() const
161 foreach( Observer *observer, m_observers )
162 observer->metadataChanged( const_cast<Meta::Album*>( this ) );
165 QPixmap
166 Meta::Album::image( int size, bool withShadow ) const
168 Q_UNUSED( withShadow );
170 QDir cacheCoverDir = QDir( Amarok::saveLocation( "albumcovers/cache/" ) );
171 if ( size <= 1 )
172 size = AmarokConfig::coverPreviewSize();
173 QString sizeKey = QString::number( size ) + '@';
175 QImage img;
176 if( cacheCoverDir.exists( sizeKey + "nocover.png" ) )
177 img = QImage( cacheCoverDir.filePath( sizeKey + "nocover.png" ) );
178 else
180 QImage orgImage = QImage( KStandardDirs::locate( "data", "amarok/images/nocover.png" ) ); //optimise this!
181 img = orgImage.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation ); //scaled does not
182 img.save( cacheCoverDir.filePath( sizeKey + "nocover.png" ), "PNG" );
185 //if ( withShadow )
186 //s = makeShadowedImage( s );
188 return QPixmap::fromImage( img );
191 //Meta::Genre
193 void
194 Meta::Genre::addMatchTo( QueryMaker *qm )
196 qm->addMatch( GenrePtr( this ) );
199 void
200 Meta::Genre::notifyObservers() const
202 foreach( Observer *observer, m_observers )
203 observer->metadataChanged( const_cast<Meta::Genre*>( this ) );
206 //Meta::Composer
208 void
209 Meta::Composer::addMatchTo( QueryMaker *qm )
211 qm->addMatch( ComposerPtr( this ) );
214 void
215 Meta::Composer::notifyObservers() const
217 foreach( Observer *observer, m_observers )
218 observer->metadataChanged( const_cast<Meta::Composer*>( this ) );
221 //Meta::Year
223 void
224 Meta::Year::addMatchTo( QueryMaker *qm )
226 qm->addMatch( YearPtr( this ) );
229 void
230 Meta::Year::notifyObservers() const
232 foreach( Observer *observer, m_observers )
233 observer->metadataChanged( const_cast<Meta::Year*>( this ) );