From fb8a761278d70cd9d540a5abcf137bc86cf3521d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Wed, 5 Oct 2011 20:22:48 +0200 Subject: [PATCH 1/9] Adding charts infoplugin --- src/libtomahawk/CMakeLists.txt | 2 + .../infoplugins/generic/chartsplugin.cpp | 403 ++++++++++++++++++ .../infoplugins/generic/chartsplugin.h | 81 ++++ src/libtomahawk/infosystem/infosystem.h | 7 + .../infosystem/infosystemworker.cpp | 9 + src/libtomahawk/widgets/whatshotwidget.cpp | 33 +- src/libtomahawk/widgets/whatshotwidget.h | 2 + src/libtomahawk/widgets/whatshotwidget.ui | 26 +- src/tomahawkapp.cpp | 2 + 9 files changed, 562 insertions(+), 3 deletions(-) create mode 100644 src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp create mode 100644 src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 6d64c0d0b..515866eb4 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -110,6 +110,7 @@ set( libSources infosystem/infosystemworker.cpp infosystem/infoplugins/generic/echonestplugin.cpp infosystem/infoplugins/generic/lastfmplugin.cpp + infosystem/infoplugins/generic/chartsplugin.cpp infosystem/infoplugins/generic/musixmatchplugin.cpp infosystem/infoplugins/generic/musicbrainzPlugin.cpp @@ -335,6 +336,7 @@ set( libHeaders infosystem/infosystemcache.h infosystem/infoplugins/generic/echonestplugin.h infosystem/infoplugins/generic/lastfmplugin.h + infosystem/infoplugins/generic/chartsplugin.h infosystem/infoplugins/generic/musixmatchplugin.h infosystem/infoplugins/generic/musicbrainzPlugin.h diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp new file mode 100644 index 000000000..e75ddf95b --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -0,0 +1,403 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Hugo Lindström + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "chartsplugin.h" + +#include +#include +#include +#include +#include + +#include "album.h" +#include "typedefs.h" +#include "audio/audioengine.h" +#include "tomahawksettings.h" +#include "utils/tomahawkutils.h" +#include "utils/logger.h" + +#include + +#define CHART_URL "http://charts.tomahawk-player.org:10080/" +#include + +using namespace Tomahawk::InfoSystem; + +static QString +md5( const QByteArray& src ) +{ + QByteArray const digest = QCryptographicHash::hash( src, QCryptographicHash::Md5 ); + return QString::fromLatin1( digest.toHex() ).rightJustified( 32, '0' ); +} + + +ChartsPlugin::ChartsPlugin() + : InfoPlugin() +{ + + tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; + + QUrl url = QUrl(CHART_URL); + QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); + connect( reply, SIGNAL( finished() ), SLOT( chartResources() ) ); + + m_supportedGetTypes << InfoChart << InfoChartCapabilities; + +} + + +ChartsPlugin::~ChartsPlugin() +{ + qDebug() << Q_FUNC_INFO; +} + + +void +ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) +{ + qDebug() << Q_FUNC_INFO; + if( !nam ) + return; +} + + +void +ChartsPlugin::dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + emit info( requestId, requestData, QVariant() ); + return; +} + + +void +ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + switch ( requestData.type ) + { + + case InfoChart: + fetchChart( requestId, requestData ); + break; + + case InfoChartCapabilities: + fetchChartCapabilities( requestId, requestData ); + break; + default: + dataError( requestId, 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 +ChartsPlugin::fetchChart( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) + { + dataError( requestId, requestData ); + return; + } + InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + Tomahawk::InfoSystem::InfoCriteriaHash criteria; + if ( !hash.contains( "chart_id" ) ) + { + dataError( requestId, requestData ); + return; + } else { + criteria["chart_id"] = hash["chart_id"]; + } + if ( hash.contains( "chart_source" ) ) + { + criteria["chart_source"] = hash["chart_source"]; + } + + emit getCachedInfo( requestId, criteria, 0, requestData ); +} + +void +ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) + { + dataError( requestId, requestData ); + return; + } + InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + Tomahawk::InfoSystem::InfoCriteriaHash criteria; + + emit getCachedInfo( requestId, criteria, 0, requestData ); +} + +void +ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) +{ + if ( !lastfm::nam() ) + { + tLog() << "Have a null QNAM, uh oh"; + emit info( requestId, requestData, QVariant() ); + return; + } + + switch ( requestData.type ) + { + case InfoChart: + { + + 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 = lastfm::nam()->get( QNetworkRequest( url ) ); + reply->setProperty( "requestId", requestId ); + reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); + + connect( reply, SIGNAL( finished() ), SLOT( chartReturned() ) ); + return; + } + + case InfoChartCapabilities: + { + + QVariantMap result; + foreach( QVariant chartResource, m_chartResources ) + { + + QList album_charts; + QList track_charts; + QVariantMap charts; + + if( !m_chartTypes.isEmpty() ) + foreach( QVariant type, m_chartTypes ) + { + // Itunes supplys charts based on geo, for now, only take US charts + if( type.toMap().value( "source" ).toString() == chartResource.toString() + && type.toMap().value( "geo" ).isValid() + && type.toMap().value( "geo" ).toString() != "us" ) + continue; + + if( type.toMap().value( "source" ).toString() == chartResource.toString() ) + { + if( type.toMap().value( "type" ).toString() == "Album" ) + { + album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); + charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); + } + if( type.toMap().value( "type" ).toString() == "Track" ) + { + track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); + charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + } + } + } + + result.insert( chartResource.toString() , QVariant::fromValue( charts ) ); + } + emit info( + requestId, + requestData, + result + ); + return; + } + + + + default: + { + tLog() << "Couldn't figure out what to do with this type of request after cache miss"; + emit info( requestId, requestData, QVariant() ); + return; + } + } +} + + +void +ChartsPlugin::chartResources() +{ + + tDebug() << "ChartsPlugin: InfoChart resources returned!"; + QNetworkReply* reply = qobject_cast( sender() ); + + + if ( reply->error() == QNetworkReply::NoError ) + { + QJson::Parser p; + bool ok; + QVariantMap res = p.parse( reply, &ok ).toMap(); + + if ( !ok ) + { + tLog() << "Failed to parse resources" << p.errorString() << "On line" << p.errorLine(); + + return; + } + + m_chartResources = res.value( "chart_sources" ).toList(); + qDebug() << "Resources" << m_chartResources; + + if(!m_chartResources.isEmpty()){ + + foreach(QVariant resource, m_chartResources){ + tDebug() << "ChartsPlugin: InfoChart fetching possible types for "<< resource.toString(); + + QUrl url = QUrl( QString( CHART_URL "/source/%1" ).arg(resource.toString() ) ); + qDebug() << "Getting types from " << url; + + QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); + + connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); + } + } + } + +} + +void +ChartsPlugin::chartTypes() +{ + + tDebug() << "ChartsPlugin: InfoChart types returned!"; + QNetworkReply* reply = qobject_cast( sender() ); + + + if ( reply->error() == QNetworkReply::NoError ) + { + QJson::Parser p; + bool ok; + QVariantMap res = p.parse( reply, &ok ).toMap(); + + if ( !ok ) + { + tLog() << "Failed to parse resources" << p.errorString() << "On line" << p.errorLine(); + + return; + } + + foreach(QVariant chart, res.value( "charts" ).toMap() ) + m_chartTypes.append(chart); + + } + +} + +void +ChartsPlugin::chartReturned() +{ + + QNetworkReply* reply = qobject_cast( sender() ); + + QVariantMap returnedData; + + if ( reply->error() == QNetworkReply::NoError ) + { + QJson::Parser p; + bool ok; + QVariantMap res = p.parse( reply, &ok ).toMap(); + + if ( !ok ) + { + tLog() << "Failed to parse json from chart lookup:" << p.errorString() << "On line" << p.errorLine(); + + return; + }else qDebug() << res; + + + QVariantList chartResponse = res.value( "list" ).toList(); + QList top_tracks; + QList top_albums; + + + if( res.value( "type" ).toString() == "Album" ) + setChartType( Album ); + else if( res.value( "type" ).toString() == "Track" ) + setChartType( Track ); + else + setChartType( None ); + + + foreach ( QVariant chartR, chartResponse ) + { + QString title, artist, album; + QVariantMap chartMap = chartR.toMap(); + + if ( chartMap.contains( "track" ) ) + { + + title = chartMap.value( "track" ).toString(); + artist = chartMap.value( "artist" ).toString(); + + if ( title.isEmpty() && artist.isEmpty() ) // don't have enough... + { + tLog() << "Didn't get an artist and track name from itunes, not enough to build a query on. Aborting" << title << artist << album; + + } + else{ + + if( chartType() == Album ){ + + ArtistAlbumPair pair; + pair.artist = artist; + pair.album = title; + top_albums << pair; + + }else if( chartType() == Track ){ + + ArtistTrackPair pair; + pair.artist = artist; + pair.track = title; + top_tracks << pair; + } + + } + } + } + if( chartType() == Track ){ + tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks"; + returnedData["tracks"] = QVariant::fromValue( top_tracks ); + returnedData["type"] = "tracks"; + } + + if( chartType() == Album ){ + tDebug() << "ChartsPlugin:" << "\tgot " << top_albums.size() << " albums"; + returnedData["albums"] = QVariant::fromValue( top_albums ); + returnedData["type"] = "albums"; + } + + Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); + + emit info( + reply->property( "requestId" ).toUInt(), + requestData, + returnedData + ); + // TODO update cache + + }else qDebug() << "Network error"; + +} + diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h new file mode 100644 index 000000000..b358f3a91 --- /dev/null +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -0,0 +1,81 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Hugo Lindström + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef ChartsPlugin_H +#define ChartsPlugin_H + +#include "infosystem/infosystem.h" +#include "infosystem/infosystemworker.h" + +#include + +class QNetworkReply; + +namespace Tomahawk +{ + +namespace InfoSystem +{ + +class ChartsPlugin : public InfoPlugin +{ + Q_OBJECT + +public: + ChartsPlugin(); + virtual ~ChartsPlugin(); + + enum ChartType { + None = 0x00, + Track = 0x01, + Album = 0x02, + Artist = 0x04 + + }; + void setChartType( ChartType type ) { m_chartType = type; } + ChartType chartType() const { return m_chartType; } + +public slots: + void chartReturned(); + void chartResources(); + void chartTypes(); + void namChangedSlot( QNetworkAccessManager *nam ); + +protected slots: + virtual void getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); + virtual void notInCacheSlot( uint requestId, Tomahawk::InfoSystem::InfoCriteriaHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ); + + virtual void pushInfo( QString caller, Tomahawk::InfoSystem::InfoType type, QVariant data ); + +private: + void fetchChart( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); + void fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); + void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); + + QVariantList m_chartResources; + QVariantList m_chartTypes; + QList m_charts; + ChartType m_chartType; + +}; + +} + +} + +#endif // ChartsPlugin_H diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index 4de22ea6d..23ea52246 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -135,6 +135,11 @@ struct ArtistTrackPair { QString track; }; +struct ArtistAlbumPair { + QString artist; + QString album; +}; + struct Chart { Chart(){} Chart(const QString _id, const QString _label, const QString _type) { @@ -284,8 +289,10 @@ Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoGenericMap ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoCriteriaHash ); Q_DECLARE_METATYPE( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::ArtistTrackPair ); +Q_DECLARE_METATYPE( Tomahawk::InfoSystem::ArtistAlbumPair ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::Chart ); Q_DECLARE_METATYPE( QList ); +Q_DECLARE_METATYPE( QList ); Q_DECLARE_METATYPE( QList ); #endif // TOMAHAWK_INFOSYSTEM_H diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index b868503cf..0df655dfa 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -25,6 +25,7 @@ #include "infosystemcache.h" #include "infoplugins/generic/echonestplugin.h" #include "infoplugins/generic/musixmatchplugin.h" +#include "infoplugins/generic/chartsplugin.h" #include "infoplugins/generic/lastfmplugin.h" #include "infoplugins/generic/musicbrainzPlugin.h" #include "utils/tomahawkutils.h" @@ -85,10 +86,18 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac InfoPluginPtr mbptr( new MusicBrainzPlugin() ); m_plugins.append( mbptr ); registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() ); + + + + InfoPluginPtr chartsptr( new ChartsPlugin() ); + m_plugins.append( chartsptr ); + registerInfoTypes( chartsptr, chartsptr.data()->supportedGetTypes(), chartsptr.data()->supportedPushTypes() ); + InfoPluginPtr lfmptr( new LastFmPlugin() ); m_plugins.append( lfmptr ); registerInfoTypes( lfmptr, lfmptr.data()->supportedGetTypes(), lfmptr.data()->supportedPushTypes() ); + #ifdef Q_WS_MAC InfoPluginPtr admptr( new AdiumPlugin() ); m_plugins.append( admptr ); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 54833f90e..9a189b859 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -78,7 +78,6 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->breadCrumbRight->setModel(m_crumbModelLeft); ui->breadCrumbRight->setUseAnimation(true);*/ - m_tracksModel = new PlaylistModel( ui->tracksViewLeft ); m_tracksModel->setStyle( TrackModel::Short ); @@ -206,6 +205,21 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat foreach ( const QString& artist, artists ) m_artistsModel->addArtists( Artist::get( artist ) ); } + else if( type == "albums" ) + { + + setLeftViewTracks(); + m_tracksModel->clear(); + + const QList albums = returnedData["albums"].value >(); + tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); + + foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) + { + query_ptr query = Query::get( album.artist, QString(), album.album, uuid() ); + m_tracksModel->append( query ); + } + } else if( type == "tracks" ) { setLeftViewTracks(); @@ -241,7 +255,9 @@ WhatsHotWidget::infoSystemFinished( QString target ) void WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) { - tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data(); + + + tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb current changed" << index.data(); QStandardItem* item = m_crumbModelLeft->itemFromIndex(index); if( !item ) return; @@ -249,10 +265,20 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) return; + // Get the base eg. source identifier + QList indexes; + while (index.parent().isValid()) + { + indexes.prepend(index); + index = index.parent(); + } + + const QString chartId = item->data().toString(); Tomahawk::InfoSystem::InfoCriteriaHash criteria; criteria.insert("chart_id", chartId); + criteria.insert("chart_source", index.data().toString()); Tomahawk::InfoSystem::InfoRequestData requestData; QVariantMap customData; @@ -262,6 +288,9 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria ); requestData.type = Tomahawk::InfoSystem::InfoChart; + qDebug() << Q_FUNC_INFO << "RequestData custom" << requestData.customData; + qDebug() << Q_FUNC_INFO << "RequestData caller" << requestData.caller; + qDebug() << Q_FUNC_INFO << "RequestData input" << requestData.input; Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); } diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index d6d0b6a0f..6da5eb23a 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -84,6 +84,7 @@ private slots: private: void setLeftViewArtists(); void setLeftViewTracks(); + QStandardItem* parseNode( QStandardItem* parentItem, const QString &label, const QVariant &data ); Ui::WhatsHotWidget *ui; @@ -91,6 +92,7 @@ private: TreeModel* m_artistsModel; TreeProxyModel* m_artistsProxy; QStandardItemModel* m_crumbModelLeft; + TreeModel* m_albumsModel; QTimer* m_timer; }; diff --git a/src/libtomahawk/widgets/whatshotwidget.ui b/src/libtomahawk/widgets/whatshotwidget.ui index 902455cfb..56e09ebc1 100644 --- a/src/libtomahawk/widgets/whatshotwidget.ui +++ b/src/libtomahawk/widgets/whatshotwidget.ui @@ -30,6 +30,30 @@ + + + true + + + + true + + + + 9 + 9 + 839 + 471 + + + + + 320 + 0 + + + + @@ -57,7 +81,7 @@ ArtistView QTreeView -
artistview.h
+
artistview.h
HeaderBreadCrumb diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 22f36aeb8..4b78abd85 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -407,7 +407,9 @@ TomahawkApp::registerMetaTypes() qRegisterMetaType< DirLister::Mode >("DirLister::Mode"); qRegisterMetaType< Tomahawk::InfoSystem::ArtistTrackPair >("Tomahawk::InfoSystem::ArtistTrackPair"); + qRegisterMetaType< Tomahawk::InfoSystem::ArtistAlbumPair >("Tomahawk::InfoSystem::ArtistAlbumPair"); qRegisterMetaType< QList >("QList"); + qRegisterMetaType< QList >("QList"); qRegisterMetaType< Tomahawk::InfoSystem::Chart>("Tomahawk::InfoSystem::Chart"); qRegisterMetaType< QList >("QList"); qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" ); From 2ee085d13dcea5de478f9ed9e2c982cbc06a7ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Wed, 5 Oct 2011 22:33:08 +0200 Subject: [PATCH 2/9] Doing so for now. Need to create ui for specific albums --- .../infoplugins/generic/chartsplugin.cpp | 6 ++-- src/libtomahawk/widgets/whatshotwidget.cpp | 28 +++++++++---------- src/libtomahawk/widgets/whatshotwidget.ui | 26 +---------------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index e75ddf95b..868b90739 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -265,7 +265,7 @@ ChartsPlugin::chartResources() foreach(QVariant resource, m_chartResources){ tDebug() << "ChartsPlugin: InfoChart fetching possible types for "<< resource.toString(); - QUrl url = QUrl( QString( CHART_URL "/source/%1" ).arg(resource.toString() ) ); + QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); qDebug() << "Getting types from " << url; QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); @@ -298,8 +298,10 @@ ChartsPlugin::chartTypes() return; } - foreach(QVariant chart, res.value( "charts" ).toMap() ) + foreach(QVariant chart, res.value( "charts" ).toMap() ){ m_chartTypes.append(chart); + qDebug() << "Chart types" << chart; + } } diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 9a189b859..26c83a7fd 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -78,8 +78,11 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->breadCrumbRight->setModel(m_crumbModelLeft); ui->breadCrumbRight->setUseAnimation(true);*/ - m_tracksModel = new PlaylistModel( ui->tracksViewLeft ); - m_tracksModel->setStyle( TrackModel::Short ); + + m_tracksModel = new TreeModel( ui->tracksViewLeft ); + ui->tracksViewLeft->setTreeModel( m_tracksModel ); + + ui->tracksViewLeft->setFrameShape( QFrame::NoFrame ); ui->tracksViewLeft->setAttribute( Qt::WA_MacShowFocusRect, 0 ); @@ -207,17 +210,20 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } else if( type == "albums" ) { - - setLeftViewTracks(); - m_tracksModel->clear(); + setLeftViewArtists(); + m_artistsModel->clear(); const QList albums = returnedData["albums"].value >(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { - query_ptr query = Query::get( album.artist, QString(), album.album, uuid() ); - m_tracksModel->append( query ); + //query_ptr query = Query::get( album.artist, QString(), album.album, uuid() ); + artist_ptr artistPtr = Artist::get( album.artist ); + //album_ptr albumPtr = Album::get( 0, album.album, artistPtr ); + + m_artistsModel->addArtists( artistPtr ); + //m_albumsModel->append( query ); } } else if( type == "tracks" ) @@ -255,9 +261,7 @@ WhatsHotWidget::infoSystemFinished( QString target ) void WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) { - - - tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb current changed" << index.data(); + tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data(); QStandardItem* item = m_crumbModelLeft->itemFromIndex(index); if( !item ) return; @@ -265,7 +269,6 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) return; - // Get the base eg. source identifier QList indexes; while (index.parent().isValid()) { @@ -288,9 +291,6 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( criteria ); requestData.type = Tomahawk::InfoSystem::InfoChart; - qDebug() << Q_FUNC_INFO << "RequestData custom" << requestData.customData; - qDebug() << Q_FUNC_INFO << "RequestData caller" << requestData.caller; - qDebug() << Q_FUNC_INFO << "RequestData input" << requestData.input; Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); } diff --git a/src/libtomahawk/widgets/whatshotwidget.ui b/src/libtomahawk/widgets/whatshotwidget.ui index 56e09ebc1..902455cfb 100644 --- a/src/libtomahawk/widgets/whatshotwidget.ui +++ b/src/libtomahawk/widgets/whatshotwidget.ui @@ -30,30 +30,6 @@
- - - true - - - - true - - - - 9 - 9 - 839 - 471 - - - - - 320 - 0 - - - - @@ -81,7 +57,7 @@ ArtistView QTreeView -
artistview.h
+
artistview.h
HeaderBreadCrumb From 049184bdfd41d15bc4454dd27a844fb970a78e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Thu, 6 Oct 2011 19:52:51 +0200 Subject: [PATCH 3/9] Trying to add albums to whatshotview --- src/libtomahawk/widgets/whatshotwidget.cpp | 38 +++++++++++++++------- src/libtomahawk/widgets/whatshotwidget.h | 5 ++- src/libtomahawk/widgets/whatshotwidget.ui | 31 +++++++++++++++--- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 26c83a7fd..a41bfea08 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -58,6 +58,8 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) TomahawkUtils::unmarginLayout( ui->horizontalLayout->layout() ); TomahawkUtils::unmarginLayout( ui->horizontalLayout_2->layout() ); TomahawkUtils::unmarginLayout( ui->breadCrumbLeft->layout() ); + TomahawkUtils::unmarginLayout( ui->verticalLayout2->layout() ); + //set crumb widgets @@ -79,9 +81,8 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->breadCrumbRight->setUseAnimation(true);*/ - m_tracksModel = new TreeModel( ui->tracksViewLeft ); - ui->tracksViewLeft->setTreeModel( m_tracksModel ); - + m_tracksModel = new PlaylistModel( ui->tracksViewLeft ); + m_tracksModel->setStyle( TrackModel::ShortWithAvatars ); ui->tracksViewLeft->setFrameShape( QFrame::NoFrame ); @@ -110,6 +111,12 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->artistsViewLeft->header()->setVisible( false ); + ui->albumsViewLeft->setFrameShape( QFrame::NoFrame ); + ui->albumsViewLeft->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + + m_albumsModel = new AlbumModel( ui->albumsViewLeft ); + ui->albumsViewLeft->setAlbumModel( m_albumsModel ); + m_timer = new QTimer( this ); connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) ); @@ -210,21 +217,23 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } else if( type == "albums" ) { - setLeftViewArtists(); - m_artistsModel->clear(); - + setLeftViewAlbums(); + m_albumsModel->clear(); + QList al; const QList albums = returnedData["albums"].value >(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { - //query_ptr query = Query::get( album.artist, QString(), album.album, uuid() ); - artist_ptr artistPtr = Artist::get( album.artist ); - //album_ptr albumPtr = Album::get( 0, album.album, artistPtr ); + qDebug() << "Getting album" << album.album << "By" << album.artist; + album_ptr albumPtr = Album::get( 0, album.album, Artist::get( album.artist ) ); + al << albumPtr; - m_artistsModel->addArtists( artistPtr ); - //m_albumsModel->append( query ); } + qDebug() << "Adding albums to model"; + m_albumsModel->addAlbums( al ); + qDebug() << "Added albums"; + } else if( type == "tracks" ) { @@ -354,6 +363,13 @@ WhatsHotWidget::parseNode(QStandardItem* parentItem, const QString &label, const } +void +WhatsHotWidget::setLeftViewAlbums() +{ + ui->stackLeft->setCurrentIndex(2); +} + + void WhatsHotWidget::setLeftViewArtists() { diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index 6da5eb23a..e3dd0ff37 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -37,6 +37,7 @@ class TreeModel; class PlaylistModel; class OverlayWidget; class TreeProxyModel; +class AlbumModel; namespace Ui { @@ -83,8 +84,10 @@ private slots: private: void setLeftViewArtists(); + void setLeftViewAlbums(); void setLeftViewTracks(); + QStandardItem* parseNode( QStandardItem* parentItem, const QString &label, const QVariant &data ); Ui::WhatsHotWidget *ui; @@ -92,7 +95,7 @@ private: TreeModel* m_artistsModel; TreeProxyModel* m_artistsProxy; QStandardItemModel* m_crumbModelLeft; - TreeModel* m_albumsModel; + AlbumModel* m_albumsModel; QTimer* m_timer; }; diff --git a/src/libtomahawk/widgets/whatshotwidget.ui b/src/libtomahawk/widgets/whatshotwidget.ui index 902455cfb..c1e857163 100644 --- a/src/libtomahawk/widgets/whatshotwidget.ui +++ b/src/libtomahawk/widgets/whatshotwidget.ui @@ -44,20 +44,43 @@
+ + + + + + + + + 320 + 0 + + + + + + + + - PlaylistView - QTreeView -
playlist/playlistview.h
+ AlbumView + QListView +
playlist/albumview.h
ArtistView QTreeView -
artistview.h
+
artistview.h
+
+ + PlaylistView + QTreeView +
playlist/playlistview.h
HeaderBreadCrumb From 9caf9fc98fac6b70b4cf35f15e2c31e81fcd0a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Thu, 6 Oct 2011 23:00:19 +0200 Subject: [PATCH 4/9] Adding charts for Billboard and Itunes --- .../infoplugins/generic/chartsplugin.cpp | 188 +++++++++--------- .../infoplugins/generic/chartsplugin.h | 1 - src/libtomahawk/widgets/whatshotwidget.cpp | 34 ++-- src/libtomahawk/widgets/whatshotwidget.ui | 20 +- 4 files changed, 114 insertions(+), 129 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 868b90739..025308680 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -52,9 +52,20 @@ ChartsPlugin::ChartsPlugin() tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; - QUrl url = QUrl(CHART_URL); - QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); - connect( reply, SIGNAL( finished() ), SLOT( chartResources() ) ); + /// Add resources here + m_chartResources << "billboard" + << "itunes"; + + /// Then get each chart from resource + if(!m_chartResources.isEmpty()){ + + foreach(QVariant resource, m_chartResources) + { + QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); + QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); + connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); + } + } m_supportedGetTypes << InfoChart << InfoChartCapabilities; @@ -112,29 +123,29 @@ ChartsPlugin::pushInfo( const QString caller, const Tomahawk::InfoSystem::InfoTy } - - void ChartsPlugin::fetchChart( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) { + if ( !requestData.input.canConvert< Tomahawk::InfoSystem::InfoCriteriaHash >() ) { dataError( requestId, requestData ); return; } + InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); Tomahawk::InfoSystem::InfoCriteriaHash 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" ) ) { dataError( requestId, requestData ); return; - } else { - criteria["chart_id"] = hash["chart_id"]; - } - if ( hash.contains( "chart_source" ) ) - { - criteria["chart_source"] = hash["chart_source"]; + } + /// Set the criterias for current chart + criteria["chart_id"] = hash["chart_id"]; + criteria["chart_source"] = hash["chart_source"]; emit getCachedInfo( requestId, criteria, 0, requestData ); } @@ -147,7 +158,8 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info dataError( requestId, requestData ); return; } - InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); + + //InfoCriteriaHash hash = requestData.input.value< Tomahawk::InfoSystem::InfoCriteriaHash >(); Tomahawk::InfoSystem::InfoCriteriaHash criteria; emit getCachedInfo( requestId, criteria, 0, requestData ); @@ -168,9 +180,11 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, case InfoChart: { + /// 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"] ) ); qDebug() << Q_FUNC_INFO << "Getting chart url" << url; + /// @todo: Should add ChartPlugin nam here QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); reply->setProperty( "requestId", requestId ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); @@ -193,12 +207,15 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, if( !m_chartTypes.isEmpty() ) foreach( QVariant type, m_chartTypes ) { - // Itunes supplys charts based on geo, for now, only take US charts + /// Itunes supplys charts based on geo, for now, only take US charts + /// @todo: Add new breadcrumb option for country? if( type.toMap().value( "source" ).toString() == chartResource.toString() && type.toMap().value( "geo" ).isValid() && type.toMap().value( "geo" ).toString() != "us" ) continue; + /// Append each type to its parent source + /// @todo Add chartType enum if( type.toMap().value( "source" ).toString() == chartResource.toString() ) { if( type.toMap().value( "type" ).toString() == "Album" ) @@ -213,8 +230,13 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } } } + /// @note For displaying purposes, upper the first letter + /// @note Remeber to lower it when fetching this! + QString chartName = chartResource.toString(); + chartName[0] = chartName[0].toUpper(); - result.insert( chartResource.toString() , QVariant::fromValue( charts ) ); + /// Add the possible charts and its types to breadcrumb + result.insert( chartName , QVariant::fromValue( charts ) ); } emit info( requestId, @@ -224,8 +246,6 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, return; } - - default: { tLog() << "Couldn't figure out what to do with this type of request after cache miss"; @@ -235,56 +255,13 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } } - -void -ChartsPlugin::chartResources() -{ - - tDebug() << "ChartsPlugin: InfoChart resources returned!"; - QNetworkReply* reply = qobject_cast( sender() ); - - - if ( reply->error() == QNetworkReply::NoError ) - { - QJson::Parser p; - bool ok; - QVariantMap res = p.parse( reply, &ok ).toMap(); - - if ( !ok ) - { - tLog() << "Failed to parse resources" << p.errorString() << "On line" << p.errorLine(); - - return; - } - - m_chartResources = res.value( "chart_sources" ).toList(); - qDebug() << "Resources" << m_chartResources; - - if(!m_chartResources.isEmpty()){ - - foreach(QVariant resource, m_chartResources){ - tDebug() << "ChartsPlugin: InfoChart fetching possible types for "<< resource.toString(); - - QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); - qDebug() << "Getting types from " << url; - - QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); - - connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); - } - } - } - -} - void ChartsPlugin::chartTypes() { - + /// Get possible chart type for specific chart source tDebug() << "ChartsPlugin: InfoChart types returned!"; QNetworkReply* reply = qobject_cast( sender() ); - if ( reply->error() == QNetworkReply::NoError ) { QJson::Parser p; @@ -297,11 +274,9 @@ ChartsPlugin::chartTypes() return; } - - foreach(QVariant chart, res.value( "charts" ).toMap() ){ + /// Got types, append! + foreach(QVariant chart, res.value( "charts" ).toMap() ) m_chartTypes.append(chart); - qDebug() << "Chart types" << chart; - } } @@ -311,8 +286,8 @@ void ChartsPlugin::chartReturned() { + /// Chart request returned something! Woho QNetworkReply* reply = qobject_cast( sender() ); - QVariantMap returnedData; if ( reply->error() == QNetworkReply::NoError ) @@ -324,15 +299,16 @@ ChartsPlugin::chartReturned() if ( !ok ) { tLog() << "Failed to parse json from chart lookup:" << p.errorString() << "On line" << p.errorLine(); - return; - }else qDebug() << res; - + } + /// SO we have a result, parse it! QVariantList chartResponse = res.value( "list" ).toList(); QList top_tracks; QList top_albums; + /// Deside what type, we need to handle it differently + /// @todo: We allready know the type, append it to breadcrumb hash if( res.value( "type" ).toString() == "Album" ) setChartType( Album ); @@ -347,57 +323,77 @@ ChartsPlugin::chartReturned() QString title, artist, album; QVariantMap chartMap = chartR.toMap(); - if ( chartMap.contains( "track" ) ) + if( !chartMap.isEmpty() ) { title = chartMap.value( "track" ).toString(); + album = chartMap.value( "album" ).toString(); artist = chartMap.value( "artist" ).toString(); + /// Maybe we can use rank later on, to display something nice + /// rank = chartMap.value( "rank" ).toString(); - if ( title.isEmpty() && artist.isEmpty() ) // don't have enough... + if( chartType() == Album ) { - tLog() << "Didn't get an artist and track name from itunes, not enough to build a query on. Aborting" << title << artist << album; + /** HACK, billboard chart returns wrong typename **/ + if( res.value( "source" ).toString() == "billboard" ) + album = chartMap.value( "track" ).toString(); - } - else{ - - if( chartType() == Album ){ + 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; + }else + { + qDebug() << Q_FUNC_INFO << album << artist; ArtistAlbumPair pair; pair.artist = artist; - pair.album = title; + pair.album = album; top_albums << pair; - }else if( chartType() == Track ){ + } + } + + else if( chartType() == Track ) + { + + 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; + + }else{ ArtistTrackPair pair; pair.artist = artist; pair.track = title; top_tracks << pair; - } + } } } } - if( chartType() == Track ){ - tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks"; - returnedData["tracks"] = QVariant::fromValue( top_tracks ); - returnedData["type"] = "tracks"; - } - if( chartType() == Album ){ - tDebug() << "ChartsPlugin:" << "\tgot " << top_albums.size() << " albums"; - returnedData["albums"] = QVariant::fromValue( top_albums ); - returnedData["type"] = "albums"; - } + if( chartType() == Track ) + { + tDebug() << "ChartsPlugin:" << "\tgot " << top_tracks.size() << " tracks"; + returnedData["tracks"] = QVariant::fromValue( top_tracks ); + returnedData["type"] = "tracks"; + } - Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); + if( chartType() == Album ) + { + tDebug() << "ChartsPlugin:" << "\tgot " << top_albums.size() << " albums"; + returnedData["albums"] = QVariant::fromValue( top_albums ); + returnedData["type"] = "albums"; + } - emit info( - reply->property( "requestId" ).toUInt(), - requestData, - returnedData - ); - // TODO update cache + Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >(); + + emit info( + reply->property( "requestId" ).toUInt(), + requestData, + returnedData + ); + // TODO update cache }else qDebug() << "Network error"; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index b358f3a91..33f378744 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -52,7 +52,6 @@ public: public slots: void chartReturned(); - void chartResources(); void chartTypes(); void namChangedSlot( QNetworkAccessManager *nam ); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index a41bfea08..4960240e1 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -53,14 +53,15 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) { ui->setupUi( this ); + ui->additionsView->setFrameShape( QFrame::NoFrame ); + ui->additionsView->setAttribute( Qt::WA_MacShowFocusRect, 0 ); + TomahawkUtils::unmarginLayout( layout() ); TomahawkUtils::unmarginLayout( ui->stackLeft->layout() ); TomahawkUtils::unmarginLayout( ui->horizontalLayout->layout() ); TomahawkUtils::unmarginLayout( ui->horizontalLayout_2->layout() ); TomahawkUtils::unmarginLayout( ui->breadCrumbLeft->layout() ); - TomahawkUtils::unmarginLayout( ui->verticalLayout2->layout() ); - - + TomahawkUtils::unmarginLayout( ui->verticalLayout->layout() ); //set crumb widgets SiblingCrumbButtonFactory * crumbFactory = new SiblingCrumbButtonFactory; @@ -70,21 +71,16 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->breadCrumbLeft->setButtonFactory(crumbFactory); ui->breadCrumbLeft->setModel(m_crumbModelLeft); ui->breadCrumbLeft->setRootIcon(QIcon( RESPATH "images/charts.png" )); - //ui->breadCrumbLeft->setSelectionModel(selectionModelLeft); ui->breadCrumbLeft->setUseAnimation(true); connect(ui->breadCrumbLeft, SIGNAL(currentIndexChanged(QModelIndex)), SLOT(leftCrumbIndexChanged(QModelIndex))); - /*ui->breadCrumbRight->setButtonFactory(crumbFactory); - ui->breadCrumbRight->setRootIcon(QIcon( RESPATH "images/charts.png" )); - ui->breadCrumbRight->setModel(m_crumbModelLeft); - ui->breadCrumbRight->setUseAnimation(true);*/ - + m_albumsModel = new AlbumModel( ui->additionsView ); + ui->additionsView->setAlbumModel( m_albumsModel ); m_tracksModel = new PlaylistModel( ui->tracksViewLeft ); m_tracksModel->setStyle( TrackModel::ShortWithAvatars ); - ui->tracksViewLeft->setFrameShape( QFrame::NoFrame ); ui->tracksViewLeft->setAttribute( Qt::WA_MacShowFocusRect, 0 ); ui->tracksViewLeft->overlay()->setEnabled( false ); @@ -111,11 +107,6 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->artistsViewLeft->header()->setVisible( false ); - ui->albumsViewLeft->setFrameShape( QFrame::NoFrame ); - ui->albumsViewLeft->setAttribute( Qt::WA_MacShowFocusRect, 0 ); - - m_albumsModel = new AlbumModel( ui->albumsViewLeft ); - ui->albumsViewLeft->setAlbumModel( m_albumsModel ); m_timer = new QTimer( this ); connect( m_timer, SIGNAL( timeout() ), SLOT( checkQueries() ) ); @@ -193,7 +184,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat //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)); + ui->breadCrumbLeft->currentChangedTriggered(m_crumbModelLeft->index(0,0).child(0,0).child(0,0)); break; } case InfoSystem::InfoChart: @@ -226,13 +217,15 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { qDebug() << "Getting album" << album.album << "By" << album.artist; - album_ptr albumPtr = Album::get( 0, album.album, Artist::get( album.artist ) ); - al << albumPtr; + album_ptr albumPtr = Album::get(Artist::get( album.artist, true ), album.album ); + + if(!albumPtr.isNull()) + al << albumPtr; } qDebug() << "Adding albums to model"; m_albumsModel->addAlbums( al ); - qDebug() << "Added albums"; + } else if( type == "tracks" ) @@ -290,7 +283,8 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) Tomahawk::InfoSystem::InfoCriteriaHash criteria; criteria.insert("chart_id", chartId); - criteria.insert("chart_source", index.data().toString()); + /// Remember to lower the source! + criteria.insert("chart_source", index.data().toString().toLower()); Tomahawk::InfoSystem::InfoRequestData requestData; QVariantMap customData; diff --git a/src/libtomahawk/widgets/whatshotwidget.ui b/src/libtomahawk/widgets/whatshotwidget.ui index c1e857163..4caa5e32b 100644 --- a/src/libtomahawk/widgets/whatshotwidget.ui +++ b/src/libtomahawk/widgets/whatshotwidget.ui @@ -10,7 +10,7 @@ 513 - + @@ -45,21 +45,17 @@ - + - - - - - - 320 - 0 - + + + true + + + QAbstractItemView::ExtendedSelection - - From 8595539deaaef1bfd308b193a9ccf69e9a0d2db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sat, 8 Oct 2011 19:24:43 +0200 Subject: [PATCH 5/9] Charts --- .../infoplugins/generic/chartsplugin.cpp | 121 +++++++++++------- .../infoplugins/generic/chartsplugin.h | 5 +- .../infoplugins/generic/lastfmplugin.cpp | 28 +--- .../infosystem/infosystemworker.cpp | 8 +- src/libtomahawk/widgets/whatshotwidget.cpp | 3 +- 5 files changed, 85 insertions(+), 80 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 025308680..9254fa0fa 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "album.h" @@ -31,10 +32,10 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" -#include - -#define CHART_URL "http://charts.tomahawk-player.org:10080/" +//#define CHART_URL "http://charts.tomahawk-player.org:10080/" +#define CHART_URL "http://localhost:8080/" #include +#include using namespace Tomahawk::InfoSystem; @@ -50,23 +51,9 @@ ChartsPlugin::ChartsPlugin() : InfoPlugin() { - tDebug() << "ChartsPlugin: InfoChart fetching possible resources"; /// Add resources here - m_chartResources << "billboard" - << "itunes"; - - /// Then get each chart from resource - if(!m_chartResources.isEmpty()){ - - foreach(QVariant resource, m_chartResources) - { - QUrl url = QUrl( QString( CHART_URL "source/%1" ).arg(resource.toString() ) ); - QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); - connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); - } - } - + m_chartResources << "last.fm" << "billboard" << "itunes"; m_supportedGetTypes << InfoChart << InfoChartCapabilities; } @@ -81,9 +68,25 @@ ChartsPlugin::~ChartsPlugin() void ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) { + tDebug() << "ChartsPlugin: namChangedSLot"; + qDebug() << Q_FUNC_INFO; if( !nam ) return; + + m_nam = QWeakPointer< QNetworkAccessManager >( nam ); + + /// Then get each chart from resource + if( !m_chartResources.isEmpty() && m_nam && m_chartTypes.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 = m_nam.data()->get( QNetworkRequest( url ) ); + connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); + } + } } @@ -98,6 +101,9 @@ ChartsPlugin::dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData r void ChartsPlugin::getInfo( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ) { + qDebug() << Q_FUNC_INFO << requestData.caller; + qDebug() << Q_FUNC_INFO << requestData.customData; + switch ( requestData.type ) { @@ -168,13 +174,14 @@ ChartsPlugin::fetchChartCapabilities( uint requestId, Tomahawk::InfoSystem::Info void ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, Tomahawk::InfoSystem::InfoRequestData requestData ) { - if ( !lastfm::nam() ) + if ( !m_nam.data() ) { tLog() << "Have a null QNAM, uh oh"; emit info( requestId, requestData, QVariant() ); return; } + switch ( requestData.type ) { case InfoChart: @@ -184,8 +191,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, 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; - /// @todo: Should add ChartPlugin nam here - QNetworkReply* reply = lastfm::nam()->get( QNetworkRequest( url ) ); + QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); reply->setProperty( "requestId", requestId ); reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) ); @@ -197,36 +203,56 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, { QVariantMap result; + foreach( QVariant chartResource, m_chartResources ) { QList album_charts; QList track_charts; + QList artist_charts; QVariantMap charts; - if( !m_chartTypes.isEmpty() ) - foreach( QVariant type, m_chartTypes ) - { - /// Itunes supplys charts based on geo, for now, only take US charts - /// @todo: Add new breadcrumb option for country? - if( type.toMap().value( "source" ).toString() == chartResource.toString() - && type.toMap().value( "geo" ).isValid() - && type.toMap().value( "geo" ).toString() != "us" ) - continue; + if( chartResource.toString() == "last.fm") + { - /// Append each type to its parent source - /// @todo Add chartType enum - if( type.toMap().value( "source" ).toString() == chartResource.toString() ) + 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 + { + + foreach( QVariant type, m_chartTypes ) { - if( type.toMap().value( "type" ).toString() == "Album" ) + /// Itunes supplys charts based on geo, for now, only take US charts + /// @todo: Add new breadcrumb option for country? + /*if( type.toMap().value( "source" ).toString() == chartResource.toString() + && type.toMap().value( "geo" ).isValid() + && type.toMap().value( "geo" ).toString() != "us" ) + continue; + */ + /// Append each type to its parent source + /// @todo Add chartType enum + if( type.toMap().value( "source" ).toString() == chartResource.toString() ) { - album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); - charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); - } - if( type.toMap().value( "type" ).toString() == "Track" ) - { - track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); - charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + if( type.toMap().value( "type" ).toString() == "Album" ) + { + album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); + charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); + } + if( type.toMap().value( "type" ).toString() == "Track" ) + { + track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); + charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); + } } } } @@ -255,6 +281,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } } + void ChartsPlugin::chartTypes() { @@ -274,10 +301,12 @@ ChartsPlugin::chartTypes() return; } - /// Got types, append! - foreach(QVariant chart, res.value( "charts" ).toMap() ) - m_chartTypes.append(chart); + /// Got types, append! + foreach(QVariant chart, res.value( "charts" ).toMap() ){ + m_chartTypes.append(chart); + + } } } @@ -335,8 +364,8 @@ ChartsPlugin::chartReturned() if( chartType() == Album ) { /** HACK, billboard chart returns wrong typename **/ - if( res.value( "source" ).toString() == "billboard" ) - album = chartMap.value( "track" ).toString(); + //if( res.value( "source" ).toString() == "billboard" ) + // album = chartMap.value( "track" ).toString(); if ( album.isEmpty() && artist.isEmpty() ) // don't have enough... { diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 33f378744..32d0f2bd2 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -21,7 +21,7 @@ #include "infosystem/infosystem.h" #include "infosystem/infosystemworker.h" - +#include #include class QNetworkReply; @@ -71,6 +71,9 @@ private: QList m_charts; ChartType m_chartType; + QVariantMap m_chartResult; + bool chartHasReturned; + QWeakPointer< QNetworkAccessManager > m_nam; }; } diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index 55d08df0a..aa47e9e6c 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -416,32 +416,6 @@ 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"] ); @@ -495,7 +469,7 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash criteria, default: { - tLog() << "Couldn't figure out what to do with this type of request after cache miss"; + tLog() << Q_FUNC_INFO << "Couldn't figure out what to do with this type of request after cache miss"; emit info( requestId, requestData, QVariant() ); return; } diff --git a/src/libtomahawk/infosystem/infosystemworker.cpp b/src/libtomahawk/infosystem/infosystemworker.cpp index 0df655dfa..872d4f9b9 100644 --- a/src/libtomahawk/infosystem/infosystemworker.cpp +++ b/src/libtomahawk/infosystem/infosystemworker.cpp @@ -87,11 +87,9 @@ InfoSystemWorker::init( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache> cac m_plugins.append( mbptr ); registerInfoTypes( mbptr, mbptr.data()->supportedGetTypes(), mbptr.data()->supportedPushTypes() ); - - - InfoPluginPtr chartsptr( new ChartsPlugin() ); - m_plugins.append( chartsptr ); - registerInfoTypes( chartsptr, chartsptr.data()->supportedGetTypes(), chartsptr.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 ); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 4960240e1..23ba6ef3a 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -208,12 +208,13 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } else if( type == "albums" ) { + + /// @todo: Fill the empty albums with resolved ones. setLeftViewAlbums(); m_albumsModel->clear(); QList al; const QList albums = returnedData["albums"].value >(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); - foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { qDebug() << "Getting album" << album.album << "By" << album.artist; From 36855783a7bf7810a402fd5cd13696fe7d1a9b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sat, 8 Oct 2011 20:14:26 +0200 Subject: [PATCH 6/9] Now supports charts from last.fm, billboard, itunes. Known issue: sometimes fail to populate breadcrumb with itunes resource --- .../infosystem/infoplugins/generic/chartsplugin.cpp | 12 ++++++------ src/libtomahawk/widgets/whatshotwidget.cpp | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 9254fa0fa..69f8dee98 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -32,8 +32,8 @@ #include "utils/tomahawkutils.h" #include "utils/logger.h" -//#define CHART_URL "http://charts.tomahawk-player.org:10080/" -#define CHART_URL "http://localhost:8080/" +#define CHART_URL "http://charts.tomahawk-player.org:10080/" +//#define CHART_URL "http://localhost:8080/" #include #include @@ -234,11 +234,11 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, { /// Itunes supplys charts based on geo, for now, only take US charts /// @todo: Add new breadcrumb option for country? - /*if( type.toMap().value( "source" ).toString() == chartResource.toString() + if( type.toMap().value( "source" ).toString() == chartResource.toString() && type.toMap().value( "geo" ).isValid() && type.toMap().value( "geo" ).toString() != "us" ) continue; - */ + /// Append each type to its parent source /// @todo Add chartType enum if( type.toMap().value( "source" ).toString() == chartResource.toString() ) @@ -364,8 +364,8 @@ ChartsPlugin::chartReturned() if( chartType() == Album ) { /** HACK, billboard chart returns wrong typename **/ - //if( res.value( "source" ).toString() == "billboard" ) - // album = chartMap.value( "track" ).toString(); + if( res.value( "source" ).toString() == "billboard" ) + album = chartMap.value( "track" ).toString(); if ( album.isEmpty() && artist.isEmpty() ) // don't have enough... { diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 23ba6ef3a..c048fba66 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -208,13 +208,12 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat } else if( type == "albums" ) { - - /// @todo: Fill the empty albums with resolved ones. setLeftViewAlbums(); m_albumsModel->clear(); QList al; const QList albums = returnedData["albums"].value >(); tDebug( LOGVERBOSE ) << "WhatsHot: got albums! " << albums.size(); + foreach ( const Tomahawk::InfoSystem::ArtistAlbumPair& album, albums ) { qDebug() << "Getting album" << album.album << "By" << album.artist; @@ -227,7 +226,6 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat qDebug() << "Adding albums to model"; m_albumsModel->addAlbums( al ); - } else if( type == "tracks" ) { From 777ebd77c83421b419d1cee0897fedd220cac8c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sun, 9 Oct 2011 13:28:43 +0200 Subject: [PATCH 7/9] Now fills itunes chart correctly --- .../infoplugins/generic/chartsplugin.cpp | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 69f8dee98..69ffba174 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -86,6 +86,7 @@ ChartsPlugin::namChangedSlot( QNetworkAccessManager *nam ) QNetworkReply* reply = m_nam.data()->get( QNetworkRequest( url ) ); connect( reply, SIGNAL( finished() ), SLOT( chartTypes() ) ); } + } } @@ -204,6 +205,20 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, QVariantMap result; + /// Itunes have alot of country specified charts, + /// Get those for later use + QList geos; + foreach( QVariant type, m_chartTypes ) + { + + if( type.toMap().value( "geo" ).isValid() ) { + + geos.append( type.toMap().value( "geo" ).toString() ); + } + } + /// We only need a unique list + geos = QSet::fromList(geos).toList(); + foreach( QVariant chartResource, m_chartResources ) { @@ -227,17 +242,55 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } - else + else if( chartResource.toString() == "itunes") { + QVariantMap geoCharts; - foreach( QVariant type, m_chartTypes ) + foreach(QVariant country, geos) + { + QList geoAlbum_charts; + QList geoTrack_charts; + + foreach( QVariant type, m_chartTypes ) { + /// Itunes supplys charts based on geo, for now, only take US charts /// @todo: Add new breadcrumb option for country? if( type.toMap().value( "source" ).toString() == chartResource.toString() - && type.toMap().value( "geo" ).isValid() - && type.toMap().value( "geo" ).toString() != "us" ) - continue; + && type.toMap().value( "geo" ).isValid() ) + { + + if( type.toMap().value( "geo" ).toString() == country.toString() ) + { + QString countryString = "Geo: " + type.toMap().value( "geo" ).toString().toUpper(); + + if( type.toMap().value( "type" ).toString() == "Album" ) + { + geoAlbum_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString() , "album" ) ); + geoCharts.insert( "Albums", QVariant::fromValue >( geoAlbum_charts ) ); + charts.insert( countryString, QVariant::fromValue( geoCharts ) ); + } + + if( type.toMap().value( "type" ).toString() == "Track" ) + { + + geoTrack_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); + geoCharts.insert( "Tracks", QVariant::fromValue >( geoTrack_charts ) ); + charts.insert( countryString, QVariant::fromValue( geoCharts ) ); + + } + } + + } + } + } + + }else{ + + foreach( QVariant type, m_chartTypes ) + { + // && type.toMap().value( "geo" ).toString() != "us" ) + // continue; /// Append each type to its parent source /// @todo Add chartType enum @@ -254,8 +307,9 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, charts.insert( "Tracks", QVariant::fromValue >( track_charts ) ); } } - } - } + } + } + /// @note For displaying purposes, upper the first letter /// @note Remeber to lower it when fetching this! QString chartName = chartResource.toString(); From 8a9a48fda1cff3a13f0779dc9e1ad9a6d29d2f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sun, 9 Oct 2011 14:13:39 +0200 Subject: [PATCH 8/9] Style fix --- .../infoplugins/generic/chartsplugin.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 69ffba174..429e5c376 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -211,8 +211,8 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, foreach( QVariant type, m_chartTypes ) { - if( type.toMap().value( "geo" ).isValid() ) { - + if( type.toMap().value( "geo" ).isValid() ) + { geos.append( type.toMap().value( "geo" ).toString() ); } } @@ -252,10 +252,10 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, QList geoTrack_charts; foreach( QVariant type, m_chartTypes ) - { + { + + /// Itunes supplys charts based on geo, create breadcrumb for each of them - /// Itunes supplys charts based on geo, for now, only take US charts - /// @todo: Add new breadcrumb option for country? if( type.toMap().value( "source" ).toString() == chartResource.toString() && type.toMap().value( "geo" ).isValid() ) { @@ -280,17 +280,14 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, } } - } } } }else{ - + /// Billboard, and maybe others foreach( QVariant type, m_chartTypes ) { - // && type.toMap().value( "geo" ).toString() != "us" ) - // continue; /// Append each type to its parent source /// @todo Add chartType enum @@ -301,6 +298,7 @@ ChartsPlugin::notInCacheSlot( uint requestId, QHash criteria, album_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "album" ) ); charts.insert( "Albums", QVariant::fromValue >( album_charts ) ); } + if( type.toMap().value( "type" ).toString() == "Track" ) { track_charts.append( Chart( type.toMap().value("id").toString(), type.toMap().value("name").toString(), "tracks" ) ); From 9749df00d196e961d7b627fa9f84791aee60c6e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sun, 9 Oct 2011 14:15:22 +0200 Subject: [PATCH 9/9] Increase timer, fixes itunes breadcrumb init --- src/libtomahawk/widgets/whatshotwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index c048fba66..b1bf9f9b4 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -118,8 +118,8 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); - - QTimer::singleShot( 0, this, SLOT( fetchData() ) ); + /// Itunes response is big, so maybe wait for it here? + QTimer::singleShot( 1000, this, SLOT( fetchData() ) ); }