/*****************************************************************************
* sort.c : Playlist sorting functions
*****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
+ * Copyright (C) 1999-2004 the VideoLAN team
* $Id$
*
- * Authors: Clément Stenac <zorglub@videolan.org>
+ * Authors: Clément Stenac <zorglub@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include <stdlib.h> /* free(), strtol() */
#include <stdio.h> /* sprintf() */
/**
* Sort the playlist.
* \param p_playlist the playlist
- * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_RANDOM
+ * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_ALBUM, SORT_RANDOM
* \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
* \return VLC_SUCCESS on success
*/
*
* \param p_playlist the playlist
* \param p_node the node to sort
- * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_RANDOM
+ * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_ALBUM, SORT_RANDOM
* \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
* \return VLC_SUCCESS on success
*/
*
* \param p_playlist the playlist
* \param p_node the node to sort
- * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_RANDOM
+ * \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_ALBUM, SORT_RANDOM
* \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
* \return VLC_SUCCESS on success
*/
}
else if( i_mode == SORT_AUTHOR )
{
- msg_Err( p_playlist,"META SORT not implemented" );
+ char *psz_a = vlc_input_item_GetInfo(
+ &pp_items[i]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
+ char *psz_b = vlc_input_item_GetInfo(
+ &pp_items[i_small]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
+ 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 == -1 )
+ {
+ i_test = -1;
+ }
+ // both are nodes
+ else if( pp_items[i]->i_children >= 0 &&
+ pp_items[i_small]->i_children >= 0 )
+ {
+ i_test = strcasecmp( pp_items[i]->input.psz_name,
+ pp_items[i_small]->input.psz_name );
+ }
+ else if( psz_a == NULL && psz_b != NULL )
+ {
+ i_test = 1;
+ }
+ else if( psz_a != NULL && psz_b == NULL )
+ {
+ i_test = -1;
+ }
+ else if( psz_a == NULL && psz_b == NULL )
+ {
+ i_test = strcasecmp( pp_items[i]->input.psz_name,
+ pp_items[i_small]->input.psz_name );
+ }
+ else
+ {
+ i_test = strcmp( psz_b, psz_a );
+ }
}
+ else if( i_mode == SORT_ALBUM )
+ {
+ char *psz_a = vlc_input_item_GetInfo(
+ &pp_items[i]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_COLLECTION) );
+ char *psz_b = vlc_input_item_GetInfo(
+ &pp_items[i_small]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_COLLECTION) );
+ 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 == -1 )
+ {
+ i_test = -1;
+ }
+ // both are nodes
+ else if( pp_items[i]->i_children >= 0 &&
+ pp_items[i_small]->i_children >= 0 )
+ {
+ i_test = strcasecmp( pp_items[i]->input.psz_name,
+ pp_items[i_small]->input.psz_name );
+ }
+ else if( psz_a == NULL && psz_b != NULL )
+ {
+ i_test = 1;
+ }
+ else if( psz_a != NULL && psz_b == NULL )
+ {
+ i_test = -1;
+ }
+ else if( psz_a == NULL && psz_b == NULL )
+ {
+ i_test = strcasecmp( pp_items[i]->input.psz_name,
+ pp_items[i_small]->input.psz_name );
+ }
+ else
+ {
+ i_test = strcmp( psz_b, psz_a );
+ }
+ }
else if( i_mode == SORT_TITLE_NODES_FIRST )
{
/* Alphabetic sort, all nodes first */
else if ( i_mode == SORT_AUTHOR )
{
psz_search = vlc_input_item_GetInfo( &pp_items[i]->input,
- _("Meta-information"), _( "Artist" ) );
+ _(VLC_META_INFO_CAT), _(VLC_META_ARTIST) );
+ }
+ else if ( i_mode == SORT_ALBUM )
+ {
+ psz_search = vlc_input_item_GetInfo( &pp_items[i]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_COLLECTION) );
+ }
+ else if ( i_mode == SORT_GENRE )
+ {
+ psz_search = vlc_input_item_GetInfo( &pp_items[i]->input,
+ _(VLC_META_INFO_CAT), _(VLC_META_GENRE) );
}
if( psz_search && !strcmp( psz_search, "" ) )