1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

Here comes the charts!

This commit is contained in:
Hugo Lindström 2011-10-12 22:09:26 +02:00
parent 248d26fe69
commit 3b1268bbfd
4 changed files with 77 additions and 35 deletions

View File

@ -46,7 +46,7 @@ ChartsPlugin::ChartsPlugin()
/// Add resources here
m_chartResources << "last.fm" << "billboard" << "itunes";
m_chartResources << "billboard" << "itunes";
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
}
@ -98,10 +98,30 @@ ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData req
qDebug() << Q_FUNC_INFO << requestData.caller;
qDebug() << Q_FUNC_INFO << requestData.customData;
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
bool foundSource;
switch ( requestData.type )
{
case InfoChart:
/// We need something to check if the request is actually ment to go to this plugin
if ( !hash.contains( "chart_source" ) )
{
dataError( requestId, requestData );
break;
}else
{
foreach(QVariant resource, m_chartResources)
if(resource.toString() == hash["chart_source"])
foundSource = true;
if(!foundSource){
dataError( requestId, requestData );
break;
}
}
fetchChart( requestId, requestData );
break;
@ -159,9 +179,7 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info
return;
}
//InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
emit getCachedInfo( requestId, criteria, 0, requestData );
}
@ -182,7 +200,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
{
/// Fetch the chart, we need source and id
QUrl url = QUrl( QString( CHART_URL "/source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) );
QUrl url = QUrl( QString( CHART_URL "source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) );
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
@ -191,6 +209,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
return;
}
case InfoChartCapabilities:
@ -217,25 +236,9 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
QList<Chart> album_charts;
QList<Chart> track_charts;
QList<Chart> artist_charts;
QVariantMap charts;
if( chartResource.toString() == "last.fm")
{
track_charts.append( Chart( "chart.getTopTracks", "Top Tracks", "tracks" ) );
track_charts.append( Chart( "chart.getLovedTracks", "Loved Tracks", "tracks" ) );
track_charts.append( Chart( "chart.getHypedTracks", "Hyped Tracks", "tracks" ) );
artist_charts.append( Chart( "chart.getTopArtists", "Top Artists", "artists" ) );
artist_charts.append( Chart( "chart.getHypedArtists", "Hyped Artists", "artists" ) );
charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) );
charts.insert( "Artists", QVariant::fromValue<QList<Chart> >( artist_charts ) );
}
else if( chartResource.toString() == "itunes")
if( chartResource.toString() == "itunes")
{
QVariantMap geoCharts;
@ -472,4 +475,3 @@ ChartsPlugin::chartReturned()
}else qDebug() << "Network error";
}

View File

@ -398,11 +398,25 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
emit info( requestId, requestData, QVariant() );
return;
}
bool foundSource;
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
switch ( requestData.type )
{
case InfoChart:
{
/// We need something to check if the request is actually ment to go to this plugin
if ( !hash.contains( "chart_source" ) )
{
dataError( requestId, requestData );
break;
}else
{
if("last.fm" != hash["chart_source"]){
dataError( requestId, requestData );
break;
}
}
tDebug() << "LastFmPlugin: InfoChart not in cache, fetching";
QMap<QString, QString> args;
tDebug() << "LastFmPlugin: " << "args chart_id" << criteria["chart_id"];
@ -416,6 +430,32 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
return;
}
case InfoChartCapabilities:
{
QList<Chart> track_charts;
track_charts.append( Chart( "chart.getTopTracks", "Top Tracks", "tracks" ) );
track_charts.append( Chart( "chart.getLovedTracks", "Loved Tracks", "tracks" ) );
track_charts.append( Chart( "chart.getHypedTracks", "Hyped Tracks", "tracks" ) );
QList<Chart> artist_charts;
artist_charts.append( Chart( "chart.getTopArtists", "Top Artists", "artists" ) );
artist_charts.append( Chart( "chart.getHypedArtists", "Hyped Artists", "artists" ) );
QVariantMap charts;
charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) );
charts.insert( "Artists", QVariant::fromValue<QList<Chart> >( artist_charts ) );
QVariantMap result;
result.insert( "Last.fm", QVariant::fromValue<QVariantMap>( charts ) );
emit info(
requestId,
requestData,
result
);
return;
}
case InfoArtistSimilars:
{
lastfm::Artist a( criteria["artist"] );
@ -469,7 +509,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
default:
{
tLog() << Q_FUNC_INFO << "Couldn't figure out what to do with this type of request after cache miss";
tLog() << "Couldn't figure out what to do with this type of request after cache miss";
emit info( requestId, requestData, QVariant() );
return;
}
@ -809,4 +849,3 @@ LastFmPlugin::parseTrackList( QNetworkReply* reply )
return tracks;
}

View File

@ -86,14 +86,12 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
InfoPluginPtr mbptr( new MusicBrainzPlugin() );
m_plugins.append( mbptr );
registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() );
InfoPluginPtr sptr( new ChartsPlugin() );
m_plugins.append( sptr );
registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() );
InfoPluginPtr lfmptr( new LastFmPlugin() );
m_plugins.append( lfmptr );
registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() );
InfoPluginPtr sptr( new ChartsPlugin() );
m_plugins.append( sptr );
registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() );
#ifdef Q_WS_MAC

View File

@ -121,8 +121,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
/// Itunes response is big, so maybe wait for it here?
QTimer::singleShot( 1000, this, SLOT( fetchData() ) );
QTimer::singleShot( 2000, this, SLOT( fetchData() ) );
}
@ -143,7 +142,7 @@ WhatsHotWidget::fetchData()
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo );
requestData.type = Tomahawk::InfoSystem::InfoChartCapabilities;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true );
tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities";
}
@ -167,6 +166,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
tDebug( LOGVERBOSE ) << "WhatsHot: got something...";
QVariantMap returnedData = output.toMap();
qDebug() << "WhatsHot::" << returnedData;
switch ( requestData.type )
{
case InfoSystem::InfoChartCapabilities:
@ -182,12 +182,15 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
tDebug( LOGVERBOSE ) << "WhatsHot:: appending" << childItem->text();
rootItem->appendRow(childItem);
}
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
//HACK ALERT - we want the second crumb to expand right away, so we
//force it here. We should find a more elegant want to do this
ui->breadCrumbLeft->currentChangedTriggered(m_crumbModelLeft->index(0,0).child(0,0).child(0,0));
/// @note: this expands the billboard chart, as its fast loading and intersting album view ;) i think
ui->breadCrumbLeft->currentChangedTriggered(m_crumbModelLeft->index(1,0).child(0,0).child(0,0));
break;
}
case InfoSystem::InfoChart:
@ -296,7 +299,7 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria );
requestData.type = Tomahawk::InfoSystem::InfoChart;
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true );
}