xbmc/xbmc — pull request #5164 by Montellese (2014-08-05 21:07:47+00:00)
Title: Proper support for "unsorted" behaviour

This is an initial approach at properly handling sorting the items in a list by the original order they were added to the list. Right now we are abusing CFileItem::m_iprogramCount (what is that one used for anyway?) for this all over the place.

Furthermore the old SORT_METHOD_UNSORTED available to plugins is broken (see http://trac.xbmc.org/ticket/10252) as it is translated to SortByNone which simply does nothing (i.e. keep the items in a list sorted in the same order as the previous sort order which can be anything). Plugins can work around that by properly setting m_iprogramCount and using SORT_METHOD_PLAYLIST but it requires quite a bit of extra work and the knowledge that it's actually required.

Therefore I've added a new member CFileItem::m_iPosition which is automatically set in a CFileItem when it is added to a CFileItemList and updated whenever the items in the list change.

I wasn't sure if we could move some places in the code that use the m_iprogramCount and SortByPlaylist workaround because the sort order might be stored in the database so switching from SortByPlaylist to SortByUnsorted might result in unexpected behaviour with stored views.

Is this something we want or do we want to keep using the m_iprogramCount workaround (and maybe just remove the comments about it being a hack)? Does anyone know if there's an actual use case to CFileItem::m_iprogramCount?