diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 025308680..9254fa0fa 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "album.h" @@ -31,10 +32,10 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" -#include - -#define CHART_URL "http://charts.tomahawk-player.org:10080/" +//#define CHART_URL "http://charts.tomahawk-player.org:10080/" +#define CHART_URL "http://localhost:8080/" #include +#include using namespace Tomahawk::InfoSystem; @@ -50,23 +51,9 @@ ChartsPlugin::ChartsPlugin() : InfoPlugin() { - tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; /// Add resources here - m_chartResources << "billboard" - << "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_chartResources << "last.fm" << "billboard" << "itunes"; m_supportedGetTypes << InfoChart << InfoChartCapabilities; } @@ -81,9 +68,25 @@ ChartsPlugin::~ChartsPlugin() void ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) { + tDebug() << "ChartsPlugin: namChangedSLot"; + qDebug() << Q_FUNC_INFO; if( !nam ) 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 ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) { + qDebug() << Q_FUNC_INFO << requestData.caller; + qDebug() << Q_FUNC_INFO << requestData.customData; + switch ( requestData.type ) { @@ -168,13 +174,14 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info void ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { - if ( !lastfm::nam() ) + if ( !m_nam.data() ) { tLog() << "Have a null QNAM, uh oh"; emit info( requestId, requestData, QVariant() ); return; } + switch ( requestData.type ) { case InfoChart: @@ -184,8 +191,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, 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; - /// @todo: Should add ChartPlugin nam here - QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); reply->setProperty( "requestId", requestId ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); @@ -197,36 +203,56 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, { QVariantMap result; + foreach( QVariant chartResource, m_chartResources ) { QList album_charts; QList track_charts; + QList artist_charts; QVariantMap charts; - if( !m_chartTypes.isEmpty() ) - 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; + if( chartResource.toString() == "last.fm") + { - /// Append each type to its parent source - /// @todo Add chartType enum - if( type.toMap().value( "source" ).toString() == chartResource.toString() ) + 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 >( track_charts ) ); + charts.insert( "Artists", QVariant::fromValue >( 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" ) ); - charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); - } - if( type.toMap().value( "type" ).toString() == "Track" ) - { - track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); - charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + if( type.toMap().value( "type" ).toString() == "Album" ) + { + album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); + charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); + } + if( type.toMap().value( "type" ).toString() == "Track" ) + { + track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); + charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + } } } } @@ -255,6 +281,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } } + void ChartsPlugin::chartTypes() { @@ -274,10 +301,12 @@ ChartsPlugin::chartTypes() 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 ) { /** HACK, billboard chart returns wrong typename **/ - if( res.value( "source" ).toString() == "billboard" ) - album = chartMap.value( "track" ).toString(); + //if( res.value( "source" ).toString() == "billboard" ) + // album = chartMap.value( "track" ).toString(); if ( album.isEmpty() && artist.isEmpty() ) // don't have enough... { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 33f378744..32d0f2bd2 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -21,7 +21,7 @@ #include "infosystem/infosystem.h" #include "infosystem/infosystemworker.h" - +#include #include class QNetworkReply; @@ -71,6 +71,9 @@ private: QList m_charts; ChartType m_chartType; + QVariantMap m_chartResult; + bool chartHasReturned; + QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index 55d08df0a..aa47e9e6c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -416,32 +416,6 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, return; } - case InfoChartCapabilities: - { - QList 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 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 >( track_charts ) ); - charts.insert( "Artists", QVariant::fromValue >( artist_charts ) ); - - QVariantMap result; - result.insert( "Last.fm", QVariant::fromValue( charts ) ); - - emit info( - requestId, - requestData, - result - ); - return; - } - case InfoArtistSimilars: { lastfm::Artist a( criteria["artist"] ); @@ -495,7 +469,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, 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() ); return; } diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 0df655dfa..872d4f9b9 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -87,11 +87,9 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac m_plugins.append( mbptr ); registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() ); - - - InfoPluginPtr chartsptr( new ChartsPlugin() ); - m_plugins.append( chartsptr ); - registerInfoTypes( chartsptr, chartsptr.data()->supportedGetTypes(), chartsptr.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 ); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 4960240e1..23ba6ef3a 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -208,12 +208,13 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } else if( type == "albums" ) { + + /// @todo: Fill the empty albums with resolved ones. setLeftViewAlbums(); m_albumsModel->clear(); QList al; const QList albums = returnedData["albums"].value >(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); - foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { qDebug() << "Getting album" << album.album << "By" << album.artist;