]> git.sesse.net Git - vlc/blobdiff - src/control/flat_media_list_view.c
macosx: Fix #1694 "Fullscreen video after end of playlist".
[vlc] / src / control / flat_media_list_view.c
index d493ac7c12bf1f8072e54c89f63b8967f7a4df60..f367e7b8dea64e17615e1c9da93be8d5de2ed374 100644 (file)
@@ -2,7 +2,7 @@
  * flat_media_list_view.c: libvlc flat media list view functions.
  *****************************************************************************
  * Copyright (C) 2007 the VideoLAN team
- * $Id: flat_media_list.c 21287 2007-08-20 01:28:12Z pdherbemont $
+ * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
  *
@@ -42,8 +42,39 @@ struct libvlc_media_list_view_private_t
 /*
  * Private functions
  */
-static void flat_media_list_view_release( libvlc_media_list_view_t * p_mlv );
 
+/**************************************************************************
+ *       ml_item_added  (private) (Callback from media_list_view item_added)
+ **************************************************************************/
+static void
+ml_item_added( const libvlc_event_t * p_event, libvlc_media_list_view_t * p_mlv )
+{
+    int index = vlc_array_count( &p_mlv->p_this_view_data->array );
+    libvlc_media_t * p_md = p_event->u.media_list_item_added.item;
+    libvlc_media_retain( p_md );
+    trace("appending item at index %d\n", index);
+
+    libvlc_media_list_view_will_add_item( p_mlv, p_md, index );
+    vlc_array_append( &p_mlv->p_this_view_data->array, p_md );
+    libvlc_media_list_view_item_added( p_mlv, p_md, index );
+}
+
+/**************************************************************************
+ *       ml_item_removed  (private) (Callback from media_list_view)
+ **************************************************************************/
+static void
+ml_item_removed( const libvlc_event_t * p_event, libvlc_media_list_view_t * p_mlv )
+{
+    libvlc_media_t * p_md = p_event->u.media_list_item_deleted.item;
+    int i = vlc_array_index_of_item( &p_mlv->p_this_view_data->array, p_md );
+    if( i >= 0 )
+    {
+        libvlc_media_list_view_will_delete_item( p_mlv, p_md, i );
+        vlc_array_remove( &p_mlv->p_this_view_data->array, i );
+        libvlc_media_list_view_item_deleted( p_mlv, p_md, i );
+        libvlc_media_release( p_md );
+    }
+}
 
 /**************************************************************************
  *       flat_media_list_view_count  (private)
@@ -61,15 +92,15 @@ flat_media_list_view_count( libvlc_media_list_view_t * p_mlv,
  *       flat_media_list_view_item_at_index  (private)
  * (called by flat_media_list_view_item_at_index)
  **************************************************************************/
-static libvlc_media_descriptor_t *
+static libvlc_media_t *
 flat_media_list_view_item_at_index( libvlc_media_list_view_t * p_mlv,
                                     int index,
                                     libvlc_exception_t * p_e )
 {
-    libvlc_media_descriptor_t * p_md;
+    libvlc_media_t * p_md;
     (void)p_e;
     p_md = vlc_array_item_at_index( &p_mlv->p_this_view_data->array, index );
-    libvlc_media_descriptor_retain( p_md );
+    libvlc_media_retain( p_md );
     return p_md;
 }
 
@@ -82,6 +113,7 @@ flat_media_list_view_children_at_index( libvlc_media_list_view_t * p_mlv,
                                         int index,
                                         libvlc_exception_t * p_e )
 {
+    (void)p_mlv; (void)index; (void)p_e;
     return NULL;
 }
 
@@ -100,6 +132,33 @@ flat_media_list_view_release( libvlc_media_list_view_t * p_mlv )
  * Public libvlc functions
  */
 
+/* Little helper */
+static void
+import_mlist_rec( libvlc_media_list_view_t * p_mlv,
+                  libvlc_media_list_t * p_mlist,
+                  libvlc_exception_t * p_e )
+{
+    int i, count;
+    count = libvlc_media_list_count( p_mlist, p_e );
+    for( i = 0; i < count; i++ )
+    {
+        libvlc_media_t * p_md;
+        libvlc_media_list_t * p_submlist;
+        p_md = libvlc_media_list_item_at_index( p_mlist, i, p_e );
+        vlc_array_append( &p_mlv->p_this_view_data->array, p_md );
+        p_submlist = libvlc_media_subitems( p_md, p_e );
+        if( p_submlist )
+        {
+            libvlc_media_list_lock( p_submlist );
+            import_mlist_rec( p_mlv, p_submlist, p_e );
+            libvlc_media_list_unlock( p_submlist );
+            libvlc_media_list_release( p_submlist );
+        }
+        /* No need to release the md, as we want to retain it, as it is
+         * stored in our array */
+    }
+}
+                        
 /**************************************************************************
  *       libvlc_media_list_flat_view (Public)
  **************************************************************************/
@@ -109,7 +168,6 @@ libvlc_media_list_flat_view( libvlc_media_list_t * p_mlist,
 {
     trace("\n");
     libvlc_media_list_view_t * p_mlv;
-    libvlc_media_list_lock( p_mlist );
     struct libvlc_media_list_view_private_t * p_this_view_data;
     p_this_view_data = malloc(sizeof(struct libvlc_media_list_view_private_t));
     vlc_array_init( &p_this_view_data->array );
@@ -117,8 +175,16 @@ libvlc_media_list_flat_view( libvlc_media_list_t * p_mlist,
                                         flat_media_list_view_count,
                                         flat_media_list_view_item_at_index,
                                         flat_media_list_view_children_at_index,
+                                        libvlc_media_list_flat_view,
                                         flat_media_list_view_release,
                                         p_this_view_data,
                                         p_e );
+    libvlc_media_list_lock( p_mlist );
+    import_mlist_rec( p_mlv, p_mlist, p_e );
+    libvlc_media_list_view_set_ml_notification_callback( p_mlv,
+        ml_item_added,
+        ml_item_removed );
+    libvlc_media_list_unlock( p_mlist );
+
     return p_mlv;
 }