1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 15:29:42 +01:00

Sort new releases by date, show newest release first.

This commit is contained in:
Leo Franchi 2012-06-14 09:20:41 +02:00
parent a512d85672
commit a1874a941d

View File

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