From 5f473a0c5c892b4fe515f6f7a0a82c065b673fcd Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser <muesli@gmail.com> Date: Thu, 7 Jun 2012 12:15:38 +0200 Subject: [PATCH] * Support loading and cache artists' biographies in Artist object directly. --- src/libtomahawk/Artist.cpp | 46 ++++++++++++++++++++++++++++++++++++++ src/libtomahawk/Artist.h | 5 +++++ 2 files changed, 51 insertions(+) diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 1a85915ad..ba44cda76 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -85,6 +85,7 @@ Artist::Artist( unsigned int id, const QString& name ) , m_coverLoaded( false ) , m_coverLoading( false ) , m_simArtistsLoaded( false ) + , m_biographyLoaded( false ) , m_infoJobs( 0 ) #ifndef ENABLE_HEADLESS , m_cover( 0 ) @@ -191,6 +192,35 @@ Artist::similarArtists() const } +QString +Artist::biography() const +{ + if ( !m_biographyLoaded ) + { + Tomahawk::InfoSystem::InfoRequestData requestData; + requestData.caller = infoid(); + requestData.customData = QVariantMap(); + + requestData.input = name(); + requestData.type = Tomahawk::InfoSystem::InfoArtistBiography; + 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_biography; +} + + void Artist::loadStats() { @@ -313,6 +343,22 @@ Artist::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVari break; } + case InfoSystem::InfoArtistBiography: + { + QVariantMap bmap = output.toMap(); + + foreach ( const QString& source, bmap.keys() ) + { + if ( source == "last.fm" ) + m_biography = bmap[ source ].toHash()[ "text" ].toString(); + } + + m_biographyLoaded = true; + emit biographyLoaded(); + + break; + } + default: Q_ASSERT( false ); } diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index deeb2fb21..3eef077a1 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -59,6 +59,8 @@ 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 QPixmap cover( const QSize& size, bool forceLoad = true ) const; @@ -77,6 +79,7 @@ signals: void updated(); void coverChanged(); void similarArtistsLoaded(); + void biographyLoaded(); void statsLoaded(); private slots: @@ -98,6 +101,7 @@ private: mutable bool m_coverLoading; QHash<Tomahawk::ModelMode, bool> m_albumsLoaded; bool m_simArtistsLoaded; + bool m_biographyLoaded; mutable QString m_uuid; mutable int m_infoJobs; @@ -105,6 +109,7 @@ private: QList<Tomahawk::album_ptr> m_databaseAlbums; QList<Tomahawk::album_ptr> m_officialAlbums; QList<Tomahawk::artist_ptr> m_similarArtists; + QString m_biography; bool m_playbackHistoryLoaded; QList< PlaybackLog > m_playbackHistory;