]> git.sesse.net Git - vlc/commitdiff
* Makefile.am : Added src/playlist/item-ext.c and src/playlist/info.c
authorClément Stenac <zorglub@videolan.org>
Mon, 5 Jan 2004 12:59:43 +0000 (12:59 +0000)
committerClément Stenac <zorglub@videolan.org>
Mon, 5 Jan 2004 12:59:43 +0000 (12:59 +0000)
* src/playlist/item.c
  src/playlist/info.c
  src/playlist/item-ext.c
  src/playlist/group.c
  src/playlist/sort.c
  src/playlist/loadsave.c
  include/vlc_playlist.h
      - New playlist_info structures and accessors
        It works pretty like the old input_info (with categories)
        It provides modularity to the playlist
      - Removed ppsz_options and i_options from playlist_item
        (we use the special category Options)
      - Added a unique id to each playlist_item to be able to track the
        items accross playlist reorders
      - Simplified adding of items.
           - playlist_AddExt is removed
           - playlist_AddItem is still here and exported but should not be used
           - use playlist_Add( p_playlist, uri, name, duration, mode, pos )
             and use the accessors for all other things
      - Added setters for fields of the playlist_item structure
      - Introduced "item-change" and "playlist-current" playlist variables
        to give more flexibility than only intf-change

      At the moment, duration is still in the structure (easier to use, IMHO)

* src/input/input.c
  src/libvlc.c :
        playlist item options parsing changed

* include/vlc_common.h : added playlist_info structures

12 files changed:
Makefile.am
include/vlc_common.h
include/vlc_playlist.h
src/input/input.c
src/libvlc.c
src/playlist/group.c
src/playlist/info.c [new file with mode: 0644]
src/playlist/item-ext.c [new file with mode: 0644]
src/playlist/item.c
src/playlist/loadsave.c
src/playlist/playlist.c
src/playlist/sort.c

index 47ebb1219ccbe8c5d60a415eda3c44974427957f..dd5f2bab178bddb4f09d06aaf511cbd70f8aa130 100644 (file)
@@ -317,6 +317,8 @@ SOURCES_libvlc_common = \
        src/playlist/loadsave.c \
        src/playlist/group.c \
        src/playlist/item.c \
+       src/playlist/item-ext.c \
+        src/playlist/info.c \
        src/input/input.c \
        src/input/es_out.c \
        src/input/stream.c \
index 37a3fc4b392023ce1207c33626168ce7d02d0552..241ad30167e4eb4f552509ebfe4c7c3bce49780d 100644 (file)
@@ -3,7 +3,7 @@
  * Collection of useful common types and macros definitions
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vlc_common.h,v 1.96 2003/12/06 22:45:53 jpsaman Exp $
+ * $Id: vlc_common.h,v 1.97 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@via.ecp.fr>
  *          Vincent Seguin <seguin@via.ecp.fr>
@@ -190,6 +190,8 @@ typedef struct msg_subscription_t msg_subscription_t;
 typedef struct playlist_t playlist_t;
 typedef struct playlist_item_t playlist_item_t;
 typedef struct playlist_group_t playlist_group_t;
+typedef struct item_info_t item_info_t;
+typedef struct item_info_category_t item_info_category_t;
 
 /* Modules */
 typedef struct module_bank_t module_bank_t;
index 652a04b1128e37c1217e7d87e8d97924fc93a122..e268aa550d7571f2466e56ac48105ff905bf99b5 100644 (file)
@@ -2,7 +2,7 @@
  * vlc_playlist.h : Playlist functions
  *****************************************************************************
  * Copyright (C) 1999, 2000, 2001, 2002 VideoLAN
- * $Id: vlc_playlist.h,v 1.18 2003/12/03 21:58:42 sigmunau Exp $
+ * $Id: vlc_playlist.h,v 1.19 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
  * @{
  */
 
+/**
+ * Playlist info item
+ * \see playlist_item_t
+ */
+
+struct item_info_t
+{
+    char * psz_name;            /**< Name of this info */
+    char * psz_value;           /**< Value of the info */
+};
+
+/**
+ * playlist item info category
+ * \see playlist_item_t
+ * \see item_info_t
+ */
+struct item_info_category_t
+{
+    char * psz_name;            /**< Name of this category */
+    int i_infos;                /**< Number of infos in the category */
+    item_info_t **pp_infos;     /**< Pointer to an array of infos */
+};
+
 /**
  * playlist item
  * \see playlist_t
@@ -41,23 +64,27 @@ struct playlist_item_t
 {
     char *     psz_name;       /**< text describing this item */
     char *     psz_uri;        /**< mrl of this item */
-    mtime_t    i_duration;     /**< A hint about the duration of this item */
-    char **    ppsz_options;   /**< options passed with the :foo=bar syntax */
-    int        i_options;      /**< number of items in the
-                                * ppsz_options array */
-    int        i_type;         /**< unused yet */
+    mtime_t    i_duration;     /**< A hint about the duration of this
+                                * item, in miliseconds*/
+    int i_categories;          /**< Number of info categories */
+    item_info_category_t **pp_categories;
+                               /**< Pointer to the first info category */
     int        i_status;       /**< unused yet */
+    int        i_nb_played;    /**< How many times was this item played ? */
     vlc_bool_t b_autodeletion; /**< Indicates whther this item is to
                                 * be deleted after playback. True mean
                                 * that this item is to be deleted
                                 * after playback, false otherwise */
     vlc_bool_t b_enabled;      /**< Indicates whether this item is to be
                                 * played or skipped */
-
-    int        i_group;         /**< unused yet */
-    char *     psz_author;     /**< Author */
+    int        i_group;         /**< Which group does this item belongs to ? */
+    int        i_id;           /**< Unique id to track this item */
 };
 
+/**
+ * playlist group
+ * \see playlist_t
+ */
 struct playlist_group_t
 {
     char *   psz_name;        /**< name of the group */
@@ -89,9 +116,10 @@ struct playlist_t
     int                   i_groups; /**< How many groups are in the playlist */
     playlist_group_t **   pp_groups;/**< array of pointers to the playlist
                                      * groups */
-    int                   i_max_id; /**< Maximal group id given */
+    int                   i_last_group; /**< Maximal group id given */
     input_thread_t *      p_input;  /**< the input thread ascosiated
                                      * with the current item */
+    int                   i_last_id; /**< Last id to an item */
     /*@}*/
 };
 
@@ -120,10 +148,13 @@ void           playlist_Destroy  ( playlist_t * );
 #define playlist_Prev(p) playlist_Command(p,PLAYLIST_SKIP,-1)
 #define playlist_Skip(p,i) playlist_Command(p,PLAYLIST_SKIP,i)
 #define playlist_Goto(p,i) playlist_Command(p,PLAYLIST_GOTO,i)
+
 VLC_EXPORT( void, playlist_Command, ( playlist_t *, playlist_command_t, int ) );
 
-VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char **, int, int, int ) );
-VLC_EXPORT( int,  playlist_AddExt,    ( playlist_t *, const char *, const char *, mtime_t, const char **, int, int, int ) );
+
+/* Item functions */
+VLC_EXPORT( int,  playlist_Add,    ( playlist_t *, const char *, const char *, int, int ) );
+/* For internal use. Do not use this one anymore */
 VLC_EXPORT( int,  playlist_AddItem, ( playlist_t *, playlist_item_t *, int, int ) );
 VLC_EXPORT( int,  playlist_Delete, ( playlist_t *, int ) );
 VLC_EXPORT( int,  playlist_Disable, ( playlist_t *, int ) );
@@ -131,18 +162,47 @@ VLC_EXPORT( int,  playlist_Enable, ( playlist_t *, int ) );
 VLC_EXPORT( int,  playlist_DisableGroup, ( playlist_t *, int ) );
 VLC_EXPORT( int,  playlist_EnableGroup, ( playlist_t *, int ) );
 
+/* Basic item informations accessors */
+VLC_EXPORT( int, playlist_SetGroup, (playlist_t *, int, int ) );
+VLC_EXPORT( int, playlist_SetName, (playlist_t *, int, char * ) );
+VLC_EXPORT( int, playlist_SetDuration, (playlist_t *, int, int ) );
+
+/* Item search functions */
+VLC_EXPORT( int, playlist_GetPositionById, (playlist_t *, int) );
+VLC_EXPORT( playlist_item_t *, playlist_GetItemById, (playlist_t *, int) );
+
+
+/* Group management functions */
 VLC_EXPORT( playlist_group_t *, playlist_CreateGroup, (playlist_t *, char* ) );
 VLC_EXPORT( int, playlist_DeleteGroup, (playlist_t *, int ) );
 VLC_EXPORT( char *, playlist_FindGroup, (playlist_t *, int ) );
 VLC_EXPORT( int, playlist_GroupToId, (playlist_t *, char * ) );
 
+/* Info functions */
+VLC_EXPORT( char * , playlist_GetInfo, ( playlist_t * , int, const char *, const char *) );
+VLC_EXPORT( char * , playlist_GetItemInfo, ( playlist_item_t * , const char *, const char *) );
+
+VLC_EXPORT( item_info_category_t*, playlist_GetCategory, ( playlist_t *, int, const char *) );
+VLC_EXPORT( item_info_category_t*, playlist_GetItemCategory, ( playlist_item_t *, const char *) );
+
+VLC_EXPORT( item_info_category_t*, playlist_CreateCategory, ( playlist_t *, int, const char *) );
+VLC_EXPORT( item_info_category_t*, playlist_CreateItemCategory, ( playlist_item_t *, const char *) );
+
+VLC_EXPORT( int, playlist_AddInfo, (playlist_t *, int, const char * , const char *, const char *, ...) );
+VLC_EXPORT( int, playlist_AddItemInfo, (playlist_item_t *, const char * , const char *, const char *, ...) );
+
+/* Option functions */
+VLC_EXPORT( int, playlist_AddOption, (playlist_t *, int, const char *, ...) );
+VLC_EXPORT( int, playlist_AddItemOption, (playlist_item_t *, const char *, ...) );
+
+/* Playlist sorting */
 #define playlist_SortTitle(p, i) playlist_Sort( p, SORT_TITLE, i)
 #define playlist_SortAuthor(p, i) playlist_Sort( p, SORT_AUTHOR, i)
 #define playlist_SortGroup(p, i) playlist_Sort( p, SORT_GROUP, i)
-
 VLC_EXPORT( int,  playlist_Sort, ( playlist_t *, int, int) );
-
 VLC_EXPORT( int,  playlist_Move, ( playlist_t *, int, int ) );
+
+/* Load/Save */
 VLC_EXPORT( int,  playlist_LoadFile, ( playlist_t *, const char * ) );
 VLC_EXPORT( int,  playlist_SaveFile, ( playlist_t *, const char * ) );
 
index 2d56bc79d7be95f281289c68eed5eb14fb28b2c6..50e57e4beebc554a72dad71eb2e26dc420613101 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: input.c,v 1.271 2003/12/03 22:14:38 sigmunau Exp $
+ * $Id: input.c,v 1.272 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -86,8 +86,9 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
 {
     input_thread_t *    p_input;                        /* thread descriptor */
     input_info_category_t * p_info;
+    item_info_category_t *p_cat;
     vlc_value_t val;
-    int i;
+    int i,j;
 
     /* Allocate descriptor */
     p_input = vlc_object_create( p_parent, VLC_OBJECT_INPUT );
@@ -98,9 +99,21 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
     }
 
     /* Parse input options */
-    for( i = 0; i < p_item->i_options; i++ )
+    for( i = 0 ; i < p_item->i_categories ; i++ )
     {
-        ParseOption( p_input, p_item->ppsz_options[i] );
+        if( !strncmp( p_item->pp_categories[i]->psz_name, "Options", 7 ) )
+        {
+            msg_Dbg(p_input,"Parsing %i options for item",
+                             p_item->pp_categories[i]->i_infos );
+            for( j = 0; j< p_item->pp_categories[i]->i_infos ; j++ )
+            {
+                msg_Dbg(p_input,"Option : %s",
+                         p_item->pp_categories[i]->pp_infos[j]->psz_name);
+                ParseOption( p_input,
+                             p_item->pp_categories[i]->pp_infos[j]->psz_value);
+            }
+            break;
+        }
     }
 
     /* Create a few object variables we'll need later on */
@@ -789,15 +802,13 @@ static int InitThread( input_thread_t * p_input )
                                                    FIND_PARENT );
         if( p_playlist )
         {
-            vlc_mutex_lock( &p_playlist->object_lock );
-            p_playlist->pp_items[ p_playlist->i_index ]->i_duration = i_length;
+            playlist_SetDuration( p_playlist, -1 , i_length );
             val.b_bool = VLC_TRUE;
-            vlc_mutex_unlock( &p_playlist->object_lock );
-            var_Set( p_playlist, "intf-change", val );
+            var_Set( p_playlist, "item-change", val );
             vlc_object_release( p_playlist );
         }
-    }            
-       
+    }
+
 
     /* get fps */
     if( demux_Control( p_input, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
index 3eb2191ff6a0d561cfe6c6be186a2071a32af206..6c8137919acd7155e5f4d9cee5230773496bfa91 100644 (file)
@@ -2,7 +2,7 @@
  * libvlc.c: main libvlc source
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: libvlc.c,v 1.106 2003/12/24 10:06:53 gbazin Exp $
+ * $Id: libvlc.c,v 1.107 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Vincent Seguin <seguin@via.ecp.fr>
  *          Samuel Hocevar <sam@zoy.org>
@@ -796,6 +796,7 @@ int VLC_AddTarget( int i_object, char const *psz_target,
                    char const **ppsz_options, int i_options,
                    int i_mode, int i_pos )
 {
+    int i;
     int i_err;
     playlist_t *p_playlist;
     vlc_t *p_vlc = vlc_current_object( i_object );
@@ -821,9 +822,14 @@ int VLC_AddTarget( int i_object, char const *psz_target,
         vlc_object_yield( p_playlist );
     }
 
-    i_err = playlist_Add( p_playlist, psz_target, ppsz_options, i_options,
+    i_err = playlist_Add( p_playlist, psz_target, psz_target,
                           i_mode, i_pos );
 
+    for( i = 0 ; i< i_options ; i++ )
+    {
+        playlist_AddOption( p_playlist, i_err , ppsz_options[i] );
+    }
+
     vlc_object_release( p_playlist );
 
     if( i_object ) vlc_object_release( p_vlc );
index 60c4d1cc5177ec46b6f7dc07e9449610ca8696bd..feb86804332faeb5586f8e3b5e67f1e5132da9aa 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.c : Playlist groups management functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: group.c,v 1.4 2003/12/11 11:30:37 zorglub Exp $
+ * $Id: group.c,v 1.5 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *
@@ -61,7 +61,7 @@ playlist_group_t * playlist_CreateGroup(playlist_t * p_playlist, char *psz_name)
     }
 
     p_group->psz_name = strdup( psz_name );
-    p_group->i_id = ++p_playlist->i_max_id;
+    p_group->i_id = ++p_playlist->i_last_group;
 
     msg_Dbg(p_playlist,"Creating group %s with id %i at position %i",
                      p_group->psz_name,
@@ -110,7 +110,7 @@ int playlist_DeleteGroup( playlist_t *p_playlist, int i_id )
 }
 
 /**
- * Find the name with the ID
+ * Find the name of the group given its ID
  *
  * \param p_playlist the playlist where to find the group
  * \param i_id the ID to search for
@@ -124,14 +124,14 @@ char *playlist_FindGroup( playlist_t *p_playlist, int i_id )
         if( p_playlist->pp_groups[i]->i_id == i_id )
         {
             if( p_playlist->pp_groups[i]->psz_name)
-            return strdup( p_playlist->pp_groups[i]->psz_name );
+                return strdup( p_playlist->pp_groups[i]->psz_name );
         }
     }
     return NULL;
 }
 
 /**
- * Find the Id with the given name
+ * Find the Id of a group given its name
  *
  * \param p_playlist the playlist where to find the group
  * \param char * the name to search for
diff --git a/src/playlist/info.c b/src/playlist/info.c
new file mode 100644 (file)
index 0000000..11cdb11
--- /dev/null
@@ -0,0 +1,496 @@
+/*****************************************************************************
+ * info.c : Playlist info management
+ *****************************************************************************
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: info.c,v 1.1 2004/01/05 12:59:43 zorglub Exp $
+ *
+ * Authors: Clément Stenac <zorglub@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <stdlib.h>                                      /* free(), strtol() */
+#include <stdio.h>                                              /* sprintf() */
+#include <string.h>                                            /* strerror() */
+
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+#include <vlc/sout.h>
+
+#include "vlc_playlist.h"
+
+/**
+ * Get one special info
+ *
+ * \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_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
+*/
+char * playlist_GetInfo( playlist_t *p_playlist, int i_item,
+                      const char * psz_cat, const char *psz_name )
+{
+    /* 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
+    {
+        return strdup("");
+    }
+    return playlist_GetItemInfo( p_playlist->pp_items[i_item] , psz_cat,
+                                 psz_name );
+}
+
+/**
+ *  Get one special info, from an 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
+ * \param psz_name the name of the info
+ * \return the info value if any, NULL else
+*/
+char * playlist_GetItemInfo( playlist_item_t *p_item,
+                      const char * psz_cat, const char *psz_name )
+{
+     int i,j ;
+     for( i = 0 ; i< p_item->i_categories ; i++ )
+     {
+         if( !strcmp( p_item->pp_categories[i]->psz_name , psz_cat ) )
+         {
+             for( j = 0 ; j< p_item->pp_categories[i]->i_infos ; j++ )
+             {
+                 if( !strcmp( p_item->pp_categories[i]->pp_infos[j]->psz_name,
+                                         psz_name ) )
+                 {
+                     return
+                     strdup(p_item->pp_categories[i]->pp_infos[j]->psz_value );
+                 }
+             }
+         }
+     }
+     return strdup("");
+}
+
+/**
+ * Get one info category. Creates 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 psz_cat the category we want
+ * \return the info category.
+ */
+item_info_category_t *
+playlist_GetCategory( playlist_t *p_playlist, int i_item,
+                      const char * psz_cat )
+{
+    int i;
+
+    /* 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
+    {
+        return NULL;
+    }
+
+    return playlist_GetItemCategory( p_playlist->pp_items[i_item] , psz_cat );
+}
+
+/**
+ * Get one info category (no p_playlist). Creates it if it does not exist
+ *
+ * \param p_item the playlist to search categories in
+ * \param psz_cat the category we want
+ * \return the info category.
+ */
+item_info_category_t *playlist_GetItemCategory( playlist_item_t *p_item,
+                                                const char *psz_cat )
+{
+    int i;
+    /* Search the category */
+    for( i = 0 ; i< p_item->i_categories ; i++ )
+    {
+        if( !strncmp( p_item->pp_categories[i]->psz_name , psz_cat,
+                                strlen(psz_cat) ) )
+        {
+            return p_item->pp_categories[i];
+        }
+    }
+
+    /* We did not find the category, create it */
+    return playlist_CreateItemCategory( 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 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_item_t *p_item = NULL;
+
+    /* 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 )
+    {
+        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 NULL;
+    }
+
+    return playlist_CreateItemCategory( 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 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 )
+{
+    item_info_category_t *p_cat;
+    int i;
+    for( i = 0 ; i< p_item->i_categories ; i++)
+    {
+        if( !strcmp( p_item->pp_categories[i]->psz_name,psz_cat ) )
+        {
+            return p_item->pp_categories[i];
+        }
+    }
+    if( ( p_cat = malloc( sizeof( item_info_category_t) ) ) == NULL )
+    {
+        return NULL;
+    }
+
+    p_cat->psz_name = strdup( psz_cat);
+    p_cat->i_infos = 0;
+    p_cat->pp_infos = NULL;
+
+    INSERT_ELEM( p_item->pp_categories ,
+                 p_item->i_categories ,
+                 p_item->i_categories ,
+                 p_cat );
+
+    return p_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 psz_cat the category we want to put the info into
+ *     (gets created if needed)
+ * \return the info category.
+ */
+int playlist_AddInfo( playlist_t *p_playlist, int i_item,
+                      const char * psz_cat, const char *psz_name,
+                      const char * psz_format, ...)
+{
+    va_list args;
+    int i;
+    int i_new = VLC_TRUE;
+    playlist_item_t *p_item;
+    char *psz_value;
+
+    /* 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 )
+    {
+        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;
+    }
+
+    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 );
+
+    return playlist_AddItemInfo( p_item , psz_cat , psz_name , psz_value );
+}
+
+
+/**
+ *  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 psz_name the name of the info
+ * \return the info value if any, NULL else
+*/
+int playlist_AddItemInfo( playlist_item_t *p_item,
+                      const char *psz_cat, const char *psz_name,
+                      const char *psz_format, ... )
+{
+    va_list args;
+    int i;
+    int i_new = VLC_TRUE;
+    item_info_t *p_info = NULL;
+    item_info_category_t *p_cat;
+
+    /* Find or create the category */
+    p_cat = playlist_GetItemCategory( p_item, psz_cat );
+    if( p_cat == NULL)
+    {
+        return -1;
+    }
+
+    for( i = 0 ; i< p_cat->i_infos ; i++)
+    {
+        if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
+        {
+            /* This info is not new */
+            p_info = p_cat->pp_infos[i];
+            i_new = VLC_FALSE;
+            break;
+        }
+    }
+
+    /* New info, create it */
+    if( p_info == NULL )
+    {
+        if( ( p_info = malloc( sizeof( item_info_t) ) ) == NULL )
+        {
+            return -1;
+        }
+        p_info->psz_name = strdup( psz_name);
+    }
+    else
+    {
+        if( p_info->psz_value != NULL ) free( p_info->psz_value ) ;
+    }
+
+    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 */
+    if( i_new == VLC_TRUE )
+    {
+        INSERT_ELEM( p_cat->pp_infos,
+                     p_cat->i_infos,
+                     p_cat->i_infos,
+                     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;
+    int i_new = VLC_TRUE;
+    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;
+}
diff --git a/src/playlist/item-ext.c b/src/playlist/item-ext.c
new file mode 100644 (file)
index 0000000..59952a8
--- /dev/null
@@ -0,0 +1,533 @@
+/*****************************************************************************
+ * item-ext.c : Exported playlist item functions
+ *****************************************************************************
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: item-ext.c,v 1.1 2004/01/05 12:59:43 zorglub Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *          Clément Stenac <zorglub@videolan.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+#include <stdlib.h>                                      /* free(), strtol() */
+#include <stdio.h>                                              /* sprintf() */
+#include <string.h>                                            /* strerror() */
+
+#include <vlc/vlc.h>
+#include <vlc/vout.h>
+#include <vlc/sout.h>
+
+#include "vlc_playlist.h"
+
+/**
+ * Add a MRL into the playlist.
+ *
+ * \param p_playlist the playlist to add into
+ * \param psz_uri the mrl to add to the playlist
+ * \param psz_name a text giving a name or description of this item
+ * \param i_mode the mode used when adding
+ * \param i_pos the position in the playlist where to add. If this is
+ *        PLAYLIST_END the item will be added at the end of the playlist
+ *        regardless of it's size
+ * \return the position of the new item
+*/
+int playlist_Add( playlist_t *p_playlist, const char * psz_uri,
+                     const char *psz_name, int i_mode, int i_pos )
+{
+    playlist_item_t * p_item;
+
+    p_item = malloc( sizeof( playlist_item_t ) );
+    if( p_item == NULL )
+    {
+        msg_Err( p_playlist, "out of memory" );
+    }
+
+    p_item->psz_name   = strdup( psz_name );
+    p_item->psz_uri    = strdup( psz_uri );
+    p_item->i_status = 0;
+    p_item->b_autodeletion = VLC_FALSE;
+    p_item->b_enabled = VLC_TRUE;
+    p_item->i_group = PLAYLIST_TYPE_MANUAL;
+    p_item->i_duration = -1;
+
+    p_item->pp_categories = NULL;
+    p_item->i_categories = 0;
+
+    playlist_CreateItemCategory( p_item, "General");
+    playlist_CreateItemCategory( p_item, "Options");
+    return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
+}
+
+/**
+ * Search the position of an item by its id
+ * \param p_playlist the playlist
+ * \param i_id the id to find
+ * \return the position, or -1 on failure
+ */
+int playlist_GetPositionById( playlist_t * p_playlist , int i_id )
+{
+    int i;
+    for( i =  0 ; i < p_playlist->i_size ; i++ )
+    {
+        if( p_playlist->pp_items[i]->i_id == i_id )
+        {
+            return i;
+        }
+    }
+    return -1;
+}
+
+
+/**
+ * Search an item by its id
+ * \param p_playlist the playlist
+ * \param i_id the id to find
+ * \return the item, or NULL on failure
+ */
+playlist_item_t * playlist_GetItemById( playlist_t * p_playlist , int i_id )
+{
+    int i;
+    for( i =  0 ; i < p_playlist->i_size ; i++ )
+    {
+        if( p_playlist->pp_items[i]->i_id == i_id )
+        {
+            return p_playlist->pp_items[i];
+        }
+    }
+    return NULL;
+}
+
+/**********************************************************************
+ * playlist_item_t structure accessors
+ * These functions give access to the fields of the playlist_item_t
+ * structure
+ **********************************************************************/
+
+/**
+ * Set the group of a playlist item
+ *
+ * \param p_playlist the playlist
+ * \param i_item the item of which we change the group
+ * \param i_group the new group
+ * \return 0 on success, -1 on failure
+ */
+int playlist_SetGroup( playlist_t *p_playlist, int i_item, int i_group )
+{
+    char *psz_group;
+    /* 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;
+    }
+
+    psz_group = playlist_FindGroup( p_playlist , i_group );
+    if( psz_group != NULL)
+    {
+        p_playlist->pp_items[i_item]->i_group = i_group ;
+    }
+    return 0;
+}
+
+/**
+ * Set the name of a playlist item
+ *
+ * \param p_playlist the playlist
+ * \param i_item the item of which we change the name
+ * \param psz_name the new name
+ * \return VLC_SUCCESS on success, VLC_EGENERIC on failure
+ */
+int playlist_SetName( playlist_t *p_playlist, int i_item, char *psz_name )
+{
+    vlc_value_t val;
+
+    /* 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;
+    }
+
+    if( p_playlist->pp_items[i_item]->psz_name)
+        free( p_playlist->pp_items[i_item]->psz_name );
+
+    if( psz_name )
+        p_playlist->pp_items[i_item]->psz_name = strdup( psz_name );
+
+    val.b_bool = i_item;
+    var_Set( p_playlist, "item-change", val );
+    return VLC_SUCCESS;
+}
+
+/**
+ * Set the duration of a playlist item
+ *
+ * \param p_playlist the playlist
+ * \param i_item the item of which we change the name
+ * \param i_duration the duration to set
+ * \return VLC_SUCCESS on success, VLC_EGENERIC on failure
+ */
+int playlist_SetDuration( playlist_t *p_playlist, int i_item, int i_duration )
+{
+    char psz_buffer[MSTRTIME_MAX_SIZE];
+    vlc_value_t val;
+
+    /* 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 VLC_EGENERIC;
+    }
+
+    p_playlist->pp_items[i_item]->i_duration = i_duration;
+    if( i_duration != -1 )
+    {
+        secstotimestr( psz_buffer, i_duration/1000000 );
+    }
+    else
+    {
+        memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
+    }
+    playlist_AddInfo( p_playlist, i_item, _("General") , _("Duration"),
+                      "%s", psz_buffer );
+
+    val.b_bool = i_item;
+    var_Set( p_playlist, "item-change", val );
+    return VLC_SUCCESS;
+}
+
+/**********************************************************************
+ * Actions on existing playlist items
+ **********************************************************************/
+
+
+/**
+ * delete an item from a playlist.
+ *
+ * \param p_playlist the playlist to remove from.
+ * \param i_pos the position of the item to remove
+ * \return returns 0
+ */
+int playlist_Delete( playlist_t * p_playlist, int i_pos )
+{
+    vlc_value_t     val;
+    int i,j;
+
+    /* if i_pos is the current played item, playlist should stop playing it */
+    if( ( p_playlist->i_status == PLAYLIST_RUNNING) && (p_playlist->i_index == i_pos) )
+    {
+        playlist_Command( p_playlist, PLAYLIST_STOP, 0 );
+    }
+
+    vlc_mutex_lock( &p_playlist->object_lock );
+    if( i_pos >= 0 && i_pos < p_playlist->i_size )
+    {
+        playlist_item_t *p_item = p_playlist->pp_items[i_pos];
+
+        msg_Dbg( p_playlist, "deleting playlist item « %s »",
+                 p_item->psz_name );
+
+        if( p_item->psz_name )
+        {
+            free( p_item->psz_name );
+        }
+        if( p_item->psz_uri )
+        {
+            free( p_item->psz_uri );
+        }
+
+        /* Free the info categories. Welcome to the segfault factory */
+        if( p_item->i_categories > 0 )
+        {
+            for( i = 0; i < p_item->i_categories; i++ )
+            {
+                for( j= 0 ; j < p_item->pp_categories[i]->i_infos; j++)
+                {
+                    if( p_item->pp_categories[i]->pp_infos[j]->psz_name)
+                    {
+                        free( p_item->pp_categories[i]->
+                                      pp_infos[j]->psz_name);
+                    }
+                    if( p_item->pp_categories[i]->pp_infos[j]->psz_value)
+                    {
+                        free( p_item->pp_categories[i]->
+                                      pp_infos[j]->psz_value);
+                    }
+                    free( p_item->pp_categories[i]->pp_infos[j] );
+                }
+                if( p_item->pp_categories[i]->psz_name)
+                {
+                    free( p_item->pp_categories[i]->psz_name );
+                }
+                free( p_item->pp_categories[i] );
+            }
+        }
+
+        /* XXX: what if the item is still in use? */
+        free( p_item );
+
+        if( i_pos <= p_playlist->i_index )
+        {
+            p_playlist->i_index--;
+        }
+
+        /* Renumber the playlist */
+        REMOVE_ELEM( p_playlist->pp_items,
+                     p_playlist->i_size,
+                     i_pos );
+        if( p_playlist->i_enabled > 0 )
+            p_playlist->i_enabled--;
+    }
+
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    val.b_bool = VLC_TRUE;
+    var_Set( p_playlist, "intf-change", val );
+
+    return 0;
+}
+
+/**
+ * Disables a playlist item
+ *
+ * \param p_playlist the playlist to disable from.
+ * \param i_pos the position of the item to disable
+ * \return returns 0
+ */
+int playlist_Disable( playlist_t * p_playlist, int i_pos )
+{
+    vlc_value_t     val;
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+
+    if( i_pos >= 0 && i_pos < p_playlist->i_size )
+    {
+        msg_Dbg( p_playlist, "disabling playlist item « %s »",
+                             p_playlist->pp_items[i_pos]->psz_name );
+
+        if( p_playlist->pp_items[i_pos]->b_enabled == VLC_TRUE )
+            p_playlist->i_enabled--;
+        p_playlist->pp_items[i_pos]->b_enabled = VLC_FALSE;
+    }
+
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    val.b_bool = i_pos;
+    var_Set( p_playlist, "item-change", val );
+
+    return 0;
+}
+
+/**
+ * Enables a playlist item
+ *
+ * \param p_playlist the playlist to enable from.
+ * \param i_pos the position of the item to enable
+ * \return returns 0
+ */
+int playlist_Enable( playlist_t * p_playlist, int i_pos )
+{
+    vlc_value_t     val;
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+    if( i_pos >= 0 && i_pos < p_playlist->i_size )
+    {
+        msg_Dbg( p_playlist, "enabling playlist item « %s »",
+                             p_playlist->pp_items[i_pos]->psz_name );
+
+        if( p_playlist->pp_items[i_pos]->b_enabled == VLC_FALSE )
+            p_playlist->i_enabled++;
+
+        p_playlist->pp_items[i_pos]->b_enabled = VLC_TRUE;
+    }
+
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    val.b_bool = i_pos;
+    var_Set( p_playlist, "item-change", val );
+
+    return 0;
+}
+
+/**
+ * Disables a playlist group
+ *
+ * \param p_playlist the playlist to disable from.
+ * \param i_pos the id of the group to disable
+ * \return returns 0
+ */
+int playlist_DisableGroup( playlist_t * p_playlist, int i_group)
+{
+    vlc_value_t     val;
+    int i;
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+    msg_Dbg(p_playlist,"Disabling group %i",i_group);
+    for( i = 0 ; i< p_playlist->i_size; i++ )
+    {
+        if( p_playlist->pp_items[i]->i_group == i_group )
+        {
+            msg_Dbg( p_playlist, "disabling playlist item « %s »",
+                           p_playlist->pp_items[i]->psz_name );
+
+            if( p_playlist->pp_items[i]->b_enabled == VLC_TRUE )
+                p_playlist->i_enabled--;
+
+            p_playlist->pp_items[i]->b_enabled = VLC_FALSE;
+            val.b_bool = i;
+            var_Set( p_playlist, "item-change", val );
+        }
+    }
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    return 0;
+}
+
+/**
+ * Enables a playlist group
+ *
+ * \param p_playlist the playlist to enable from.
+ * \param i_pos the id of the group to enable
+ * \return returns 0
+ */
+int playlist_EnableGroup( playlist_t * p_playlist, int i_group)
+{
+    vlc_value_t     val;
+    int i;
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+    for( i = 0 ; i< p_playlist->i_size; i++ )
+    {
+        if( p_playlist->pp_items[i]->i_group == i_group )
+        {
+            msg_Dbg( p_playlist, "enabling playlist item « %s »",
+                           p_playlist->pp_items[i]->psz_name );
+
+            if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
+                p_playlist->i_enabled++;
+
+            p_playlist->pp_items[i]->b_enabled = VLC_TRUE;
+            val.b_bool = i;
+            var_Set( p_playlist, "item-change", val );
+        }
+    }
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    return 0;
+}
+
+/**
+ * Move an item in a playlist
+ *
+ * Move the item in the playlist with position i_pos before the current item
+ * at position i_newpos.
+ * \param p_playlist the playlist to move items in
+ * \param i_pos the position of the item to move
+ * \param i_newpos the position of the item that will be behind the moved item
+ *        after the move
+ * \return returns 0
+ */
+int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos)
+{
+    vlc_value_t     val;
+    vlc_mutex_lock( &p_playlist->object_lock );
+
+    /* take into account that our own row disappears. */
+    if ( i_pos < i_newpos ) i_newpos--;
+
+    if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size
+                     && i_newpos <= p_playlist->i_size )
+    {
+        playlist_item_t * temp;
+
+        msg_Dbg( p_playlist, "moving playlist item « %s » (%i -> %i)",
+                             p_playlist->pp_items[i_pos]->psz_name, i_pos,
+                             i_newpos );
+
+        if( i_pos == p_playlist->i_index )
+        {
+            p_playlist->i_index = i_newpos;
+        }
+        else if( i_pos > p_playlist->i_index && i_newpos <= p_playlist->i_index )
+        {
+            p_playlist->i_index++;
+        }
+        else if( i_pos < p_playlist->i_index && i_newpos >= p_playlist->i_index )
+        {
+            p_playlist->i_index--;
+        }
+
+        if ( i_pos < i_newpos )
+        {
+            temp = p_playlist->pp_items[i_pos];
+            while ( i_pos < i_newpos )
+            {
+                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1];
+                i_pos++;
+            }
+            p_playlist->pp_items[i_newpos] = temp;
+        }
+        else if ( i_pos > i_newpos )
+        {
+            temp = p_playlist->pp_items[i_pos];
+            while ( i_pos > i_newpos )
+            {
+                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1];
+                i_pos--;
+            }
+            p_playlist->pp_items[i_newpos] = temp;
+        }
+    }
+
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    val.b_bool = VLC_TRUE;
+    var_Set( p_playlist, "intf-change", val );
+
+    return 0;
+}
index 13b98c1fa35f27b21feb930f74d2abbbb7b9fa7b..715b99fae7d950e88a64161aab8efe1572af16f9 100644 (file)
@@ -2,7 +2,7 @@
  * item.c : Playlist item functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: item.c,v 1.9 2003/12/13 17:16:11 gbazin Exp $
+ * $Id: item.c,v 1.10 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
 
 #include "vlc_playlist.h"
 
-/**
- * Add an MRL to the playlist. This is a simplified version of
- * playlist_AddExt inculded for convenince. It equals calling playlist_AddExt
- * with psz_name == psz_target and i_duration == -1
- */
-
-int playlist_Add( playlist_t *p_playlist, const char *psz_target,
-                  const char **ppsz_options, int i_options,
-                  int i_mode, int i_pos )
-{
-    return playlist_AddExt( p_playlist, psz_target, psz_target, -1,
-                            ppsz_options, i_options, i_mode, i_pos );
-}
-
-/**
- * Add a MRL into the playlist.
- *
- * \param p_playlist the playlist to add into
- * \param psz_uri the mrl to add to the playlist
- * \param psz_name a text giving a name or description of this item
- * \param i_duration a hint about the duration of this item, in microseconds, 
- *        or -1 if unknown.
- * \param ppsz_options array of options
- * \param i_options number of items in ppsz_options
- * \param i_mode the mode used when adding
- * \param i_pos the position in the playlist where to add. If this is
- *        PLAYLIST_END the item will be added at the end of the playlist
- *        regardless of it's size
- * \return always returns 0
-*/
-int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
-                     const char * psz_name, mtime_t i_duration,
-                     const char **ppsz_options, int i_options, int i_mode,
-                     int i_pos )
-{
-    playlist_item_t * p_item;
-
-    p_item = malloc( sizeof( playlist_item_t ) );
-    if( p_item == NULL )
-    {
-        msg_Err( p_playlist, "out of memory" );
-    }
-
-    p_item->psz_name   = strdup( psz_name );
-    p_item->psz_uri    = strdup( psz_uri );
-    p_item->psz_author = strdup( "" );
-    p_item->i_duration = i_duration;
-    p_item->i_type = 0;
-    p_item->i_status = 0;
-    p_item->b_autodeletion = VLC_FALSE;
-    p_item->b_enabled = VLC_TRUE;
-    p_item->i_group = PLAYLIST_TYPE_MANUAL;
-
-    p_item->ppsz_options = NULL;
-    p_item->i_options = i_options;
-
-    if( i_options > 0 )
-    {
-        int i;
-
-        p_item->ppsz_options = malloc( i_options * sizeof(char *) );
-        for( i = 0; i < i_options; i++ )
-        {
-            p_item->ppsz_options[i] = strdup( ppsz_options[i] );
-        }
-
-    }
-
-    return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
-}
-
 /**
  * Add a playlist item into a playlist
  *
@@ -111,7 +40,7 @@ int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
  * \param i_pos the possition in the playlist where to add. If this is
  *        PLAYLIST_END the item will be added at the end of the playlist
  *        regardless of it's size
- * \return always returns 0
+ * \return position of the new item
 */
 int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
                 int i_mode, int i_pos)
@@ -142,22 +71,9 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
                       {
                           free( p_item->psz_uri );
                       }
-                      if( p_item->i_options )
-                      {
-                          int i_opt;
-                          for( i_opt = 0; i_opt < p_item->i_options; i_opt++ )
-                          {
-                              free( p_item->ppsz_options[i_opt] );
-                          }
-                          free( p_item->ppsz_options );
-                      }
-                      if( p_item->psz_author )
-                      {
-                          free( p_item->psz_author );
-                      }
                       free( p_item );
                       vlc_mutex_unlock( &p_playlist->object_lock );
-                      return 0;
+                      return -1;
                  }
              }
          }
@@ -168,8 +84,8 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
 
     msg_Dbg( p_playlist, "adding playlist item « %s » ( %s )", p_item->psz_name, p_item->psz_uri);
 
-    /* Create the new playlist item */
 
+    p_item->i_id = ++p_playlist->i_last_id;
 
     /* Do a few boundary checks and allocate space for the item */
     if( i_pos == PLAYLIST_END )
@@ -223,10 +139,6 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
         {
             free( p_playlist->pp_items[i_pos]->psz_uri );
         }
-        if( p_playlist->pp_items[i_pos]->psz_author )
-        {
-            free( p_playlist->pp_items[i_pos]->psz_author );
-        }
         /* XXX: what if the item is still in use? */
         free( p_playlist->pp_items[i_pos] );
         p_playlist->pp_items[i_pos] = p_item;
@@ -247,281 +159,5 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
     val.b_bool = VLC_TRUE;
     var_Set( p_playlist, "intf-change", val );
 
-    return 0;
-}
-
-/**
- * delete an item from a playlist.
- *
- * \param p_playlist the playlist to remove from.
- * \param i_pos the position of the item to remove
- * \return returns 0
- */
-int playlist_Delete( playlist_t * p_playlist, int i_pos )
-{
-    vlc_value_t     val;
-
-    /* if i_pos is the current played item, playlist should stop playing it */
-    if( p_playlist->i_status == PLAYLIST_RUNNING &&
-        p_playlist->i_index == i_pos )
-    {
-        playlist_Command( p_playlist, PLAYLIST_SKIP, 1 );
-    }
-
-    vlc_mutex_lock( &p_playlist->object_lock );
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
-    {
-        playlist_item_t *p_item = p_playlist->pp_items[i_pos];
-
-        msg_Dbg( p_playlist, "deleting playlist item « %s »",
-                 p_item->psz_name );
-
-        if( p_item->psz_name )
-        {
-            free( p_item->psz_name );
-        }
-        if( p_item->psz_uri )
-        {
-            free( p_item->psz_uri );
-        }
-        if( p_item->psz_author )
-        {
-            free( p_item->psz_author );
-        }
-        if( p_item->i_options > 0 )
-        {
-            int i;
-
-            for( i = 0; i < p_item->i_options; i++ )
-            {
-                free( p_item->ppsz_options[i] );
-            }
-
-            free( p_item->ppsz_options );
-        }
-
-        /* XXX: what if the item is still in use? */
-        free( p_item );
-
-        if( i_pos <= p_playlist->i_index )
-        {
-            p_playlist->i_index--;
-        }
-
-        /* Renumber the playlist */
-        REMOVE_ELEM( p_playlist->pp_items,
-                     p_playlist->i_size,
-                     i_pos );
-        if( p_playlist->i_enabled > 0 )
-            p_playlist->i_enabled--;
-    }
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
-}
-
-/**
- * Disables a playlist item
- *
- * \param p_playlist the playlist to disable from.
- * \param i_pos the position of the item to disable
- * \return returns 0
- */
-int playlist_Disable( playlist_t * p_playlist, int i_pos )
-{
-    vlc_value_t     val;
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
-    {
-        msg_Dbg( p_playlist, "disabling playlist item « %s »",
-                             p_playlist->pp_items[i_pos]->psz_name );
-
-        if( p_playlist->pp_items[i_pos]->b_enabled == VLC_TRUE )
-            p_playlist->i_enabled--;
-        p_playlist->pp_items[i_pos]->b_enabled = VLC_FALSE;
-    }
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
-}
-
-/**
- * Enables a playlist item
- *
- * \param p_playlist the playlist to enable from.
- * \param i_pos the position of the item to enable
- * \return returns 0
- */
-int playlist_Enable( playlist_t * p_playlist, int i_pos )
-{
-    vlc_value_t     val;
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    if( i_pos >= 0 && i_pos < p_playlist->i_size )
-    {
-        msg_Dbg( p_playlist, "enabling playlist item « %s »",
-                             p_playlist->pp_items[i_pos]->psz_name );
-
-        if( p_playlist->pp_items[i_pos]->b_enabled == VLC_FALSE )
-            p_playlist->i_enabled++;
-
-        p_playlist->pp_items[i_pos]->b_enabled = VLC_TRUE;
-    }
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
-}
-
-/**
- * Disables a playlist group
- *
- * \param p_playlist the playlist to disable from.
- * \param i_pos the id of the group to disable
- * \return returns 0
- */
-int playlist_DisableGroup( playlist_t * p_playlist, int i_group)
-{
-    vlc_value_t     val;
-    int i;
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    msg_Dbg(p_playlist,"Disabling group %i",i_group);
-    for( i = 0 ; i< p_playlist->i_size; i++ )
-    {
-        if( p_playlist->pp_items[i]->i_group == i_group )
-        {
-            msg_Dbg( p_playlist, "disabling playlist item « %s »",
-                           p_playlist->pp_items[i]->psz_name );
-
-            if( p_playlist->pp_items[i]->b_enabled == VLC_TRUE )
-                p_playlist->i_enabled--;
-
-            p_playlist->pp_items[i]->b_enabled = VLC_FALSE;
-        }
-    }
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
-}
-
-/**
- * Enables a playlist group
- *
- * \param p_playlist the playlist to enable from.
- * \param i_pos the id of the group to enable
- * \return returns 0
- */
-int playlist_EnableGroup( playlist_t * p_playlist, int i_group)
-{
-    vlc_value_t     val;
-    int i;
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    for( i = 0 ; i< p_playlist->i_size; i++ )
-    {
-        if( p_playlist->pp_items[i]->i_group == i_group )
-        {
-            msg_Dbg( p_playlist, "enabling playlist item « %s »",
-                           p_playlist->pp_items[i]->psz_name );
-
-            if( p_playlist->pp_items[i]->b_enabled == VLC_FALSE )
-                p_playlist->i_enabled++;
-
-            p_playlist->pp_items[i]->b_enabled = VLC_TRUE;
-        }
-    }
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
-}
-
-/**
- * Move an item in a playlist
- *
- * Move the item in the playlist with position i_pos before the current item
- * at position i_newpos.
- * \param p_playlist the playlist to move items in
- * \param i_pos the position of the item to move
- * \param i_newpos the position of the item that will be behind the moved item
- *        after the move
- * \return returns 0
- */
-int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos)
-{
-    vlc_value_t     val;
-    vlc_mutex_lock( &p_playlist->object_lock );
-
-    /* take into account that our own row disappears. */
-    if ( i_pos < i_newpos ) i_newpos--;
-
-    if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size
-                     && i_newpos <= p_playlist->i_size )
-    {
-        playlist_item_t * temp;
-
-        msg_Dbg( p_playlist, "moving playlist item « %s » (%i -> %i)",
-                             p_playlist->pp_items[i_pos]->psz_name, i_pos,
-                             i_newpos );
-
-        if( i_pos == p_playlist->i_index )
-        {
-            p_playlist->i_index = i_newpos;
-        }
-        else if( i_pos > p_playlist->i_index && i_newpos <= p_playlist->i_index )
-        {
-            p_playlist->i_index++;
-        }
-        else if( i_pos < p_playlist->i_index && i_newpos >= p_playlist->i_index )
-        {
-            p_playlist->i_index--;
-        }
-
-        if ( i_pos < i_newpos )
-        {
-            temp = p_playlist->pp_items[i_pos];
-            while ( i_pos < i_newpos )
-            {
-                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1];
-                i_pos++;
-            }
-            p_playlist->pp_items[i_newpos] = temp;
-        }
-        else if ( i_pos > i_newpos )
-        {
-            temp = p_playlist->pp_items[i_pos];
-            while ( i_pos > i_newpos )
-            {
-                p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1];
-                i_pos--;
-            }
-            p_playlist->pp_items[i_newpos] = temp;
-        }
-    }
-
-    vlc_mutex_unlock( &p_playlist->object_lock );
-
-    val.b_bool = VLC_TRUE;
-    var_Set( p_playlist, "intf-change", val );
-
-    return 0;
+    return p_item->i_id;
 }
index a05935648b56cf9f064a70511ed30a59d7f7f6f8..e379b1fdbb2f4878361c5959457369a2a8428af4 100644 (file)
@@ -2,7 +2,7 @@
  * loadsave.c : Playlist loading / saving functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: loadsave.c,v 1.1 2003/10/29 18:00:46 zorglub Exp $
+ * $Id: loadsave.c,v 1.2 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -118,8 +118,8 @@ int playlist_LoadFile( playlist_t * p_playlist, const char *psz_filename )
        }
        if( i_format == 5 )
        {
-           playlist_Add ( p_playlist , (char *)&line ,
-                      0, 0, PLAYLIST_APPEND , PLAYLIST_END );
+           playlist_Add ( p_playlist , (char *)&line , (char *)&line,
+                         PLAYLIST_APPEND , PLAYLIST_END );
        }
        else
        {
index 68262c78b57f125fda0b81fe931e2af003855ac0..3ee51a723827f1b2ee963c9adbf1275cea4fce68 100644 (file)
@@ -2,7 +2,7 @@
  * playlist.c : Playlist management functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: playlist.c,v 1.70 2003/12/13 17:16:11 gbazin Exp $
+ * $Id: playlist.c,v 1.71 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
@@ -44,10 +44,6 @@ static void RunThread ( playlist_t * );
 static void SkipItem  ( playlist_t *, int );
 static void PlayItem  ( playlist_t * );
 
-#if 0
-static void Poubellize ( playlist_t *, input_thread_t * );
-#endif
-
 /**
  * Create playlist
  *
@@ -72,6 +68,14 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
     val.b_bool = VLC_TRUE;
     var_Set( p_playlist, "intf-change", val );
 
+    var_Create( p_playlist, "item-change", VLC_VAR_INTEGER );
+    val.i_int = -1;
+    var_Set( p_playlist, "item-change", val );
+
+    var_Create( p_playlist, "playlist-current", VLC_VAR_INTEGER );
+    val.i_int = -1;
+    var_Set( p_playlist, "playlist-current", val );
+
     var_Create( p_playlist, "intf-popupmenu", VLC_VAR_BOOL );
 
     var_Create( p_playlist, "intf-show", VLC_VAR_BOOL );
@@ -90,7 +94,8 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
 
     p_playlist->i_groups = 0;
     p_playlist->pp_groups = NULL;
-    p_playlist->i_max_id = 0;
+    p_playlist->i_last_group = 0;
+    p_playlist->i_last_id = 0;
 
     playlist_CreateGroup( p_playlist, "Normal" );
 
@@ -121,6 +126,7 @@ void playlist_Destroy( playlist_t * p_playlist )
     vlc_thread_join( p_playlist );
 
     var_Destroy( p_playlist, "intf-change" );
+    var_Destroy( p_playlist, "item-change" );
 
     while( p_playlist->i_groups > 0 )
     {
@@ -157,6 +163,8 @@ void playlist_Destroy( playlist_t * p_playlist )
         if( p_playlist->p_input )
         {
             input_StopThread( p_playlist->p_input );
+            val.i_int = p_playlist->i_index;
+            var_Set( p_playlist, "item-change",val );
         }
         break;
 
@@ -231,13 +239,13 @@ void playlist_Destroy( playlist_t * p_playlist )
     }
 
     vlc_mutex_unlock( &p_playlist->object_lock );
-
+#if 0
     val.b_bool = VLC_TRUE;
     var_Set( p_playlist, "intf-change", val );
-
+#endif
     return;
 }
-/* Following functions are local */
+
 
 static void ObjectGarbageCollector( playlist_t *p_playlist,
                                     int i_type,
@@ -353,8 +361,12 @@ static void RunThread ( playlist_t *p_playlist )
                     vlc_mutex_unlock( &p_playlist->object_lock );
                 }
 
+                val.i_int = p_playlist->i_index;
+                var_Set( p_playlist, "playlist-current", val);
+#if 0
                 val.b_bool = VLC_TRUE;
                 var_Set( p_playlist, "intf-change", val );
+#endif
                 continue;
             }
             else if( p_playlist->p_input->stream.control.i_status != INIT_S )
@@ -538,6 +550,7 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
  *****************************************************************************/
 static void PlayItem( playlist_t *p_playlist )
 {
+    vlc_value_t val;
     if( p_playlist->i_index == -1 )
     {
         if( p_playlist->i_size == 0 || p_playlist->i_enabled == 0)
@@ -556,4 +569,7 @@ static void PlayItem( playlist_t *p_playlist )
     msg_Dbg( p_playlist, "creating new input thread" );
     p_playlist->p_input = input_CreateThread( p_playlist,
                                   p_playlist->pp_items[p_playlist->i_index] );
+
+    val.i_int = p_playlist->i_index;
+    var_Set( p_playlist, "item-change", val );
 }
index fd7ff073f5256912c0d7e1205a9fce17a1696db8..511f70d6b4a193b82a56dc7ee873eaeb5bc5c966 100644 (file)
@@ -2,7 +2,7 @@
  * sort.c : Playlist sorting functions
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: sort.c,v 1.3 2003/12/13 17:46:07 asmax Exp $
+ * $Id: sort.c,v 1.4 2004/01/05 12:59:43 zorglub Exp $
  *
  * Authors: Clément Stenac <zorglub@videolan.org>
  *
@@ -64,7 +64,7 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
         }
         vlc_mutex_unlock( &p_playlist->object_lock );
 
-        /* Notify the interfaces (XXX: use a different variable) */
+        /* Notify the interfaces */
         var_Set( p_playlist, "intf-change", val );
 
         return 0;
@@ -89,8 +89,11 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
             }
             else if( i_mode == SORT_AUTHOR )
             {
-                 i_test = strcasecmp( p_playlist->pp_items[i]->psz_author,
-                                 p_playlist->pp_items[i_small]->psz_author );
+                 i_test = strcasecmp(
+                          playlist_GetInfo( p_playlist, i,
+                                            _("General") , _("Author") ),
+                          playlist_GetInfo( p_playlist, i_small,
+                                            _("General") , _("Author") ) );
             }
 
             if( ( i_type == SORT_NORMAL  && i_test < 0 ) ||
@@ -111,7 +114,7 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
     }
     vlc_mutex_unlock( &p_playlist->object_lock );
 
-    /* Notify the interfaces (XXX: use a different variable) */
+    /* Notify the interfaces  */
     var_Set( p_playlist, "intf-change", val );
 
     return 0;