From 5f32bdb27765eeb6432b0de2cd9a5b661ffba20e Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 31 Mar 2013 07:15:08 +0200 Subject: [PATCH] * Remove albums from internal cache when destroying them. --- src/libtomahawk/Album.cpp | 29 +++++++++++++++++++++++++++-- src/libtomahawk/Album.h | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/Album.cpp b/src/libtomahawk/Album.cpp index d7ddc62b6..66297c699 100644 --- a/src/libtomahawk/Album.cpp +++ b/src/libtomahawk/Album.cpp @@ -73,7 +73,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr return album.toStrongRef(); } - album_ptr album = album_ptr( new Album( name, artist ) ); + album_ptr album = album_ptr( new Album( name, artist ), &Album::deleteLater ); album->setWeakRef( album.toWeakRef() ); album->loadId( autoCreate ); s_albumsByName.insert( key, album ); @@ -105,7 +105,7 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar return album; } - album_ptr a = album_ptr( new Album( id, name, artist ), &QObject::deleteLater ); + album_ptr a = album_ptr( new Album( id, name, artist ), &Album::deleteLater ); a->setWeakRef( a.toWeakRef() ); s_albumsByName.insert( key, a ); @@ -153,6 +153,31 @@ Album::Album( const QString& name, const Tomahawk::artist_ptr& artist ) } +void +Album::deleteLater() +{ + QMutexLocker lock( &s_nameCacheMutex ); + + const QString key = albumCacheKey( m_artist, m_name ); + if ( s_albumsByName.contains( key ) ) + { + s_albumsByName.remove( key ); + } + + if ( m_id > 0 ) + { + s_idMutex.lockForWrite(); + if ( s_albumsById.contains( m_id ) ) + { + s_albumsById.remove( m_id ); + } + s_idMutex.unlock(); + } + + QObject::deleteLater(); +} + + void Album::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ) { diff --git a/src/libtomahawk/Album.h b/src/libtomahawk/Album.h index 88e4f88b3..edbb48f4f 100644 --- a/src/libtomahawk/Album.h +++ b/src/libtomahawk/Album.h @@ -68,6 +68,9 @@ public: void loadId( bool autoCreate ); +public slots: + void deleteLater(); + signals: void tracksAdded( const QList& tracks, Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void updated();