xbmc
SortUtils.h
1 /*
2  * Copyright (C) 2012-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "DatabaseUtils.h"
12 #include "LabelFormatter.h"
13 #include "SortFileItem.h"
14 
15 #include <map>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
20 typedef enum {
21  SortOrderNone = 0,
22  SortOrderAscending,
23  SortOrderDescending
24 } SortOrder;
25 
26 typedef enum {
27  SortAttributeNone = 0x0,
28  SortAttributeIgnoreArticle = 0x1,
29  SortAttributeIgnoreFolders = 0x2,
30  SortAttributeUseArtistSortName = 0x4,
31  SortAttributeIgnoreLabel = 0x8
32 } SortAttribute;
33 
34 typedef enum {
35  SortSpecialNone = 0,
36  SortSpecialOnTop = 1,
37  SortSpecialOnBottom = 2
38 } SortSpecial;
39 
49 typedef enum
50 {
173 } SortBy;
175 
176 typedef struct SortDescription {
177  SortBy sortBy = SortByNone;
178  SortOrder sortOrder = SortOrderAscending;
179  SortAttribute sortAttributes = SortAttributeNone;
180  int limitStart = 0;
181  int limitEnd = -1;
183 
184 typedef struct GUIViewSortDetails
185 {
186  SortDescription m_sortDescription;
187  int m_buttonLabel;
188  LABEL_MASKS m_labelMasks;
190 
191 typedef DatabaseResult SortItem;
192 typedef std::shared_ptr<SortItem> SortItemPtr;
193 typedef std::vector<SortItemPtr> SortItems;
194 
196 {
197 public:
198  static SORT_METHOD TranslateOldSortMethod(SortBy sortBy, bool ignoreArticle);
199  static SortDescription TranslateOldSortMethod(SORT_METHOD sortBy);
200 
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);
205 
210  static int GetSortLabel(SortBy sortBy);
211 
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);
217 
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);
221 
222  typedef std::string (*SortPreparator) (SortAttribute, const SortItem&);
223  typedef bool (*Sorter) (const DatabaseResult &, const DatabaseResult &);
224  typedef bool (*SorterIndirect) (const SortItemPtr &, const SortItemPtr &);
225 
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);
230 
231  static std::map<SortBy, SortPreparator> m_preparators;
232  static std::map<SortBy, Fields> m_sortingFields;
233 };
5 : Sort by path (String: Path)
Definition: SortUtils.h:62
0 :
Definition: SortUtils.h:52
31 : Sort by MPAA (String: MPAA)
Definition: SortUtils.h:114
35 : Sort by audio channels (String: AudioChannels)
Definition: SortUtils.h:122
12 : Sort by album (String: Album)
Definition: SortUtils.h:76
52 : Sort by last used (String: lastused)
Definition: SortUtils.h:156
17 : Sort by rating (String: Rating)
Definition: SortUtils.h:86
22 : Sort by playlist order (String: Playlist)
Definition: SortUtils.h:96
56 : Sort by BPM (String: bpm)
Definition: SortUtils.h:164
19 : Sort by votes (String: Votes)
Definition: SortUtils.h:90
41 : Sort by last played (String: LastPlayed)
Definition: SortUtils.h:134
45 : Sort by random (String: Random)
Definition: SortUtils.h:142
33 : Sort by video codec (String: VideoCodec)
Definition: SortUtils.h:118
50 : Sort by installation date <en>(String: installdate)
Definition: SortUtils.h:152
7 : Sort by title (String: Title)
Definition: SortUtils.h:66
43 : Sort by listener (String: Listeners)
Definition: SortUtils.h:138
29 : Sort by sort title (String: SortTitle)
Definition: SortUtils.h:110
Definition: LabelFormatter.h:21
49 : Sort by relevance
Definition: SortUtils.h:150
53 : Sort by client channel order (String: ClientChannelOrder)
Definition: SortUtils.h:158
8 : Sort by track number (String: TrackNumber)
Definition: SortUtils.h:68
47 : Sort by channel number (String: ChannelNumber)
Definition: SortUtils.h:146
54 : Sort by total number of discs (String: totaldiscs)
Definition: SortUtils.h:160
46 : Sort by channel (String: Channel)
Definition: SortUtils.h:144
48 : Sort by date taken (String: DateTaken)
Definition: SortUtils.h:148
38 : Sort by subtitle language (String: SubtitleLanguage)
Definition: SortUtils.h:128
11 : Sort by first artist then year (String: ArtistYear)
Definition: SortUtils.h:74
13 : Sort by album type (String: AlbumType)
Definition: SortUtils.h:78
58 : Sort by provider (String: Provider) SortByProvider New sort method added.
Definition: SortUtils.h:169
26 : Sort by number of watched episodes (String: WatchedEpisodes)
Definition: SortUtils.h:104
18 : Sort by user rating (String: UserRating)
Definition: SortUtils.h:88
9 : Sort by time (String: Time)
Definition: SortUtils.h:70
40 : Sort by date added (String: DateAdded)
Definition: SortUtils.h:132
23 : Sort by episode number (String: Episode)
Definition: SortUtils.h:98
28 : Sort by TV show title (String: TvShowTitle)
Definition: SortUtils.h:108
44 : Sort by bitrate (String: Bitrate)
Definition: SortUtils.h:140
42 : Sort by playcount (String: PlayCount)
Definition: SortUtils.h:136
Definition: SortUtils.h:195
25 : Sort by number of episodes (String: TotalEpisodes)
Definition: SortUtils.h:102
30 : Sort by production code (String: ProductionCode)
Definition: SortUtils.h:112
2 : Sort by Date (String: Date)
Definition: SortUtils.h:56
3 : Sort by Size (String: Size)
Definition: SortUtils.h:58
39 : Sort by studio (String: Studio)
Definition: SortUtils.h:130
32 : Sort by video resolution (String: VideoResolution)
Definition: SortUtils.h:116
SortBy
Definition: SortUtils.h:49
36 : Sort by audio codec (String: AudioCodec)
Definition: SortUtils.h:124
15 : Sort by country (String: Country)
Definition: SortUtils.h:82
14 : Sort by genre (String: Genre)
Definition: SortUtils.h:80
37 : Sort by audio language (String: AudioLanguage)
Definition: SortUtils.h:126
27 : Sort by TV show status (String: TvShowStatus)
Definition: SortUtils.h:106
16 : Sort by year (String: Year)
Definition: SortUtils.h:84
20 : Sort by top 250 (String: Top250)
Definition: SortUtils.h:92
24 : Sort by season (String: Season)
Definition: SortUtils.h:100
51 : Sort by last updated <en>(String: lastupdated)
Definition: SortUtils.h:154
10 : Sort by artist (String: Artist)
Definition: SortUtils.h:72
55 : Sort by original release date (String: Originaldate)
Definition: SortUtils.h:162
34 : Sort by video aspect ratio (String: VideoAspectRatio)
Definition: SortUtils.h:120
4 : Sort by filename (String: File)
Definition: SortUtils.h:60
6 : Sort by drive type (String: DriveType)
Definition: SortUtils.h:64
Definition: SortUtils.h:184
Definition: SortUtils.h:176
59 : Sort by user preference (String: UserPreference) SortByUserPreference New sort method added...
Definition: SortUtils.h:172
21 : Sort by program count (String: ProgramCount)
Definition: SortUtils.h:94
57 : Sort by original title (String: OriginalTitle)
Definition: SortUtils.h:166
1 : Sort by Name (String: Label)
Definition: SortUtils.h:54