From 9753e3c71f50f6e3c69a484d65604e4442cc9d7e Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 15 Apr 2013 10:08:20 +0200 Subject: [PATCH] Fix ordering, again, this time we stick to whatever is in the db. --- src/libtomahawk/playlist/InboxModel.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index 871028318..03b9d954d 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -133,7 +133,7 @@ InboxModel::loadTracks() QString sql = QString( "SELECT track.name as title, artist.name as artist, source, v as unlistened, social_attributes.timestamp " "FROM social_attributes, track, artist " "WHERE social_attributes.id = track.id AND artist.id = track.artist AND social_attributes.k = 'Inbox' " - "ORDER BY social_attributes.timestamp DESC" ); + "ORDER BY social_attributes.timestamp" ); DatabaseCommand_GenericSelect* cmd = new DatabaseCommand_GenericSelect( sql, DatabaseCommand_GenericSelect::Track, -1, 0 ); connect( cmd, SIGNAL( tracks( QList ) ), this, SLOT( tracksLoaded( QList ) ) ); @@ -142,7 +142,7 @@ InboxModel::loadTracks() void -InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > newTracks ) +InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > incoming ) { finishLoading(); @@ -151,6 +151,15 @@ InboxModel::tracksLoaded( QList< Tomahawk::query_ptr > newTracks ) foreach ( const Tomahawk::plentry_ptr ple, playlistEntries() ) tracks << ple->query(); + //We invert the result of the SQLite query. + //NOTE: this operation relies on the fact that SQLite always seems to return the records in + // their original order of insertion when the ORDER BY criterion is equal for some records + // (i.e. a stable sort). This assumption might not be true for other things that talk SQL, + // but it should work for us as long as we stick with SQLite. -- Teo + QList< Tomahawk::query_ptr > newTracks; + while ( !incoming.isEmpty() ) + newTracks.append( incoming.takeLast() ); + foreach ( Tomahawk::query_ptr newQuery, newTracks ) { QVariantList extraData = newQuery->property( "data" ).toList();