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

Adding cache for charts

This commit is contained in:
Hugo Lindström
2011-11-16 12:26:02 +01:00
parent e406fb90a9
commit 8731665257
4 changed files with 123 additions and 100 deletions

View File

@@ -19,12 +19,10 @@
#include "chartsplugin.h" #include "chartsplugin.h"
#include <QDir> #include <QtCore/QDir>
#include <QSettings> #include <QtCore/QSettings>
#include <QCryptographicHash> #include <QtNetwork/QNetworkConfiguration>
#include <QNetworkConfiguration> #include <QtNetwork/QNetworkReply>
#include <QNetworkReply>
#include <QDomElement>
#include "album.h" #include "album.h"
#include "chartsplugin_data_p.h" #include "chartsplugin_data_p.h"
@@ -50,27 +48,12 @@ ChartsPlugin::ChartsPlugin()
m_chartResources << "billboard" << "itunes" << "rdio" << "wearehunted" << "ex.fm"; m_chartResources << "billboard" << "itunes" << "rdio" << "wearehunted" << "ex.fm";
m_supportedGetTypes << InfoChart << InfoChartCapabilities; m_supportedGetTypes << InfoChart << InfoChartCapabilities;
/// Then get each chart from resource
/// We want to prepopulate the breadcrumb to fetch them before they are asked for
if ( !m_chartResources.isEmpty() && m_allChartsMap.isEmpty() )
{
tDebug() << "ChartsPlugin: InfoChart fetching possible resources";
foreach ( QVariant resource, m_chartResources )
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
tDebug() << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
m_chartsFetchJobs++;
}
}
} }
ChartsPlugin::~ChartsPlugin() ChartsPlugin::~ChartsPlugin()
{ {
qDebug() << Q_FUNC_INFO; tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
} }
@@ -85,27 +68,27 @@ ChartsPlugin::dataError( Tomahawk::InfoSystem::InfoRequestData requestData )
void void
ChartsPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ) ChartsPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
{ {
qDebug() << Q_FUNC_INFO << requestData.caller; //qDebug() << Q_FUNC_INFO << requestData.caller;
qDebug() << Q_FUNC_INFO << requestData.customData; //qDebug() << Q_FUNC_INFO << requestData.customData;
InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); InfoStringHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
bool foundSource = false; bool foundSource = false;
switch ( requestData.type ) switch ( requestData.type )
{ {
case InfoChart: case InfoChart:
/// We need something to check if the request is actually ment to go to this plugin /// We need something to check if the request is actually ment to go to this plugin
if ( !hash.contains( "chart_source" ) ) if ( !hash.contains( "chart_source" ) )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required param!";
dataError( requestData ); dataError( requestData );
break; break;
} }
else else
{ {
foreach( QVariant resource, m_chartResources ) foreach( QString resource, m_chartResources )
{ {
if( resource.toString() == hash["chart_source"] ) if( resource == hash["chart_source"] )
{ {
foundSource = true; foundSource = true;
} }
@@ -130,15 +113,6 @@ ChartsPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
} }
void
ChartsPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoType type, const QVariant input )
{
Q_UNUSED( caller )
Q_UNUSED( type)
Q_UNUSED( input )
}
void void
ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ) ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData )
{ {
@@ -155,6 +129,7 @@ ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData )
/// Each request needs to contain both a id and source /// Each request needs to contain both a id and source
if ( !hash.contains( "chart_id" ) && !hash.contains( "chart_source" ) ) if ( !hash.contains( "chart_id" ) && !hash.contains( "chart_source" ) )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Hash did not contain required params!";
dataError( requestData ); dataError( requestData );
return; return;
@@ -163,7 +138,7 @@ ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData )
criteria["chart_id"] = hash["chart_id"]; criteria["chart_id"] = hash["chart_id"];
criteria["chart_source"] = hash["chart_source"]; criteria["chart_source"] = hash["chart_source"];
emit getCachedInfo( criteria, 0, requestData ); emit getCachedInfo( criteria, 86400000, requestData );
} }
void void
@@ -171,13 +146,14 @@ ChartsPlugin::fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requ
{ {
if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() ) if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoStringHash >() )
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Could not convert requestData to InfoStringHash!";
dataError( requestData ); dataError( requestData );
return; return;
} }
Tomahawk::InfoSystem::InfoStringHash criteria; Tomahawk::InfoSystem::InfoStringHash criteria;
criteria[ "InfoChartCapabilities" ] = "all";
emit getCachedInfo( criteria, 0, requestData ); emit getCachedInfo( criteria, 86400000, requestData );
} }
void void
@@ -187,9 +163,11 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy
{ {
case InfoChart: case InfoChart:
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChart not in cache! Fetching...";
/// Fetch the chart, we need source and id /// Fetch the chart, we need source and id
QUrl url = QUrl( QString( CHART_URL "source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) ); QUrl url = QUrl( QString( CHART_URL "source/%1/chart/%2" ).arg( criteria["chart_source"] ).arg( criteria["chart_id"] ) );
qDebug() << Q_FUNC_INFO << "Getting chart url" << url; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Getting chart url" << url;
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) ); QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
@@ -201,9 +179,30 @@ ChartsPlugin::notInCacheSlot( QHash<QString, QString> criteria, Tomahawk::InfoSy
case InfoChartCapabilities: case InfoChartCapabilities:
{ {
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching...";
/// Then get each chart from resource
if ( !m_chartResources.isEmpty() && m_allChartsMap.isEmpty() )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChart fetching possible resources";
foreach ( QString resource, m_chartResources )
{
QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg( resource ) );
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
reply->setProperty( "chart_resource", resource);
tDebug() << "fetching:" << url;
connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) );
m_chartsFetchJobs++;
}
}
if ( m_chartsFetchJobs > 0 ) if ( m_chartsFetchJobs > 0 )
{ {
qDebug() << Q_FUNC_INFO << "InfoChartCapabilities still fetching!"; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities still fetching!";
m_cachedRequests.append( requestData ); m_cachedRequests.append( requestData );
return; return;
} }
@@ -226,9 +225,10 @@ void
ChartsPlugin::chartTypes() ChartsPlugin::chartTypes()
{ {
/// Get possible chart type for specificChartsPlugin: InfoChart types returned chart source /// Get possible chart type for specificChartsPlugin: InfoChart types returned chart source
tDebug() << "Got chart type result"; tDebug( LOGVERBOSE ) << "Got chart type result";
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() ); QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
if ( reply->error() == QNetworkReply::NoError ) if ( reply->error() == QNetworkReply::NoError )
{ {
QJson::Parser p; QJson::Parser p;
@@ -262,7 +262,8 @@ ChartsPlugin::chartTypes()
QHash< QString, QVariantMap > extraType; QHash< QString, QVariantMap > extraType;
foreach( const QVariant& chartObj, chartObjs.values() ) foreach( const QVariant& chartObj, chartObjs.values() )
{ {
if( !chartObj.toMap().isEmpty() ){ if( !chartObj.toMap().isEmpty() )
{
const QVariantMap chart = chartObj.toMap(); const QVariantMap chart = chartObj.toMap();
const QString id = chart.value( "id" ).toString(); const QString id = chart.value( "id" ).toString();
const QString geo = chart.value( "geo" ).toString(); const QString geo = chart.value( "geo" ).toString();
@@ -271,7 +272,8 @@ ChartsPlugin::chartTypes()
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
QString extra; QString extra;
if( !geo.isEmpty() ){ if( !geo.isEmpty() )
{
if ( !m_cachedCountries.contains( geo ) ) if ( !m_cachedCountries.contains( geo ) )
{ {
@@ -289,10 +291,10 @@ ChartsPlugin::chartTypes()
m_cachedCountries[ geo ] = extra; m_cachedCountries[ geo ] = extra;
} }
else else
{
extra = m_cachedCountries[ geo ]; extra = m_cachedCountries[ geo ];
} }
}else extra = chart.value( "extra" ).toString(); else
extra = chart.value( "extra" ).toString();
if ( name.isEmpty() ) // not a specific chart, an all chart if ( name.isEmpty() ) // not a specific chart, an all chart
name = tr( "Top Overall" ); name = tr( "Top Overall" );
@@ -304,10 +306,10 @@ ChartsPlugin::chartTypes()
if ( isDefault ) if ( isDefault )
c[ "default" ] = "true"; c[ "default" ] = "true";
QList<InfoStringHash> extraTypeData = extraType[ extra ][ type ].value< QList< InfoStringHash > >(); QList< Tomahawk::InfoSystem::InfoStringHash > extraTypeData = extraType[ extra ][ type ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >();
extraTypeData.append( c ); extraTypeData.append( c );
extraType[ extra ][ type ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( extraTypeData );
extraType[ extra ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( extraTypeData ) );
if ( isDefault ) if ( isDefault )
{ {
defaultChain.clear(); defaultChain.clear();
@@ -319,7 +321,7 @@ ChartsPlugin::chartTypes()
foreach( const QString& c, extraType.keys() ) foreach( const QString& c, extraType.keys() )
{ {
charts[ c ] = extraType[ c ]; charts[ c ] = extraType[ c ];
// qDebug() << "extraType has types:" << c; // tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "extraType has types:" << c;
} }
if( source == "itunes" ){ if( source == "itunes" ){
chartName = "iTunes"; chartName = "iTunes";
@@ -330,7 +332,8 @@ ChartsPlugin::chartTypes()
} }
} }
}else }
else
{ {
// We'll just build: // We'll just build:
// [Source] - Album - Chart Type // [Source] - Album - Chart Type
@@ -380,11 +383,11 @@ ChartsPlugin::chartTypes()
} }
} }
if( !artistCharts.isEmpty() ) if( !artistCharts.isEmpty() )
charts.insert( tr( "Artists" ), QVariant::fromValue< QList< InfoStringHash > >( artistCharts ) ); charts.insert( tr( "Artists" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( artistCharts ) );
if( !albumCharts.isEmpty() ) if( !albumCharts.isEmpty() )
charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) ); charts.insert( tr( "Albums" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( albumCharts ) );
if( !trackCharts.isEmpty() ) if( !trackCharts.isEmpty() )
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) ); charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( trackCharts ) );
/// @note For displaying purposes, upper the first letter /// @note For displaying purposes, upper the first letter
/// @note Remeber to lower it when fetching this! /// @note Remeber to lower it when fetching this!
@@ -394,7 +397,7 @@ ChartsPlugin::chartTypes()
} }
/// Add the possible charts and its types to breadcrumb /// Add the possible charts and its types to breadcrumb
// qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName; // tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "ADDING CHART TYPE TO CHARTS:" << chartName;
QVariantMap defaultMap = m_allChartsMap.value( "defaults" ).value< QVariantMap >(); QVariantMap defaultMap = m_allChartsMap.value( "defaults" ).value< QVariantMap >();
defaultMap[ source ] = defaultChain; defaultMap[ source ] = defaultChain;
m_allChartsMap[ "defaults" ] = defaultMap; m_allChartsMap[ "defaults" ] = defaultMap;
@@ -413,6 +416,10 @@ ChartsPlugin::chartTypes()
foreach ( InfoRequestData request, m_cachedRequests ) foreach ( InfoRequestData request, m_cachedRequests )
{ {
emit info( request, m_allChartsMap ); emit info( request, m_allChartsMap );
// update cache
Tomahawk::InfoSystem::InfoStringHash criteria;
criteria[ "InfoChartCapabilities" ] = "all";
emit updateCache( criteria, 86400000, request.type, m_allChartsMap );
} }
m_cachedRequests.clear(); m_cachedRequests.clear();
} }
@@ -441,8 +448,8 @@ ChartsPlugin::chartReturned()
/// SO we have a result, parse it! /// SO we have a result, parse it!
QVariantList chartResponse = res.value( "list" ).toList(); QVariantList chartResponse = res.value( "list" ).toList();
QList< InfoStringHash > top_tracks; QList< Tomahawk::InfoSystem::InfoStringHash > top_tracks;
QList< InfoStringHash > top_albums; QList< Tomahawk::InfoSystem::InfoStringHash > top_albums;
QStringList top_artists; QStringList top_artists;
/// Deside what type, we need to handle it differently /// Deside what type, we need to handle it differently
@@ -478,16 +485,16 @@ ChartsPlugin::chartReturned()
if ( album.isEmpty() && artist.isEmpty() ) // don't have enough... if ( album.isEmpty() && artist.isEmpty() ) // don't have enough...
{ {
tLog() << "Didn't get an artist and album name from chart, not enough to build a query on. Aborting" << title << album << artist; tDebug( LOGVERBOSE ) << "Didn't get an artist and album name from chart, not enough to build a query on. Aborting" << title << album << artist;
} }
else else
{ {
qDebug() << Q_FUNC_INFO << album << artist;
InfoStringHash pair; Tomahawk::InfoSystem::InfoStringHash pair;
pair["artist"] = artist; pair["artist"] = artist;
pair["album"] = album; pair["album"] = album;
top_albums << pair; top_albums.append( pair );
} }
} }
@@ -497,28 +504,28 @@ ChartsPlugin::chartReturned()
if ( title.isEmpty() && artist.isEmpty() ) // don't have enough... if ( title.isEmpty() && artist.isEmpty() ) // don't have enough...
{ {
tLog() << "Didn't get an artist and track name from charts, not enough to build a query on. Aborting" << title << artist << album; tDebug( LOGVERBOSE ) << "Didn't get an artist and track name from charts, not enough to build a query on. Aborting" << title << artist << album;
} }
else else
{ {
InfoStringHash pair; Tomahawk::InfoSystem::InfoStringHash pair;
pair["artist"] = artist; pair["artist"] = artist;
pair["track"] = title; pair["track"] = title;
top_tracks << pair; top_tracks.append( pair );
} }
}else if( chartType() == Artist ) }else if( chartType() == Artist )
{ {
if ( artist.isEmpty() ) // don't have enough... if ( artist.isEmpty() ) // don't have enough...
{ {
tLog() << "Didn't get an artist from charts, not enough to build a query on. Aborting" << artist; tDebug( LOGVERBOSE ) << "Didn't get an artist from charts, not enough to build a query on. Aborting" << artist;
} }
else else
{ {
top_artists << artist; top_artists.append( artist );
} }
} }
@@ -528,31 +535,35 @@ ChartsPlugin::chartReturned()
if( chartType() == Artist ) if( chartType() == Artist )
{ {
tDebug() << "ChartsPlugin:" << "\tgot " << top_artists.size() << " artists"; tDebug() << "ChartsPlugin:" << "\tgot " << top_artists.size() << " artists";
returnedData["artists"] = QVariant::fromValue( top_artists ); returnedData[ "artists" ] = QVariant::fromValue< QStringList >( top_artists );
returnedData[ "type" ] = "artists"; returnedData[ "type" ] = "artists";
} }
if( chartType() == Track ) if( chartType() == Track )
{ {
tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks"; tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks";
returnedData["tracks"] = QVariant::fromValue( top_tracks ); returnedData[ "tracks" ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( top_tracks );
returnedData[ "type" ] = "tracks"; returnedData[ "type" ] = "tracks";
} }
if( chartType() == Album ) if( chartType() == Album )
{ {
tDebug() << "ChartsPlugin:" << "\tgot " << top_albums.size() << " albums"; tDebug() << "ChartsPlugin:" << "\tgot " << top_albums.size() << " albums";
returnedData["albums"] = QVariant::fromValue( top_albums ); returnedData[ "albums" ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( top_albums );
returnedData[ "type" ] = "albums"; returnedData[ "type" ] = "albums";
} }
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
emit info( requestData, returnedData ); 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" ];
emit updateCache( criteria, 86400000, requestData.type, returnedData );
} }
else else
qDebug() << "Network error in fetching chart:" << reply->url().toString(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Network error in fetching chart:" << reply->url().toString();
} }

View File

@@ -21,8 +21,8 @@
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include "infosystem/infosystemworker.h" #include "infosystem/infosystemworker.h"
#include <QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QObject> #include <QtCore/QObject>
class QNetworkReply; class QNetworkReply;
@@ -47,6 +47,7 @@ public:
Artist = 0x04 Artist = 0x04
}; };
void setChartType( ChartType type ) { m_chartType = type; } void setChartType( ChartType type ) { m_chartType = type; }
ChartType chartType() const { return m_chartType; } ChartType chartType() const { return m_chartType; }
@@ -58,14 +59,19 @@ protected slots:
virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData ); virtual void getInfo( Tomahawk::InfoSystem::InfoRequestData requestData );
virtual void notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, 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( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data )
{
Q_UNUSED( caller )
Q_UNUSED( type )
Q_UNUSED( data )
}
private: private:
void fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData ); void fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData );
void fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requestData ); void fetchChartCapabilities( Tomahawk::InfoSystem::InfoRequestData requestData );
void dataError( Tomahawk::InfoSystem::InfoRequestData requestData ); void dataError( Tomahawk::InfoSystem::InfoRequestData requestData );
QVariantList m_chartResources; QStringList m_chartResources;
QList< InfoStringHash > m_charts; QList< InfoStringHash > m_charts;
ChartType m_chartType; ChartType m_chartType;

View File

@@ -20,9 +20,9 @@
#include "whatshotwidget.h" #include "whatshotwidget.h"
#include "ui_whatshotwidget.h" #include "ui_whatshotwidget.h"
#include <QPainter> #include <QtGui/QPainter>
#include <QStandardItemModel> #include <QtGui/QStandardItemModel>
#include <QStandardItem> #include <QtGui/QStandardItem>
#include "viewmanager.h" #include "viewmanager.h"
#include "sourcelist.h" #include "sourcelist.h"
@@ -156,9 +156,15 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
return; return;
} }
tDebug( LOGVERBOSE ) << "WhatsHot: got something..."; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got something...";
if ( !output.canConvert< QVariantMap >() )
{
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: Could not parse output";
return;
}
QVariantMap returnedData = output.toMap(); QVariantMap returnedData = output.toMap();
qDebug() << "WhatsHot::" << returnedData; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot::" << returnedData;
switch ( requestData.type ) switch ( requestData.type )
{ {
case InfoSystem::InfoChartCapabilities: case InfoSystem::InfoChartCapabilities:
@@ -174,9 +180,9 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
foreach ( const QString label, returnedData.keys() ) foreach ( const QString label, returnedData.keys() )
{ {
tDebug( LOGVERBOSE ) << "WhatsHot:: parsing " << label; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: parsing " << label;
QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] ); QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] );
tDebug( LOGVERBOSE ) << "WhatsHot:: appending" << childItem->text(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot:: appending" << childItem->text();
rootItem->appendRow(childItem); rootItem->appendRow(childItem);
} }
@@ -187,7 +193,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
QStandardItem* source = rootItem->child( i, 0 ); QStandardItem* source = rootItem->child( i, 0 );
if ( defaultSource.toLower() == source->text().toLower() ) if ( defaultSource.toLower() == source->text().toLower() )
{ {
qDebug() << "Setting DEFAULT SOURCE:" << source->text(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Setting DEFAULT SOURCE:" << source->text();
source->setData( true, Breadcrumb::DefaultRole ); source->setData( true, Breadcrumb::DefaultRole );
} }
@@ -203,7 +209,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
{ {
if ( cur->child( k, 0 )->text() == index ) if ( cur->child( k, 0 )->text() == index )
{ {
tDebug() << "Found DEFAULT ITEM:" << index; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Found DEFAULT ITEM:" << index;
cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default
cur->setData( true, Breadcrumb::DefaultRole ); cur->setData( true, Breadcrumb::DefaultRole );
break; break;
@@ -229,11 +235,11 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
const QString chartId = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >().value( "chart_id" ); const QString chartId = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >().value( "chart_id" );
m_queuedFetches.remove( chartId ); m_queuedFetches.remove( chartId );
tDebug( LOGVERBOSE ) << "WhatsHot: got chart! " << type << " on " << side; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got chart! " << type << " on " << side;
if( type == "artists" ) if( type == "artists" )
{ {
const QStringList artists = returnedData["artists"].toStringList(); const QStringList artists = returnedData["artists"].toStringList();
tDebug( LOGVERBOSE ) << "WhatsHot: got artists! " << artists.size(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got artists! " << artists.size();
TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft ); TreeModel* artistsModel = new TreeModel( ui->artistsViewLeft );
artistsModel->setColumnStyle( TreeModel::TrackOnly ); artistsModel->setColumnStyle( TreeModel::TrackOnly );
@@ -252,18 +258,18 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
{ {
QList<album_ptr> al; QList<album_ptr> al;
const QList< Tomahawk::InfoSystem::InfoStringHash > albums = returnedData[ "albums" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); const QList< Tomahawk::InfoSystem::InfoStringHash > albums = returnedData[ "albums" ].value< QList< Tomahawk::InfoSystem::InfoStringHash > >();
tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got albums! " << albums.size();
AlbumModel* albumModel = new AlbumModel( ui->additionsView ); AlbumModel* albumModel = new AlbumModel( ui->additionsView );
foreach ( const Tomahawk::InfoSystem::InfoStringHash& album, albums ) foreach ( const Tomahawk::InfoSystem::InfoStringHash& album, albums )
{ {
qDebug() << "Getting album" << album[ "album" ] << "By" << album[ "artist" ]; tDebug( LOGVERBOSE) << Q_FUNC_INFO << "Getting album" << album[ "album" ] << "By" << album[ "artist" ];
artist_ptr artistPtr = Artist::get( album[ "artist" ], false ); artist_ptr artistPtr = Artist::get( album[ "artist" ], false );
album_ptr albumPtr = Album::get( artistPtr, album[ "album" ], false ); album_ptr albumPtr = Album::get( artistPtr, album[ "album" ], false );
al << albumPtr; al << albumPtr;
} }
qDebug() << "Adding albums to model"; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Adding albums to model";
albumModel->addAlbums( al ); albumModel->addAlbums( al );
m_albumModels[ chartId ] = albumModel; m_albumModels[ chartId ] = albumModel;
@@ -294,7 +300,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
} }
else else
{ {
tDebug( LOGVERBOSE ) << "WhatsHot: got unknown chart type" << type; tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "WhatsHot: got unknown chart type" << type;
} }
break; break;
} }

View File

@@ -406,6 +406,7 @@ TomahawkApp::registerMetaTypes()
qRegisterMetaType< Tomahawk::InfoSystem::InfoSystemCache* >( "Tomahawk::InfoSystem::InfoSystemCache*" ); qRegisterMetaType< Tomahawk::InfoSystem::InfoSystemCache* >( "Tomahawk::InfoSystem::InfoSystemCache*" );
qRegisterMetaType< QList< Tomahawk::InfoSystem::InfoStringHash > >("QList< Tomahawk::InfoSystem::InfoStringHash > "); qRegisterMetaType< QList< Tomahawk::InfoSystem::InfoStringHash > >("QList< Tomahawk::InfoSystem::InfoStringHash > ");
qRegisterMetaTypeStreamOperators< QList< Tomahawk::InfoSystem::InfoStringHash > >("QList< Tomahawk::InfoSystem::InfoStringHash > ");
qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" ); qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" );
} }
@@ -582,4 +583,3 @@ TomahawkApp::instanceStarted( KDSingleApplicationGuard::Instance instance )
QString arg1 = instance.arguments[ 1 ]; QString arg1 = instance.arguments[ 1 ];
loadUrl( arg1 ); loadUrl( arg1 );
} }