diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 287d09ee3..cdd45dc8b 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -222,18 +222,20 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, case InfoChartCapabilities: { - if( m_result.isEmpty() ){ + if ( m_allChartsMap.isEmpty() ) + { - qDebug() << Q_FUNC_INFO << "InfoChartCapabilities is empty!"; + qDebug() << Q_FUNC_INFO << "InfoChartCapabilities is empty, probably still fetching!"; + m_cachedRequests.append( QPair< uint, InfoRequestData >( requestId, requestData ) );; - dataError( requestId, requestData ); +// dataError( requestId, requestData ); return; } emit info( requestId, requestData, - m_result + m_allChartsMap ); return; } @@ -269,11 +271,12 @@ ChartsPlugin::chartTypes() } /// Got types, append! - foreach(QVariant chart, res.value( "charts" ).toMap() ){ - m_chartTypes.append(chart); - + foreach ( QVariant chart, res.value( "charts" ).toMap() ) + { + m_chartTypes.append( chart ); } + tDebug() << "Chart types we got:" << m_chartType; /// Itunes have alot of country specified charts, /// Get those for later use QList geos; @@ -337,22 +340,24 @@ ChartsPlugin::chartTypes() } } - }else{ + } + else + { /// Billboard, and maybe others - foreach( QVariant type, m_chartTypes ) + 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( "source" ).toString() == chartResource.toString() ) { - if( type.toMap().value( "type" ).toString() == "Album" ) + 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" ) + 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 ) ); @@ -367,9 +372,23 @@ ChartsPlugin::chartTypes() chartName[0] = chartName[0].toUpper(); /// Add the possible charts and its types to breadcrumb - m_result.insert( chartName , QVariant::fromValue( charts ) ); + m_allChartsMap.insert( chartName , QVariant::fromValue( charts ) ); } } + else + { + tLog() << "Error fetching charts:" << reply->errorString(); + } + + if ( !m_cachedRequests.isEmpty() ) + { + QPair< uint, InfoRequestData > request; + foreach ( request, m_cachedRequests ) + { + emit info( request.first, request.second, m_allChartsMap ); + } + m_cachedRequests.clear(); + } } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 16f5e3668..7205eac0f 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -71,9 +71,10 @@ private: QList m_charts; ChartType m_chartType; - QVariantMap m_result; - QVariantMap m_chartResult; - bool chartHasReturned; + QVariantMap m_allChartsMap; + + QList< QPair< uint, InfoRequestData > > m_cachedRequests; + QWeakPointer< QNetworkAccessManager > m_nam; }; diff --git a/src/libtomahawk/infosystem/infosystemcache.cpp b/src/libtomahawk/infosystem/infosystemcache.cpp index 300ad7b78..8b1099b50 100644 --- a/src/libtomahawk/infosystem/infosystemcache.cpp +++ b/src/libtomahawk/infosystem/infosystemcache.cpp @@ -40,7 +40,7 @@ InfoSystemCache::InfoSystemCache( QObject* parent ) , m_cacheVersion( 2 ) { TomahawkSettings *s = TomahawkSettings::instance(); - if( s->infoSystemCacheVersion() != m_cacheVersion ) + if ( s->infoSystemCacheVersion() != m_cacheVersion ) { tLog() << "Cache version outdated, old:" << s->infoSystemCacheVersion() << "new:" << m_cacheVersion