1 /*****************************************************************************
2 * sorting.h : commun sorting & column display code
3 ****************************************************************************
4 * Copyright © 2008 the VideoLAN team and AUTHORS
7 * Authors: Rafaël Carré <funman@videolanorg>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_QT_SORTING_H_
25 #define VLC_QT_SORTING_H_
27 #include <vlc_media_library.h>
28 #include <vlc_input_item.h>
30 /* You can use these numbers with | and & to determine what you want to show */
33 COLUMN_TITLE
= 0x0001,
34 COLUMN_DURATION
= 0x0002,
35 COLUMN_ARTIST
= 0x0004,
36 COLUMN_GENRE
= 0x0008,
37 COLUMN_ALBUM
= 0x0010,
38 COLUMN_TRACK_NUMBER
= 0x0020,
39 COLUMN_DESCRIPTION
= 0x0040,
41 COLUMN_NUMBER
= 0x0100,
42 COLUMN_RATING
= 0x0200,
43 COLUMN_COVER
= 0x0400,
44 COLUMN_DISC_NUMBER
= 0x0800,
47 /* Add new entries here and update the COLUMN_END value*/
52 #define COLUMN_DEFAULT (COLUMN_TITLE|COLUMN_DURATION|COLUMN_ALBUM)
54 /* Return the title of a column */
55 static inline const char * psz_column_title( uint32_t i_column
)
59 case COLUMN_NUMBER
: return _("ID");
60 case COLUMN_TITLE
: return VLC_META_TITLE
;
61 case COLUMN_DURATION
: return _("Duration");
62 case COLUMN_ARTIST
: return VLC_META_ARTIST
;
63 case COLUMN_GENRE
: return VLC_META_GENRE
;
64 case COLUMN_ALBUM
: return VLC_META_ALBUM
;
65 case COLUMN_TRACK_NUMBER
: return VLC_META_TRACK_NUMBER
;
66 case COLUMN_DESCRIPTION
: return VLC_META_DESCRIPTION
;
67 case COLUMN_URI
: return _("URI");
68 case COLUMN_RATING
: return VLC_META_RATING
;
69 case COLUMN_COVER
: return _("Cover");
70 case COLUMN_DISC_NUMBER
: return VLC_META_DISCNUMBER
;
71 case COLUMN_DATE
: return VLC_META_DATE
;
76 /* Return the meta data associated with an item for a column
77 * Returned value has to be freed */
78 static inline char * psz_column_meta( input_item_t
*p_item
, uint32_t i_column
)
81 char psz_duration
[MSTRTIME_MAX_SIZE
];
87 return input_item_GetTitleFbName( p_item
);
89 i_duration
= SEC_FROM_VLC_TICK( input_item_GetDuration( p_item
) );
90 if( i_duration
== 0 ) return NULL
;
91 secstotimestr( psz_duration
, i_duration
);
92 return strdup( psz_duration
);
94 return input_item_GetArtist( p_item
);
96 return input_item_GetGenre( p_item
);
98 return input_item_GetAlbum( p_item
);
99 case COLUMN_TRACK_NUMBER
:
100 return input_item_GetTrackNum( p_item
);
101 case COLUMN_DESCRIPTION
:
102 return input_item_GetDescription( p_item
);
104 return input_item_GetURI( p_item
);
106 return input_item_GetRating( p_item
);
108 return input_item_GetArtworkURL( p_item
);
109 case COLUMN_DISC_NUMBER
:
110 return input_item_GetDiscNumber( p_item
);
112 return input_item_GetDate( p_item
);
118 /* Return the playlist sorting mode for a given column */
119 static inline int i_column_sorting( uint32_t i_column
)
123 case COLUMN_NUMBER
: return SORT_ID
;
124 case COLUMN_TITLE
: return SORT_TITLE_NODES_FIRST
;
125 case COLUMN_DURATION
: return SORT_DURATION
;
126 case COLUMN_ARTIST
: return SORT_ARTIST
;
127 case COLUMN_GENRE
: return SORT_GENRE
;
128 case COLUMN_ALBUM
: return SORT_ALBUM
;
129 case COLUMN_TRACK_NUMBER
: return SORT_TRACK_NUMBER
;
130 case COLUMN_DESCRIPTION
: return SORT_DESCRIPTION
;
131 case COLUMN_URI
: return SORT_URI
;
132 case COLUMN_RATING
: return SORT_RATING
;
133 case COLUMN_DISC_NUMBER
: return SORT_DISC_NUMBER
;
134 case COLUMN_DATE
: return SORT_DATE
;
139 /* Return the media library query select type */
140 static inline ml_select_e
meta_to_mlmeta( uint32_t i_column
)
144 case COLUMN_NUMBER
: return ML_ID
;
145 case COLUMN_TITLE
: return ML_TITLE
;
146 case COLUMN_DURATION
: return ML_DURATION
;
147 case COLUMN_ARTIST
: return ML_ARTIST
;
148 case COLUMN_GENRE
: return ML_GENRE
;
149 case COLUMN_ALBUM
: return ML_ALBUM
;
150 case COLUMN_TRACK_NUMBER
: return ML_TRACK_NUMBER
;
151 case COLUMN_DESCRIPTION
: return ML_EXTRA
;
152 case COLUMN_URI
: return ML_URI
;
153 case COLUMN_RATING
: return ML_VOTE
;
154 case COLUMN_COVER
: return ML_COVER
;
155 case COLUMN_DISC_NUMBER
: return ML_DISC_NUMBER
;
156 case COLUMN_DATE
: return ML_YEAR
;