diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 640b8e492..fb4ef3705 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -152,8 +152,8 @@ ChartsPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requ } Tomahawk::InfoSystem::InfoStringHash criteria; - criteria[ "InfoChartCapabilities" ] = "all"; - emit getCachedInfo( criteria, 86400000, requestData ); + criteria[ "InfoChartCapabilities" ] = "chartsplugin"; + emit getCachedInfo( criteria, 604800000, requestData ); } void @@ -181,6 +181,9 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy { tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching..."; + // we never need to re-fetch + if ( !m_allChartsMap.isEmpty() ) + return; /// Then get each chart from resource @@ -418,8 +421,8 @@ ChartsPlugin::chartTypes() emit info( request, m_allChartsMap ); // update cache Tomahawk::InfoSystem::InfoStringHash criteria; - criteria[ "InfoChartCapabilities" ] = "all"; - emit updateCache( criteria, 86400000, request.type, m_allChartsMap ); + criteria[ "InfoChartCapabilities" ] = "chartsplugin"; + emit updateCache( criteria, 604800000, request.type, m_allChartsMap ); } m_cachedRequests.clear(); } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp index a1df2b20c..9eab12814 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.cpp @@ -23,11 +23,9 @@ #include <QCryptographicHash> #include <QNetworkConfiguration> #include <QNetworkReply> -#include <QDomElement> #include "album.h" #include "typedefs.h" -#include "audio/audioengine.h" #include "tomahawksettings.h" #include "utils/tomahawkutils.h" #include "utils/logger.h" @@ -140,16 +138,6 @@ hypemPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) } } - -void -hypemPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) -{ - Q_UNUSED( caller ) - Q_UNUSED( type) - Q_UNUSED( input ) -} - - void hypemPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -173,8 +161,9 @@ hypemPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) /// Set the criterias for current chart criteria["chart_id"] = hash["chart_id"]; criteria["chart_source"] = hash["chart_source"]; - - emit getCachedInfo( criteria, 0, requestData ); + /// @todo + /// set cache time based on wether requested type is 3day, lastweek or recent. + emit getCachedInfo( criteria, 86400000, requestData ); } void @@ -198,7 +187,7 @@ hypemPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSys case InfoChart: { /// Fetch the chart, we need source and id - + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChart not in cache! Fetching..."; QUrl url = QUrl( QString( HYPEM_URL "%1/%2" ).arg( criteria["chart_id"].toLower() ).arg(HYPEM_END_URL) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; @@ -212,6 +201,7 @@ hypemPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSys case InfoChartCapabilities: { + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching..."; if ( m_chartsFetchJobs > 0 ) { qDebug() << Q_FUNC_INFO << "InfoChartCapabilities still fetching!"; @@ -390,7 +380,14 @@ hypemPlugin::chartReturned() emit info( requestData, returnedData ); - // TODO update cache + // update cache + Tomahawk::InfoSystem::InfoStringHash criteria; + Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); + criteria[ "chart_id" ] = origData[ "chart_id" ]; + criteria[ "chart_source" ] = origData[ "chart_source" ]; + /// @todo + /// set cache time based on wether requested type is 3day, lastweek or recent. + emit updateCache( criteria, 86400000, requestData.type, returnedData ); } else qDebug() << "Network error in fetching chart:" << reply->url().toString(); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h index cbdfb000d..70a3b7d5e 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/hypemPlugin.h @@ -57,8 +57,13 @@ public slots: protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); + virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) + { + Q_UNUSED( caller ) + Q_UNUSED( type) + Q_UNUSED( input ) + } - virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ); private: void fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp index 3ce6cdb3a..8af09946b 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.cpp @@ -23,7 +23,6 @@ #include <QCryptographicHash> #include <QNetworkConfiguration> #include <QNetworkReply> -#include <QDomElement> #include "album.h" #include "typedefs.h" @@ -47,19 +46,6 @@ SpotifyPlugin::SpotifyPlugin() m_supportedGetTypes << InfoChart << InfoChartCapabilities; - // we never need to re-fetch - if ( !m_allChartsMap.isEmpty() ) - return; - - /// We need to fetch possible types before they are asked for - tDebug() << "SpotifyPlugin: InfoChart fetching possible resources"; - - QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) ); - QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); - tDebug() << Q_FUNC_INFO << "fetching:" << url; - connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); - m_chartsFetchJobs++; - } @@ -107,14 +93,6 @@ SpotifyPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) } -void -SpotifyPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) -{ - Q_UNUSED( caller ) - Q_UNUSED( type) - Q_UNUSED( input ) -} - void SpotifyPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) { @@ -123,17 +101,22 @@ SpotifyPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) dataError( requestData ); return; } + InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); Tomahawk::InfoSystem::InfoStringHash criteria; - if ( !hash.contains( "chart_id" ) ) + /// Each request needs to contain both a id and source + if ( !hash.contains( "chart_id" ) && !hash.contains( "chart_source" ) ) { + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required params!"; dataError( requestData ); return; - } else { - criteria["chart_id"] = hash["chart_id"]; - } - emit getCachedInfo( criteria, 604800000 /* Expire chart cache in 1 week */, requestData ); + } + /// Set the criterias for current chart + criteria["chart_id"] = hash["chart_id"]; + criteria["chart_source"] = hash["chart_source"]; + + emit getCachedInfo( criteria, 86400000 /* Expire chart cache in 1 day */, requestData ); } void SpotifyPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requestData ) @@ -145,7 +128,8 @@ SpotifyPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData req } Tomahawk::InfoSystem::InfoStringHash criteria; - emit getCachedInfo( criteria, 0, requestData ); + criteria[ "InfoChartCapabilities" ] = "spotifyplugin"; + emit getCachedInfo( criteria, 604800000, requestData ); } void @@ -157,6 +141,7 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To case InfoChart: { /// Fetch the chart, we need source and id + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChart not in cache! Fetching..."; QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/%1/" ).arg( criteria["chart_id"] ) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; @@ -169,6 +154,21 @@ SpotifyPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, To } case InfoChartCapabilities: { + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching..."; + + // we never need to re-fetch + if ( !m_allChartsMap.isEmpty() ) + return; + + /// We need to fetch possible types before they are asked for + tDebug() << "SpotifyPlugin: InfoChart fetching possible resources"; + + QUrl url = QUrl( QString( SPOTIFY_API_URL "toplist/charts" ) ); + QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); + tDebug() << Q_FUNC_INFO << "fetching:" << url; + connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); + m_chartsFetchJobs++; + if ( m_chartsFetchJobs > 0 ) { qDebug() << Q_FUNC_INFO << "InfoChartCapabilities still fetching!"; @@ -275,6 +275,9 @@ SpotifyPlugin::chartTypes() foreach ( InfoRequestData request, m_cachedRequests ) { emit info( request, m_allChartsMap ); + Tomahawk::InfoSystem::InfoStringHash criteria; + criteria[ "InfoChartCapabilities" ] = "spotifyplugin"; + emit updateCache( criteria,604800000, request.type, m_allChartsMap ); } m_cachedRequests.clear(); } @@ -379,9 +382,14 @@ SpotifyPlugin::chartReturned() Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); - emit info( requestData, returnedData ); + // update cache + Tomahawk::InfoSystem::InfoStringHash criteria; + Tomahawk::InfoSystem::InfoStringHash origData = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); + criteria[ "chart_id" ] = origData[ "chart_id" ]; + criteria[ "chart_source" ] = origData[ "chart_source" ]; + emit updateCache( criteria, 86400000, requestData.type, returnedData ); } else qDebug() << "Network error in fetching chart:" << reply->url().toString(); diff --git a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h index e691d5aef..0f690685b 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/spotifyPlugin.h @@ -57,7 +57,12 @@ public slots: protected slots: virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); - virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ); + virtual void pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input ) + { + Q_UNUSED( caller ) + Q_UNUSED( type) + Q_UNUSED( input ) + } private: void fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData );