mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-15 10:33:59 +02:00
* Work on image provider & unique cover IDs.
This commit is contained in:
@@ -30,7 +30,7 @@ Item {
|
||||
showLabels: false
|
||||
//artistName: model.artistName
|
||||
//trackName: model.trackName
|
||||
artworkId: index
|
||||
artworkId: model.coverID
|
||||
|
||||
scale: PathView.itemScale
|
||||
itemBrightness: PathView.itemBrightness
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
};
|
||||
|
@@ -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 )
|
||||
{
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -43,11 +43,11 @@ PlayableModel::PlayableModel( QObject* parent, bool loading )
|
||||
, m_readOnly( true )
|
||||
, m_loading( loading )
|
||||
{
|
||||
|
||||
QHash<int, QByteArray> 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;
|
||||
|
@@ -69,7 +69,8 @@ public:
|
||||
FilesizeRole,
|
||||
OriginRole,
|
||||
ScoreRole,
|
||||
NameRole
|
||||
NameRole,
|
||||
CoverIDRole = Qt::UserRole + 100
|
||||
};
|
||||
|
||||
|
||||
|
@@ -3,6 +3,7 @@
|
||||
#include "playlist/PlayableProxyModel.h"
|
||||
#include "Query.h"
|
||||
#include "Album.h"
|
||||
#include "Artist.h"
|
||||
|
||||
#include <QDeclarativeImageProvider>
|
||||
#include <QModelIndex>
|
||||
@@ -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 );
|
||||
|
Reference in New Issue
Block a user