1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Return the chart list if we receive it after the infosystem request

This commit is contained in:
Leo Franchi
2011-10-14 16:07:14 -04:00
parent d07f191a1e
commit f4f9a148af
3 changed files with 37 additions and 17 deletions

View File

@@ -222,18 +222,20 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria,
case InfoChartCapabilities: 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; return;
} }
emit info( emit info(
requestId, requestId,
requestData, requestData,
m_result m_allChartsMap
); );
return; return;
} }
@@ -269,11 +271,12 @@ ChartsPlugin::chartTypes()
} }
/// Got types, append! /// Got types, append!
foreach(QVariant chart, res.value( "charts" ).toMap() ){ foreach ( QVariant chart, res.value( "charts" ).toMap() )
m_chartTypes.append(chart); {
m_chartTypes.append( chart );
} }
tDebug() << "Chart types we got:" << m_chartType;
/// Itunes have alot of country specified charts, /// Itunes have alot of country specified charts,
/// Get those for later use /// Get those for later use
QList<QString> geos; QList<QString> geos;
@@ -337,22 +340,24 @@ ChartsPlugin::chartTypes()
} }
} }
}else{ }
else
{
/// Billboard, and maybe others /// Billboard, and maybe others
foreach( QVariant type, m_chartTypes ) foreach ( QVariant type, m_chartTypes )
{ {
/// Append each type to its parent source /// Append each type to its parent source
/// @todo Add chartType enum /// @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" ) ); album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) );
charts.insert( "Albums", QVariant::fromValue<QList<Chart> >( album_charts ) ); charts.insert( "Albums", QVariant::fromValue<QList<Chart> >( 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" ) ); track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) );
charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) ); charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) );
@@ -367,9 +372,23 @@ ChartsPlugin::chartTypes()
chartName[0] = chartName[0].toUpper(); chartName[0] = chartName[0].toUpper();
/// Add the possible charts and its types to breadcrumb /// Add the possible charts and its types to breadcrumb
m_result.insert( chartName , QVariant::fromValue<QVariantMap>( charts ) ); m_allChartsMap.insert( chartName , QVariant::fromValue<QVariantMap>( 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();
}
} }

View File

@@ -71,9 +71,10 @@ private:
QList<Chart> m_charts; QList<Chart> m_charts;
ChartType m_chartType; ChartType m_chartType;
QVariantMap m_result; QVariantMap m_allChartsMap;
QVariantMap m_chartResult;
bool chartHasReturned; QList< QPair< uint, InfoRequestData > > m_cachedRequests;
QWeakPointer< QNetworkAccessManager > m_nam; QWeakPointer< QNetworkAccessManager > m_nam;
}; };

View File

@@ -40,7 +40,7 @@ InfoSystemCache::InfoSystemCache( QObject* parent )
, m_cacheVersion( 2 ) , m_cacheVersion( 2 )
{ {
TomahawkSettings *s = TomahawkSettings::instance(); TomahawkSettings *s = TomahawkSettings::instance();
if( s->infoSystemCacheVersion() != m_cacheVersion ) if ( s->infoSystemCacheVersion() != m_cacheVersion )
{ {
tLog() << "Cache version outdated, old:" << s->infoSystemCacheVersion() tLog() << "Cache version outdated, old:" << s->infoSystemCacheVersion()
<< "new:" << m_cacheVersion << "new:" << m_cacheVersion