]> git.sesse.net Git - vlc/blobdiff - src/playlist/sort.c
[patch] unifying meta-information access, the 2nd by Daniel Stränger
[vlc] / src / playlist / sort.c
index 72e1d97627298a964e9d09512955d05231befdbc..b530d93fc8070eb11c2c7864a6b0d5b1ba36b82a 100644 (file)
@@ -1,10 +1,10 @@
 /*****************************************************************************
  * 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
@@ -18,7 +18,7 @@
  *
  * 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() */
@@ -40,7 +40,7 @@ int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
 /**
  * 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
  */
@@ -86,7 +86,7 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
  *
  * \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
  */
@@ -110,7 +110,7 @@ int playlist_NodeSort( playlist_t * p_playlist , playlist_item_t *p_node,
  *
  * \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
  */
@@ -173,6 +173,11 @@ int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
                 i_test = strcasecmp( pp_items[i]->input.psz_name,
                                          pp_items[i_small]->input.psz_name );
             }
+            else if( i_mode == SORT_TITLE_NUMERIC )
+            {
+                i_test = atoi( pp_items[i]->input.psz_name ) -
+                         atoi( pp_items[i_small]->input.psz_name );
+            }
             else if( i_mode == SORT_DURATION )
             {
                 i_test = pp_items[i]->input.i_duration -
@@ -180,8 +185,90 @@ int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
             }
             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 */
@@ -237,8 +324,18 @@ int playlist_NodeGroup( playlist_t * p_playlist , int i_view,
         }
         else if ( i_mode == SORT_AUTHOR )
         {
-            psz_search = playlist_ItemGetInfo( pp_items[i],
-                            _("Meta-information"), _( "Artist" ) );
+            psz_search = vlc_input_item_GetInfo( &pp_items[i]->input,
+                            _(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, "" ) )