1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-03 02:42:52 +02:00

* Added getByUniqueId( uuid ) methods to Artist, Album and Query.

This commit is contained in:
Christian Muehlhaeuser
2012-07-14 13:20:38 +02:00
committed by Michael Zanetti
parent 9104d3b92d
commit bc94658e56
6 changed files with 105 additions and 25 deletions

View File

@@ -35,13 +35,27 @@ 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 >();
static QMutex s_nameCacheMutex;
static QMutex s_idCacheMutex;
static QMutex s_mutex;
static QReadWriteLock s_idMutex;
inline QString
albumCacheKey( const Tomahawk::artist_ptr& artist, const QString& albumName )
{
return QString( "%1\t\t%2" ).arg( artist->name() ).arg( albumName );
}
Album::~Album()
{
QMutexLocker lock( &s_mutex );
s_albumsByName.remove( albumCacheKey( artist(), name() ) );
s_albumsByUniqueId.remove( uniqueId() );
/* if ( id() > 0 )
s_albumsById.remove( id() );*/
m_ownRef.clear();
#ifndef ENABLE_HEADLESS
@@ -55,14 +69,13 @@ albumCacheKey( const Tomahawk::artist_ptr& artist, const QString& albumName )
return QString( "%1\t\t%2" ).arg( artist->name().toLower() ).arg( albumName.toLower() );
}
album_ptr
Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate )
{
if ( !Database::instance() || !Database::instance()->impl() )
return album_ptr();
QMutexLocker l( &s_nameCacheMutex );
QMutexLocker l( &s_mutex );
const QString key = albumCacheKey( artist, name );
if ( s_albumsByName.contains( key ) )
@@ -75,6 +88,8 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr
album->loadId( autoCreate );
s_albumsByName.insert( key, album );
s_albumsByUniqueId[ album->uniqueId() ] = album;
return album;
}
@@ -83,9 +98,8 @@ album_ptr
Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist )
{
static QHash< unsigned int, album_ptr > s_albums;
static QMutex s_mutex;
QMutexLocker lock( &s_idCacheMutex );
QMutexLocker lock( &s_mutex );
const QString key = albumCacheKey( artist, name );
if ( s_albumsByName.contains( key ) )
@@ -101,6 +115,8 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
a->setWeakRef( a.toWeakRef() );
s_albumsByName.insert( key, a );
s_albumsByUniqueId[ a->uniqueId() ] = a;
s_albumsByName[ albumCacheKey( artist, name ) ] = a;
if ( id > 0 )
{
s_albumsById.insert( id, a );
@@ -110,6 +126,18 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
}
album_ptr
Album::getByUniqueId( const QString& uuid )
{
QMutexLocker lock( &s_mutex );
if ( s_albumsByUniqueId.contains( uuid ) )
return s_albumsByUniqueId.value( uuid );
return album_ptr();
}
Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist )
: QObject()
, m_waitingForId( false )
@@ -209,7 +237,7 @@ Album::cover( const QSize& size, bool forceLoad ) const
trackInfo["album"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = infoid();
requestData.caller = uniqueId();
requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
requestData.customData = QVariantMap();
@@ -257,7 +285,7 @@ Album::cover( const QSize& size, bool forceLoad ) const
void
Album::infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData, const QVariant& output )
{
if ( requestData.caller != infoid() ||
if ( requestData.caller != uniqueId() ||
requestData.type != Tomahawk::InfoSystem::InfoAlbumCoverArt )
{
return;
@@ -285,7 +313,7 @@ Album::infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData,
void
Album::infoSystemFinished( const QString& target )
{
if ( target != infoid() )
if ( target != uniqueId() )
return;
disconnect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
@@ -326,7 +354,7 @@ Album::tracks( ModelMode mode, const Tomahawk::collection_ptr& collection )
QString
Album::infoid() const
Album::uniqueId() const
{
if ( m_uuid.isEmpty() )
m_uuid = uuid();

View File

@@ -47,6 +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 );
Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist );
Album( const QString& name, const Tomahawk::artist_ptr& artist );
@@ -55,6 +56,7 @@ public:
unsigned int id() const;
QString name() const { return m_name; }
QString sortname() const { return m_sortname; }
QString uniqueId() const;
artist_ptr artist() const;
#ifndef ENABLE_HEADLESS
@@ -82,7 +84,6 @@ private slots:
private:
Q_DISABLE_COPY( Album )
QString infoid() const;
void setIdFuture( QFuture<unsigned int> future );
mutable bool m_waitingForId;
@@ -109,6 +110,7 @@ private:
static QHash< QString, album_ptr > s_albumsByName;
static QHash< unsigned int, album_ptr > s_albumsById;
static QHash< QString, album_ptr > s_albumsByUniqueId;
friend class ::IdThreadWorker;
};

View File

@@ -38,13 +38,19 @@ using namespace Tomahawk;
QHash< QString, artist_ptr > Artist::s_artistsByName = QHash< QString, artist_ptr >();
QHash< unsigned int, artist_ptr > Artist::s_artistsById = QHash< unsigned int, artist_ptr >();
QHash< QString, artist_ptr > Artist::s_artistsByUniqueId = QHash< QString, artist_ptr >();
static QMutex s_nameCacheMutex;
static QMutex s_idCacheMutex;
static QMutex s_mutex;
static QReadWriteLock s_idMutex;
Artist::~Artist()
{
QMutexLocker lock( &s_mutex );
s_artistsByName.remove( name() );
s_artistsByUniqueId.remove( uniqueId() );
/* if ( id() > 0 )
s_artistsById.remove( id() );*/
m_ownRef.clear();
#ifndef ENABLE_HEADLESS
@@ -61,7 +67,7 @@ Artist::get( const QString& name, bool autoCreate )
const QString sortname = name.toLower();
QMutexLocker lock( &s_nameCacheMutex );
QMutexLocker lock( &s_mutex );
if ( s_artistsByName.contains( sortname ) )
return s_artistsByName.value( sortname );
@@ -76,6 +82,7 @@ Artist::get( const QString& name, bool autoCreate )
artist->setWeakRef( artist.toWeakRef() );
artist->loadId( autoCreate );
s_artistsByName.insert( sortname, artist );
s_artistsByUniqueId[ artist->uniqueId() ] = artist;
return artist;
}
@@ -84,7 +91,7 @@ Artist::get( const QString& name, bool autoCreate )
artist_ptr
Artist::get( unsigned int id, const QString& name )
{
QMutexLocker lock( &s_idCacheMutex );
QMutexLocker lock( &s_mutex );
const QString sortname = name.toLower();
if ( s_artistsByName.contains( sortname ) )
@@ -100,6 +107,7 @@ Artist::get( unsigned int id, const QString& name )
a->setWeakRef( a.toWeakRef() );
s_artistsByName.insert( sortname, a );
s_artistsByUniqueId[ a->uniqueId() ] = a;
if ( id > 0 )
{
s_artistsById.insert( id, a );
@@ -109,6 +117,18 @@ Artist::get( unsigned int id, const QString& name )
}
artist_ptr
Artist::getByUniqueId( const QString& uuid )
{
QMutexLocker lock( &s_mutex );
if ( s_artistsByUniqueId.contains( uuid ) )
return s_artistsByUniqueId.value( uuid );
return artist_ptr();
}
Artist::Artist( unsigned int id, const QString& name )
: QObject()
, m_waitingForFuture( false )
@@ -179,7 +199,7 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
artistInfo["artist"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = infoid();
requestData.caller = uniqueId();
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
@@ -219,7 +239,7 @@ Artist::similarArtists() const
artistInfo["artist"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = infoid();
requestData.caller = uniqueId();
requestData.customData = QVariantMap();
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
@@ -301,7 +321,7 @@ Artist::biography() const
if ( !m_biographyLoaded )
{
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = infoid();
requestData.caller = uniqueId();
requestData.customData = QVariantMap();
requestData.input = name();
@@ -389,7 +409,7 @@ Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data )
void
Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output )
{
if ( requestData.caller != infoid() )
if ( requestData.caller != uniqueId() )
return;
QVariantMap returnedData = output.value< QVariantMap >();
@@ -478,7 +498,7 @@ Artist::infoSystemFinished( QString target )
{
Q_UNUSED( target );
if ( target != infoid() )
if ( target != uniqueId() )
return;
if ( --m_infoJobs == 0 )
@@ -509,7 +529,7 @@ Artist::cover( const QSize& size, bool forceLoad ) const
trackInfo["artist"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = infoid();
requestData.caller = uniqueId();
requestData.type = Tomahawk::InfoSystem::InfoArtistImages;
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
requestData.customData = QVariantMap();
@@ -582,7 +602,7 @@ Artist::tracks( ModelMode mode, const Tomahawk::collection_ptr& collection )
QString
Artist::infoid() const
Artist::uniqueId() const
{
if ( m_uuid.isEmpty() )
m_uuid = uuid();

View File

@@ -46,6 +46,7 @@ Q_OBJECT
public:
static artist_ptr get( const QString& name, bool autoCreate = false );
static artist_ptr get( unsigned int id, const QString& name );
static artist_ptr getByUniqueId( const QString& uuid );
Artist( unsigned int id, const QString& name );
explicit Artist( const QString& name );
@@ -54,6 +55,7 @@ public:
unsigned int id() const;
QString name() const { return m_name; }
QString sortname() const { return m_sortname; }
QString uniqueId() const;
QList<Tomahawk::album_ptr> albums( ModelMode mode = Mixed, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ) const;
QList<Tomahawk::artist_ptr> similarArtists() const;
@@ -65,7 +67,7 @@ public:
QList< Tomahawk::PlaybackLog > playbackHistory( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() ) const;
void setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData );
unsigned int playbackCount( const Tomahawk::source_ptr& source = Tomahawk::source_ptr() );
QString biography() const;
#ifndef ENABLE_HEADLESS
@@ -98,7 +100,6 @@ private slots:
private:
Artist();
QString infoid() const;
void setIdFuture( QFuture<unsigned int> idFuture );
@@ -133,11 +134,12 @@ private:
#endif
QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface;
QWeakPointer< Tomahawk::Artist > m_ownRef;
static QHash< QString, artist_ptr > s_artistsByName;
static QHash< unsigned int, artist_ptr > s_artistsById;
static QHash< QString, artist_ptr > s_artistsByUniqueId;
friend class ::IdThreadWorker;
};

View File

@@ -39,6 +39,9 @@
using namespace Tomahawk;
QHash< QString, query_ptr > Query::s_queriesByUniqueId = QHash< QString, query_ptr >();
static QMutex s_mutex;
SocialAction::SocialAction() {}
SocialAction::~SocialAction() {}
@@ -94,6 +97,9 @@ 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;
}
@@ -109,10 +115,25 @@ 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 )
@@ -150,6 +171,10 @@ 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();
}

View File

@@ -85,6 +85,7 @@ 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();
@@ -276,6 +277,8 @@ private:
QStringList m_lyrics;
mutable int m_infoJobs;
static QHash< QString, query_ptr > s_queriesByUniqueId;
};
}; //ns