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 >();