1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 06:36:55 +02:00
This commit is contained in:
Hugo Lindström
2011-10-08 19:24:43 +02:00
parent 9caf9fc98f
commit 8595539dea
5 changed files with 85 additions and 80 deletions

View File

@@ -22,6 +22,7 @@
#include <QSettings> #include <QSettings>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QNetworkConfiguration> #include <QNetworkConfiguration>
#include <QNetworkReply>
#include <QDomElement> #include <QDomElement>
#include "album.h" #include "album.h"
@@ -31,10 +32,10 @@
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
#include <lastfm/ws.h> //#define CHART_URL "http://charts.tomahawk-player.org:10080/"
#define CHART_URL "http://localhost:8080/"
#define CHART_URL "http://charts.tomahawk-player.org:10080/"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <qjson/serializer.h>
using namespace Tomahawk::InfoSystem; using namespace Tomahawk::InfoSystem;
@@ -50,23 +51,9 @@ ChartsPlugin::ChartsPlugin()
: InfoPlugin() : InfoPlugin()
{ {
tDebug() << "ChartsPlugin: InfoChart fetching possible resources";
/// Add resources here /// Add resources here
m_chartResources << "billboard" m_chartResources << "last.fm" << "billboard" << "itunes";
<< "itunes";
/// Then get each chart from resource
if(!m_chartResources.isEmpty()){
foreach(QVariant resource, m_chartResources)
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) );
QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
}
}
m_supportedGetTypes << InfoChart << InfoChartCapabilities; m_supportedGetTypes << InfoChart << InfoChartCapabilities;
} }
@@ -81,9 +68,25 @@ ChartsPlugin::~ChartsPlugin()
void void
ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam )
{ {
tDebug() << "ChartsPlugin: namChangedSLot";
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if( !nam ) if( !nam )
return; return;
m_nam = QWeakPointer< QNetworkAccessManager >( nam );
/// Then get each chart from resource
if( !m_chartResources.isEmpty() && m_nam && m_chartTypes.isEmpty() ){
tDebug() << "ChartsPlugin: InfoChart fetching possible resources";
foreach(QVariant resource, m_chartResources)
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) );
QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
}
}
} }
@@ -98,6 +101,9 @@ ChartsPlugin::dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData r
void void
ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData )
{ {
qDebug() << Q_FUNC_INFO << requestData.caller;
qDebug() << Q_FUNC_INFO << requestData.customData;
switch ( requestData.type ) switch ( requestData.type )
{ {
@@ -168,13 +174,14 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info
void void
ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria, Tomahawk::InfoSystem::InfoRequestData requestData )
{ {
if ( !lastfm::nam() ) if ( !m_nam.data() )
{ {
tLog() << "Have a null QNAM, uh oh"; tLog() << "Have a null QNAM, uh oh";
emit info( requestId, requestData, QVariant() ); emit info( requestId, requestData, QVariant() );
return; return;
} }
switch ( requestData.type ) switch ( requestData.type )
{ {
case InfoChart: case InfoChart:
@@ -184,8 +191,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
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;
/// @todo: Should add ChartPlugin nam here QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) );
QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestId", requestId ); reply->setProperty( "requestId", requestId );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
@@ -197,36 +203,56 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
{ {
QVariantMap result; QVariantMap result;
foreach( QVariant chartResource, m_chartResources ) foreach( QVariant chartResource, m_chartResources )
{ {
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( !m_chartTypes.isEmpty() ) if( chartResource.toString() == "last.fm")
foreach( QVariant type, m_chartTypes ) {
{
/// Itunes supplys charts based on geo, for now, only take US charts
/// @todo: Add new breadcrumb option for country?
if( type.toMap().value( "source" ).toString() == chartResource.toString()
&& type.toMap().value( "geo" ).isValid()
&& type.toMap().value( "geo" ).toString() != "us" )
continue;
/// Append each type to its parent source track_charts.append( Chart( "chart.getTopTracks", "Top Tracks", "tracks" ) );
/// @todo Add chartType enum track_charts.append( Chart( "chart.getLovedTracks", "Loved Tracks", "tracks" ) );
if( type.toMap().value( "source" ).toString() == chartResource.toString() ) 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
{
foreach( QVariant type, m_chartTypes )
{ {
if( type.toMap().value( "type" ).toString() == "Album" ) /// Itunes supplys charts based on geo, for now, only take US charts
/// @todo: Add new breadcrumb option for country?
/*if( type.toMap().value( "source" ).toString() == chartResource.toString()
&& type.toMap().value( "geo" ).isValid()
&& type.toMap().value( "geo" ).toString() != "us" )
continue;
*/
/// Append each type to its parent source
/// @todo Add chartType enum
if( type.toMap().value( "source" ).toString() == chartResource.toString() )
{ {
album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); if( type.toMap().value( "type" ).toString() == "Album" )
charts.insert( "Albums", QVariant::fromValue<QList<Chart> >( album_charts ) ); {
} album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) );
if( type.toMap().value( "type" ).toString() == "Track" ) charts.insert( "Albums", QVariant::fromValue<QList<Chart> >( album_charts ) );
{ }
track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); if( type.toMap().value( "type" ).toString() == "Track" )
charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) ); {
track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) );
charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) );
}
} }
} }
} }
@@ -255,6 +281,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
} }
} }
void void
ChartsPlugin::chartTypes() ChartsPlugin::chartTypes()
{ {
@@ -274,10 +301,12 @@ ChartsPlugin::chartTypes()
return; return;
} }
/// Got types, append!
foreach(QVariant chart, res.value( "charts" ).toMap() )
m_chartTypes.append(chart);
/// Got types, append!
foreach(QVariant chart, res.value( "charts" ).toMap() ){
m_chartTypes.append(chart);
}
} }
} }
@@ -335,8 +364,8 @@ ChartsPlugin::chartReturned()
if( chartType() == Album ) if( chartType() == Album )
{ {
/** HACK, billboard chart returns wrong typename **/ /** HACK, billboard chart returns wrong typename **/
if( res.value( "source" ).toString() == "billboard" ) //if( res.value( "source" ).toString() == "billboard" )
album = chartMap.value( "track" ).toString(); // album = chartMap.value( "track" ).toString();
if ( album.isEmpty() && artist.isEmpty() ) // don't have enough... if ( album.isEmpty() && artist.isEmpty() ) // don't have enough...
{ {

View File

@@ -21,7 +21,7 @@
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include "infosystem/infosystemworker.h" #include "infosystem/infosystemworker.h"
#include <QNetworkReply>
#include <QObject> #include <QObject>
class QNetworkReply; class QNetworkReply;
@@ -71,6 +71,9 @@ private:
QList<Chart> m_charts; QList<Chart> m_charts;
ChartType m_chartType; ChartType m_chartType;
QVariantMap m_chartResult;
bool chartHasReturned;
QWeakPointer< QNetworkAccessManager > m_nam;
}; };
} }

View File

@@ -416,32 +416,6 @@ 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"] );
@@ -495,7 +469,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
default: default:
{ {
tLog() << "Couldn't figure out what to do with this type of request after cache miss"; tLog() << Q_FUNC_INFO << "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;
} }

View File

@@ -87,11 +87,9 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac
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 );
InfoPluginPtr chartsptr( new ChartsPlugin() ); registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() );
m_plugins.append( chartsptr );
registerInfoTypes( chartsptr, chartsptr.data()->supportedGetTypes(), chartsptr.data()->supportedPushTypes() );
InfoPluginPtr lfmptr( new LastFmPlugin() ); InfoPluginPtr lfmptr( new LastFmPlugin() );
m_plugins.append( lfmptr ); m_plugins.append( lfmptr );

View File

@@ -208,12 +208,13 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
} }
else if( type == "albums" ) else if( type == "albums" )
{ {
/// @todo: Fill the empty albums with resolved ones.
setLeftViewAlbums(); setLeftViewAlbums();
m_albumsModel->clear(); m_albumsModel->clear();
QList<album_ptr> al; QList<album_ptr> al;
const QList<Tomahawk::InfoSystem::ArtistAlbumPair> albums = returnedData["albums"].value<QList<Tomahawk::InfoSystem::ArtistAlbumPair> >(); const QList<Tomahawk::InfoSystem::ArtistAlbumPair> albums = returnedData["albums"].value<QList<Tomahawk::InfoSystem::ArtistAlbumPair> >();
tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size();
foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums )
{ {
qDebug() << "Getting album" << album.album << "By" << album.artist; qDebug() << "Getting album" << album.album << "By" << album.artist;