I think I have found the problem: the current XBMC has distinct code for loading movies/shows/etc by directory or by playlist.
When loading from smart-playlists, all items are always sort using the current sort method and order (inside CGUIMediaWindow->SortItems()): this method creates a CGUIViewState instance, whose type changes depending on the item type (movies, tvshows), and every item type has different order methods (specified in the class constructor).
The current costructor for CGUIViewStateVideoTVShows is the following:
Code:
CGUIViewStateVideoTVShows::CGUIViewStateVideoTVShows(const CFileItemList& items) : CGUIViewStateWindowVideo(items)
{
if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS("%L", "%M", "%L", "%M")); // Label, #Episodes | Label, #Episodes
else
AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%L", "%M", "%L", "%M")); // Label, #Episodes | Label, #Episodes
AddSortMethod(SORT_METHOD_YEAR, 562, LABEL_MASKS("%L","%Y","%L","%Y")); // Label, Year | Label, Year
if (items.IsSmartPlayList() || items.GetProperty("library.filter").asBoolean())
{
AddSortMethod(SORT_METHOD_PLAYLIST_ORDER, 559, LABEL_MASKS("%L", "%M", "%L", "%M")); // Label, #Episodes | Label, #Episodes
SetSortMethod(SORT_METHOD_PLAYLIST_ORDER);
}
else
SetSortMethod(g_settings.m_viewStateVideoNavTvShows.m_sortMethod);
SetViewAsControl(g_settings.m_viewStateVideoNavTvShows.m_viewMode);
SetSortOrder(g_settings.m_viewStateVideoNavTvShows.m_sortOrder);
LoadViewState(items.GetPath(), WINDOW_VIDEO_NAV);
}
This code sorts by label and episode count (for tvshows the label is always set to the show title, not the sort title).
So I replaced the label field with the sort title field (as in the movies class constructor):
Code:
CGUIViewStateVideoTVShows::CGUIViewStateVideoTVShows(const CFileItemList& items) : CGUIViewStateWindowVideo(items)
{
if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 551, LABEL_MASKS("%T", "%M", "%T", "%M")); // Title, #Episodes | Title, #Episodes
else
AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 551, LABEL_MASKS("%T", "%M", "%T", "%M")); // Title, #Episodes | Title, #Episodes
AddSortMethod(SORT_METHOD_YEAR, 562, LABEL_MASKS("%T", "%Y", "%T", "%Y")); // Title, Year | Title, Year
if (items.IsSmartPlayList() || items.GetProperty("library.filter").asBoolean())
{
AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 551, LABEL_MASKS("%T", "%M", "%T", "%M")); // Title, #Episodes | Title, #Episodes
SetSortMethod(SORT_METHOD_PLAYLIST_ORDER);
}
else
SetSortMethod(g_settings.m_viewStateVideoNavTitles.m_sortMethod);
SetViewAsControl(g_settings.m_viewStateVideoNavTvShows.m_viewMode);
SetSortOrder(g_settings.m_viewStateVideoNavTvShows.m_sortOrder);
LoadViewState(items.GetPath(), WINDOW_VIDEO_NAV);
}
This way XBMC uses the sort title for tvshows too.
I tried on my computer and tvshows are correctly sorted by sorttitle even inside playlists.
Is this ok for a commit?