diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index be4416a96..287d09ee3 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -70,9 +70,11 @@ ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) 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"; + /// We need to fetch them before they are asked for + 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() ) ); @@ -220,108 +222,18 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, case InfoChartCapabilities: { + if( m_result.isEmpty() ){ - QVariantMap result; + qDebug() << Q_FUNC_INFO << "InfoChartCapabilities is empty!"; - /// 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() ); - } + dataError( requestId, requestData ); + return; } - /// We only need a unique list - geos = QSet::fromList(geos).toList(); - foreach( QVariant chartResource, m_chartResources ) - { - - QList album_charts; - QList track_charts; - QVariantMap charts; - - if( chartResource.toString() == "itunes") - { - QVariantMap geoCharts; - - foreach(QVariant country, geos) - { - QList geoAlbum_charts; - QList geoTrack_charts; - - foreach( QVariant type, m_chartTypes ) - { - - /// Itunes supplys charts based on geo, create breadcrumb for each of them - - if( type.toMap().value( "source" ).toString() == chartResource.toString() - && 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{ - /// Billboard, and maybe others - foreach( QVariant type, m_chartTypes ) - { - - /// Append each type to its parent source - /// @todo Add chartType enum - if( type.toMap().value( "source" ).toString() == chartResource.toString() ) - { - 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 ) ); - } - } - } - } - - /// @note For displaying purposes, upper the first letter - /// @note Remeber to lower it when fetching this! - QString chartName = chartResource.toString(); - chartName[0] = chartName[0].toUpper(); - - /// Add the possible charts and its types to breadcrumb - result.insert( chartName , QVariant::fromValue( charts ) ); - } emit info( requestId, requestData, - result + m_result ); return; } @@ -361,6 +273,102 @@ ChartsPlugin::chartTypes() m_chartTypes.append(chart); } + + /// 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 ) + { + + QList album_charts; + QList track_charts; + QVariantMap charts; + + if( chartResource.toString() == "itunes") + { + QVariantMap geoCharts; + + foreach(QVariant country, geos) + { + QList geoAlbum_charts; + QList geoTrack_charts; + + foreach( QVariant type, m_chartTypes ) + { + + /// Itunes supplys charts based on geo, create breadcrumb for each of them + + if( type.toMap().value( "source" ).toString() == chartResource.toString() + && 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{ + /// Billboard, and maybe others + foreach( QVariant type, m_chartTypes ) + { + + /// Append each type to its parent source + /// @todo Add chartType enum + if( type.toMap().value( "source" ).toString() == chartResource.toString() ) + { + 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 ) ); + } + } + } + } + + /// @note For displaying purposes, upper the first letter + /// @note Remeber to lower it when fetching this! + QString chartName = chartResource.toString(); + chartName[0] = chartName[0].toUpper(); + + /// Add the possible charts and its types to breadcrumb + m_result.insert( chartName , QVariant::fromValue( charts ) ); + } } } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 32d0f2bd2..16f5e3668 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -71,6 +71,7 @@ private: QList m_charts; ChartType m_chartType; + QVariantMap m_result; QVariantMap m_chartResult; bool chartHasReturned; QWeakPointer< QNetworkAccessManager > m_nam;