1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 13:17:34 +02:00

* Added similar tracks and playback history methods to Artist.

This commit is contained in:
Christian Muehlhaeuser
2012-05-05 16:43:47 +02:00
parent 01f98ddc7f
commit b9e772f3e3
2 changed files with 119 additions and 8 deletions

View File

@@ -23,8 +23,8 @@
#include "Collection.h" #include "Collection.h"
#include "database/Database.h" #include "database/Database.h"
#include "database/DatabaseImpl.h" #include "database/DatabaseImpl.h"
#include "Query.h"
#include "database/DatabaseCommand_AllAlbums.h" #include "database/DatabaseCommand_AllAlbums.h"
#include "database/DatabaseCommand_TrackStats.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -83,6 +83,7 @@ Artist::Artist( unsigned int id, const QString& name )
, m_name( name ) , m_name( name )
, m_infoLoaded( false ) , m_infoLoaded( false )
, m_infoLoading( false ) , m_infoLoading( false )
, m_simArtistsLoaded( false )
, m_infoJobs( 0 ) , m_infoJobs( 0 )
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
, m_cover( 0 ) , m_cover( 0 )
@@ -138,12 +139,12 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases; requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
connect( Tomahawk::InfoSystem::InfoSystem::instance(), connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection ); SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
connect( Tomahawk::InfoSystem::InfoSystem::instance(), connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( finished( QString ) ), SIGNAL( finished( QString ) ),
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection ); SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
m_infoJobs++; m_infoJobs++;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
@@ -164,6 +165,87 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
} }
QList<Tomahawk::artist_ptr>
Artist::similarArtists() const
{
if ( !m_simArtistsLoaded )
{
Tomahawk::InfoSystem::InfoStringHash artistInfo;
artistInfo["artist"] = name();
Tomahawk::InfoSystem::InfoRequestData requestData;
requestData.caller = m_uuid;
requestData.customData = QVariantMap();
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoArtistSimilars;
requestData.requestId = TomahawkUtils::infosystemRequestId();
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
SIGNAL( finished( QString ) ),
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
m_infoJobs++;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
return m_similarArtists;
}
void
Artist::loadStats()
{
artist_ptr a = m_ownRef.toStrongRef();
DatabaseCommand_TrackStats* cmd = new DatabaseCommand_TrackStats( a );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>(cmd) );
}
QList< Tomahawk::PlaybackLog >
Artist::playbackHistory( const Tomahawk::source_ptr& source ) const
{
QList< Tomahawk::PlaybackLog > history;
foreach ( const PlaybackLog& log, m_playbackHistory )
{
if ( source.isNull() || log.source == source )
{
history << log;
}
}
return history;
}
void
Artist::setPlaybackHistory( const QList< Tomahawk::PlaybackLog >& playbackData )
{
m_playbackHistory = playbackData;
emit statsLoaded();
}
unsigned int
Artist::playbackCount( const source_ptr& source )
{
unsigned int count = 0;
foreach ( const PlaybackLog& log, m_playbackHistory )
{
if ( source.isNull() || log.source == source )
count++;
}
return count;
}
void void
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data ) Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data )
{ {
@@ -183,11 +265,11 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
if ( requestData.caller != m_uuid ) if ( requestData.caller != m_uuid )
return; return;
QVariantMap returnedData = output.value< QVariantMap >();
switch ( requestData.type ) switch ( requestData.type )
{ {
case Tomahawk::InfoSystem::InfoArtistReleases: case Tomahawk::InfoSystem::InfoArtistReleases:
{ {
QVariantMap returnedData = output.value< QVariantMap >();
QStringList albumNames = returnedData[ "albums" ].toStringList(); QStringList albumNames = returnedData[ "albums" ].toStringList();
Tomahawk::InfoSystem::InfoStringHash inputInfo; Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >(); inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
@@ -212,7 +294,6 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
{ {
if ( !output.isNull() && output.isValid() ) if ( !output.isNull() && output.isValid() )
{ {
QVariantMap returnedData = output.value< QVariantMap >();
const QByteArray ba = returnedData["imgbytes"].toByteArray(); const QByteArray ba = returnedData["imgbytes"].toByteArray();
if ( ba.length() ) if ( ba.length() )
{ {
@@ -224,7 +305,21 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
break; break;
} }
case InfoSystem::InfoArtistSimilars:
{
const QStringList artists = returnedData["artists"].toStringList();
foreach ( const QString& artist, artists )
{
m_similarArtists << Artist::get( artist );
}
m_simArtistsLoaded = true;
emit similarArtistsLoaded();
break;
}
default: default:
Q_ASSERT( false ); Q_ASSERT( false );
} }

View File

@@ -30,6 +30,7 @@
#include "Typedefs.h" #include "Typedefs.h"
#include "DllMacro.h" #include "DllMacro.h"
#include "Query.h"
#include "infosystem/InfoSystem.h" #include "infosystem/InfoSystem.h"
namespace Tomahawk namespace Tomahawk
@@ -53,6 +54,13 @@ public:
bool infoLoaded() const { return m_infoLoaded; } bool infoLoaded() const { return m_infoLoaded; }
QList<Tomahawk::album_ptr> albums( ModelMode mode = Mixed, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ) const; QList<Tomahawk::album_ptr> albums( ModelMode mode = Mixed, const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr() ) const;
QList<Tomahawk::artist_ptr> similarArtists() const;
void loadStats();
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() );
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS
QPixmap cover( const QSize& size, bool forceLoad = true ) const; QPixmap cover( const QSize& size, bool forceLoad = true ) const;
#endif #endif
@@ -68,6 +76,8 @@ signals:
void updated(); void updated();
void coverChanged(); void coverChanged();
void similarArtistsLoaded();
void statsLoaded();
private slots: private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks ); void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
@@ -86,11 +96,17 @@ private:
bool m_infoLoaded; bool m_infoLoaded;
mutable bool m_infoLoading; mutable bool m_infoLoading;
QHash<Tomahawk::ModelMode, bool> m_albumsLoaded; QHash<Tomahawk::ModelMode, bool> m_albumsLoaded;
bool m_simArtistsLoaded;
mutable QString m_uuid; mutable QString m_uuid;
mutable int m_infoJobs; mutable int m_infoJobs;
QList<Tomahawk::album_ptr> m_databaseAlbums; QList<Tomahawk::album_ptr> m_databaseAlbums;
QList<Tomahawk::album_ptr> m_officialAlbums; QList<Tomahawk::album_ptr> m_officialAlbums;
QList<Tomahawk::artist_ptr> m_similarArtists;
bool m_playbackHistoryLoaded;
QList< PlaybackLog > m_playbackHistory;
mutable QByteArray m_coverBuffer; mutable QByteArray m_coverBuffer;
#ifndef ENABLE_HEADLESS #ifndef ENABLE_HEADLESS