1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

Fix NewReleases loading bug by using the new generic cache

This commit is contained in:
Casey Link
2012-04-13 16:21:39 -05:00
parent 0cf9a26004
commit a542797038
2 changed files with 18 additions and 5 deletions

View File

@@ -12,6 +12,7 @@
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "utils/tomahawkutils.h" #include "utils/tomahawkutils.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/tomahawkcache.h"
#include <qjson/parser.h> #include <qjson/parser.h>
#include <qjson/serializer.h> #include <qjson/serializer.h>
@@ -27,6 +28,15 @@ NewReleasesPlugin::NewReleasesPlugin()
{ {
m_nrVersion = "0"; m_nrVersion = "0";
m_supportedGetTypes << InfoNewReleaseCapabilities << InfoNewRelease; m_supportedGetTypes << InfoNewReleaseCapabilities << InfoNewRelease;
QVariantList source_qvarlist = TomahawkUtils::Cache::instance()->getData( "NewReleasesPlugin", "nr_sources" ).toList();
foreach( const QVariant & source, source_qvarlist ) {
m_nrSources.append( source.toString() );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetched source from cache" << source.toString();
}
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "total sources" << m_nrSources.size() << source_qvarlist.size();
if( m_nrSources.size() == 0 )
fetchNRSourcesList( true );
} }
NewReleasesPlugin::~NewReleasesPlugin() NewReleasesPlugin::~NewReleasesPlugin()
@@ -129,7 +139,7 @@ void NewReleasesPlugin::notInCacheSlot ( InfoStringHash criteria, InfoRequestDat
case InfoNewReleaseCapabilities: { case InfoNewReleaseCapabilities: {
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching..."; tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching...";
fetchNRSourcesList(); fetchNRSourcesList( false );
m_cachedRequests.append ( requestData ); m_cachedRequests.append ( requestData );
return; return;
@@ -143,10 +153,12 @@ void NewReleasesPlugin::notInCacheSlot ( InfoStringHash criteria, InfoRequestDat
} }
} }
void NewReleasesPlugin::fetchNRSourcesList() void NewReleasesPlugin::fetchNRSourcesList( bool fetchOnlySourcesList )
{ {
QUrl url = QUrl ( QString ( CHART_URL "newreleases" ) ); QUrl url = QUrl ( QString ( CHART_URL "newreleases" ) );
QNetworkReply* reply = TomahawkUtils::nam()->get ( QNetworkRequest ( url ) ); QNetworkReply* reply = TomahawkUtils::nam()->get ( QNetworkRequest ( url ) );
reply->setProperty( "only_source_list", fetchOnlySourcesList );
tDebug() << "fetching:" << url; tDebug() << "fetching:" << url;
connect ( reply, SIGNAL ( finished() ), SLOT ( nrSourcesList() ) ); connect ( reply, SIGNAL ( finished() ), SLOT ( nrSourcesList() ) );
@@ -173,7 +185,8 @@ void NewReleasesPlugin::nrSourcesList()
foreach ( const QVariant &source, sources ) { foreach ( const QVariant &source, sources ) {
m_nrSources << source.toString(); m_nrSources << source.toString();
} }
TomahawkUtils::Cache::instance()->putData( "NewReleasesPlugin", 172800000 /* 2 days */, "nr_sources", m_nrSources );
if( !reply->property( "only_source_list" ).toBool() )
fetchAllNRSources(); fetchAllNRSources();
} }
} }

View File

@@ -69,7 +69,7 @@ private:
* Fetch list of newlreeases sources (e.g., rovi) * Fetch list of newlreeases sources (e.g., rovi)
* Populates the m_nrSources member. * Populates the m_nrSources member.
*/ */
void fetchNRSourcesList(); void fetchNRSourcesList( bool fetchOnlySourcesList );
/** /**
* Requests newrelease list for each source in m_chartSources * Requests newrelease list for each source in m_chartSources
*/ */