libvlc: clean up deprecated functions
[vlc.git] / lib / media_library.c
1 /*****************************************************************************
2  * media_library.c: libvlc tags tree functions
3  * Create a tree of the 'tags' of a media_list's medias.
4  *****************************************************************************
5  * Copyright (C) 2007 VLC authors and VideoLAN
6  * $Id$
7  *
8  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc/vlc.h>
30
31 #include <vlc_common.h>
32
33 #include "libvlc_internal.h"
34
35 struct libvlc_media_library_t
36 {
37     libvlc_event_manager_t * p_event_manager;
38     libvlc_instance_t *      p_libvlc_instance;
39     int                      i_refcount;
40     libvlc_media_list_t *    p_mlist;
41 };
42
43
44 /*
45  * Private functions
46  */
47
48 /*
49  * Public libvlc functions
50  */
51
52 /**************************************************************************
53  *       new (Public)
54  **************************************************************************/
55 libvlc_media_library_t *
56 libvlc_media_library_new( libvlc_instance_t * p_inst )
57 {
58     libvlc_media_library_t * p_mlib;
59
60     p_mlib = malloc(sizeof(libvlc_media_library_t));
61
62     if( !p_mlib )
63     {
64         libvlc_printerr( "Not enough memory" );
65         return NULL;
66     }
67
68     p_mlib->p_libvlc_instance = p_inst;
69     p_mlib->i_refcount = 1;
70     p_mlib->p_mlist = NULL;
71
72     p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib );
73     if( unlikely(p_mlib->p_event_manager == NULL) )
74     {
75         free(p_mlib);
76         return NULL;
77     }
78
79     libvlc_retain( p_inst );
80     return p_mlib;
81 }
82
83 /**************************************************************************
84  *       release (Public)
85  **************************************************************************/
86 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
87 {
88     p_mlib->i_refcount--;
89
90     if( p_mlib->i_refcount > 0 )
91         return;
92
93     libvlc_event_manager_release( p_mlib->p_event_manager );
94     libvlc_release( p_mlib->p_libvlc_instance );
95     free( p_mlib );
96 }
97
98 /**************************************************************************
99  *       retain (Public)
100  **************************************************************************/
101 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
102 {
103     p_mlib->i_refcount++;
104 }
105
106 /**************************************************************************
107  *       load (Public)
108  *
109  * It doesn't yet load the playlists
110  **************************************************************************/
111 int libvlc_media_library_load( libvlc_media_library_t * p_mlib )
112 {
113     char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
114     char * psz_uri;
115
116     if( psz_datadir == NULL
117      || asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
118                   psz_datadir ) == -1 )
119         psz_uri = NULL;
120     free( psz_datadir );
121
122     if( psz_uri == NULL )
123     {
124         libvlc_printerr( "Not enough memory" );
125         return -1;
126     }
127
128     if( p_mlib->p_mlist )
129         libvlc_media_list_release( p_mlib->p_mlist );
130
131     p_mlib->p_mlist = libvlc_media_list_new( p_mlib->p_libvlc_instance );
132
133     int ret = libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri );
134     free( psz_uri );
135     return ret;
136 }
137
138 /**************************************************************************
139  *        media_list (Public)
140  **************************************************************************/
141 libvlc_media_list_t *
142 libvlc_media_library_media_list( libvlc_media_library_t * p_mlib )
143 {
144     if( p_mlib->p_mlist )
145         libvlc_media_list_retain( p_mlib->p_mlist );
146     return p_mlib->p_mlist;
147 }