mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-29 20:22:30 +01:00
Implement fetching and displaying of the Top Tracks Chart.
This commit is contained in:
parent
a21992a99a
commit
fc235ccf1b
src
libtomahawk
tomahawkapp.cpp@ -47,7 +47,7 @@ LastFmPlugin::LastFmPlugin()
|
|||||||
: InfoPlugin()
|
: InfoPlugin()
|
||||||
, m_scrobbler( 0 )
|
, m_scrobbler( 0 )
|
||||||
{
|
{
|
||||||
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs << InfoChartArtists;
|
m_supportedGetTypes << InfoAlbumCoverArt << InfoArtistImages << InfoArtistSimilars << InfoArtistSongs << InfoChartArtists << InfoChartTracks;
|
||||||
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove << InfoUnLove;
|
m_supportedPushTypes << InfoSubmitScrobble << InfoSubmitNowPlaying << InfoLove << InfoUnLove;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -151,6 +151,10 @@ LastFmPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData req
|
|||||||
fetchChartArtists( requestId, requestData );
|
fetchChartArtists( requestId, requestData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case InfoChartTracks:
|
||||||
|
fetchChartTracks( requestId, requestData );
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
dataError( requestId, requestData );
|
dataError( requestId, requestData );
|
||||||
}
|
}
|
||||||
@ -321,6 +325,25 @@ LastFmPlugin::fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoReque
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LastFmPlugin::fetchChartTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
|
{
|
||||||
|
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() )
|
||||||
|
{
|
||||||
|
dataError( requestId, requestData );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
|
if ( hash.contains( "country" ) )
|
||||||
|
{
|
||||||
|
criteria["country"] = hash["country"];
|
||||||
|
}
|
||||||
|
|
||||||
|
emit getCachedInfo( requestId, criteria, 2419200000, requestData );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
LastFmPlugin::fetchCoverArt( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
LastFmPlugin::fetchCoverArt( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||||
{
|
{
|
||||||
@ -397,6 +420,25 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case InfoChartTracks:
|
||||||
|
{
|
||||||
|
tDebug() << "LastfmPlugin: InfoChartTracks not in cache, fetching";
|
||||||
|
QMap<QString, QString> args;
|
||||||
|
if( criteria.contains( "country" ) ) {
|
||||||
|
args["method"] = "geo.getTopTracks";
|
||||||
|
args["country"] = criteria["country"];
|
||||||
|
} else {
|
||||||
|
args["method"] = "chart.getTopTracks";
|
||||||
|
}
|
||||||
|
args["limit"] = "100";
|
||||||
|
QNetworkReply* reply = lastfm::ws::get(args);
|
||||||
|
reply->setProperty( "requestId", requestId );
|
||||||
|
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||||
|
|
||||||
|
connect( reply, SIGNAL( finished() ), SLOT( chartTopTracksReturned() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case InfoArtistSimilars:
|
case InfoArtistSimilars:
|
||||||
{
|
{
|
||||||
lastfm::Artist a( criteria["artist"] );
|
lastfm::Artist a( criteria["artist"] );
|
||||||
@ -519,6 +561,42 @@ LastFmPlugin::chartTopArtistsReturned()
|
|||||||
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LastFmPlugin::chartTopTracksReturned()
|
||||||
|
{
|
||||||
|
tDebug() << "LastfmPlugin: InfoChartTracks data returned!";
|
||||||
|
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
|
||||||
|
QList<lastfm::Track> tracks = parseTrackList( reply );
|
||||||
|
|
||||||
|
QList<ArtistTrackPair> top_tracks;
|
||||||
|
|
||||||
|
foreach( const lastfm::Track &t, tracks ) {
|
||||||
|
ArtistTrackPair pair;
|
||||||
|
pair.artist = t.artist().toString();
|
||||||
|
pair.track = t.title();
|
||||||
|
top_tracks << pair;
|
||||||
|
}
|
||||||
|
|
||||||
|
tDebug() << "\tgot " << top_tracks.size() << " tracks";
|
||||||
|
|
||||||
|
QVariantMap returnedData;
|
||||||
|
returnedData["tracks"] = QVariant::fromValue( top_tracks );
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
|
||||||
|
|
||||||
|
emit info(
|
||||||
|
reply->property( "requestId" ).toUInt(),
|
||||||
|
requestData,
|
||||||
|
returnedData
|
||||||
|
);
|
||||||
|
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
|
||||||
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
|
if( origData.contains("country") )
|
||||||
|
criteria["country"] = origData["country"];
|
||||||
|
emit updateCache( criteria, 0, requestData.type, returnedData );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LastFmPlugin::topTracksReturned()
|
LastFmPlugin::topTracksReturned()
|
||||||
{
|
{
|
||||||
@ -539,7 +617,7 @@ LastFmPlugin::topTracksReturned()
|
|||||||
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
|
Tomahawk::InfoSystem::InfoCriteriaHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash>();
|
||||||
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
criteria["artist"] = origData["artist"];
|
criteria["artist"] = origData["artist"];
|
||||||
emit updateCache( criteria, 2419200000, requestData.type, returnedData );
|
emit updateCache( criteria, 0, requestData.type, returnedData );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -746,3 +824,21 @@ LastFmPlugin::createScrobbler()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<lastfm::Track>
|
||||||
|
LastFmPlugin::parseTrackList( QNetworkReply * reply )
|
||||||
|
{
|
||||||
|
QList<lastfm::Track> tracks;
|
||||||
|
try {
|
||||||
|
lastfm::XmlQuery lfm = lastfm::ws::parse(reply);
|
||||||
|
foreach (lastfm::XmlQuery xq, lfm.children( "track" )) {
|
||||||
|
tracks.append( lastfm::Track( xq ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (lastfm::ws::ParseError& e)
|
||||||
|
{
|
||||||
|
qWarning() << e.what();
|
||||||
|
}
|
||||||
|
return tracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ public slots:
|
|||||||
void similarArtistsReturned();
|
void similarArtistsReturned();
|
||||||
void topTracksReturned();
|
void topTracksReturned();
|
||||||
void chartTopArtistsReturned();
|
void chartTopArtistsReturned();
|
||||||
|
void chartTopTracksReturned();
|
||||||
|
|
||||||
void namChangedSlot( QNetworkAccessManager *nam );
|
void namChangedSlot( QNetworkAccessManager *nam );
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ private:
|
|||||||
void fetchSimilarArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchSimilarArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchTopTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
void fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void fetchChartArtists( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
void fetchChartTracks( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
|
||||||
void createScrobbler();
|
void createScrobbler();
|
||||||
void nowPlaying( const QVariant &input );
|
void nowPlaying( const QVariant &input );
|
||||||
@ -76,6 +78,8 @@ private:
|
|||||||
|
|
||||||
void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData );
|
||||||
|
|
||||||
|
QList<lastfm::Track> parseTrackList( QNetworkReply * reply );
|
||||||
|
|
||||||
lastfm::MutableTrack m_track;
|
lastfm::MutableTrack m_track;
|
||||||
lastfm::Audioscrobbler* m_scrobbler;
|
lastfm::Audioscrobbler* m_scrobbler;
|
||||||
QString m_pw;
|
QString m_pw;
|
||||||
|
@ -122,6 +122,11 @@ struct InfoRequestData {
|
|||||||
QVariantMap customData;
|
QVariantMap customData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ArtistTrackPair {
|
||||||
|
QString artist;
|
||||||
|
QString track;
|
||||||
|
};
|
||||||
|
|
||||||
typedef QMap< InfoType, QVariant > InfoTypeMap;
|
typedef QMap< InfoType, QVariant > InfoTypeMap;
|
||||||
typedef QMap< InfoType, uint > InfoTimeoutMap;
|
typedef QMap< InfoType, uint > InfoTimeoutMap;
|
||||||
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
|
typedef QMap< QString, QMap< QString, QString > > InfoGenericMap;
|
||||||
@ -258,5 +263,7 @@ Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData );
|
|||||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap );
|
||||||
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCriteriaHash );
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCriteriaHash );
|
||||||
Q_DECLARE_METATYPE( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > );
|
Q_DECLARE_METATYPE( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > );
|
||||||
|
Q_DECLARE_METATYPE( Tomahawk::InfoSystem::ArtistTrackPair );
|
||||||
|
Q_DECLARE_METATYPE( QList<Tomahawk::InfoSystem::ArtistTrackPair> );
|
||||||
|
|
||||||
#endif // TOMAHAWK_INFOSYSTEM_H
|
#endif // TOMAHAWK_INFOSYSTEM_H
|
||||||
|
@ -56,9 +56,10 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
|||||||
|
|
||||||
|
|
||||||
m_tracksModel = new PlaylistModel( ui->tracksView );
|
m_tracksModel = new PlaylistModel( ui->tracksView );
|
||||||
m_tracksModel->setStyle( TrackModel::ShortWithAvatars );
|
m_tracksModel->setStyle( TrackModel::Short );
|
||||||
|
|
||||||
ui->tracksView->overlay()->setEnabled( false );
|
ui->tracksView->overlay()->setEnabled( false );
|
||||||
ui->tracksView->setPlaylistModel( m_tracksModel );
|
ui->tracksView->setTrackModel( m_tracksModel );
|
||||||
ui->tracksView->setHeaderHidden( true );
|
ui->tracksView->setHeaderHidden( true );
|
||||||
ui->tracksView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
ui->tracksView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
||||||
|
|
||||||
@ -99,7 +100,11 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
|||||||
|
|
||||||
requestData.type = Tomahawk::InfoSystem::InfoChartArtists;
|
requestData.type = Tomahawk::InfoSystem::InfoChartArtists;
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||||
tDebug() << "WhatsHot: requested InfoChartArtists";
|
|
||||||
|
requestData.type = Tomahawk::InfoSystem::InfoChartTracks;
|
||||||
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
||||||
|
|
||||||
|
tDebug() << "WhatsHot: requested InfoChartArtists+Tracks";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -113,7 +118,7 @@ void
|
|||||||
WhatsHotWidget::checkQueries()
|
WhatsHotWidget::checkQueries()
|
||||||
{
|
{
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
// m_tracksModel->ensureResolved();
|
m_tracksModel->ensureResolved();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -141,7 +146,17 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case InfoSystem::InfoChartTracks:
|
||||||
|
{
|
||||||
|
const QList<Tomahawk::InfoSystem::ArtistTrackPair> tracks = returnedData["tracks"].value<QList<Tomahawk::InfoSystem::ArtistTrackPair> >();
|
||||||
|
tDebug() << "WhatsHot: got tracks! " << tracks.size();
|
||||||
|
foreach ( const Tomahawk::InfoSystem::ArtistTrackPair& track, tracks )
|
||||||
|
{
|
||||||
|
query_ptr query = Query::get( track.artist, track.track, QString(), uuid() );
|
||||||
|
m_tracksModel->append( query );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -389,6 +389,8 @@ TomahawkApp::registerMetaTypes()
|
|||||||
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
|
qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" );
|
||||||
|
|
||||||
qRegisterMetaType< DirLister::Mode >("DirLister::Mode");
|
qRegisterMetaType< DirLister::Mode >("DirLister::Mode");
|
||||||
|
qRegisterMetaType< Tomahawk::InfoSystem::ArtistTrackPair >("Tomahawk::InfoSystem::ArtistTrackPair");
|
||||||
|
qRegisterMetaType< QList<Tomahawk::InfoSystem::ArtistTrackPair> >("QList<Tomahawk::InfoSystem::ArtistTrackPair>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user