]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/sorting.h
Add a function to get the Title and fallback to the name if the title is empty.
[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     COLUMN_URI          = 0x0100,
36
37     /* Add new entries here and update the COLUMN_END value*/
38
39     COLUMN_END          = 0x0200
40 };
41
42 #define COLUMN_DEFAULT (COLUMN_TITLE|COLUMN_DURATION|COLUMN_ALBUM)
43
44 /* Return the title of a column */
45 static const char * psz_column_title( uint32_t i_column )
46 {
47     switch( i_column )
48     {
49     case COLUMN_NUMBER:          return _("ID");
50     case COLUMN_TITLE:           return VLC_META_TITLE;
51     case COLUMN_DURATION:        return _("Duration");
52     case COLUMN_ARTIST:          return VLC_META_ARTIST;
53     case COLUMN_GENRE:           return VLC_META_GENRE;
54     case COLUMN_ALBUM:           return VLC_META_ALBUM;
55     case COLUMN_TRACK_NUMBER:    return VLC_META_TRACK_NUMBER;
56     case COLUMN_DESCRIPTION:     return VLC_META_DESCRIPTION;
57     case COLUMN_URI:             return _("URI");
58     default: abort();
59     }
60 }
61
62 /* Return the meta data associated with an item for a column
63  * Returned value has to be freed */
64 static char * psz_column_meta( input_item_t *p_item, uint32_t i_column )
65 {
66     int i_duration;
67     char psz_duration[MSTRTIME_MAX_SIZE];
68     switch( i_column )
69     {
70     case COLUMN_NUMBER:
71         return NULL;
72     case COLUMN_TITLE:
73         return input_item_GetTitleFbName( p_item );
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     case COLUMN_URI:
89         return input_item_GetURI( p_item );
90     default:
91         abort();
92     }
93 }
94
95 /* Return the playlist sorting mode for a given column */
96 static inline int i_column_sorting( uint32_t i_column )
97 {
98     switch( i_column )
99     {
100     case COLUMN_NUMBER:         return SORT_ID;
101     case COLUMN_TITLE:          return SORT_TITLE_NODES_FIRST;
102     case COLUMN_DURATION:       return SORT_DURATION;
103     case COLUMN_ARTIST:         return SORT_ARTIST;
104     case COLUMN_GENRE:          return SORT_GENRE;
105     case COLUMN_ALBUM:          return SORT_ALBUM;
106     case COLUMN_TRACK_NUMBER:   return SORT_TRACK_NUMBER;
107     case COLUMN_DESCRIPTION:    return SORT_DESCRIPTION;
108     case COLUMN_URI:            return SORT_URI;
109     default: abort();
110     }
111 }