mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 14:46:33 +02:00
Here comes the charts!
This commit is contained in:
@@ -46,7 +46,7 @@ ChartsPlugin::ChartsPlugin()
|
|||||||
|
|
||||||
|
|
||||||
/// Add resources here
|
/// Add resources here
|
||||||
m_chartResources << "last.fm" << "billboard" << "itunes";
|
m_chartResources << "billboard" << "itunes";
|
||||||
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
|
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.caller;
|
||||||
qDebug() << Q_FUNC_INFO << requestData.customData;
|
qDebug() << Q_FUNC_INFO << requestData.customData;
|
||||||
|
|
||||||
|
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
|
bool foundSource;
|
||||||
|
|
||||||
switch ( requestData.type )
|
switch ( requestData.type )
|
||||||
{
|
{
|
||||||
|
|
||||||
case InfoChart:
|
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 );
|
fetchChart( requestId, requestData );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -159,9 +179,7 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
|
||||||
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
Tomahawk::InfoSystem::InfoCriteriaHash criteria;
|
||||||
|
|
||||||
emit getCachedInfo( requestId, criteria, 0, requestData );
|
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
|
/// 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;
|
qDebug() << Q_FUNC_INFO << "Getting chart url" << url;
|
||||||
|
|
||||||
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( 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() ) );
|
connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) );
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case InfoChartCapabilities:
|
case InfoChartCapabilities:
|
||||||
@@ -217,25 +236,9 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
|
|
||||||
QList<Chart> album_charts;
|
QList<Chart> album_charts;
|
||||||
QList<Chart> track_charts;
|
QList<Chart> track_charts;
|
||||||
QList<Chart> artist_charts;
|
|
||||||
QVariantMap charts;
|
QVariantMap charts;
|
||||||
|
|
||||||
if( chartResource.toString() == "last.fm")
|
if( chartResource.toString() == "itunes")
|
||||||
{
|
|
||||||
|
|
||||||
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")
|
|
||||||
{
|
{
|
||||||
QVariantMap geoCharts;
|
QVariantMap geoCharts;
|
||||||
|
|
||||||
@@ -472,4 +475,3 @@ ChartsPlugin::chartReturned()
|
|||||||
}else qDebug() << "Network error";
|
}else qDebug() << "Network error";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -398,11 +398,25 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
emit info( requestId, requestData, QVariant() );
|
emit info( requestId, requestData, QVariant() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
bool foundSource;
|
||||||
|
InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >();
|
||||||
switch ( requestData.type )
|
switch ( requestData.type )
|
||||||
{
|
{
|
||||||
case InfoChart:
|
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";
|
tDebug() << "LastFmPlugin: InfoChart not in cache, fetching";
|
||||||
QMap<QString, QString> args;
|
QMap<QString, QString> args;
|
||||||
tDebug() << "LastFmPlugin: " << "args chart_id" << criteria["chart_id"];
|
tDebug() << "LastFmPlugin: " << "args chart_id" << criteria["chart_id"];
|
||||||
@@ -416,6 +430,32 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
return;
|
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:
|
case InfoArtistSimilars:
|
||||||
{
|
{
|
||||||
lastfm::Artist a( criteria["artist"] );
|
lastfm::Artist a( criteria["artist"] );
|
||||||
@@ -469,7 +509,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
|
|||||||
|
|
||||||
default:
|
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() );
|
emit info( requestId, requestData, QVariant() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -809,4 +849,3 @@ LastFmPlugin::parseTrackList( QNetworkReply* reply )
|
|||||||
|
|
||||||
return tracks;
|
return tracks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -86,14 +86,12 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
|
|||||||
InfoPluginPtr mbptr( new MusicBrainzPlugin() );
|
InfoPluginPtr mbptr( new MusicBrainzPlugin() );
|
||||||
m_plugins.append( mbptr );
|
m_plugins.append( mbptr );
|
||||||
registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() );
|
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() );
|
InfoPluginPtr lfmptr( new LastFmPlugin() );
|
||||||
m_plugins.append( lfmptr );
|
m_plugins.append( lfmptr );
|
||||||
registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() );
|
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
|
#ifdef Q_WS_MAC
|
||||||
|
@@ -121,8 +121,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
|||||||
|
|
||||||
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
|
connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) );
|
||||||
|
|
||||||
/// Itunes response is big, so maybe wait for it here?
|
QTimer::singleShot( 2000, this, SLOT( fetchData() ) );
|
||||||
QTimer::singleShot( 1000, this, SLOT( fetchData() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +142,7 @@ WhatsHotWidget::fetchData()
|
|||||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo );
|
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo );
|
||||||
|
|
||||||
requestData.type = Tomahawk::InfoSystem::InfoChartCapabilities;
|
requestData.type = Tomahawk::InfoSystem::InfoChartCapabilities;
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true );
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities";
|
tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities";
|
||||||
}
|
}
|
||||||
@@ -167,6 +166,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
|
|
||||||
tDebug( LOGVERBOSE ) << "WhatsHot: got something...";
|
tDebug( LOGVERBOSE ) << "WhatsHot: got something...";
|
||||||
QVariantMap returnedData = output.toMap();
|
QVariantMap returnedData = output.toMap();
|
||||||
|
qDebug() << "WhatsHot::" << returnedData;
|
||||||
switch ( requestData.type )
|
switch ( requestData.type )
|
||||||
{
|
{
|
||||||
case InfoSystem::InfoChartCapabilities:
|
case InfoSystem::InfoChartCapabilities:
|
||||||
@@ -182,12 +182,15 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
tDebug( LOGVERBOSE ) << "WhatsHot:: appending" << childItem->text();
|
tDebug( LOGVERBOSE ) << "WhatsHot:: appending" << childItem->text();
|
||||||
rootItem->appendRow(childItem);
|
rootItem->appendRow(childItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
|
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
|
||||||
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
|
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
|
||||||
|
|
||||||
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
|
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
|
||||||
//HACK ALERT - we want the second crumb to expand right away, so we
|
//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
|
//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;
|
break;
|
||||||
}
|
}
|
||||||
case InfoSystem::InfoChart:
|
case InfoSystem::InfoChart:
|
||||||
@@ -296,7 +299,7 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
|
|||||||
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria );
|
requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria );
|
||||||
|
|
||||||
requestData.type = Tomahawk::InfoSystem::InfoChart;
|
requestData.type = Tomahawk::InfoSystem::InfoChart;
|
||||||
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
|
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user