1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 09:19:41 +01:00

If we can't retrieve source list from cache, re-fetch.

This commit is contained in:
Casey Link 2012-04-13 16:15:44 -05:00
parent a6754e7467
commit 0cf9a26004
2 changed files with 9 additions and 4 deletions

View File

@ -56,6 +56,8 @@ ChartsPlugin::ChartsPlugin()
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "total sources" << m_chartResources.size() << source_qvarlist.size();
if( m_chartResources.size() == 0 )
fetchChartSourcesList( true );
m_supportedGetTypes << InfoChart << InfoChartCapabilities;
}
@ -189,7 +191,7 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy
case InfoChartCapabilities:
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching...";
fetchChartSourcesList();
fetchChartSourcesList( false );
m_cachedRequests.append( requestData );
return;
@ -205,10 +207,12 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy
}
void
ChartsPlugin::fetchChartSourcesList()
ChartsPlugin::fetchChartSourcesList( bool fetchOnlySourceList )
{
QUrl url = QUrl( QString( CHART_URL "charts" ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "only_source_list", fetchOnlySourceList );
tDebug() << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartSourcesList() ) );
@ -241,7 +245,8 @@ ChartsPlugin::chartSourcesList()
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "storing sources in cache" << m_chartResources;
TomahawkUtils::Cache::instance()->putData( "ChartsPlugin", 172800000 /* 2 days */, "chart_sources", m_chartResources );
fetchAllChartSources();
if( !reply->property("only_source_list" ).toBool() )
fetchAllChartSources();
}
}

View File

@ -81,7 +81,7 @@ private:
* Fetch list of chart sources (e.g., itunes, billboard)
* Populates the m_chartResources member.
*/
void fetchChartSourcesList();
void fetchChartSourcesList( bool fetchOnlySourceList );
/**
* Requests charts list for each chart source in m_chartResources
*/