/*****************************************************************************
* sort.c : Playlist sorting functions
*****************************************************************************
- * Copyright (C) 1999-2004 the VideoLAN team
+ * Copyright (C) 1999-2007 the VideoLAN team
* $Id$
*
* Authors: Clément Stenac <zorglub@videolan.org>
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
#include "vlc_playlist.h"
#include "playlist_internal.h"
vlc_value_t val;
val.b_bool = VLC_TRUE;
+ (void)p_playlist; // a bit surprising we don't need p_playlist!
+
if( i_mode == SORT_RANDOM )
{
for( i_position = 0; i_position < i_items ; i_position ++ )
return VLC_SUCCESS;
}
-#define DO_META_SORT( node ) { \
- char *psz_a = pp_items[i]->p_input->p_meta ? \
- pp_items[i]->p_input->p_meta->psz_##node : NULL ; \
- char *psz_b = pp_items[i_small]->p_input->p_meta ? \
- pp_items[i_small]->p_input->p_meta->psz_##node : NULL; \
+#define META_STRCASECMP_NAME( i, i_small ) { \
+ char *psz_i = input_item_GetName( pp_items[i]->p_input ); \
+ char *psz_ismall = input_item_GetName( pp_items[i_small]->p_input ); \
+ i_test = strcasecmp( psz_i, psz_ismall ); \
+ free( psz_i ); \
+ free( psz_ismall ); \
+}
+
+
+#define DO_META_SORT_ADV( node, integer ) { \
+ char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
+ char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
/* Nodes go first */ \
if( pp_items[i]->i_children == -1 && pp_items[i_small]->i_children >= 0 ) \
i_test = 1;\
else if( pp_items[i]->i_children >= 0 && \
pp_items[i_small]->i_children >= 0 ) \
{ \
- i_test = strcasecmp( pp_items[i]->p_input->psz_name, \
- pp_items[i_small]->p_input->psz_name ); \
+ META_STRCASECMP_NAME( i, i_small ) \
} \
/* Both are items */ \
else if( psz_a == NULL && psz_b != NULL ) \
/* No meta, sort by name */ \
else if( psz_a == NULL && psz_b == NULL ) \
{ \
- i_test = strcasecmp( pp_items[i]->p_input->psz_name, \
- pp_items[i_small]->p_input->psz_name ); \
+ META_STRCASECMP_NAME( i, i_small ); \
} \
else \
{ \
- i_test = strcmp( psz_b, psz_a ); \
+ if( !integer ) i_test = strcmp( psz_a, psz_b ); \
+ else i_test = atoi( psz_a ) - atoi( psz_b ); \
} \
+ free( psz_a ); \
+ free( psz_b ); \
}
+#define DO_META_SORT( node ) DO_META_SORT_ADV( node, VLC_FALSE )
for( i_position = 0; i_position < i_items -1 ; i_position ++ )
{
if( i_mode == SORT_TITLE )
{
- i_test = strcasecmp( pp_items[i]->p_input->psz_name,
- pp_items[i_small]->p_input->psz_name );
+ META_STRCASECMP_NAME( i, i_small );
}
else if( i_mode == SORT_TITLE_NUMERIC )
{
- i_test = atoi( pp_items[i]->p_input->psz_name ) -
- atoi( pp_items[i_small]->p_input->psz_name );
+ char *psz_i = input_item_GetName( pp_items[i]->p_input );
+ char *psz_ismall =
+ input_item_GetName( pp_items[i_small]->p_input );
+ i_test = atoi( psz_i ) - atoi( psz_ismall );
+ free( psz_i );
+ free( psz_ismall );
}
else if( i_mode == SORT_DURATION )
{
- i_test = pp_items[i]->p_input->i_duration -
- pp_items[i_small]->p_input->i_duration;
+ i_test = input_item_GetDuration( pp_items[i]->p_input ) -
+ input_item_GetDuration( pp_items[i_small]->p_input );
}
else if( i_mode == SORT_ARTIST )
{
- DO_META_SORT( artist );
+ DO_META_SORT( Artist );
+ }
+ else if( i_mode == SORT_GENRE )
+ {
+ DO_META_SORT( Genre );
}
else if( i_mode == SORT_ALBUM )
{
- DO_META_SORT( album );
+ DO_META_SORT( Album );
+ }
+ else if( i_mode == SORT_TRACK_NUMBER )
+ {
+ DO_META_SORT_ADV( TrackNumber, VLC_TRUE );
+ }
+ else if( i_mode == SORT_DESCRIPTION )
+ {
+ DO_META_SORT( Description );
+ }
+ else if( i_mode == SORT_RATING )
+ {
+ DO_META_SORT( Rating );
+ }
+ else if( i_mode == SORT_ID )
+ {
+ i_test = pp_items[i]->i_id - pp_items[i_small]->i_id;
}
else if( i_mode == SORT_TITLE_NODES_FIRST )
{
pp_items[i_position] = pp_items[i_small];
pp_items[i_small] = p_temp;
}
+#undef DO_META_SORT
+#undef DO_META_SORT_ADV
+
return VLC_SUCCESS;
}