]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/sorting.h
e4917802c59b306ea4bb7dc9dbdb1f8764fca4e6
[vlc] / modules / gui / qt4 / components / playlist / sorting.h
1 /*****************************************************************************
2  * sorting.h : commun sorting & column display code
3  ****************************************************************************
4  * Copyright © 2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Rafaël Carré <funman@videolanorg>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /* You can use these numbers with | and & to determine what you want to show */
25 enum
26 {
27     COLUMN_NUMBER       = 0x0001,
28     COLUMN_TITLE        = 0x0002,
29     COLUMN_DURATION     = 0x0004,
30     COLUMN_ARTIST       = 0x0008,
31     COLUMN_GENRE        = 0x0010,
32     COLUMN_ALBUM        = 0x0020,
33     COLUMN_TRACK_NUMBER = 0x0040,
34     COLUMN_DESCRIPTION  = 0x0080,
35
36     /* Add new entries here */
37
38     COLUMN_END
39 };
40
41 /* Return the title of a column */
42 static const char * psz_column_title( uint32_t i_column )
43 {
44     switch( i_column )
45     {
46     case COLUMN_NUMBER:          return "";
47     case COLUMN_TITLE:           return VLC_META_TITLE;
48     case COLUMN_DURATION:        return _("Duration");
49     case COLUMN_ARTIST:          return VLC_META_ARTIST;
50     case COLUMN_GENRE:           return VLC_META_GENRE;
51     case COLUMN_ALBUM:           return VLC_META_ALBUM;
52     case COLUMN_TRACK_NUMBER:    return VLC_META_TRACK_NUMBER;
53     case COLUMN_DESCRIPTION:     return VLC_META_DESCRIPTION;
54     default: abort();
55     }
56 }
57
58 /* Return the meta data associated with an item for a column
59  * Returned value has to be freed */
60 static char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
61 {
62     char *psz;
63     int i_duration;
64     char psz_duration[MSTRTIME_MAX_SIZE];
65     switch( i_column )
66     {
67     case COLUMN_NUMBER:
68         return NULL;
69     case COLUMN_TITLE:
70         psz = input_item_GetTitle( p_item );
71         if( !psz )
72             psz = input_item_GetName( p_item );
73         return psz;
74     case COLUMN_DURATION:
75         i_duration = input_item_GetDuration( p_item ) / 1000000;
76         secstotimestr( psz_duration, i_duration );
77         return strdup( psz_duration );
78     case COLUMN_ARTIST:
79         return input_item_GetArtist( p_item );
80     case COLUMN_GENRE:
81         return input_item_GetGenre( p_item );
82     case COLUMN_ALBUM:
83         return input_item_GetAlbum( p_item );
84     case COLUMN_TRACK_NUMBER:
85         return input_item_GetTrackNum( p_item );
86     case COLUMN_DESCRIPTION:
87         return input_item_GetDescription( p_item );
88     default:
89         abort();
90     }
91 }
92
93 /* Return the playlist sorting mode for a given column */
94 static inline int i_column_sorting( uint32_t i_column )
95 {
96     switch( i_column )
97     {
98     case COLUMN_NUMBER:         return SORT_ID;
99     case COLUMN_TITLE:          return SORT_TITLE_NODES_FIRST;
100     case COLUMN_DURATION:       return SORT_DURATION;
101     case COLUMN_ARTIST:         return SORT_ARTIST;
102     case COLUMN_GENRE:          return SORT_GENRE;
103     case COLUMN_ALBUM:          return SORT_ALBUM;
104     case COLUMN_TRACK_NUMBER:   return SORT_TRACK_NUMBER;
105     case COLUMN_DESCRIPTION:    return SORT_DESCRIPTION;
106     default: abort();
107     }
108 }