From a1874a941d77da61d48c8e59e7f373f5938087c9 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 14 Jun 2012 09:20:41 +0200 Subject: [PATCH] Sort new releases by date, show newest release first. --- .../generic/newreleases/NewReleasesPlugin.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp b/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp index 54910bf49..b5b2ae1a2 100644 --- a/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp +++ b/src/infoplugins/generic/newreleases/NewReleasesPlugin.cpp @@ -24,6 +24,20 @@ using namespace Tomahawk::InfoSystem; +bool newReleaseSort( const InfoStringHash& left, const InfoStringHash& right ) +{ + if ( !left.contains( "date" ) || !right.contains( "date" ) ) + { + return true; + } + + const QDate lDate = QDate::fromString( left[ "date" ], "yyyy-MM-dd" ); + const QDate rDate = QDate::fromString( right[ "date" ], "yyyy-MM-dd" ); + + return lDate > rDate; +} + + NewReleasesPlugin::NewReleasesPlugin() : InfoPlugin() , m_nrFetchJobs ( 0 ) @@ -274,6 +288,7 @@ void NewReleasesPlugin::nrList() } } + if ( !albumNRs.isEmpty() ) newreleases.insert ( tr ( "Albums" ), QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > > ( albumNRs ) ); @@ -334,11 +349,14 @@ void NewReleasesPlugin::nrReturned() Tomahawk::InfoSystem::InfoStringHash pair; pair["artist"] = artist; pair["album"] = album; + pair["date"] = date; newreleases.append( pair ); } } - tDebug() << "NewReleasesPlugin:" << "\tgot " << newreleases.size() << " albums"; + qSort( newreleases.begin(), newreleases.end(), newReleaseSort ); + +// tDebug() << "NewReleasesPlugin:" << "\tgot " << newreleases.size() << " albums"; returnedData[ "albums" ] = QVariant::fromValue< QList< Tomahawk::InfoSystem::InfoStringHash > >( newreleases ); returnedData[ "type" ] = "albums"; Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();