Skip to content

Commit

Permalink
Merge pull request #1686 from jmarshallnz/sort_those_nodes
Browse files Browse the repository at this point in the history
Store sorting information for smartplaylists and library nodes
  • Loading branch information
Arne Morten Kvarving committed Nov 8, 2012
2 parents 5132cf8 + 49e2160 commit 73c9e9f
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 210 deletions.
134 changes: 11 additions & 123 deletions xbmc/FileItem.cpp
Expand Up @@ -702,7 +702,17 @@ void CFileItem::ToSortable(SortItem &sortable)
GetMusicInfoTag()->ToSortable(sortable);

if (HasVideoInfoTag())
{
GetVideoInfoTag()->ToSortable(sortable);

if (GetVideoInfoTag()->m_type == "tvshow")
{
if (HasProperty("totalepisodes"))
sortable[FieldNumberOfEpisodes] = GetProperty("totalepisodes");
if (HasProperty("unwatchedepisodes"))
sortable[FieldNumberOfWatchedEpisodes] = GetProperty("unwatchedepisodes");
}
}

if (HasPictureInfoTag())
GetPictureInfoTag()->ToSortable(sortable);
Expand Down Expand Up @@ -1825,131 +1835,9 @@ void CFileItemList::Sort(SORT_METHOD sortMethod, SortOrder sortOrder)
if (sortMethod == m_sortMethod && m_sortOrder == sortOrder)
return;

SortDescription sorting;
SortDescription sorting = SortUtils::TranslateOldSortMethod(sortMethod);
sorting.sortOrder = sortOrder;

switch (sortMethod)
{
case SORT_METHOD_LABEL:
case SORT_METHOD_LABEL_IGNORE_FOLDERS:
case SORT_METHOD_LABEL_IGNORE_THE:
sorting.sortBy = SortByLabel;
break;
case SORT_METHOD_DATE:
sorting.sortBy = SortByDate;
break;
case SORT_METHOD_SIZE:
sorting.sortBy = SortBySize;
break;
case SORT_METHOD_BITRATE:
sorting.sortBy = SortByBitrate;
break;
case SORT_METHOD_DRIVE_TYPE:
sorting.sortBy = SortByDriveType;
break;
case SORT_METHOD_TRACKNUM:
sorting.sortBy = SortByTrackNumber;
break;
case SORT_METHOD_EPISODE:
sorting.sortBy = SortByEpisodeNumber;
break;
case SORT_METHOD_DURATION:
case SORT_METHOD_VIDEO_RUNTIME:
sorting.sortBy = SortByTime;
break;
case SORT_METHOD_TITLE:
case SORT_METHOD_TITLE_IGNORE_THE:
case SORT_METHOD_VIDEO_TITLE:
sorting.sortBy = SortByTitle;
break;
case SORT_METHOD_ARTIST:
case SORT_METHOD_ARTIST_IGNORE_THE:
sorting.sortBy = SortByArtist;
break;
case SORT_METHOD_ALBUM:
case SORT_METHOD_ALBUM_IGNORE_THE:
sorting.sortBy = SortByAlbum;
break;
case SORT_METHOD_GENRE:
sorting.sortBy = SortByGenre;
break;
case SORT_METHOD_COUNTRY:
sorting.sortBy = SortByCountry;
break;
case SORT_METHOD_DATEADDED:
sorting.sortBy = SortByDateAdded;
break;
case SORT_METHOD_FILE:
sorting.sortBy = SortByFile;
break;
case SORT_METHOD_SONG_RATING:
case SORT_METHOD_VIDEO_RATING:
sorting.sortBy = SortByRating;
break;
case SORT_METHOD_VIDEO_SORT_TITLE:
case SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE:
sorting.sortBy = SortBySortTitle;
break;
case SORT_METHOD_YEAR:
sorting.sortBy = SortByYear;
break;
case SORT_METHOD_PRODUCTIONCODE:
sorting.sortBy = SortByProductionCode;
break;
case SORT_METHOD_PROGRAM_COUNT:
sorting.sortBy = SortByProgramCount;
break;
case SORT_METHOD_PLAYLIST_ORDER:
sorting.sortBy = SortByPlaylistOrder;
break;
case SORT_METHOD_MPAA_RATING:
sorting.sortBy = SortByMPAA;
break;
case SORT_METHOD_STUDIO:
case SORT_METHOD_STUDIO_IGNORE_THE:
sorting.sortBy = SortByStudio;
break;
case SORT_METHOD_FULLPATH:
sorting.sortBy = SortByPath;
break;
case SORT_METHOD_LASTPLAYED:
sorting.sortBy = SortByLastPlayed;
break;
case SORT_METHOD_PLAYCOUNT:
sorting.sortBy = SortByPlaycount;
break;
case SORT_METHOD_LISTENERS:
sorting.sortBy = SortByListeners;
break;
case SORT_METHOD_CHANNEL:
sorting.sortBy = SortByChannel;
break;
default:
CLog::Log(LOGWARNING, "Unknown sort method %d", sortMethod);
return;
}

if (sortMethod == SORT_METHOD_LABEL_IGNORE_THE ||
sortMethod == SORT_METHOD_TITLE_IGNORE_THE ||
sortMethod == SORT_METHOD_ARTIST_IGNORE_THE ||
sortMethod == SORT_METHOD_ALBUM_IGNORE_THE ||
sortMethod == SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE ||
sortMethod == SORT_METHOD_STUDIO_IGNORE_THE)
sorting.sortAttributes = (SortAttribute)((int)sorting.sortAttributes | SortAttributeIgnoreArticle);

if (sortMethod == SORT_METHOD_FILE ||
sortMethod == SORT_METHOD_VIDEO_SORT_TITLE ||
sortMethod == SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE ||
sortMethod == SORT_METHOD_LABEL_IGNORE_FOLDERS ||
sortMethod == SORT_METHOD_DATEADDED ||
sortMethod == SORT_METHOD_VIDEO_RATING ||
sortMethod == SORT_METHOD_YEAR ||
sortMethod == SORT_METHOD_PLAYLIST_ORDER ||
sortMethod == SORT_METHOD_LASTPLAYED ||
sortMethod == SORT_METHOD_PLAYCOUNT ||
m_sortIgnoreFolders)
sorting.sortAttributes = (SortAttribute)((int)sorting.sortAttributes | SortAttributeIgnoreFolders);

Sort(sorting);

m_sortMethod = sortMethod;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/FileItem.h
Expand Up @@ -29,7 +29,7 @@
#include "utils/ISerializable.h"
#include "utils/ISortable.h"
#include "XBDateTime.h"
#include "SortFileItem.h"
#include "utils/SortUtils.h"
#include "utils/LabelFormatter.h"
#include "GUIPassword.h"
#include "threads/CriticalSection.h"
Expand Down
35 changes: 34 additions & 1 deletion xbmc/GUIViewState.cpp
Expand Up @@ -47,6 +47,10 @@
#if defined(TARGET_ANDROID)
#include "filesystem/AndroidAppDirectory.h"
#endif

#define PROPERTY_SORT_ORDER "sort.order"
#define PROPERTY_SORT_ASCENDING "sort.ascending"

using namespace std;
using namespace ADDON;
using namespace PVR;
Expand Down Expand Up @@ -244,11 +248,14 @@ void CGUIViewState::GetSortMethodLabelMasks(LABEL_MASKS& masks) const

void CGUIViewState::AddSortMethod(SORT_METHOD sortMethod, int buttonLabel, LABEL_MASKS labelmasks)
{
for (size_t i = 0; i < m_sortMethods.size(); ++i)
if (m_sortMethods[i].m_sortMethod == sortMethod)
return;

SORT_METHOD_DETAILS sort;
sort.m_sortMethod=sortMethod;
sort.m_buttonLabel=buttonLabel;
sort.m_labelMasks=labelmasks;

m_sortMethods.push_back(sort);
}

Expand Down Expand Up @@ -469,6 +476,32 @@ void CGUIViewState::SaveViewToDb(const CStdString &path, int windowID, CViewStat
}
}

void CGUIViewState::AddPlaylistOrder(const CFileItemList &items, LABEL_MASKS label_masks)
{
SORT_METHOD sortMethod = SORT_METHOD_PLAYLIST_ORDER;
int sortLabel = 559;
SortOrder sortOrder = SortOrderAscending;
if (items.HasProperty(PROPERTY_SORT_ORDER))
{
SortBy sortBy = (SortBy)items.GetProperty(PROPERTY_SORT_ORDER).asInteger();
if (sortBy != SortByNone)
{
sortMethod = SortUtils::TranslateOldSortMethod(sortBy, g_guiSettings.GetBool("filelists.ignorethewhensorting"));
if (sortMethod == SORT_METHOD_NONE)
sortMethod = SORT_METHOD_PLAYLIST_ORDER;
else
{
sortLabel = SortUtils::GetSortLabel(sortBy);
sortOrder = items.GetProperty(PROPERTY_SORT_ASCENDING).asBoolean() ? SortOrderAscending : SortOrderDescending;
}
}
}
AddSortMethod(sortMethod, sortLabel, label_masks);
SetSortMethod(sortMethod);
SetSortOrder(sortOrder);
}


CGUIViewStateFromItems::CGUIViewStateFromItems(const CFileItemList &items) : CGUIViewState(items)
{
const vector<SORT_METHOD_DETAILS> &details = items.GetSortDetails();
Expand Down
9 changes: 8 additions & 1 deletion xbmc/GUIViewState.h
Expand Up @@ -21,7 +21,7 @@
*/

#include "utils/LabelFormatter.h"
#include "SortFileItem.h"
#include "utils/SortUtils.h"
#include "MediaSource.h"

class CViewState; // forward
Expand Down Expand Up @@ -76,6 +76,13 @@ class CGUIViewState
#endif
void AddLiveTVSources();

/*! \brief Add the sort order defined in a smartplaylist
Defaults to SORT_METHOD_PLAYLIST_ORDER if no order is defined.
\param items the list of items for the view state.
\param label_mask the label masks for formatting items.
*/
void AddPlaylistOrder(const CFileItemList &items, LABEL_MASKS label_masks);

void AddSortMethod(SORT_METHOD sortMethod, int buttonLabel, LABEL_MASKS labelmasks);
void SetSortMethod(SORT_METHOD sortMethod);
void SetSortOrder(SortOrder sortOrder);
Expand Down
1 change: 0 additions & 1 deletion xbmc/SortFileItem.h
Expand Up @@ -20,7 +20,6 @@
*/

#include "utils/LabelFormatter.h"
#include "utils/SortUtils.h"

typedef enum {
SORT_METHOD_NONE=0,
Expand Down
2 changes: 1 addition & 1 deletion xbmc/ViewState.h
Expand Up @@ -19,7 +19,7 @@
*
*/

#include "SortFileItem.h"
#include "utils/SortUtils.h"

#define DEFAULT_VIEW_AUTO (VIEW_TYPE_AUTO << 16)
#define DEFAULT_VIEW_LIST (VIEW_TYPE_LIST << 16)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/dialogs/GUIDialogSmartPlaylistEditor.cpp
Expand Up @@ -296,7 +296,7 @@ void CGUIDialogSmartPlaylistEditor::UpdateButtons()
for (unsigned int i = 0; i < orders.size(); i++)
{
CGUIMessage msg(GUI_MSG_LABEL_ADD, GetID(), CONTROL_ORDER_FIELD, orders[i]);
msg.SetLabel(CSmartPlaylistRule::GetLocalizedOrder(orders[i]));
msg.SetLabel(SortUtils::GetSortLabel(orders[i]));
OnMessage(msg);
}
{
Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/HTSPDirectory.cpp
Expand Up @@ -397,9 +397,9 @@ bool CHTSPDirectory::GetChannels( const CURL &base
items.AddSortMethod(SORT_METHOD_ALBUM, 558, LABEL_MASKS("%B", "%Z", "%L", ""));

if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
items.AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 20364, LABEL_MASKS("%Z", "%B", "%L", ""));
items.AddSortMethod(SORT_METHOD_LABEL_IGNORE_THE, 551, LABEL_MASKS("%Z", "%B", "%L", ""));
else
items.AddSortMethod(SORT_METHOD_LABEL, 20364, LABEL_MASKS("%Z", "%B", "%L", ""));
items.AddSortMethod(SORT_METHOD_LABEL, 551, LABEL_MASKS("%Z", "%B", "%L", ""));

items.SetContent("livetv");

Expand Down
4 changes: 2 additions & 2 deletions xbmc/filesystem/MythDirectory.cpp
Expand Up @@ -329,9 +329,9 @@ bool CMythDirectory::GetRecordings(const CStdString& base, CFileItemList &items,
if (type != TV_SHOWS)
{
if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
items.AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 551 /* Name */, LABEL_MASKS("%K", "%J"));
items.AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 556, LABEL_MASKS("%K", "%J"));
else
items.AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 551 /* Name */, LABEL_MASKS("%K", "%J"));
items.AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 556, LABEL_MASKS("%K", "%J"));
}
items.AddSortMethod(SORT_METHOD_DATE, 552 /* Date */, LABEL_MASKS("%K", "%J"));

Expand Down
10 changes: 5 additions & 5 deletions xbmc/filesystem/PluginDirectory.cpp
Expand Up @@ -292,7 +292,7 @@ void CPluginDirectory::AddSortMethod(int handle, SORT_METHOD sortMethod, const C
}
case SORT_METHOD_DURATION:
{
dir->m_listItems->AddSortMethod(SORT_METHOD_DURATION, 555, LABEL_MASKS("%T", "%D"));
dir->m_listItems->AddSortMethod(SORT_METHOD_DURATION, 180, LABEL_MASKS("%T", "%D"));
break;
}
case SORT_METHOD_VIDEO_RATING:
Expand Down Expand Up @@ -329,19 +329,19 @@ void CPluginDirectory::AddSortMethod(int handle, SORT_METHOD sortMethod, const C
case SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE:
{
if (g_guiSettings.GetBool("filelists.ignorethewhensorting"))
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 369, LABEL_MASKS("%T", label2Mask));
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE_IGNORE_THE, 556, LABEL_MASKS("%T", label2Mask));
else
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 369, LABEL_MASKS("%T", label2Mask));
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_SORT_TITLE, 556, LABEL_MASKS("%T", label2Mask));
break;
}
case SORT_METHOD_MPAA_RATING:
{
dir->m_listItems->AddSortMethod(SORT_METHOD_MPAA_RATING, 563, LABEL_MASKS("%T", "%O"));
dir->m_listItems->AddSortMethod(SORT_METHOD_MPAA_RATING, 20074, LABEL_MASKS("%T", "%O"));
break;
}
case SORT_METHOD_VIDEO_RUNTIME:
{
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_RUNTIME, 555, LABEL_MASKS("%T", "%D"));
dir->m_listItems->AddSortMethod(SORT_METHOD_VIDEO_RUNTIME, 180, LABEL_MASKS("%T", "%D"));
break;
}
case SORT_METHOD_STUDIO:
Expand Down
4 changes: 4 additions & 0 deletions xbmc/filesystem/SmartPlaylistDirectory.cpp
Expand Up @@ -32,6 +32,8 @@
#include "utils/URIUtils.h"

#define PROPERTY_PATH_DB "path.db"
#define PROPERTY_SORT_ORDER "sort.order"
#define PROPERTY_SORT_ASCENDING "sort.ascending"

namespace XFILE
{
Expand Down Expand Up @@ -240,6 +242,8 @@ namespace XFILE
}
}
items.SetLabel(playlist.GetName());
items.SetProperty(PROPERTY_SORT_ORDER, (int)playlist.GetOrder());
items.SetProperty(PROPERTY_SORT_ASCENDING, playlist.GetOrderDirection() == SortOrderAscending);

// go through and set the playlist order
for (int i = 0; i < items.Size(); i++)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/interfaces/json-rpc/JSONUtils.h
Expand Up @@ -23,7 +23,7 @@
#include <stdlib.h>

#include "JSONRPCUtils.h"
#include "SortFileItem.h"
#include "utils/SortUtils.h"
#include "interfaces/IAnnouncer.h"
#include "playlists/SmartPlayList.h"
#include "utils/JSONVariantWriter.h"
Expand Down

0 comments on commit 73c9e9f

Please sign in to comment.