From 0cf9a26004443045014047b334b122746e6bda6c Mon Sep 17 00:00:00 2001 From: Casey Link Date: Fri, 13 Apr 2012 16:15:44 -0500 Subject: [PATCH] If we can't retrieve source list from cache, re-fetch. --- .../infosystem/infoplugins/generic/chartsplugin.cpp | 11 ++++++++--- .../infosystem/infoplugins/generic/chartsplugin.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 855b7071a..56e005997 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -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 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 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(); } } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 8ac140854..352ac2a3a 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -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 */