diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index a3da31e81..b28388c11 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -46,7 +46,7 @@ ChartsPlugin::ChartsPlugin() /// Add resources here - m_chartResources << "last.fm" << "billboard" << "itunes"; + m_chartResources << "billboard" << "itunes"; m_supportedGetTypes << InfoChart << InfoChartCapabilities; } @@ -98,10 +98,30 @@ ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData req qDebug() << Q_FUNC_INFO << requestData.caller; qDebug() << Q_FUNC_INFO << requestData.customData; + InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + bool foundSource; + switch ( requestData.type ) { case InfoChart: + /// We need something to check if the request is actually ment to go to this plugin + if ( !hash.contains( "chart_source" ) ) + { + dataError( requestId, requestData ); + break; + }else + { + foreach(QVariant resource, m_chartResources) + if(resource.toString() == hash["chart_source"]) + foundSource = true; + + if(!foundSource){ + dataError( requestId, requestData ); + break; + } + + } fetchChart( requestId, requestData ); break; @@ -159,9 +179,7 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info return; } - //InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); Tomahawk::InfoSystem::InfoCriteriaHash criteria; - emit getCachedInfo( requestId, criteria, 0, requestData ); } @@ -182,7 +200,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, { /// 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; QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); @@ -191,6 +209,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) ); return; + } case InfoChartCapabilities: @@ -217,25 +236,9 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, QList album_charts; QList track_charts; - QList artist_charts; QVariantMap charts; - if( chartResource.toString() == "last.fm") - { - - track_charts.append( Chart( "chart.getTopTracks", "Top Tracks", "tracks" ) ); - track_charts.append( Chart( "chart.getLovedTracks", "Loved Tracks", "tracks" ) ); - track_charts.append( Chart( "chart.getHypedTracks", "Hyped Tracks", "tracks" ) ); - - artist_charts.append( Chart( "chart.getTopArtists", "Top Artists", "artists" ) ); - artist_charts.append( Chart( "chart.getHypedArtists", "Hyped Artists", "artists" ) ); - - charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); - charts.insert( "Artists", QVariant::fromValue >( artist_charts ) ); - - - } - else if( chartResource.toString() == "itunes") + if( chartResource.toString() == "itunes") { QVariantMap geoCharts; @@ -472,4 +475,3 @@ ChartsPlugin::chartReturned() }else qDebug() << "Network error"; } - diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index aa47e9e6c..9f7783b36 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -398,11 +398,25 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, emit info( requestId, requestData, QVariant() ); return; } - + bool foundSource; + InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); switch ( requestData.type ) { case InfoChart: { + /// We need something to check if the request is actually ment to go to this plugin + if ( !hash.contains( "chart_source" ) ) + { + dataError( requestId, requestData ); + break; + }else + { + if("last.fm" != hash["chart_source"]){ + dataError( requestId, requestData ); + break; + } + + } tDebug() << "LastFmPlugin: InfoChart not in cache, fetching"; QMap args; tDebug() << "LastFmPlugin: " << "args chart_id" << criteria["chart_id"]; @@ -416,6 +430,32 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, return; } + case InfoChartCapabilities: + { + QList track_charts; + track_charts.append( Chart( "chart.getTopTracks", "Top Tracks", "tracks" ) ); + track_charts.append( Chart( "chart.getLovedTracks", "Loved Tracks", "tracks" ) ); + track_charts.append( Chart( "chart.getHypedTracks", "Hyped Tracks", "tracks" ) ); + + QList artist_charts; + artist_charts.append( Chart( "chart.getTopArtists", "Top Artists", "artists" ) ); + artist_charts.append( Chart( "chart.getHypedArtists", "Hyped Artists", "artists" ) ); + + QVariantMap charts; + charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + charts.insert( "Artists", QVariant::fromValue >( artist_charts ) ); + + QVariantMap result; + result.insert( "Last.fm", QVariant::fromValue( charts ) ); + + emit info( + requestId, + requestData, + result + ); + return; + } + case InfoArtistSimilars: { lastfm::Artist a( criteria["artist"] ); @@ -469,7 +509,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, default: { - tLog() << Q_FUNC_INFO << "Couldn't figure out what to do with this type of request after cache miss"; + tLog() << "Couldn't figure out what to do with this type of request after cache miss"; emit info( requestId, requestData, QVariant() ); return; } @@ -809,4 +849,3 @@ LastFmPlugin::parseTrackList( QNetworkReply* reply ) return tracks; } - diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 2743bbf74..5fd330a4c 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -86,14 +86,12 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac InfoPluginPtr mbptr( new MusicBrainzPlugin() ); m_plugins.append( mbptr ); registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() ); - - InfoPluginPtr sptr( new ChartsPlugin() ); - m_plugins.append( sptr ); - registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() ); - InfoPluginPtr lfmptr( new LastFmPlugin() ); m_plugins.append( lfmptr ); registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() ); + InfoPluginPtr sptr( new ChartsPlugin() ); + m_plugins.append( sptr ); + registerInfoTypes( sptr, sptr.data()->supportedGetTypes(), sptr.data()->supportedPushTypes() ); #ifdef Q_WS_MAC diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 34894187f..b9cc0c02e 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -121,8 +121,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); - /// Itunes response is big, so maybe wait for it here? - QTimer::singleShot( 1000, this, SLOT( fetchData() ) ); + QTimer::singleShot( 2000, this, SLOT( fetchData() ) ); } @@ -143,7 +142,7 @@ WhatsHotWidget::fetchData() requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( artistInfo ); requestData.type = Tomahawk::InfoSystem::InfoChartCapabilities; - Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true ); tDebug( LOGVERBOSE ) << "WhatsHot: requested InfoChartCapabilities"; } @@ -167,6 +166,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat tDebug( LOGVERBOSE ) << "WhatsHot: got something..."; QVariantMap returnedData = output.toMap(); + qDebug() << "WhatsHot::" << returnedData; switch ( requestData.type ) { case InfoSystem::InfoChartCapabilities: @@ -182,12 +182,15 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat tDebug( LOGVERBOSE ) << "WhatsHot:: appending" << childItem->text(); rootItem->appendRow(childItem); } + KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this); ui->breadCrumbLeft->setSelectionModel(selectionModelLeft); + //ui->breadCrumbRight->setSelectionModel(selectionModelLeft); //HACK ALERT - we want the second crumb to expand right away, so we //force it here. We should find a more elegant want to do this - ui->breadCrumbLeft->currentChangedTriggered(m_crumbModelLeft->index(0,0).child(0,0).child(0,0)); + /// @note: this expands the billboard chart, as its fast loading and intersting album view ;) i think + ui->breadCrumbLeft->currentChangedTriggered(m_crumbModelLeft->index(1,0).child(0,0).child(0,0)); break; } case InfoSystem::InfoChart: @@ -296,7 +299,7 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria ); requestData.type = Tomahawk::InfoSystem::InfoChart; - Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); + Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData, 2000, true ); }