From 777ebd77c83421b419d1cee0897fedd220cac8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sun, 9 Oct 2011 13:28:43 +0200 Subject: [PATCH] Now fills itunes chart correctly --- .../infoplugins/generic/chartsplugin.cpp | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 69f8dee98..69ffba174 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -86,6 +86,7 @@ ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); } + } } @@ -204,6 +205,20 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, QVariantMap result; + /// Itunes have alot of country specified charts, + /// Get those for later use + QList geos; + foreach( QVariant type, m_chartTypes ) + { + + if( type.toMap().value( "geo" ).isValid() ) { + + geos.append( type.toMap().value( "geo" ).toString() ); + } + } + /// We only need a unique list + geos = QSet::fromList(geos).toList(); + foreach( QVariant chartResource, m_chartResources ) { @@ -227,17 +242,55 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } - else + else if( chartResource.toString() == "itunes") { + QVariantMap geoCharts; - foreach( QVariant type, m_chartTypes ) + foreach(QVariant country, geos) + { + QList geoAlbum_charts; + QList geoTrack_charts; + + 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; + && type.toMap().value( "geo" ).isValid() ) + { + + if( type.toMap().value( "geo" ).toString() == country.toString() ) + { + QString countryString = "Geo: " + type.toMap().value( "geo" ).toString().toUpper(); + + if( type.toMap().value( "type" ).toString() == "Album" ) + { + geoAlbum_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString() , "album" ) ); + geoCharts.insert( "Albums", QVariant::fromValue >( geoAlbum_charts ) ); + charts.insert( countryString, QVariant::fromValue( geoCharts ) ); + } + + if( type.toMap().value( "type" ).toString() == "Track" ) + { + + geoTrack_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); + geoCharts.insert( "Tracks", QVariant::fromValue >( geoTrack_charts ) ); + charts.insert( countryString, QVariant::fromValue( geoCharts ) ); + + } + } + + } + } + } + + }else{ + + foreach( QVariant type, m_chartTypes ) + { + // && type.toMap().value( "geo" ).toString() != "us" ) + // continue; /// Append each type to its parent source /// @todo Add chartType enum @@ -254,8 +307,9 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); } } - } - } + } + } + /// @note For displaying purposes, upper the first letter /// @note Remeber to lower it when fetching this! QString chartName = chartResource.toString();