mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
* Added similar tracks and playback history methods to Artist.
This commit is contained in:
parent
01f98ddc7f
commit
b9e772f3e3
@ -23,8 +23,8 @@
|
||||
#include "Collection.h"
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseImpl.h"
|
||||
#include "Query.h"
|
||||
#include "database/DatabaseCommand_AllAlbums.h"
|
||||
#include "database/DatabaseCommand_TrackStats.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
@ -83,6 +83,7 @@ Artist::Artist( unsigned int id, const QString& name )
|
||||
, m_name( name )
|
||||
, m_infoLoaded( false )
|
||||
, m_infoLoading( false )
|
||||
, m_simArtistsLoaded( false )
|
||||
, m_infoJobs( 0 )
|
||||
#ifndef ENABLE_HEADLESS
|
||||
, m_cover( 0 )
|
||||
@ -138,12 +139,12 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
|
||||
requestData.type = Tomahawk::InfoSystem::InfoArtistReleases;
|
||||
|
||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(),
|
||||
SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ),
|
||||
SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), Qt::UniqueConnection );
|
||||
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 );
|
||||
SIGNAL( finished( QString ) ),
|
||||
SLOT( infoSystemFinished( QString ) ), Qt::UniqueConnection );
|
||||
|
||||
m_infoJobs++;
|
||||
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
|
||||
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 )
|
||||
return;
|
||||
|
||||
QVariantMap returnedData = output.value< QVariantMap >();
|
||||
switch ( requestData.type )
|
||||
{
|
||||
case Tomahawk::InfoSystem::InfoArtistReleases:
|
||||
{
|
||||
QVariantMap returnedData = output.value< QVariantMap >();
|
||||
QStringList albumNames = returnedData[ "albums" ].toStringList();
|
||||
Tomahawk::InfoSystem::InfoStringHash inputInfo;
|
||||
inputInfo = requestData.input.value< InfoSystem::InfoStringHash >();
|
||||
@ -212,7 +294,6 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
|
||||
{
|
||||
if ( !output.isNull() && output.isValid() )
|
||||
{
|
||||
QVariantMap returnedData = output.value< QVariantMap >();
|
||||
const QByteArray ba = returnedData["imgbytes"].toByteArray();
|
||||
if ( ba.length() )
|
||||
{
|
||||
@ -224,7 +305,21 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari
|
||||
|
||||
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:
|
||||
Q_ASSERT( false );
|
||||
}
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include "Typedefs.h"
|
||||
#include "DllMacro.h"
|
||||
#include "Query.h"
|
||||
#include "infosystem/InfoSystem.h"
|
||||
|
||||
namespace Tomahawk
|
||||
@ -53,6 +54,13 @@ public:
|
||||
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::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
|
||||
QPixmap cover( const QSize& size, bool forceLoad = true ) const;
|
||||
#endif
|
||||
@ -68,6 +76,8 @@ signals:
|
||||
|
||||
void updated();
|
||||
void coverChanged();
|
||||
void similarArtistsLoaded();
|
||||
void statsLoaded();
|
||||
|
||||
private slots:
|
||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||
@ -86,11 +96,17 @@ private:
|
||||
bool m_infoLoaded;
|
||||
mutable bool m_infoLoading;
|
||||
QHash<Tomahawk::ModelMode, bool> m_albumsLoaded;
|
||||
bool m_simArtistsLoaded;
|
||||
|
||||
mutable QString m_uuid;
|
||||
mutable int m_infoJobs;
|
||||
|
||||
QList<Tomahawk::album_ptr> m_databaseAlbums;
|
||||
QList<Tomahawk::album_ptr> m_officialAlbums;
|
||||
QList<Tomahawk::artist_ptr> m_similarArtists;
|
||||
|
||||
bool m_playbackHistoryLoaded;
|
||||
QList< PlaybackLog > m_playbackHistory;
|
||||
|
||||
mutable QByteArray m_coverBuffer;
|
||||
#ifndef ENABLE_HEADLESS
|
||||
|
Loading…
x
Reference in New Issue
Block a user