From 83f9d86e1df3b53e55ee28a9174647b5cdaa4223 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Thu, 19 Jul 2012 21:35:54 +0200 Subject: [PATCH] * Work on image provider & unique cover IDs. --- data/qml/StationView.qml | 2 +- src/libtomahawk/Album.cpp | 27 ++++++++++---- src/libtomahawk/Album.h | 6 ++- src/libtomahawk/Query.cpp | 37 +++++++------------ src/libtomahawk/Query.h | 4 +- src/libtomahawk/playlist/PlayableItem.cpp | 5 ++- src/libtomahawk/playlist/PlayableModel.cpp | 16 +++++--- src/libtomahawk/playlist/PlayableModel.h | 3 +- .../widgets/DeclarativeCoverArtProvider.cpp | 12 +++++- 9 files changed, 66 insertions(+), 46 deletions(-) diff --git a/data/qml/StationView.qml b/data/qml/StationView.qml index 03ac0bd93..d0a038d3a 100644 --- a/data/qml/StationView.qml +++ b/data/qml/StationView.qml @@ -30,7 +30,7 @@ Item { showLabels: false //artistName: model.artistName //trackName: model.trackName - artworkId: index + artworkId: model.coverID scale: PathView.itemScale itemBrightness: PathView.itemBrightness diff --git a/src/libtomahawk/Album.cpp b/src/libtomahawk/Album.cpp index c2a9bac87..725fd55be 100644 --- a/src/libtomahawk/Album.cpp +++ b/src/libtomahawk/Album.cpp @@ -35,7 +35,7 @@ using namespace Tomahawk; QHash< QString, album_ptr > Album::s_albumsByName = QHash< QString, album_ptr >(); QHash< unsigned int, album_ptr > Album::s_albumsById = QHash< unsigned int, album_ptr >(); -QHash< QString, album_ptr > Album::s_albumsByUniqueId = QHash< QString, album_ptr >(); +QHash< QString, album_ptr > Album::s_albumsByCoverId = QHash< QString, album_ptr >(); static QMutex s_mutex; static QReadWriteLock s_idMutex; @@ -52,7 +52,7 @@ Album::~Album() { QMutexLocker lock( &s_mutex ); s_albumsByName.remove( albumCacheKey( artist(), name() ) ); - s_albumsByUniqueId.remove( uniqueId() ); + s_albumsByCoverId.remove( coverId() ); /* if ( id() > 0 ) s_albumsById.remove( id() );*/ @@ -83,7 +83,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr album->setWeakRef( album.toWeakRef() ); album->loadId( autoCreate ); - s_albumsByUniqueId[ album->uniqueId() ] = album; + s_albumsByCoverId[ album->coverId() ] = album; s_albumsByName[ key ] = album; return album; @@ -104,7 +104,7 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar album_ptr a = album_ptr( new Album( id, name, artist ), &QObject::deleteLater ); a->setWeakRef( a.toWeakRef() ); - s_albumsByUniqueId[ a->uniqueId() ] = a; + s_albumsByCoverId[ a->coverId() ] = a; s_albumsByName[ albumCacheKey( artist, name ) ] = a; if ( id > 0 ) s_albumsById.insert( id, a ); @@ -114,12 +114,12 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar album_ptr -Album::getByUniqueId( const QString& uuid ) +Album::getByCoverId( const QString& uuid ) { QMutexLocker lock( &s_mutex ); - if ( s_albumsByUniqueId.contains( uuid ) ) - return s_albumsByUniqueId.value( uuid ); + if ( s_albumsByCoverId.contains( uuid ) ) + return s_albumsByCoverId.value( uuid ); return album_ptr(); } @@ -295,6 +295,9 @@ Album::infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData, } m_coverLoaded = true; + s_albumsByCoverId.remove( coverId() ); + m_coverId = uuid(); + s_albumsByCoverId[ m_coverId ] = m_ownRef.toStrongRef(); emit coverChanged(); } } @@ -351,3 +354,13 @@ Album::uniqueId() const return m_uuid; } + + +QString +Album::coverId() const +{ + if ( m_coverId.isEmpty() ) + m_coverId = uuid(); + + return m_coverId; +} diff --git a/src/libtomahawk/Album.h b/src/libtomahawk/Album.h index 8942d87fd..1a3f923e9 100644 --- a/src/libtomahawk/Album.h +++ b/src/libtomahawk/Album.h @@ -47,7 +47,7 @@ Q_OBJECT public: static album_ptr get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate = false ); static album_ptr get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ); - static album_ptr getByUniqueId( const QString& uuid ); + static album_ptr getByCoverId( const QString& uuid ); Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ); Album( const QString& name, const Tomahawk::artist_ptr& artist ); @@ -57,6 +57,7 @@ public: QString name() const { return m_name; } QString sortname() const { return m_sortname; } QString uniqueId() const; + QString coverId() const; artist_ptr artist() const; #ifndef ENABLE_HEADLESS @@ -98,6 +99,7 @@ private: bool m_coverLoaded; mutable bool m_coverLoading; mutable QString m_uuid; + mutable QString m_coverId; #ifndef ENABLE_HEADLESS mutable QPixmap* m_cover; @@ -110,7 +112,7 @@ private: static QHash< QString, album_ptr > s_albumsByName; static QHash< unsigned int, album_ptr > s_albumsById; - static QHash< QString, album_ptr > s_albumsByUniqueId; + static QHash< QString, album_ptr > s_albumsByCoverId; friend class ::IdThreadWorker; }; diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 9457b2f81..b9c943113 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -39,9 +39,6 @@ using namespace Tomahawk; -QHash< QString, query_ptr > Query::s_queriesByUniqueId = QHash< QString, query_ptr >(); -static QMutex s_mutex; - SocialAction::SocialAction() {} SocialAction::~SocialAction() {} @@ -97,9 +94,6 @@ Query::get( const QString& artist, const QString& track, const QString& album, c if ( autoResolve ) Pipeline::instance()->resolve( q ); - QMutexLocker lock( &s_mutex ); - s_queriesByUniqueId[ qid ] = q; - return q; } @@ -115,25 +109,10 @@ Query::get( const QString& query, const QID& qid ) if ( !qid.isEmpty() ) Pipeline::instance()->resolve( q ); - QMutexLocker lock( &s_mutex ); - s_queriesByUniqueId[ qid ] = q; - return q; } -query_ptr -Query::getByUniqueId( const QString& qid ) -{ - QMutexLocker lock( &s_mutex ); - - if ( s_queriesByUniqueId.contains( qid ) ) - return s_queriesByUniqueId.value( qid ); - - return query_ptr(); -} - - Query::Query( const QString& artist, const QString& track, const QString& album, const QID& qid, bool autoResolve ) : m_qid( qid ) , m_artist( artist ) @@ -171,9 +150,6 @@ Query::Query( const QString& query, const QID& qid ) Query::~Query() { QMutexLocker lock( &m_mutex ); - QMutexLocker slock( &s_mutex ); - - s_queriesByUniqueId.remove( id() ); m_ownRef.clear(); m_results.clear(); @@ -374,6 +350,19 @@ Query::id() const } +QString +Query::coverId() const +{ + if ( m_albumPtr->coverLoaded() ) + { + if ( !m_albumPtr->cover( QSize( 0, 0 ) ).isNull() ) + return m_albumPtr->coverId(); + + return m_artistPtr->uniqueId(); + } +} + + void Query::setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime ) { diff --git a/src/libtomahawk/Query.h b/src/libtomahawk/Query.h index 8c22a2bad..4d6f5c3b9 100644 --- a/src/libtomahawk/Query.h +++ b/src/libtomahawk/Query.h @@ -85,7 +85,6 @@ public: static query_ptr get( const QString& artist, const QString& track, const QString& album, const QID& qid = QString(), bool autoResolve = true ); static query_ptr get( const QString& query, const QID& qid ); - static query_ptr getByUniqueId( const QString& qid ); virtual ~Query(); @@ -96,6 +95,7 @@ public: unsigned int numResults() const; QID id() const; + QString coverId() const; /// sorter for list of results static bool resultSorter( const result_ptr& left, const result_ptr& right ); @@ -272,8 +272,6 @@ private: QStringList m_lyrics; mutable int m_infoJobs; - - static QHash< QString, query_ptr > s_queriesByUniqueId; }; }; //ns diff --git a/src/libtomahawk/playlist/PlayableItem.cpp b/src/libtomahawk/playlist/PlayableItem.cpp index e0890df96..8b45639fd 100644 --- a/src/libtomahawk/playlist/PlayableItem.cpp +++ b/src/libtomahawk/playlist/PlayableItem.cpp @@ -94,8 +94,8 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare connect( query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) ); - connect( query->displayQuery().data(), SIGNAL( coverChanged() ), - SIGNAL( coverChanged() ) ); + connect( query->displayQuery().data(), SIGNAL( coverChanged() ), SIGNAL( coverChanged() ) ); + connect( query->displayQuery().data(), SIGNAL( coverChanged() ), SIGNAL( dataChanged() ) ); } @@ -164,6 +164,7 @@ PlayableItem::onResultsChanged() emit dataChanged(); } + QString PlayableItem::name() const { diff --git a/src/libtomahawk/playlist/PlayableModel.cpp b/src/libtomahawk/playlist/PlayableModel.cpp index d8064aa0f..c708c6e17 100644 --- a/src/libtomahawk/playlist/PlayableModel.cpp +++ b/src/libtomahawk/playlist/PlayableModel.cpp @@ -43,11 +43,11 @@ PlayableModel::PlayableModel( QObject* parent, bool loading ) , m_readOnly( true ) , m_loading( loading ) { - QHash roleNames; - roleNames.insert(ArtistRole, "artistName"); - roleNames.insert(TrackRole, "trackName"); - setRoleNames(roleNames); + roleNames.insert( ArtistRole, "artistName" ); + roleNames.insert( TrackRole, "trackName" ); + roleNames.insert( CoverIDRole, "coverID" ); + setRoleNames( roleNames ); connect( AudioEngine::instance(), SIGNAL( started( Tomahawk::result_ptr ) ), SLOT( onPlaybackStarted( Tomahawk::result_ptr ) ), Qt::DirectConnection ); connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ), Qt::DirectConnection ); @@ -166,6 +166,12 @@ PlayableModel::queryData( const query_ptr& query, int column, int role ) const if ( role == Qt::SizeHintRole ) return QSize( 0, 18 ); + if ( role == CoverIDRole ) + { + tDebug() << "Cover role for:" << query->toString(); + return query->displayQuery()->id(); + } + if ( role != Qt::DisplayRole ) // && role != Qt::ToolTipRole ) return QVariant(); @@ -266,7 +272,7 @@ PlayableModel::data( const QModelIndex& index, int role ) const } int column = index.column(); - if ( role >= Qt::UserRole ) + if ( role < CoverIDRole && role >= Qt::UserRole ) { // Map user-role to column column = role - Qt::UserRole; diff --git a/src/libtomahawk/playlist/PlayableModel.h b/src/libtomahawk/playlist/PlayableModel.h index f8b963bec..39ecb84f9 100644 --- a/src/libtomahawk/playlist/PlayableModel.h +++ b/src/libtomahawk/playlist/PlayableModel.h @@ -69,7 +69,8 @@ public: FilesizeRole, OriginRole, ScoreRole, - NameRole + NameRole, + CoverIDRole = Qt::UserRole + 100 }; diff --git a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp index 20389b774..af5a14ff0 100644 --- a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp +++ b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp @@ -3,6 +3,7 @@ #include "playlist/PlayableProxyModel.h" #include "Query.h" #include "Album.h" +#include "Artist.h" #include #include @@ -40,10 +41,19 @@ QPixmap DeclarativeCoverArtProvider::requestPixmap(const QString &id, QSize *siz // } // } - album_ptr album = Album::getByUniqueId(id); + tDebug() << "Getting by id:" << id; + album_ptr album = Album::getByCoverId(id); if ( !album.isNull() ) { return album->cover(requestedSize); } + artist_ptr artist = Artist::getByUniqueId(id); + if ( !artist.isNull() ) { + return artist->cover(requestedSize); + } +/* query_ptr query = Query::getByCoverId(id); + if ( !query.isNull() ) { + return query->cover(requestedSize); + }*/ // TODO: create default cover art image QPixmap pixmap( *size );