From be933ef2241d79558f91796cc5b3a161f72ebf9c Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 19 Oct 2020 00:52:24 +0200 Subject: sync with upstream --- xbmc/utils/SortUtils.h | 224 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 xbmc/utils/SortUtils.h (limited to 'xbmc/utils/SortUtils.h') diff --git a/xbmc/utils/SortUtils.h b/xbmc/utils/SortUtils.h new file mode 100644 index 0000000..79629d4 --- /dev/null +++ b/xbmc/utils/SortUtils.h @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2012-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "DatabaseUtils.h" +#include "LabelFormatter.h" +#include "SortFileItem.h" + +#include +#include +#include +#include + +typedef enum { + SortOrderNone = 0, + SortOrderAscending, + SortOrderDescending +} SortOrder; + +typedef enum { + SortAttributeNone = 0x0, + SortAttributeIgnoreArticle = 0x1, + SortAttributeIgnoreFolders = 0x2, + SortAttributeUseArtistSortName = 0x4, + SortAttributeIgnoreLabel = 0x8 +} SortAttribute; + +typedef enum { + SortSpecialNone = 0, + SortSpecialOnTop = 1, + SortSpecialOnBottom = 2 +} SortSpecial; + +/// +/// \defgroup List_of_sort_methods List of sort methods +/// \addtogroup List_of_sort_methods +/// +/// \brief These ID's can be used with the \ref built_in_functions_6 "Container.SetSortMethod(id)" function +/// \note The on field named part with String shows the string used on +/// GUI to set this sort type. +/// +///@{ +typedef enum { + /// __0__ : + SortByNone = 0, + /// __1__ : Sort by Name (String: Label) + SortByLabel, + /// __2__ : Sort by Date (String: Date) + SortByDate, + /// __3__ : Sort by Size (String: Size) + SortBySize, + /// __4__ : Sort by filename (String: File) + SortByFile, + /// __5__ : Sort by path (String: Path) + SortByPath, + /// __6__ : Sort by drive type (String: DriveType) + SortByDriveType, + /// __7__ : Sort by title (String: Title) + SortByTitle, + /// __8__ : Sort by track number (String: TrackNumber) + SortByTrackNumber, + /// __9__ : Sort by time (String: Time) + SortByTime, + /// __10__ : Sort by artist (String: Artist) + SortByArtist, + /// __11__ : Sort by first artist then year (String: ArtistYear) + SortByArtistThenYear, + /// __12__ : Sort by album (String: Album) + SortByAlbum, + /// __13__ : Sort by album type (String: AlbumType) + SortByAlbumType, + /// __14__ : Sort by genre (String: Genre) + SortByGenre, + /// __15__ : Sort by country (String: Country) + SortByCountry, + /// __16__ : Sort by year (String: Year) + SortByYear, + /// __17__ : Sort by rating (String: Rating) + SortByRating, + /// __18__ : Sort by user rating (String: UserRating) + SortByUserRating, + /// __19__ : Sort by votes (String: Votes) + SortByVotes, + /// __20__ : Sort by top 250 (String: Top250) + SortByTop250, + /// __21__ : Sort by program count (String: ProgramCount) + SortByProgramCount, + /// __22__ : Sort by playlist order (String: Playlist) + SortByPlaylistOrder, + /// __23__ : Sort by episode number (String: Episode) + SortByEpisodeNumber, + /// __24__ : Sort by season (String: Season) + SortBySeason, + /// __25__ : Sort by number of episodes (String: TotalEpisodes) + SortByNumberOfEpisodes, + /// __26__ : Sort by number of watched episodes (String: WatchedEpisodes) + SortByNumberOfWatchedEpisodes, + /// __27__ : Sort by TV show status (String: TvShowStatus) + SortByTvShowStatus, + /// __28__ : Sort by TV show title (String: TvShowTitle) + SortByTvShowTitle, + /// __29__ : Sort by sort title (String: SortTitle) + SortBySortTitle, + /// __30__ : Sort by production code (String: ProductionCode) + SortByProductionCode, + /// __31__ : Sort by MPAA (String: MPAA) + SortByMPAA, + /// __32__ : Sort by video resolution (String: VideoResolution) + SortByVideoResolution, + /// __33__ : Sort by video codec (String: VideoCodec) + SortByVideoCodec, + /// __34__ : Sort by video aspect ratio (String: VideoAspectRatio) + SortByVideoAspectRatio, + /// __35__ : Sort by audio channels (String: AudioChannels) + SortByAudioChannels, + /// __36__ : Sort by audio codec (String: AudioCodec) + SortByAudioCodec, + /// __37__ : Sort by audio language (String: AudioLanguage) + SortByAudioLanguage, + /// __38__ : Sort by subtitle language (String: SubtitleLanguage) + SortBySubtitleLanguage, + /// __39__ : Sort by studio (String: Studio) + SortByStudio, + /// __40__ : Sort by date added (String: DateAdded) + SortByDateAdded, + /// __41__ : Sort by last played (String: LastPlayed) + SortByLastPlayed, + /// __42__ : Sort by playcount (String: PlayCount) + SortByPlaycount, + /// __43__ : Sort by listener (String: Listeners) + SortByListeners, + /// __44__ : Sort by bitrate (String: Bitrate) + SortByBitrate, + /// __45__ : Sort by random (String: Random) + SortByRandom, + /// __46__ : Sort by channel (String: Channel) + SortByChannel, + /// __47__ : Sort by channel number (String: ChannelNumber) + SortByChannelNumber, + /// __48__ : Sort by date taken (String: DateTaken) + SortByDateTaken, + /// __49__ : Sort by relevance + SortByRelevance, + /// __50__ : Sort by installation date (String: installdate) + SortByInstallDate, + /// __51__ : Sort by last updated (String: lastupdated) + SortByLastUpdated, + /// __52__ : Sort by last used (String: lastused) + SortByLastUsed, + /// __53__ : Sort by client channel order (String: ClientChannelOrder) + SortByClientChannelOrder, + /// __54__ : Sort by total number of discs (String: totaldiscs) + SortByTotalDiscs, + /// __55__ : Sort by original release date (String: Originaldate) + SortByOrigDate, + /// __56__ : Sort by BPM (String: bpm) + SortByBPM, +} SortBy; +///@} + +typedef struct SortDescription { + SortBy sortBy = SortByNone; + SortOrder sortOrder = SortOrderAscending; + SortAttribute sortAttributes = SortAttributeNone; + int limitStart = 0; + int limitEnd = -1; +} SortDescription; + +typedef struct GUIViewSortDetails +{ + SortDescription m_sortDescription; + int m_buttonLabel; + LABEL_MASKS m_labelMasks; +} GUIViewSortDetails; + +typedef DatabaseResult SortItem; +typedef std::shared_ptr SortItemPtr; +typedef std::vector SortItems; + +class SortUtils +{ +public: + static SORT_METHOD TranslateOldSortMethod(SortBy sortBy, bool ignoreArticle); + static SortDescription TranslateOldSortMethod(SORT_METHOD sortBy); + + static SortBy SortMethodFromString(const std::string& sortMethod); + static const std::string& SortMethodToString(SortBy sortMethod); + static SortOrder SortOrderFromString(const std::string& sortOrder); + static const std::string& SortOrderToString(SortOrder sortOrder); + + /*! \brief retrieve the label id associated with a sort method for displaying in the UI. + \param sortBy the sort method in question. + \return the label id of the sort method. + */ + static int GetSortLabel(SortBy sortBy); + + static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, DatabaseResults& items, int limitEnd = -1, int limitStart = 0); + static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, SortItems& items, int limitEnd = -1, int limitStart = 0); + static void Sort(const SortDescription &sortDescription, DatabaseResults& items); + static void Sort(const SortDescription &sortDescription, SortItems& items); + static bool SortFromDataset(const SortDescription &sortDescription, const MediaType &mediaType, const std::unique_ptr &dataset, DatabaseResults &results); + + static void GetFieldsForSQLSort(const MediaType& mediaType, SortBy sortMethod, FieldList& fields); + static const Fields& GetFieldsForSorting(SortBy sortBy); + static std::string RemoveArticles(const std::string &label); + + typedef std::string (*SortPreparator) (SortAttribute, const SortItem&); + typedef bool (*Sorter) (const DatabaseResult &, const DatabaseResult &); + typedef bool (*SorterIndirect) (const SortItemPtr &, const SortItemPtr &); + +private: + static const SortPreparator& getPreparator(SortBy sortBy); + static Sorter getSorter(SortOrder sortOrder, SortAttribute attributes); + static SorterIndirect getSorterIndirect(SortOrder sortOrder, SortAttribute attributes); + + static std::map m_preparators; + static std::map m_sortingFields; +}; -- cgit v1.2.3