]> git.sesse.net Git - vlc/blobdiff - src/playlist/info.c
Updated Dutch translation.
[vlc] / src / playlist / info.c
index 0cb75594cd25b79dce08915097ac3e2ec9307f38..f0961102dcd2bdcbddc5a68ea762ec101ce4cd29 100644 (file)
@@ -2,7 +2,7 @@
  * info.c : Playlist info management
  *****************************************************************************
  * Copyright (C) 1999-2004 VideoLAN
- * $Id: info.c,v 1.4 2004/01/15 19:23:14 sigmunau Exp $
+ * $Id: info.c,v 1.10 2004/02/28 17:10:23 gbazin Exp $
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
 
 /**
  * Get one special info
+ * Must be entered with playlist lock
  *
  * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
+ * \param i_item position of the item on
+ *               which we want the info ( -1 for current )
  * \param psz_cat the category in which the info is stored
  * \param psz_name the name of the info
- * \return the info value if any, NULL else
+ * \return the info value if any, an empty string else
 */
-char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
-                      const char * psz_cat, const char *psz_name )
+char * playlist_GetInfo( playlist_t *p_playlist, int i_pos,
+                         const char * psz_cat, const char *psz_name )
 {
+    playlist_item_t *p_item;
+    char *psz_buffer;
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
     {
         return strdup("");
     }
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
+    p_item = playlist_ItemGetByPos( p_playlist, i_pos );
+    if( !p_item )
     {
         return strdup("");
     }
-    return playlist_GetItemInfo( p_playlist->pp_items[i_item] , psz_cat,
-                                 psz_name );
+    vlc_mutex_lock( &p_item->lock );
+    psz_buffer = playlist_ItemGetInfo( p_item ,
+                                       psz_cat, psz_name );
+    vlc_mutex_unlock( &p_item->lock );
+
+    return psz_buffer;
 }
 
 /**
@@ -69,9 +70,9 @@ char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
  * \param p_item the item on which we want the info
  * \param psz_cat the category in which the info is stored
  * \param psz_name the name of the info
- * \return the info value if any, NULL else
+ * \return the info value if any, an empty string else
 */
-char * playlist_GetItemInfo( playlist_item_t *p_item,
+char * playlist_ItemGetInfo( playlist_item_t *p_item,
                       const char * psz_cat, const char *psz_name )
 {
      int i,j ;
@@ -94,47 +95,40 @@ char * playlist_GetItemInfo( playlist_item_t *p_item,
 }
 
 /**
- * Get one info category. Creates it if it does not exist
+ * Get one info category. Create it if it does not exist
  *
- * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
+ * \param p_playlist the playlist to get the category from
+ * \param i_item the position of the item on which we want
+ *               the info ( -1 for current )
  * \param psz_cat the category we want
  * \return the info category.
  */
 item_info_category_t *
-playlist_GetCategory( playlist_t *p_playlist, int i_item,
+playlist_GetCategory( playlist_t *p_playlist, int i_pos,
                       const char * psz_cat )
 {
+    playlist_item_t *p_item;
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
     {
         return NULL;
     }
-
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
+    p_item=  playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
         return NULL;
     }
-
-    return playlist_GetItemCategory( p_playlist->pp_items[i_item] , psz_cat );
+    return playlist_ItemGetCategory( p_item , psz_cat );
 }
 
 /**
- * Get one info category (no p_playlist). Creates it if it does not exist
+ * Get one info category (no p_playlist). Create it if it does not exist
  *
- * \param p_item the playlist to search categories in
+ * \param p_item the playlist item to get the category from
  * \param psz_cat the category we want
  * \return the info category.
  */
-item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
+item_info_category_t *playlist_ItemGetCategory( playlist_item_t *p_item,
                                                 const char *psz_cat )
 {
     int i;
@@ -149,21 +143,22 @@ item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
     }
 
     /* We did not find the category, create it */
-    return playlist_CreateItemCategory( p_item, psz_cat );
+    return playlist_ItemCreateCategory( p_item, psz_cat );
 }
 
 
 /**
  * Create one info category.
  *
- * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
+ * \param p_playlist the playlist
+ * \param i_item the position of the item for which we create
+ *               the category ( -1 for current )
  * \param psz_cat the category we want to create
  * \return the info category.
  */
 item_info_category_t *
-playlist_CreateCategory( playlist_t *p_playlist, int i_item,
-                      const char * psz_cat )
+playlist_CreateCategory( playlist_t *p_playlist, int i_pos,
+                         const char * psz_cat )
 {
     playlist_item_t *p_item = NULL;
 
@@ -172,34 +167,25 @@ playlist_CreateCategory( playlist_t *p_playlist, int i_item,
     {
         return NULL;
     }
-
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-        p_item = p_playlist->pp_items[i_item];
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        p_item = p_playlist->pp_items[p_playlist->i_index];
-    }
-    else
+    p_item = playlist_ItemGetByPos( p_playlist , i_pos );
+    if( !p_item )
     {
         return NULL;
     }
 
-    return playlist_CreateItemCategory( p_item, psz_cat );
+    return playlist_ItemCreateCategory( p_item, psz_cat );
 }
 
 /**
  * Create one info category for an item ( no p_playlist required )
  *
- * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
+ * \param p_playlist the playlist
+ * \param p_item the item to create category for
  * \param psz_cat the category we want to create
  * \return the info category.
  */
 item_info_category_t *
-playlist_CreateItemCategory( playlist_item_t *p_item, const char *psz_cat )
+playlist_ItemCreateCategory( playlist_item_t *p_item, const char *psz_cat )
 {
     item_info_category_t *p_cat;
     int i;
@@ -230,11 +216,14 @@ playlist_CreateItemCategory( playlist_item_t *p_item, const char *psz_cat )
 /**
  * Add an info item
  *
- * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
+ * \param p_playlist the playlist
+ * \param i_item the position of the item on which we want
+ *               the info ( -1 for current )
  * \param psz_cat the category we want to put the info into
- *     (gets created if needed)
- * \return the info category.
+ *                (gets created if needed)
+ * \param psz_name the name of the info
+ * \param psz_format printf-style info
+ * \return VLC_SUCCESS
  */
 int playlist_AddInfo( playlist_t *p_playlist, int i_item,
                       const char * psz_cat, const char *psz_name,
@@ -248,41 +237,22 @@ int playlist_AddInfo( playlist_t *p_playlist, int i_item,
     /* Check the existence of the playlist */
     if( p_playlist == NULL)
     {
-        return -1;
+        return VLC_EGENERIC;
     }
 
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
+    p_item = playlist_ItemGetByPos( p_playlist, i_item );
+    if( !p_item )
     {
-        p_item = p_playlist->pp_items[i_item];
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        p_item = p_playlist->pp_items[p_playlist->i_index];
-    }
-    else
-    {
-        return -1;
+            return VLC_ENOOBJ;
     }
 
     va_start( args, psz_format );
-
-    /* Convert our message to a string */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
     vasprintf( &psz_value, psz_format, args );
-#else
-    psz_value = (char*)malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE );
-    if( psz_value == NULL )
-    {
-       msg_Err( p_playlist, "out of memory" );
-       return VLC_EGENERIC;
-    }
-    vsprintf( psz_value, psz_format, args );
-#endif
-
     va_end( args );
 
-    i_ret = playlist_AddItemInfo( p_item , psz_cat , psz_name , psz_value );
+    vlc_mutex_lock( &p_item->lock );
+    i_ret = playlist_ItemAddInfo( p_item , psz_cat , psz_name , psz_value );
+    vlc_mutex_unlock( &p_item->lock );
 
     free( psz_value );
     return i_ret;
@@ -292,12 +262,13 @@ int playlist_AddInfo( playlist_t *p_playlist, int i_item,
 /**
  *  Add info to one item ( no need for p_playlist )
  *
- * \param p_item the item on which we want the info
- * \param psz_cat the category in which the info is stored (must exist !)
+ * \param p_item the item for which we add the info
+ * \param psz_cat the category in which the info is stored
  * \param psz_name the name of the info
- * \return the info value if any, NULL else
+ * \param psz_format printf-style info
+ * \return VLC_SUCCESS on success
 */
-int playlist_AddItemInfo( playlist_item_t *p_item,
+int playlist_ItemAddInfo( playlist_item_t *p_item,
                       const char *psz_cat, const char *psz_name,
                       const char *psz_format, ... )
 {
@@ -308,10 +279,10 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
     item_info_category_t *p_cat;
 
     /* Find or create the category */
-    p_cat = playlist_GetItemCategory( p_item, psz_cat );
+    p_cat = playlist_ItemGetCategory( p_item, psz_cat );
     if( p_cat == NULL)
     {
-        return -1;
+        return VLC_EGENERIC;
     }
 
     for( i = 0 ; i< p_cat->i_infos ; i++)
@@ -330,7 +301,7 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
     {
         if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
         {
-            return -1;
+            return VLC_EGENERIC;
         }
         p_info->psz_name = strdup( psz_name);
     }
@@ -340,20 +311,7 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
     }
 
     va_start( args, psz_format );
-
-    /* Convert our message to a string */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
     vasprintf( &p_info->psz_value, psz_format, args );
-#else
-    p_info->psz_value =
-             (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE );
-    if( p_info->psz_value == NULL )
-    {
-        return -1;
-    }
-    vsprintf( p_info->psz_value, psz_format, args );
-#endif
-
     va_end( args );
 
     /* If this is new, insert it */
@@ -365,130 +323,5 @@ int playlist_AddItemInfo( playlist_item_t *p_item,
                      p_info );
     }
 
-    return 0;
-}
-
-/**
- * Add a special info : option
- *
- * \param p_playlist the playlist to get the info from
- * \param i_item the item on which we want the info ( -1 for current )
- * \param psz_value the option to add
- * \return the info category.
- */
-int playlist_AddOption( playlist_t *p_playlist, int i_item,
-                        const char * psz_format, ...)
-{
-    va_list args;
-    item_info_t *p_info = NULL;
-    item_info_category_t *p_cat;
-
-    /* Check the existence of the playlist */
-    if( p_playlist == NULL)
-    {
-        return -1;
-    }
-
-    /* Get a correct item */
-    if( i_item >= 0 && i_item < p_playlist->i_size )
-    {
-    }
-    else if( p_playlist->i_size > 0 )
-    {
-        i_item = p_playlist->i_index;
-    }
-    else
-    {
-        return -1;
-    }
-
-    p_cat = playlist_GetCategory( p_playlist, i_item , "Options" );
-
-    if( p_cat == NULL)
-    {
-        return -1;
-    }
-
-    if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
-    {
-        msg_Err( p_playlist, "out of memory" );
-        return -1;
-    }
-
-    p_info->psz_name = strdup( "option" );
-
-    va_start( args, psz_format );
-
-    /* Convert our message to a string */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
-    vasprintf( &p_info->psz_value, psz_format, args );
-#else
-    p_info->psz_value =
-              (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE );
-    if( p_info->psz_value == NULL )
-    {
-       msg_Err( p_playlist, "out of memory" );
-       return -1;
-    }
-    vsprintf( p_info->psz_value, psz_format, args );
-#endif
-
-    va_end( args );
-
-
-    INSERT_ELEM( p_cat->pp_infos ,
-                 p_cat->i_infos,
-                 p_cat->i_infos,
-                 p_info );
-    return 0;
-}
-
-/**
- *  Add a option to one item ( no need for p_playlist )
- *
- * \param p_item the item on which we want the info
- * \param psz_format the option
- * \return 0 on success
-*/
-int playlist_AddItemOption( playlist_item_t *p_item,
-                      const char *psz_format, ... )
-{
-    va_list args;
-    item_info_t *p_info = NULL;
-    item_info_category_t *p_cat;
-
-    p_cat = playlist_GetItemCategory( p_item, "Options" );
-    if( p_cat == NULL)
-    {
-        return -1;
-    }
-
-    if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
-    {
-        return -1;
-    }
-    p_info->psz_name = strdup( "option" );
-
-    va_start( args, psz_format );
-
-    /* Convert our message to a string */
-#if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
-    vasprintf( &p_info->psz_value, psz_format, args );
-#else
-    p_info->psz_value =
-             (char*) malloc( strlen(psz_format) + INTF_MAX_MSG_SIZE );
-    if( p_info->psz_value == NULL )
-    {
-        return -1;
-    }
-    vsprintf( p_info->psz_value, psz_format, args );
-#endif
-
-    va_end( args );
-
-    INSERT_ELEM( p_cat->pp_infos,
-                     p_cat->i_infos,
-                     p_cat->i_infos,
-                     p_info );
-    return 0;
+    return VLC_SUCCESS;
 }