From f796f1f1330409a171491d829a6e5a8182e34842 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell <tomahawk@jefferai.org> Date: Thu, 20 Oct 2011 16:46:09 -0400 Subject: [PATCH] Remove unnecessary Chart type from InfoSytem. It was just mapping strings, so just use a string map we already have --- .../infoplugins/generic/chartsplugin.cpp | 38 ++++++++++++------- .../infoplugins/generic/chartsplugin.h | 2 +- .../infoplugins/generic/lastfmplugin.cpp | 33 +++++++++++----- src/libtomahawk/infosystem/infosystem.h | 14 ------- src/libtomahawk/widgets/whatshotwidget.cpp | 10 ++--- src/tomahawkapp.cpp | 2 - 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 8c6da8048..924e42a89 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -317,11 +317,14 @@ ChartsPlugin::chartTypes() if ( name.startsWith( "iTunes Store:" ) ) // truncate name = name.mid( 13 ); - const Chart c( id, name, "album" ); - QList<Chart> countryTypeData = countries[ country ][ type ].value<QList<Chart> >(); + InfoStringHash c; + c[ "id" ] = id; + c[ "label" ] = name; + c[ "type" ] = "album"; + QList<InfoStringHash> countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >(); countryTypeData.append( c ); - countries[ country ].insert( type, QVariant::fromValue<QList<Chart> >( countryTypeData ) ); + countries[ country ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( countryTypeData ) ); } foreach( const QString& c, countries.keys() ) @@ -335,21 +338,28 @@ ChartsPlugin::chartTypes() // We'll just build: // [Source] - Album - Chart Type // [Source] - Track - Chart Type - QList< Chart > albumCharts; - QList< Chart > trackCharts; + QList< InfoStringHash > albumCharts; + QList< InfoStringHash > trackCharts; foreach( const QVariant& chartObj, chartObjs.values() ) { const QVariantMap chart = chartObj.toMap(); const QString type = chart.value( "type" ).toString(); - const QString id = chart.value( "id" ).toString(); - const QString name = chart.value( "name" ).toString(); + InfoStringHash c; + c[ "id" ] = chart.value( "id" ).toString(); + c[ "label" ] = chart.value( "name" ).toString(); if ( type == "Album" ) - albumCharts.append( Chart( id, name, "album" ) ); + { + c[ "type" ] = "album"; + albumCharts.append( c ); + } else if ( type == "Track" ) - trackCharts.append( Chart( id, name, "tracks" ) ); + { + c[ "type" ] = "tracks"; + trackCharts.append( c ); + } } - charts.insert( tr( "Albums" ), QVariant::fromValue< QList<Chart> >( albumCharts ) ); - charts.insert( tr( "Tracks" ), QVariant::fromValue< QList<Chart> >( trackCharts ) ); + charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) ); + charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) ); /// @note For displaying purposes, upper the first letter /// @note Remeber to lower it when fetching this! @@ -359,7 +369,7 @@ ChartsPlugin::chartTypes() /// Add the possible charts and its types to breadcrumb // qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName; - m_allChartsMap.insert( chartName , QVariant::fromValue<QVariantMap>( charts ) ); + m_allChartsMap.insert( chartName , QVariant::fromValue< QVariantMap >( charts ) ); } else @@ -402,8 +412,8 @@ ChartsPlugin::chartReturned() /// SO we have a result, parse it! QVariantList chartResponse = res.value( "list" ).toList(); - QList<InfoStringHash> top_tracks; - QList<InfoStringHash> top_albums; + QList< InfoStringHash > top_tracks; + QList< InfoStringHash > top_albums; /// Deside what type, we need to handle it differently /// @todo: We allready know the type, append it to breadcrumb hash diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h index 3a75f1f0b..3d35b39cf 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.h @@ -67,7 +67,7 @@ private: void dataError( uint requestId, Tomahawk::InfoSystem::InfoRequestData requestData ); QVariantList m_chartResources; - QList<Chart> m_charts; + QList<InfoStringHash> m_charts; ChartType m_chartType; QVariantMap m_allChartsMap; diff --git a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp index 8b5d477bd..ae99903ec 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp @@ -434,18 +434,33 @@ LastFmPlugin::notInCacheSlot( uint requestId, QHash<QString, QString> criteria, case InfoChartCapabilities: { - QList<Chart> 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< InfoStringHash > track_charts; + InfoStringHash c; + c[ "type" ] = "tracks"; + c[ "id" ] = "chart.getTopTracks"; + c[ "label" ] = "Top Tracks"; + track_charts.append( c ); + c[ "id" ] = "chart.getLovedTracks"; + c[ "label" ] = "Loved Tracks"; + track_charts.append( c ); + c[ "id" ] = "chart.getHypedTracks"; + c[ "label" ] = "Hyped Tracks"; + track_charts.append( c ); - QList<Chart> artist_charts; - artist_charts.append( Chart( "chart.getTopArtists", "Top Artists", "artists" ) ); - artist_charts.append( Chart( "chart.getHypedArtists", "Hyped Artists", "artists" ) ); + QList< InfoStringHash > artist_charts; + c[ "type" ] = "artists"; + c[ "id" ] = "chart.getTopArtists"; + c[ "label" ] = "Top Artists"; + artist_charts.append( c ); + c[ "id" ] = "chart.getHypedArtists"; + c[ "label" ] = "Hyped Artists"; + artist_charts.append( c ); + + QVariantMap charts; - charts.insert( "Tracks", QVariant::fromValue<QList<Chart> >( track_charts ) ); - charts.insert( "Artists", QVariant::fromValue<QList<Chart> >( artist_charts ) ); + charts.insert( "Tracks", QVariant::fromValue< QList< InfoStringHash > >( track_charts ) ); + charts.insert( "Artists", QVariant::fromValue< QList< InfoStringHash > >( artist_charts ) ); QVariantMap result; result.insert( "Last.fm", QVariant::fromValue<QVariantMap>( charts ) ); diff --git a/src/libtomahawk/infosystem/infosystem.h b/src/libtomahawk/infosystem/infosystem.h index ee6662037..ebef34a42 100644 --- a/src/libtomahawk/infosystem/infosystem.h +++ b/src/libtomahawk/infosystem/infosystem.h @@ -130,18 +130,6 @@ struct InfoRequestData { QVariantMap customData; }; -struct Chart { - Chart(){} - Chart(const QString _id, const QString _label, const QString _type) { - id = _id; - label = _label; - type = _type; - } - QString id; - QString label; - QString type; -}; - typedef QMap< InfoType, QVariant > InfoTypeMap; typedef QMap< InfoType, uint > InfoTimeoutMap; typedef QHash< QString, QString > InfoStringHash; @@ -276,8 +264,6 @@ inline uint qHash( Tomahawk::InfoSystem::InfoStringHash hash ) Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoRequestData ); Q_DECLARE_METATYPE( Tomahawk::InfoSystem::InfoStringHash ); Q_DECLARE_METATYPE( QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > ); -Q_DECLARE_METATYPE( Tomahawk::InfoSystem::Chart ); Q_DECLARE_METATYPE( QList<Tomahawk::InfoSystem::InfoStringHash> ); -Q_DECLARE_METATYPE( QList<Tomahawk::InfoSystem::Chart> ); #endif // TOMAHAWK_INFOSYSTEM_H diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 38e444ee3..3f2fb795c 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -334,13 +334,13 @@ WhatsHotWidget::parseNode( QStandardItem* parentItem, const QString &label, cons QStandardItem *sourceItem = new QStandardItem(label); - if ( data.canConvert<QList<Tomahawk::InfoSystem::Chart> >() ) + if ( data.canConvert< QList< Tomahawk::InfoSystem::InfoStringHash > >() ) { - QList<Tomahawk::InfoSystem::Chart> charts = data.value<QList<Tomahawk::InfoSystem::Chart> >(); - foreach ( Tomahawk::InfoSystem::Chart chart, charts) + QList< Tomahawk::InfoSystem::InfoStringHash > charts = data.value< QList< Tomahawk::InfoSystem::InfoStringHash > >(); + foreach ( Tomahawk::InfoSystem::InfoStringHash chart, charts ) { - QStandardItem *childItem= new QStandardItem( chart.label ); - childItem->setData( chart.id ); + QStandardItem *childItem= new QStandardItem( chart[ "label" ] ); + childItem->setData( chart[ "id" ] ); sourceItem->appendRow( childItem ); } } diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 798684eab..c2a3c098b 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -414,8 +414,6 @@ TomahawkApp::registerMetaTypes() qRegisterMetaType< QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache > >( "QWeakPointer< Tomahawk::InfoSystem::InfoSystemCache >" ); qRegisterMetaType< QList<Tomahawk::InfoSystem::InfoStringHash> >("QList<Tomahawk::InfoSystem::InfoStringHash>"); - qRegisterMetaType< Tomahawk::InfoSystem::Chart>("Tomahawk::InfoSystem::Chart"); - qRegisterMetaType< QList<Tomahawk::InfoSystem::Chart> >("QList<Tomahawk::InfoSystem::Chart>"); qRegisterMetaType< QPersistentModelIndex >( "QPersistentModelIndex" ); }