Qt: correctly display the right treeView columns
[vlc.git] / modules / gui / qt4 / components / playlist / sorting.h
blobf0ea8722c75619a347fd1ff43bd536e549645cd3
1 /*****************************************************************************
2 * sorting.h : commun sorting & column display code
3 ****************************************************************************
4 * Copyright © 2008 the VideoLAN team and AUTHORS
5 * $Id$
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 _SORTING_H_
25 #define _SORTING_H_
26 #include <vlc_media_library.h>
27 /* You can use these numbers with | and & to determine what you want to show */
28 enum
30 COLUMN_TITLE = 0x0001,
31 COLUMN_DURATION = 0x0002,
32 COLUMN_ARTIST = 0x0004,
33 COLUMN_GENRE = 0x0008,
34 COLUMN_ALBUM = 0x0010,
35 COLUMN_TRACK_NUMBER = 0x0020,
36 COLUMN_DESCRIPTION = 0x0040,
37 COLUMN_URI = 0x0080,
38 COLUMN_NUMBER = 0x0100,
39 COLUMN_RATING = 0x0200,
40 COLUMN_COVER = 0x0400,
42 /* Add new entries here and update the COLUMN_END value*/
44 COLUMN_END = 0x0800
47 #define COLUMN_DEFAULT (COLUMN_TITLE|COLUMN_DURATION|COLUMN_ALBUM)
49 /* Return the title of a column */
50 static inline const char * psz_column_title( uint32_t i_column )
52 switch( i_column )
54 case COLUMN_NUMBER: return _("ID");
55 case COLUMN_TITLE: return VLC_META_TITLE;
56 case COLUMN_DURATION: return _("Duration");
57 case COLUMN_ARTIST: return VLC_META_ARTIST;
58 case COLUMN_GENRE: return VLC_META_GENRE;
59 case COLUMN_ALBUM: return VLC_META_ALBUM;
60 case COLUMN_TRACK_NUMBER: return VLC_META_TRACK_NUMBER;
61 case COLUMN_DESCRIPTION: return VLC_META_DESCRIPTION;
62 case COLUMN_URI: return _("URI");
63 case COLUMN_RATING: return VLC_META_RATING;
64 case COLUMN_COVER: return VLC_META_ART_URL;
65 default: abort();
69 /* Return the meta data associated with an item for a column
70 * Returned value has to be freed */
71 static inline char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
73 int i_duration;
74 char psz_duration[MSTRTIME_MAX_SIZE];
75 switch( i_column )
77 case COLUMN_NUMBER:
78 return NULL;
79 case COLUMN_TITLE:
80 return input_item_GetTitleFbName( p_item );
81 case COLUMN_DURATION:
82 i_duration = input_item_GetDuration( p_item ) / 1000000;
83 if( i_duration == 0 ) return NULL;
84 secstotimestr( psz_duration, i_duration );
85 return strdup( psz_duration );
86 case COLUMN_ARTIST:
87 return input_item_GetArtist( p_item );
88 case COLUMN_GENRE:
89 return input_item_GetGenre( p_item );
90 case COLUMN_ALBUM:
91 return input_item_GetAlbum( p_item );
92 case COLUMN_TRACK_NUMBER:
93 return input_item_GetTrackNum( p_item );
94 case COLUMN_DESCRIPTION:
95 return input_item_GetDescription( p_item );
96 case COLUMN_URI:
97 return input_item_GetURI( p_item );
98 case COLUMN_RATING:
99 return input_item_GetRating( p_item );
100 case COLUMN_COVER:
101 return input_item_GetArtworkURL( p_item );
102 default:
103 abort();
107 /* Return the playlist sorting mode for a given column */
108 static inline int i_column_sorting( uint32_t i_column )
110 switch( i_column )
112 case COLUMN_NUMBER: return SORT_ID;
113 case COLUMN_TITLE: return SORT_TITLE_NODES_FIRST;
114 case COLUMN_DURATION: return SORT_DURATION;
115 case COLUMN_ARTIST: return SORT_ARTIST;
116 case COLUMN_GENRE: return SORT_GENRE;
117 case COLUMN_ALBUM: return SORT_ALBUM;
118 case COLUMN_TRACK_NUMBER: return SORT_TRACK_NUMBER;
119 case COLUMN_DESCRIPTION: return SORT_DESCRIPTION;
120 case COLUMN_URI: return SORT_URI;
121 case COLUMN_RATING: return SORT_RATING;
122 default: abort();
126 static inline ml_select_e meta_to_mlmeta( uint32_t i_column )
128 switch( i_column )
130 case COLUMN_NUMBER: return ML_ID;
131 case COLUMN_TITLE: return ML_TITLE;
132 case COLUMN_DURATION: return ML_DURATION;
133 case COLUMN_ARTIST: return ML_ARTIST;
134 case COLUMN_GENRE: return ML_GENRE;
135 case COLUMN_ALBUM: return ML_ALBUM;
136 case COLUMN_TRACK_NUMBER: return ML_TRACK_NUMBER;
137 case COLUMN_DESCRIPTION: return ML_EXTRA;
138 case COLUMN_URI: return ML_URI;
139 case COLUMN_RATING: return ML_VOTE;
140 case COLUMN_COVER: return ML_COVER;
141 default: abort();
145 #endif