]> git.sesse.net Git - vlc/blobdiff - src/playlist/sort.c
Fix a bug when sorting the playlist:
[vlc] / src / playlist / sort.c
index 43016144c5f149b4898707c17d6226c4d83c3aa7..5cbf2ac370fc1bd7444326b0976a3f3311281b4b 100644 (file)
@@ -54,32 +54,54 @@ static int playlist_NodeSort( playlist_t * p_playlist , playlist_item_t *p_node,
 }
 
 /**
- * Sort a node recursively.
- *
- * This function must be entered with the playlist lock !
- *
+ * Sort a node recursively
  * \param p_playlist the playlist
  * \param p_node the node to sort
  * \param i_mode: SORT_ID, SORT_TITLE, SORT_ARTIST, SORT_ALBUM, SORT_RANDOM
  * \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
  * \return VLC_SUCCESS on success
  */
-int playlist_RecursiveNodeSort( playlist_t *p_playlist, playlist_item_t *p_node,
-                                int i_mode, int i_type )
+static int recursiveNodeSort( playlist_t *p_playlist, playlist_item_t *p_node,
+                              int i_mode, int i_type )
 {
     int i;
+    /* Sort the current node */
     playlist_NodeSort( p_playlist, p_node, i_mode, i_type );
+
+    /* And all the children */
     for( i = 0 ; i< p_node->i_children; i++ )
     {
         if( p_node->pp_children[i]->i_children != -1 )
         {
-            playlist_RecursiveNodeSort( p_playlist, p_node->pp_children[i],
-                                        i_mode,i_type );
+            recursiveNodeSort( p_playlist, p_node->pp_children[i],
+                               i_mode, i_type );
         }
     }
     return VLC_SUCCESS;
 }
 
+
+/**
+ * Sort a node recursively.
+ *
+ * This function must be entered with the playlist lock !
+ *
+ * \param p_playlist the playlist
+ * \param p_node the node to sort
+ * \param i_mode: SORT_ID, SORT_TITLE, SORT_ARTIST, SORT_ALBUM, SORT_RANDOM
+ * \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
+ * \return VLC_SUCCESS on success
+ */
+int playlist_RecursiveNodeSort( playlist_t *p_playlist, playlist_item_t *p_node,
+                                int i_mode, int i_type )
+{
+    /* Ask the playlist to reset as we are changing the order */
+    pl_priv(p_playlist)->b_reset_currently_playing = true;
+
+    /* Do the real job recursively */
+    return recursiveNodeSort( p_playlist, p_node, i_mode, i_type );
+}
+
 static int sort_mode = 0;
 static int sort_type = 0;
 
@@ -89,8 +111,6 @@ static int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
 {
     int i_position;
     playlist_item_t *p_temp;
-    vlc_value_t val;
-    val.b_bool = true;
     sort_mode = i_mode;
     sort_type = i_type;
 
@@ -121,8 +141,8 @@ static int playlist_cmp(const void *first, const void *second)
 {
 
 #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 ); \
+    char *psz_i = input_item_GetTitleFbName( (*(playlist_item_t **)first)->p_input ); \
+    char *psz_ismall = input_item_GetTitleFbName( (*(playlist_item_t **)second)->p_input ); \
     if( psz_i != NULL && psz_ismall != NULL ) i_test = strcasecmp( psz_i, psz_ismall ); \
     else if ( psz_i == NULL && psz_ismall != NULL ) i_test = 1; \
     else if ( psz_ismall == NULL && psz_i != NULL ) i_test = -1; \
@@ -159,7 +179,7 @@ static int playlist_cmp(const void *first, const void *second)
     } \
     else \
     { \
-        if( !integer ) i_test = strcmp( psz_a, psz_b ); \
+        if( !integer ) i_test = strcasecmp( psz_a, psz_b ); \
         else           i_test = atoi( psz_a ) - atoi( psz_b ); \
     } \
     free( psz_a ); \
@@ -170,14 +190,15 @@ static int playlist_cmp(const void *first, const void *second)
     int i_test = 0;
 
     if( sort_mode == SORT_TITLE )
-        {
-            META_STRCASECMP_NAME( );
-        }
+    {
+        META_STRCASECMP_NAME( );
+    }
     else if( sort_mode == SORT_TITLE_NUMERIC )
     {
-        char *psz_i = input_item_GetName( (*(playlist_item_t **)first)->p_input );
-        char *psz_ismall =
-                input_item_GetName( (*(playlist_item_t **)second)->p_input );
+        char *psz_i = input_item_GetTitleFbName(
+                                (*(playlist_item_t **)first)->p_input );
+        char *psz_ismall = input_item_GetTitleFbName(
+                                (*(playlist_item_t **)second)->p_input );
         i_test = atoi( psz_i ) - atoi( psz_ismall );
         free( psz_i );
         free( psz_ismall );
@@ -235,23 +256,7 @@ static int playlist_cmp(const void *first, const void *second)
         }
         else
         {
-            if ( (*(playlist_item_t **)first)->p_input->psz_name != NULL &&
-                 (*(playlist_item_t **)second)->p_input->psz_name != NULL )
-            {
-                i_test = strcasecmp( (*(playlist_item_t **)first)->p_input->psz_name,
-                                 (*(playlist_item_t **)second)->p_input->psz_name );
-            }
-            else if ( (*(playlist_item_t **)first)->p_input->psz_name != NULL &&
-                 (*(playlist_item_t **)second)->p_input->psz_name == NULL )
-            {
-                i_test = 1;
-            }
-            else if ( (*(playlist_item_t **)first)->p_input->psz_name == NULL &&
-                 (*(playlist_item_t **)second)->p_input->psz_name != NULL )
-            {
-                i_test = -1;
-            }
-            else i_test = 0;
+            META_STRCASECMP_NAME();
         }
     }
     else if( sort_mode == SORT_URI )