[PVR][Estuary] Timer settings dialog: Show client name in timer type selection dialog...
[xbmc.git] / xbmc / utils / SortUtils.h
blob19a7d07f559a794334effcfa5811296d1c828376
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "DatabaseUtils.h"
12 #include "LabelFormatter.h"
13 #include "SortFileItem.h"
15 #include <map>
16 #include <memory>
17 #include <string>
18 #include <vector>
20 typedef enum {
21 SortOrderNone = 0,
22 SortOrderAscending,
23 SortOrderDescending
24 } SortOrder;
26 typedef enum {
27 SortAttributeNone = 0x0,
28 SortAttributeIgnoreArticle = 0x1,
29 SortAttributeIgnoreFolders = 0x2,
30 SortAttributeUseArtistSortName = 0x4,
31 SortAttributeIgnoreLabel = 0x8
32 } SortAttribute;
34 typedef enum {
35 SortSpecialNone = 0,
36 SortSpecialOnTop = 1,
37 SortSpecialOnBottom = 2
38 } SortSpecial;
40 ///
41 /// \defgroup List_of_sort_methods List of sort methods
42 /// \addtogroup List_of_sort_methods
43 ///
44 /// \brief These ID's can be used with the \ref built_in_functions_6 "Container.SetSortMethod(id)" function
45 /// \note The on field named part with <b>String</b> shows the string used on
46 /// GUI to set this sort type.
47 ///
48 ///@{
49 typedef enum
51 /// __0__ :
52 SortByNone = 0,
53 /// __1__ : Sort by Name <em>(String: <b><c>Label</c></b>)</em>
54 SortByLabel,
55 /// __2__ : Sort by Date <em>(String: <b><c>Date</c></b>)</em>
56 SortByDate,
57 /// __3__ : Sort by Size <em>(String: <b><c>Size</c></b>)</em>
58 SortBySize,
59 /// __4__ : Sort by filename <em>(String: <b><c>File</c></b>)</em>
60 SortByFile,
61 /// __5__ : Sort by path <em>(String: <b><c>Path</c></b>)</em>
62 SortByPath,
63 /// __6__ : Sort by drive type <em>(String: <b><c>DriveType</c></b>)</em>
64 SortByDriveType,
65 /// __7__ : Sort by title <em>(String: <b><c>Title</c></b>)</em>
66 SortByTitle,
67 /// __8__ : Sort by track number <em>(String: <b><c>TrackNumber</c></b>)</em>
68 SortByTrackNumber,
69 /// __9__ : Sort by time <em>(String: <b><c>Time</c></b>)</em>
70 SortByTime,
71 /// __10__ : Sort by artist <em>(String: <b><c>Artist</c></b>)</em>
72 SortByArtist,
73 /// __11__ : Sort by first artist then year <em>(String: <b><c>ArtistYear</c></b>)</em>
74 SortByArtistThenYear,
75 /// __12__ : Sort by album <em>(String: <b><c>Album</c></b>)</em>
76 SortByAlbum,
77 /// __13__ : Sort by album type <em>(String: <b><c>AlbumType</c></b>)</em>
78 SortByAlbumType,
79 /// __14__ : Sort by genre <em>(String: <b><c>Genre</c></b>)</em>
80 SortByGenre,
81 /// __15__ : Sort by country <em>(String: <b><c>Country</c></b>)</em>
82 SortByCountry,
83 /// __16__ : Sort by year <em>(String: <b><c>Year</c></b>)</em>
84 SortByYear,
85 /// __17__ : Sort by rating <em>(String: <b><c>Rating</c></b>)</em>
86 SortByRating,
87 /// __18__ : Sort by user rating <em>(String: <b><c>UserRating</c></b>)</em>
88 SortByUserRating,
89 /// __19__ : Sort by votes <em>(String: <b><c>Votes</c></b>)</em>
90 SortByVotes,
91 /// __20__ : Sort by top 250 <em>(String: <b><c>Top250</c></b>)</em>
92 SortByTop250,
93 /// __21__ : Sort by program count <em>(String: <b><c>ProgramCount</c></b>)</em>
94 SortByProgramCount,
95 /// __22__ : Sort by playlist order <em>(String: <b><c>Playlist</c></b>)</em>
96 SortByPlaylistOrder,
97 /// __23__ : Sort by episode number <em>(String: <b><c>Episode</c></b>)</em>
98 SortByEpisodeNumber,
99 /// __24__ : Sort by season <em>(String: <b><c>Season</c></b>)</em>
100 SortBySeason,
101 /// __25__ : Sort by number of episodes <em>(String: <b><c>TotalEpisodes</c></b>)</em>
102 SortByNumberOfEpisodes,
103 /// __26__ : Sort by number of watched episodes <em>(String: <b><c>WatchedEpisodes</c></b>)</em>
104 SortByNumberOfWatchedEpisodes,
105 /// __27__ : Sort by TV show status <em>(String: <b><c>TvShowStatus</c></b>)</em>
106 SortByTvShowStatus,
107 /// __28__ : Sort by TV show title <em>(String: <b><c>TvShowTitle</c></b>)</em>
108 SortByTvShowTitle,
109 /// __29__ : Sort by sort title <em>(String: <b><c>SortTitle</c></b>)</em>
110 SortBySortTitle,
111 /// __30__ : Sort by production code <em>(String: <b><c>ProductionCode</c></b>)</em>
112 SortByProductionCode,
113 /// __31__ : Sort by MPAA <em>(String: <b><c>MPAA</c></b>)</em>
114 SortByMPAA,
115 /// __32__ : Sort by video resolution <em>(String: <b><c>VideoResolution</c></b>)</em>
116 SortByVideoResolution,
117 /// __33__ : Sort by video codec <em>(String: <b><c>VideoCodec</c></b>)</em>
118 SortByVideoCodec,
119 /// __34__ : Sort by video aspect ratio <em>(String: <b><c>VideoAspectRatio</c></b>)</em>
120 SortByVideoAspectRatio,
121 /// __35__ : Sort by audio channels <em>(String: <b><c>AudioChannels</c></b>)</em>
122 SortByAudioChannels,
123 /// __36__ : Sort by audio codec <em>(String: <b><c>AudioCodec</c></b>)</em>
124 SortByAudioCodec,
125 /// __37__ : Sort by audio language <em>(String: <b><c>AudioLanguage</c></b>)</em>
126 SortByAudioLanguage,
127 /// __38__ : Sort by subtitle language <em>(String: <b><c>SubtitleLanguage</c></b>)</em>
128 SortBySubtitleLanguage,
129 /// __39__ : Sort by studio <em>(String: <b><c>Studio</c></b>)</em>
130 SortByStudio,
131 /// __40__ : Sort by date added <em>(String: <b><c>DateAdded</c></b>)</em>
132 SortByDateAdded,
133 /// __41__ : Sort by last played <em>(String: <b><c>LastPlayed</c></b>)</em>
134 SortByLastPlayed,
135 /// __42__ : Sort by playcount <em>(String: <b><c>PlayCount</c></b>)</em>
136 SortByPlaycount,
137 /// __43__ : Sort by listener <em>(String: <b><c>Listeners</c></b>)</em>
138 SortByListeners,
139 /// __44__ : Sort by bitrate <em>(String: <b><c>Bitrate</c></b>)</em>
140 SortByBitrate,
141 /// __45__ : Sort by random <em>(String: <b><c>Random</c></b>)</em>
142 SortByRandom,
143 /// __46__ : Sort by channel <em>(String: <b><c>Channel</c></b>)</em>
144 SortByChannel,
145 /// __47__ : Sort by channel number <em>(String: <b><c>ChannelNumber</c></b>)</em>
146 SortByChannelNumber,
147 /// __48__ : Sort by date taken <em>(String: <b><c>DateTaken</c></b>)</em>
148 SortByDateTaken,
149 /// __49__ : Sort by relevance
150 SortByRelevance,
151 /// __50__ : Sort by installation date <en>(String: <b><c>installdate</c></b>)</em>
152 SortByInstallDate,
153 /// __51__ : Sort by last updated <en>(String: <b><c>lastupdated</c></b>)</em>
154 SortByLastUpdated,
155 /// __52__ : Sort by last used <em>(String: <b><c>lastused</c></b>)</em>
156 SortByLastUsed,
157 /// __53__ : Sort by client channel order <em>(String: <b><c>ClientChannelOrder</c></b>)</em>
158 SortByClientChannelOrder,
159 /// __54__ : Sort by total number of discs <em>(String: <b><c>totaldiscs</c></b>)</em>
160 SortByTotalDiscs,
161 /// __55__ : Sort by original release date <em>(String: <b><c>Originaldate</c></b>)</em>
162 SortByOrigDate,
163 /// __56__ : Sort by BPM <em>(String: <b><c>bpm</c></b>)</em>
164 SortByBPM,
165 /// __57__ : Sort by original title <em>(String: <b><c>OriginalTitle</c></b>)</em>
166 SortByOriginalTitle,
167 /// __58__ : Sort by provider <em>(String: <b><c>Provider</c></b>)</em>
168 /// @skinning_v20 <b>SortByProvider</b> New sort method added.
169 SortByProvider,
170 /// __59__ : Sort by user preference <em>(String: <b><c>UserPreference</c></b>)</em>
171 /// @skinning_v20 <b>SortByUserPreference</b> New sort method added.
172 SortByUserPreference,
173 } SortBy;
174 ///@}
176 typedef struct SortDescription {
177 SortBy sortBy = SortByNone;
178 SortOrder sortOrder = SortOrderAscending;
179 SortAttribute sortAttributes = SortAttributeNone;
180 int limitStart = 0;
181 int limitEnd = -1;
182 } SortDescription;
184 typedef struct GUIViewSortDetails
186 SortDescription m_sortDescription;
187 int m_buttonLabel;
188 LABEL_MASKS m_labelMasks;
189 } GUIViewSortDetails;
191 typedef DatabaseResult SortItem;
192 typedef std::shared_ptr<SortItem> SortItemPtr;
193 typedef std::vector<SortItemPtr> SortItems;
195 class SortUtils
197 public:
198 static SORT_METHOD TranslateOldSortMethod(SortBy sortBy, bool ignoreArticle);
199 static SortDescription TranslateOldSortMethod(SORT_METHOD sortBy);
201 static SortBy SortMethodFromString(const std::string& sortMethod);
202 static const std::string& SortMethodToString(SortBy sortMethod);
203 static SortOrder SortOrderFromString(const std::string& sortOrder);
204 static const std::string& SortOrderToString(SortOrder sortOrder);
206 /*! \brief retrieve the label id associated with a sort method for displaying in the UI.
207 \param sortBy the sort method in question.
208 \return the label id of the sort method.
210 static int GetSortLabel(SortBy sortBy);
212 static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, DatabaseResults& items, int limitEnd = -1, int limitStart = 0);
213 static void Sort(SortBy sortBy, SortOrder sortOrder, SortAttribute attributes, SortItems& items, int limitEnd = -1, int limitStart = 0);
214 static void Sort(const SortDescription &sortDescription, DatabaseResults& items);
215 static void Sort(const SortDescription &sortDescription, SortItems& items);
216 static bool SortFromDataset(const SortDescription &sortDescription, const MediaType &mediaType, const std::unique_ptr<dbiplus::Dataset> &dataset, DatabaseResults &results);
218 static void GetFieldsForSQLSort(const MediaType& mediaType, SortBy sortMethod, FieldList& fields);
219 static const Fields& GetFieldsForSorting(SortBy sortBy);
220 static std::string RemoveArticles(const std::string &label);
222 typedef std::string (*SortPreparator) (SortAttribute, const SortItem&);
223 typedef bool (*Sorter) (const DatabaseResult &, const DatabaseResult &);
224 typedef bool (*SorterIndirect) (const SortItemPtr &, const SortItemPtr &);
226 private:
227 static const SortPreparator& getPreparator(SortBy sortBy);
228 static Sorter getSorter(SortOrder sortOrder, SortAttribute attributes);
229 static SorterIndirect getSorterIndirect(SortOrder sortOrder, SortAttribute attributes);
231 static std::map<SortBy, SortPreparator> m_preparators;
232 static std::map<SortBy, Fields> m_sortingFields;