control/media_list.c: Implement read-only media_list.
authorPierre d'Herbemont <pdherbemont@videolan.org>
Tue, 25 Dec 2007 23:16:56 +0000 (23:16 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Tue, 25 Dec 2007 23:16:56 +0000 (23:16 +0000)
include/vlc/libvlc.h
src/control/libvlc_internal.h
src/control/media_list.c

index 14eecf1..efd5215 100644 (file)
@@ -546,6 +546,10 @@ VLC_PUBLIC_API int
                                      libvlc_media_descriptor_t *,
                                      libvlc_exception_t * );
 
+/* This indicates if this media list is read-only from a user point of view */
+VLC_PUBLIC_API vlc_bool_t
+    libvlc_media_list_is_readonly( libvlc_media_list_t * p_mlist );
+
 VLC_PUBLIC_API void
     libvlc_media_list_lock( libvlc_media_list_t * );
 VLC_PUBLIC_API void
index 350e3e3..15fbc4a 100644 (file)
@@ -114,6 +114,10 @@ struct libvlc_media_list_t
     /* Other way to see that media list */
     /* Used in flat_media_list.c */
     libvlc_media_list_t *       p_flat_mlist;
+
+    /* This indicates if this media list is read-only
+     * from a user point of view */
+    vlc_bool_t                  b_read_only;
 };
 
 typedef void (*libvlc_media_list_view_release_func_t)( libvlc_media_list_view_t * p_mlv ) ;
@@ -297,6 +301,18 @@ VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
 VLC_EXPORT (void, libvlc_media_descriptor_set_state,
                         ( libvlc_media_descriptor_t *, libvlc_state_t, libvlc_exception_t * ) );
 
+/* Media List */
+VLC_EXPORT ( void, _libvlc_media_list_insert_media_descriptor,
+                        ( libvlc_media_list_t * p_mlist,
+                          libvlc_media_descriptor_t * p_md,
+                          int index,
+                          libvlc_exception_t * p_e ) );
+
+VLC_EXPORT ( void, _libvlc_media_list_remove_index,
+                        ( libvlc_media_list_t * p_mlist,
+                          int index,
+                          libvlc_exception_t * p_e ) );
+
 /* Media List View */
 VLC_EXPORT ( libvlc_media_list_view_t *, libvlc_media_list_view_new,
                           ( libvlc_media_list_t * p_mlist,
index 959c910..6f69b68 100644 (file)
@@ -124,6 +124,7 @@ libvlc_media_list_new( libvlc_instance_t * p_inst,
 
     /* Code for that one should be handled in flat_media_list.c */
     p_mlist->p_flat_mlist = NULL;
+    p_mlist->b_read_only = VLC_FALSE;
 
     libvlc_event_manager_register_event_type( p_mlist->p_event_manager,
             libvlc_MediaListItemAdded, p_e );
@@ -322,6 +323,22 @@ void libvlc_media_list_insert_media_descriptor(
                                    libvlc_media_descriptor_t * p_md,
                                    int index,
                                    libvlc_exception_t * p_e )
+{
+    if( p_mlist->b_read_only )
+    {
+        /* We are read only from user side */
+        libvlc_exception_raise( p_e, "Trying to write into a read-only media list." );
+        return;
+    }
+    _libvlc_media_list_insert_media_descriptor( p_mlist, p_md, index, p_e );
+}
+
+/* LibVLC internal version */
+void _libvlc_media_list_insert_media_descriptor(
+                                   libvlc_media_list_t * p_mlist,
+                                   libvlc_media_descriptor_t * p_md,
+                                   int index,
+                                   libvlc_exception_t * p_e )
 {
     (void)p_e;
     libvlc_media_descriptor_retain( p_md );
@@ -339,6 +356,20 @@ void libvlc_media_list_insert_media_descriptor(
 void libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
                                      int index,
                                      libvlc_exception_t * p_e )
+{
+    if( p_mlist->b_read_only )
+    {
+        /* We are read only from user side */
+        libvlc_exception_raise( p_e, "Trying to write into a read-only media list." );
+        return;
+    }
+    _libvlc_media_list_remove_index( p_mlist, index, p_e );
+}
+
+/* LibVLC internal version */
+void _libvlc_media_list_remove_index( libvlc_media_list_t * p_mlist,
+                                     int index,
+                                     libvlc_exception_t * p_e )
 {
     libvlc_media_descriptor_t * p_md;
 
@@ -388,6 +419,16 @@ int libvlc_media_list_index_of_item( libvlc_media_list_t * p_mlist,
     return -1;
 }
 
+/**************************************************************************
+ *       libvlc_media_list_is_readonly (Public)
+ *
+ * This indicates if this media list is read-only from a user point of view
+ **************************************************************************/
+vlc_bool_t libvlc_media_list_is_readonly( libvlc_media_list_t * p_mlist )
+{
+    return p_mlist->b_read_only;
+}
+
 /**************************************************************************
  *       libvlc_media_list_lock (Public)
  *
@@ -411,7 +452,6 @@ void libvlc_media_list_unlock( libvlc_media_list_t * p_mlist )
 }
 
 
-
 /**************************************************************************
  *       libvlc_media_list_p_event_manager (Public)
  *