- char *psz_search = NULL;
- int i_nodes = 0;
- playlist_item_t **pp_nodes = NULL;
- playlist_item_t *p_node;
- vlc_bool_t b_found;
- int i,j;
- for( i = 0; i< i_item ; i++ )
- {
- if( psz_search ) free( psz_search );
- if( i_mode == SORT_TITLE )
- {
- psz_search = strdup( pp_items[i]->input.psz_name );
- }
- else if ( i_mode == SORT_AUTHOR )
+
+#define META_STRCASECMP_NAME( ) { \
+ char *psz_i = input_item_GetName( (*(playlist_item_t **)first)->p_input ); \
+ char *psz_ismall = input_item_GetName( (*(playlist_item_t **)second)->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( (*(playlist_item_t **)first)->p_input, vlc_meta_##node ); \
+ char *psz_b = input_item_GetMeta( (*(playlist_item_t **)second)->p_input, vlc_meta_##node ); \
+ /* Nodes go first */ \
+ if( (*(playlist_item_t **)first)->i_children == -1 && (*(playlist_item_t **)second)->i_children >= 0 ) \
+ i_test = 1;\
+ else if( (*(playlist_item_t **)first)->i_children >= 0 &&\
+ (*(playlist_item_t **)second)->i_children == -1 ) \
+ i_test = -1; \
+ /* Both are nodes, sort by name */ \
+ else if( (*(playlist_item_t **)first)->i_children >= 0 && \
+ (*(playlist_item_t **)second)->i_children >= 0 ) \
+ { \
+ META_STRCASECMP_NAME( ) \
+ } \
+ /* Both are items */ \
+ else if( psz_a == NULL && psz_b != NULL ) \
+ i_test = 1; \
+ else if( psz_a != NULL && psz_b == NULL ) \
+ i_test = -1;\
+ /* No meta, sort by name */ \
+ else if( psz_a == NULL && psz_b == NULL ) \
+ { \
+ META_STRCASECMP_NAME( ); \
+ } \
+ else \
+ { \
+ 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, false )
+
+ int i_test = 0;
+
+ if( sort_mode == SORT_TITLE )