move Meta::Album::image to Meta::Track::image
Ian Monroe
ian at monroe.nu
Tue Jun 26 07:20:55 CEST 2007
I have a patch that does what the subject says. This is necessary
because the images are unique to Album/Artist combinations. It would
be possible I suppose to have "Albums" be unique to Album/Artist
combinations as well (with compliation albums somewhere in the mix).
Because of that and since I made the changes as my battery was running
out on a bus in the middle of Illinois, I decided I should send the
patch for feedback instead of just commit it. :)
This was mainly done since I added album images to the playlist, which
is also in this diff.
Thanks,
Ian
-------------- next part --------------
=== src/collection/sqlcollection/sqlmeta.cpp
==================================================================
--- src/collection/sqlcollection/sqlmeta.cpp (revision 9560)
+++ src/collection/sqlcollection/sqlmeta.cpp (local)
@@ -620,10 +620,10 @@
}
QPixmap
-SqlAlbum::image( int size, bool withShadow ) const
+SqlTrack::image( int size, bool withShadow ) const
{
//TODO implement this
- return Meta::Album::image( size, withShadow );
+ return Meta::Track::image( size, withShadow );
}
//---------------SqlComposer---------------------------------
=== src/collection/sqlcollection/sqlmeta.h
==================================================================
--- src/collection/sqlcollection/sqlmeta.h (revision 9560)
+++ src/collection/sqlcollection/sqlmeta.h (local)
@@ -59,6 +59,7 @@
virtual void setYear( const QString &newYear );
virtual GenrePtr genre() const { return m_genre; }
virtual void setGenre( const QString &newGenre );
+ virtual QPixmap image( int size = 1, bool withShadow = false ) const;
virtual QString type() const;
@@ -194,7 +195,7 @@
//updating album images is possible or local tracks, but let's ignore it for now
virtual bool canUpdateImage() const { return false; }
- virtual QPixmap image( int size = 1, bool withShadow = false ) const;
+
virtual void updateImage() { }
//SQL specific methods
=== src/collectiondb.cpp
==================================================================
--- src/collectiondb.cpp (revision 9560)
+++ src/collectiondb.cpp (local)
@@ -4870,7 +4870,6 @@
CollectionDB::md5sum( const QString& artist, const QString& album, const QString& file )
{
KMD5 context( artist.toLower().toLocal8Bit() + album.toLower().toLocal8Bit() + file.toLocal8Bit() );
-// debug() << "MD5 SUM for " << artist << ", " << album << ": " << context.hexDigest() << endl;
return context.hexDigest();
}
=== src/meta/lastfm/LastFmMeta.cpp
==================================================================
--- src/meta/lastfm/LastFmMeta.cpp (revision 9560)
+++ src/meta/lastfm/LastFmMeta.cpp (local)
@@ -368,5 +368,18 @@
//TODO
}
+QPixmap
+Track::image( int size, bool withShadow ) const
+{
+ if( !d || d->albumArt.isNull() )
+ return Meta::Track::image( size, withShadow );
+ //TODO implement shadow
+ //TODO improve this
+ if( d->albumArt.width() != size )
+ return d->albumArt.scaled( size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
+ else
+ return d->albumArt;
+}
+
#include "LastFmMeta.moc"
=== src/meta/lastfm/LastFmMeta.h
==================================================================
--- src/meta/lastfm/LastFmMeta.h (revision 9560)
+++ src/meta/lastfm/LastFmMeta.h (local)
@@ -52,6 +52,7 @@
virtual Meta::ArtistPtr artist() const;
virtual Meta::GenrePtr genre() const;
virtual Meta::ComposerPtr composer() const;
+ virtual QPixmap image( int size, bool withShadow ) const;
virtual Meta::YearPtr year() const;
virtual void setAlbum( const QString &newAlbum );
=== src/meta/lastfm/LastFmMeta_p.h
==================================================================
--- src/meta/lastfm/LastFmMeta_p.h (revision 9560)
+++ src/meta/lastfm/LastFmMeta_p.h (local)
@@ -205,18 +205,6 @@
return QString();
}
- QPixmap image( int size, bool withShadow ) const
- {
- if( !d || d->albumArt.isNull() )
- return Meta::Album::image( size, withShadow );
- //TODO implement shadow
- //TODO improve this
- if( d->albumArt.width() != size )
- return d->albumArt.scaled( size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
- else
- return d->albumArt;
- }
-
Track::Private * const d;
};
=== src/meta/meta.cpp
==================================================================
--- src/meta/meta.cpp (revision 9560)
+++ src/meta/meta.cpp (local)
@@ -30,6 +30,7 @@
#include <QImage>
#include <KStandardDirs>
+#include <KCodecs>
bool
Meta::Track::inCollection() const
@@ -80,15 +81,26 @@
}
QPixmap
-Meta::Album::image( int size, bool withShadow ) const
+Meta::Track::image( int size, bool withShadow ) const
{
QDir cacheCoverDir = QDir( Amarok::saveLocation( "albumcovers/cache/" ) );
+ QDir savedCoverDir = QDir( Amarok::saveLocation( "albumcovers/large/" ) );
if ( size <= 1 )
size = AmarokConfig::coverPreviewSize();
QString sizeKey = QString::number( size ) + '@';
-
+ QString md5key = md5sum( artist()->name(), album()->name() );
QImage img;
- if( cacheCoverDir.exists( sizeKey + "nocover.png" ) )
+ if( cacheCoverDir.exists( sizeKey + md5key ) )
+ {
+ img = QImage( cacheCoverDir.filePath( sizeKey + md5key ) );
+ }
+ else if( savedCoverDir.exists( md5key ) )
+ {
+ img = QImage( savedCoverDir.filePath( md5key ) );
+ img.scaled( size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
+ img.save( cacheCoverDir.filePath( sizeKey + md5key ), "PNG" );
+ }
+ else if( cacheCoverDir.exists( sizeKey + "nocover.png" ) )
img = QImage( cacheCoverDir.filePath( sizeKey + "nocover.png" ) );
else
{
@@ -103,6 +115,14 @@
return QPixmap::fromImage( img );
}
+QByteArray
+Meta::Track::md5sum( const QString& artist, const QString& album, const QString& file )
+{
+ KMD5 context( artist.toLower().toLocal8Bit() + album.toLower().toLocal8Bit() + file.toLocal8Bit() );
+ return context.hexDigest();
+}
+
+
void
Meta::Genre::addMatchTo( QueryMaker *qm )
{
=== src/meta/meta.h
==================================================================
--- src/meta/meta.h (revision 9560)
+++ src/meta/meta.h (local)
@@ -113,6 +113,8 @@
/** Returns the genre of this track */
virtual GenrePtr genre() const = 0;
virtual void setGenre( const QString &newGenre ) = 0;
+ /** returns the cover for the track */
+ virtual QPixmap image( int size = 1, bool withShadow = false ) const;
/** Returns the year of this track */
virtual YearPtr year() const = 0;
virtual void setYear( const QString &newYear ) = 0;
@@ -179,6 +181,8 @@
virtual void subscribe( TrackObserver *observer ) = 0;
virtual void unsubscribe( TrackObserver *observer ) = 0;
+ private:
+ static QByteArray md5sum( const QString& artist, const QString& album, const QString& file = QString() );
};
class AMAROK_EXPORT Artist : public MetaBase
@@ -205,9 +209,6 @@
virtual ArtistPtr albumArtist() const = 0;
/** returns all tracks on this album */
virtual TrackList tracks() = 0;
-
- /** returns the cover of the album */
- virtual QPixmap image( int size = 1, bool withShadow = false ) const;
/** Returns true if it is possible to update the cover of the album */
virtual bool canUpdateImage() const { return false; }
/** updates the cover of the album */
=== src/meta/proxy/MetaProxy.cpp
==================================================================
--- src/meta/proxy/MetaProxy.cpp (revision 9560)
+++ src/meta/proxy/MetaProxy.cpp (local)
@@ -408,4 +408,11 @@
d->observers.removeAll( observer );
}
-
+QPixmap
+MetaProxy::Track::image( int size, bool withShadow ) const
+{
+ if( d && d->realTrack )
+ return d->realTrack->image( size, withShadow );
+ else
+ return Meta::Track::image( size, withShadow );
+}
=== src/meta/proxy/MetaProxy.h
==================================================================
--- src/meta/proxy/MetaProxy.h (revision 9560)
+++ src/meta/proxy/MetaProxy.h (local)
@@ -51,6 +51,7 @@
virtual Meta::ArtistPtr artist() const;
virtual Meta::GenrePtr genre() const;
virtual Meta::ComposerPtr composer() const;
+ virtual QPixmap image( int size, bool withShadow ) const;
virtual Meta::YearPtr year() const;
virtual void setAlbum( const QString &newAlbum );
=== src/meta/proxy/MetaProxy_p.h
==================================================================
--- src/meta/proxy/MetaProxy_p.h (revision 9560)
+++ src/meta/proxy/MetaProxy_p.h (local)
@@ -186,14 +186,6 @@
return QString();
}
- QPixmap image( int size, bool withShadow ) const
- {
- if( d && d->realTrack )
- return d->realTrack->album()->image( size, withShadow );
- else
- return Meta::Album::image( size, withShadow );
- }
-
MetaProxy::Track::Private * const d;
};
=== src/playlist/PlaylistModel.cpp
==================================================================
--- src/playlist/PlaylistModel.cpp (revision 9560)
+++ src/playlist/PlaylistModel.cpp (local)
@@ -119,7 +119,7 @@
case Artist: return track->artist()->name();
case Bitrate: return track->bitrate();
case Composer: return track->composer()->name();
- case CoverImage: return track->album()->image( 50 );
+ case CoverImage: return track->image( 50 );
case Comment: return track->comment();
case DiscNumber: return track->discNumber();
case Filesize: return track->filesize();
More information about the Amarok-devel
mailing list