1
/*****************************************************************************
2
* playlist.c : Playlist groups management functions
3
*****************************************************************************
4
* Copyright (C) 1999-2004 VideoLAN
5
* $Id: group.c 7209 2004-03-31 20:52:31Z gbazin $
7
* Authors: Cl�ment Stenac <zorglub@videolan.org>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22
*****************************************************************************/
23
#include <stdlib.h> /* free(), strtol() */
24
#include <stdio.h> /* sprintf() */
25
#include <string.h> /* strerror() */
28
#include <vlc/input.h>
30
#include "vlc_playlist.h"
36
* \param p_playlist pointer to a playlist
37
* \param psz_name the name of the group to be created
38
* \return a pointer to the created group, or NULL on error
40
playlist_group_t *playlist_CreateGroup( playlist_t *p_playlist, char *psz_name)
42
playlist_group_t *p_group;
45
for( i = 0 ; i < p_playlist->i_groups; i++ )
47
if( !strcasecmp( p_playlist->pp_groups[i]->psz_name , psz_name ) )
49
msg_Info( p_playlist, "this group already exists");
50
return p_playlist->pp_groups[i];
54
/* Allocate the group structure */
55
if( ( p_group = malloc( sizeof(playlist_group_t) ) ) == NULL )
57
msg_Err( p_playlist, "out of memory" );
61
p_group->psz_name = strdup( psz_name );
62
p_group->i_id = ++p_playlist->i_last_group;
64
msg_Dbg(p_playlist,"creating group %s with id %i at position %i",
67
p_playlist->i_groups);
69
INSERT_ELEM ( p_playlist->pp_groups,
80
* \param p_playlist the playlist to remove the group from
81
* \param i_id the identifier of the group to remove
84
int playlist_DeleteGroup( playlist_t *p_playlist, int i_id )
88
for( i=0 ; i<= p_playlist->i_groups; i++ )
90
playlist_group_t *p_group = p_playlist->pp_groups[i];
92
if( p_group->i_id == i_id )
95
if( p_group->psz_name )
97
free( p_group->psz_name );
99
REMOVE_ELEM( p_playlist->pp_groups,
100
p_playlist->i_groups,
111
* Find the name of the group given its ID
113
* \param p_playlist the playlist where to find the group
114
* \param i_id the ID to search for
115
* \return the name of the group
117
char *playlist_FindGroup( playlist_t *p_playlist, int i_id )
120
for( i=0 ; i< p_playlist->i_groups; i++ )
122
if( p_playlist->pp_groups[i]->i_id == i_id )
124
if( p_playlist->pp_groups[i]->psz_name)
125
return strdup( p_playlist->pp_groups[i]->psz_name );
132
* Find the id of a group given its name
134
* \param p_playlist the playlist where to find the group
135
* \param psz_name the name to search for
136
* \return the id of the group
138
int playlist_GroupToId( playlist_t *p_playlist, char *psz_name )
141
for( i = 0 ; i< p_playlist->i_groups; i++ )
143
if( p_playlist->pp_groups[i]->psz_name)
145
if( ! strcasecmp( p_playlist->pp_groups[i]->psz_name, psz_name ) )
147
return p_playlist->pp_groups[i]->i_id;