mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 19:14:06 +02:00
* Added coverID() related methods to Artist, Album, Track.
This commit is contained in:
committed by
Michael Zanetti
parent
d03cb674c9
commit
c47d52b144
@@ -37,6 +37,7 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
QHash< QString, album_wptr > Album::s_albumsByName = QHash< QString, album_wptr >();
|
QHash< QString, album_wptr > Album::s_albumsByName = QHash< QString, album_wptr >();
|
||||||
QHash< unsigned int, album_wptr > Album::s_albumsById = QHash< unsigned int, album_wptr >();
|
QHash< unsigned int, album_wptr > Album::s_albumsById = QHash< unsigned int, album_wptr >();
|
||||||
|
QHash< QString, album_ptr > Album::s_albumsByCoverId = QHash< QString, album_ptr >();
|
||||||
|
|
||||||
static QMutex s_nameCacheMutex;
|
static QMutex s_nameCacheMutex;
|
||||||
static QReadWriteLock s_idMutex;
|
static QReadWriteLock s_idMutex;
|
||||||
@@ -79,6 +80,7 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr
|
|||||||
album->setWeakRef( album.toWeakRef() );
|
album->setWeakRef( album.toWeakRef() );
|
||||||
album->loadId( autoCreate );
|
album->loadId( autoCreate );
|
||||||
s_albumsByName.insert( key, album );
|
s_albumsByName.insert( key, album );
|
||||||
|
s_albumsByCoverId.insert( album->coverId(), album );
|
||||||
|
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
@@ -110,6 +112,7 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
|
|||||||
album_ptr a = album_ptr( new Album( id, name, artist ), &Album::deleteLater );
|
album_ptr a = album_ptr( new Album( id, name, artist ), &Album::deleteLater );
|
||||||
a->setWeakRef( a.toWeakRef() );
|
a->setWeakRef( a.toWeakRef() );
|
||||||
s_albumsByName.insert( key, a );
|
s_albumsByName.insert( key, a );
|
||||||
|
s_albumsByCoverId.insert( a->coverId(), a );
|
||||||
|
|
||||||
if ( id > 0 )
|
if ( id > 0 )
|
||||||
{
|
{
|
||||||
@@ -122,6 +125,18 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
album_ptr
|
||||||
|
Album::getByCoverId( const QString& uuid )
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &s_nameCacheMutex );
|
||||||
|
|
||||||
|
if ( s_albumsByCoverId.contains( uuid ) )
|
||||||
|
return s_albumsByCoverId.value( uuid );
|
||||||
|
|
||||||
|
return album_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist )
|
Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_waitingForId( false )
|
, m_waitingForId( false )
|
||||||
@@ -327,6 +342,10 @@ Album::infoSystemInfo( const Tomahawk::InfoSystem::InfoRequestData& requestData,
|
|||||||
m_coverBuffer = ba;
|
m_coverBuffer = ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_albumsByCoverId.remove( coverId() );
|
||||||
|
m_coverId = uuid();
|
||||||
|
s_albumsByCoverId.insert( m_coverId, m_ownRef.toStrongRef() );
|
||||||
|
|
||||||
m_coverLoaded = true;
|
m_coverLoaded = true;
|
||||||
emit coverChanged();
|
emit coverChanged();
|
||||||
}
|
}
|
||||||
@@ -383,3 +402,13 @@ Album::infoid() const
|
|||||||
|
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
Album::coverId() const
|
||||||
|
{
|
||||||
|
if ( m_coverId.isEmpty() )
|
||||||
|
m_coverId = uuid();
|
||||||
|
|
||||||
|
return m_coverId;
|
||||||
|
}
|
||||||
|
@@ -45,12 +45,14 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
static album_ptr get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate = false );
|
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 get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist );
|
||||||
|
static album_ptr getByCoverId( const QString& uuid );
|
||||||
|
|
||||||
Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist );
|
Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist );
|
||||||
Album( const QString& name, const Tomahawk::artist_ptr& artist );
|
Album( const QString& name, const Tomahawk::artist_ptr& artist );
|
||||||
virtual ~Album();
|
virtual ~Album();
|
||||||
|
|
||||||
unsigned int id() const;
|
unsigned int id() const;
|
||||||
|
QString coverId() const;
|
||||||
QString name() const { return m_name; }
|
QString name() const { return m_name; }
|
||||||
QString sortname() const { return m_sortname; }
|
QString sortname() const { return m_sortname; }
|
||||||
|
|
||||||
@@ -98,6 +100,7 @@ private:
|
|||||||
mutable bool m_coverLoaded;
|
mutable bool m_coverLoaded;
|
||||||
mutable bool m_coverLoading;
|
mutable bool m_coverLoading;
|
||||||
mutable QString m_uuid;
|
mutable QString m_uuid;
|
||||||
|
mutable QString m_coverId;
|
||||||
|
|
||||||
mutable QByteArray m_coverBuffer;
|
mutable QByteArray m_coverBuffer;
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
@@ -110,6 +113,7 @@ private:
|
|||||||
|
|
||||||
static QHash< QString, album_wptr > s_albumsByName;
|
static QHash< QString, album_wptr > s_albumsByName;
|
||||||
static QHash< unsigned int, album_wptr > s_albumsById;
|
static QHash< unsigned int, album_wptr > s_albumsById;
|
||||||
|
static QHash< QString, album_ptr > s_albumsByCoverId;
|
||||||
|
|
||||||
friend class ::IdThreadWorker;
|
friend class ::IdThreadWorker;
|
||||||
};
|
};
|
||||||
|
@@ -39,6 +39,7 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
QHash< QString, artist_wptr > Artist::s_artistsByName = QHash< QString, artist_wptr >();
|
QHash< QString, artist_wptr > Artist::s_artistsByName = QHash< QString, artist_wptr >();
|
||||||
QHash< unsigned int, artist_wptr > Artist::s_artistsById = QHash< unsigned int, artist_wptr >();
|
QHash< unsigned int, artist_wptr > Artist::s_artistsById = QHash< unsigned int, artist_wptr >();
|
||||||
|
QHash< QString, artist_ptr > Artist::s_artistsByCoverId = QHash< QString, artist_ptr >();
|
||||||
|
|
||||||
static QMutex s_nameCacheMutex;
|
static QMutex s_nameCacheMutex;
|
||||||
static QReadWriteLock s_idMutex;
|
static QReadWriteLock s_idMutex;
|
||||||
@@ -77,6 +78,7 @@ Artist::get( const QString& name, bool autoCreate )
|
|||||||
artist->setWeakRef( artist.toWeakRef() );
|
artist->setWeakRef( artist.toWeakRef() );
|
||||||
artist->loadId( autoCreate );
|
artist->loadId( autoCreate );
|
||||||
s_artistsByName.insert( key, artist );
|
s_artistsByName.insert( key, artist );
|
||||||
|
s_artistsByCoverId.insert( artist->coverId(), artist );
|
||||||
|
|
||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
@@ -110,6 +112,7 @@ Artist::get( unsigned int id, const QString& name )
|
|||||||
artist_ptr a = artist_ptr( new Artist( id, name ), &Artist::deleteLater );
|
artist_ptr a = artist_ptr( new Artist( id, name ), &Artist::deleteLater );
|
||||||
a->setWeakRef( a.toWeakRef() );
|
a->setWeakRef( a.toWeakRef() );
|
||||||
s_artistsByName.insert( key, a );
|
s_artistsByName.insert( key, a );
|
||||||
|
s_artistsByCoverId.insert( a->coverId(), a );
|
||||||
|
|
||||||
if ( id > 0 )
|
if ( id > 0 )
|
||||||
{
|
{
|
||||||
@@ -122,6 +125,18 @@ Artist::get( unsigned int id, const QString& name )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
artist_ptr
|
||||||
|
Artist::getByCoverId( const QString& uuid )
|
||||||
|
{
|
||||||
|
QMutexLocker lock( &s_nameCacheMutex );
|
||||||
|
|
||||||
|
if ( s_artistsByCoverId.contains( uuid ) )
|
||||||
|
return s_artistsByCoverId.value( uuid );
|
||||||
|
|
||||||
|
return artist_ptr();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Artist::Artist( unsigned int id, const QString& name )
|
Artist::Artist( unsigned int id, const QString& name )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_waitingForFuture( false )
|
, m_waitingForFuture( false )
|
||||||
@@ -481,6 +496,10 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
|
|||||||
m_coverBuffer = ba;
|
m_coverBuffer = ba;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_artistsByCoverId.remove( coverId() );
|
||||||
|
m_coverId = uuid();
|
||||||
|
s_artistsByCoverId.insert( m_coverId, m_ownRef.toStrongRef() );
|
||||||
|
|
||||||
m_coverLoaded = true;
|
m_coverLoaded = true;
|
||||||
emit coverChanged();
|
emit coverChanged();
|
||||||
}
|
}
|
||||||
@@ -642,3 +661,13 @@ Artist::infoid() const
|
|||||||
|
|
||||||
return m_uuid;
|
return m_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
Artist::coverId() const
|
||||||
|
{
|
||||||
|
if ( m_coverId.isEmpty() )
|
||||||
|
m_coverId = uuid();
|
||||||
|
|
||||||
|
return m_coverId;
|
||||||
|
}
|
||||||
|
@@ -43,12 +43,14 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
static artist_ptr get( const QString& name, bool autoCreate = false );
|
static artist_ptr get( const QString& name, bool autoCreate = false );
|
||||||
static artist_ptr get( unsigned int id, const QString& name );
|
static artist_ptr get( unsigned int id, const QString& name );
|
||||||
|
static artist_ptr getByCoverId( const QString& uuid );
|
||||||
|
|
||||||
Artist( unsigned int id, const QString& name );
|
Artist( unsigned int id, const QString& name );
|
||||||
explicit Artist( const QString& name );
|
explicit Artist( const QString& name );
|
||||||
virtual ~Artist();
|
virtual ~Artist();
|
||||||
|
|
||||||
unsigned int id() const;
|
unsigned int id() const;
|
||||||
|
QString coverId() const;
|
||||||
QString name() const { return m_name; }
|
QString name() const { return m_name; }
|
||||||
QString sortname() const { return m_sortname; }
|
QString sortname() const { return m_sortname; }
|
||||||
|
|
||||||
@@ -117,6 +119,7 @@ private:
|
|||||||
bool m_biographyLoaded;
|
bool m_biographyLoaded;
|
||||||
|
|
||||||
mutable QString m_uuid;
|
mutable QString m_uuid;
|
||||||
|
mutable QString m_coverId;
|
||||||
mutable int m_infoJobs;
|
mutable int m_infoJobs;
|
||||||
|
|
||||||
QList<Tomahawk::album_ptr> m_databaseAlbums;
|
QList<Tomahawk::album_ptr> m_databaseAlbums;
|
||||||
@@ -138,6 +141,7 @@ private:
|
|||||||
|
|
||||||
static QHash< QString, artist_wptr > s_artistsByName;
|
static QHash< QString, artist_wptr > s_artistsByName;
|
||||||
static QHash< unsigned int, artist_wptr > s_artistsById;
|
static QHash< unsigned int, artist_wptr > s_artistsById;
|
||||||
|
static QHash< QString, artist_ptr > s_artistsByCoverId;
|
||||||
|
|
||||||
friend class ::IdThreadWorker;
|
friend class ::IdThreadWorker;
|
||||||
};
|
};
|
||||||
|
@@ -494,10 +494,25 @@ Track::coverLoaded() const
|
|||||||
|
|
||||||
return m_artistPtr->coverLoaded();
|
return m_artistPtr->coverLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
QString
|
||||||
|
Track::coverId() const
|
||||||
|
{
|
||||||
|
if ( m_albumPtr && m_albumPtr->coverLoaded() && !m_albumPtr->cover( QSize( 0, 0 ) ).isNull() )
|
||||||
|
{
|
||||||
|
return m_albumPtr->coverId();
|
||||||
|
}
|
||||||
|
else if ( m_artistPtr )
|
||||||
|
{
|
||||||
|
return m_artistPtr->coverId();
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QList<Tomahawk::query_ptr>
|
QList<Tomahawk::query_ptr>
|
||||||
Track::similarTracks() const
|
Track::similarTracks() const
|
||||||
{
|
{
|
||||||
|
@@ -84,6 +84,7 @@ public:
|
|||||||
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
|
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
|
||||||
#endif
|
#endif
|
||||||
bool coverLoaded() const;
|
bool coverLoaded() const;
|
||||||
|
QString coverId() const;
|
||||||
|
|
||||||
void setLoved( bool loved, bool postToInfoSystem = true );
|
void setLoved( bool loved, bool postToInfoSystem = true );
|
||||||
bool loved();
|
bool loved();
|
||||||
|
Reference in New Issue
Block a user