]> git.sesse.net Git - vlc/blobdiff - src/control/media_list.c
control/flat_media_list.c: Remove an other typo that could cause a crash.
[vlc] / src / control / media_list.c
index be1b0d2ab945eb736877e74d684ab666c926e0ea..136d1529ceabbfd2f5804d77f57005487bafa7a8 100644 (file)
@@ -106,13 +106,7 @@ media_descriptor_changed( const libvlc_event_t * p_event, void * user_data )
 static void
 media_descriptor_subitem_added( const libvlc_event_t * p_event, void * user_data )
 {
-    libvlc_media_list_t * p_mlist = user_data;
-    libvlc_media_descriptor_t * p_new_md;
-
-    p_new_md = p_event->u.media_descriptor_subitem_added.new_child;
-
-    /* For now, just add the new item to this media list */
-    libvlc_media_list_add_media_descriptor( p_mlist, p_new_md, NULL );
+    /* Todo: Just forward that event to our event_manager */
 }
 
 /**************************************************************************
@@ -153,87 +147,6 @@ uninstall_media_descriptor_observer( libvlc_media_list_t * p_mlist,
                          p_mlist, NULL );
 }
 
-/**************************************************************************
- *       dynamic_list_propose_item (private) (Event Callback)
- *
- * This is called if the dynamic sublist's data provider adds a new item.
- **************************************************************************/
-static void
-dynamic_list_propose_item( const libvlc_event_t * p_event, void * p_user_data )
-{
-    libvlc_media_list_t * p_submlist = p_user_data;
-    libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_added.item;
-
-    //libvlc_media_descriptor_lock( p_md );
-    if( libvlc_tag_query_match( p_submlist->p_query, p_md, NULL ) )
-    {
-        libvlc_media_list_lock( p_submlist );
-        libvlc_media_list_add_media_descriptor( p_submlist, p_md, NULL );
-        libvlc_media_list_unlock( p_submlist );
-    }
-    //libvlc_media_descriptor_unlock( p_md );
-}
-
-/**************************************************************************
- *       dynamic_list_remove_item (private) (Event Callback)
- *
- * This is called if the dynamic sublist's data provider adds a new item.
- **************************************************************************/
-static void
-dynamic_list_remove_item( const libvlc_event_t * p_event, void * p_user_data )
-{
-    libvlc_media_list_t * p_submlist = p_user_data;
-    libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_deleted.item;
-
-    //libvlc_media_descriptor_lock( p_md );
-    if( libvlc_tag_query_match( p_submlist->p_query, p_md, NULL ) )
-    {
-        int i;
-        libvlc_media_list_lock( p_submlist );        
-        i = libvlc_media_list_index_of_item( p_submlist, p_md, NULL );
-        if ( i < 0 )
-        {
-            /* We've missed one item addition, that could happen especially
-             * if we add item in a threaded maner, so we just ignore */
-            libvlc_media_list_unlock( p_submlist );
-            //libvlc_media_descriptor_unlock( p_md );           
-            return;
-        }
-        libvlc_media_list_remove_index( p_submlist, i, NULL );
-        libvlc_media_list_unlock( p_submlist );
-    }
-    //libvlc_media_descriptor_unlock( p_md );
-}
-
-/**************************************************************************
- *       dynamic_list_change_item (private) (Event Callback)
- *
- * This is called if the dynamic sublist's data provider adds a new item.
- **************************************************************************/
-static void
-dynamic_list_change_item( const libvlc_event_t * p_event , void * p_user_data)
-{
-    libvlc_media_list_t * p_submlist = p_user_data;
-    libvlc_media_descriptor_t * p_md = p_event->u.media_list_item_changed.item;
-    int index;
-
-    libvlc_media_list_lock( p_submlist );        
-    
-    index = libvlc_media_list_index_of_item( p_submlist, p_md, NULL );
-    if( index < 0 )
-    {
-        libvlc_media_list_unlock( p_submlist );     
-        return; /* Not found, no prob, just ignore */
-    }
-
-    //libvlc_media_descriptor_lock( p_md );
-    if( !libvlc_tag_query_match( p_submlist->p_query, p_md, NULL ) )
-        libvlc_media_list_remove_index( p_submlist, index, NULL );
-    //libvlc_media_descriptor_unlock( p_md );
-
-    libvlc_media_list_unlock( p_submlist );        
-}
-
 /*
  * Public libvlc functions
  */
@@ -257,6 +170,9 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
     p_mlist->p_libvlc_instance = p_inst;
     p_mlist->p_event_manager = libvlc_event_manager_new( p_mlist, p_inst, p_e );
 
+    /* Code for that one should be handled in flat_media_list.c */
+    p_mlist->p_flat_mlist = NULL;
+
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListItemAdded, p_e );
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
@@ -275,7 +191,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
     
     ARRAY_INIT(p_mlist->items);
     p_mlist->i_refcount = 1;
-    p_mlist->p_media_provider = NULL;
+    p_mlist->psz_name = NULL;
 
     return p_mlist;
 }
@@ -299,11 +215,9 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
     vlc_mutex_unlock( &p_mlist->object_lock );        
 
     /* Refcount null, time to free */
-    if( p_mlist->p_media_provider )
-        libvlc_media_list_release( p_mlist->p_media_provider );
 
-    if( p_mlist->p_query )
-        libvlc_tag_query_release( p_mlist->p_query );
+    /* Handled in flat_media_list.c */
+    libvlc_media_list_flat_media_list_release( p_mlist );
 
     libvlc_event_manager_release( p_mlist->p_event_manager );
 
@@ -314,6 +228,7 @@ void libvlc_media_list_release( libvlc_media_list_t * p_mlist )
  
     free( p_mlist );
 }
+
 /**************************************************************************
  *       libvlc_media_list_retain (Public)
  *
@@ -326,6 +241,77 @@ void libvlc_media_list_retain( libvlc_media_list_t * p_mlist )
     vlc_mutex_unlock( &p_mlist->object_lock );
 }
 
+
+/**************************************************************************
+ *       add_file_content (Public)
+ **************************************************************************/
+void
+libvlc_media_list_add_file_content( libvlc_media_list_t * p_mlist,
+                                    const char * psz_uri,
+                                    libvlc_exception_t * p_e )
+{
+    input_item_t * p_input_item;
+    libvlc_media_descriptor_t * p_md;
+
+    p_input_item = input_ItemNewExt( p_mlist->p_libvlc_instance->p_libvlc_int, psz_uri,
+                                _("Media Library"), 0, NULL, -1 );
+
+    if( !p_input_item )
+    {
+        libvlc_exception_raise( p_e, "Can't create an input item" );
+        return;
+    }
+
+    p_md = libvlc_media_descriptor_new_from_input_item(
+            p_mlist->p_libvlc_instance,
+            p_input_item, p_e );
+
+    if( !p_md )
+    {
+        vlc_gc_decref( p_input_item );
+        return;
+    }
+
+    libvlc_media_list_add_media_descriptor( p_mlist, p_md, p_e );
+    if( libvlc_exception_raised( p_e ) )
+        return;
+
+    input_Read( p_mlist->p_libvlc_instance->p_libvlc_int, p_input_item, VLC_TRUE );
+
+    return;
+}
+
+/**************************************************************************
+ *       set_name (Public)
+ **************************************************************************/
+void libvlc_media_list_set_name( libvlc_media_list_t * p_mlist,
+                                 const char * psz_name,
+                                 libvlc_exception_t * p_e)
+
+{
+    (void)p_e;
+    vlc_mutex_lock( &p_mlist->object_lock );
+    free( p_mlist->psz_name );
+    p_mlist->psz_name = psz_name ? strdup( psz_name ) : NULL;
+    vlc_mutex_unlock( &p_mlist->object_lock );
+}
+
+/**************************************************************************
+ *       name (Public)
+ **************************************************************************/
+char * libvlc_media_list_name( libvlc_media_list_t * p_mlist,
+                               libvlc_exception_t * p_e)
+{
+    char *ret;
+    (void)p_e;
+
+    vlc_mutex_lock( &p_mlist->object_lock );
+    ret = p_mlist->psz_name ? strdup( p_mlist->psz_name ) : NULL;
+    vlc_mutex_unlock( &p_mlist->object_lock );
+
+    return ret;
+}
+
 /**************************************************************************
  *       libvlc_media_list_count (Public)
  *
@@ -464,65 +450,3 @@ libvlc_media_list_event_manager( libvlc_media_list_t * p_mlist,
     (void)p_e;
     return p_mlist->p_event_manager;
 }
-
-/**************************************************************************
- *       libvlc_media_list_dynamic_sublist (Public)
- *
- * Lock should be hold when entering.
- **************************************************************************/
-libvlc_media_list_t *
-libvlc_media_list_dynamic_sublist( libvlc_media_list_t * p_mlist,
-                                   libvlc_tag_query_t * p_query,
-                                   libvlc_exception_t * p_e )
-{
-    libvlc_media_list_t * p_submlist;
-    libvlc_event_manager_t * p_em;
-    int count, i;
-
-    (void)p_e;
-
-    p_submlist = libvlc_media_list_new( p_mlist->p_libvlc_instance, p_e );
-    if( !p_submlist )
-    {
-        if( !libvlc_exception_raised( p_e ) )
-            libvlc_exception_raise( p_e, "Can't get the new media_list" );
-        return NULL;
-    }
-
-    /* We have a query */
-    libvlc_tag_query_retain( p_query );
-    p_submlist->p_query = p_query;
-
-    /* We have a media provider */
-    libvlc_media_list_retain( p_mlist );
-    p_submlist->p_media_provider = p_mlist;
-
-
-    libvlc_media_list_lock( p_submlist );        
-    
-    count = libvlc_media_list_count( p_mlist, p_e );
-
-    /* This should be running in a thread, a good plan to achieve that
-     * move all the dynamic code to libvlc_tag_query. */
-    for( i = 0; i < count; i++ )
-    {
-        libvlc_media_descriptor_t * p_md;
-        p_md = libvlc_media_list_item_at_index( p_mlist, i, p_e );
-        if( libvlc_tag_query_match( p_query, p_md, NULL ) )
-            libvlc_media_list_add_media_descriptor( p_submlist, p_md, p_e );
-    }
-
-    /* And we will listen to its event, so we can update p_submlist
-     * accordingly */
-    p_em = libvlc_media_list_event_manager( p_mlist, p_e );
-    libvlc_event_attach( p_em, libvlc_MediaListItemAdded,
-                         dynamic_list_propose_item, p_submlist, p_e );
-    libvlc_event_attach( p_em, libvlc_MediaListItemDeleted,
-                         dynamic_list_remove_item, p_submlist, p_e );
-    libvlc_event_attach( p_em, libvlc_MediaListItemChanged,
-                         dynamic_list_change_item, p_submlist, p_e );
-
-    libvlc_media_list_unlock( p_submlist );        
-
-    return p_submlist;
-}