]> git.sesse.net Git - vlc/blob - src/control/media_library.c
libvlc: Split libvlc_internal in different independant headers.
[vlc] / src / control / media_library.c
1 /*****************************************************************************
2  * tree.c: libvlc tags tree functions
3  * Create a tree of the 'tags' of a media_list's medias.
4  *****************************************************************************
5  * Copyright (C) 2007 the VideoLAN team
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
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <vlc/libvlc.h>
26 #include <vlc/libvlc_media.h>
27 #include <vlc/libvlc_media_list.h>
28 #include <vlc/libvlc_media_library.h>
29 #include <vlc/libvlc_events.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                           libvlc_exception_t * p_e )
58 {
59     (void)p_e;
60     libvlc_media_library_t * p_mlib;
61
62     p_mlib = malloc(sizeof(libvlc_media_library_t));
63
64     if( !p_mlib )
65         return NULL;
66
67     p_mlib->p_libvlc_instance = p_inst;
68     p_mlib->i_refcount = 1;
69     p_mlib->p_mlist = NULL;
70
71     p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e );
72
73     return p_mlib;
74 }
75
76 /**************************************************************************
77  *       release (Public)
78  **************************************************************************/
79 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
80 {
81     p_mlib->i_refcount--;
82
83     if( p_mlib->i_refcount > 0 )
84         return;
85
86     libvlc_event_manager_release( p_mlib->p_event_manager );
87     free( p_mlib );
88 }
89
90 /**************************************************************************
91  *       retain (Public)
92  **************************************************************************/
93 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
94 {
95     p_mlib->i_refcount++;
96 }
97
98 /**************************************************************************
99  *       load (Public)
100  *
101  * It doesn't yet load the playlists
102  **************************************************************************/
103 void
104 libvlc_media_library_load( libvlc_media_library_t * p_mlib,
105                            libvlc_exception_t * p_e )
106 {
107     char *psz_datadir = config_GetUserDataDir();
108     char * psz_uri;
109
110     if( !psz_datadir ) /* XXX: i doubt that this can ever happen */
111     {
112         libvlc_exception_raise( p_e, "Can't get data directory" );
113         return;
114     }
115
116     if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
117                   psz_datadir ) == -1 )
118     {
119         free( psz_datadir );
120         libvlc_exception_raise( p_e, "Can't get create the path" );
121         return;
122     }
123     free( psz_datadir );
124     if( p_mlib->p_mlist )
125         libvlc_media_list_release( p_mlib->p_mlist );
126
127     p_mlib->p_mlist = libvlc_media_list_new(
128                         p_mlib->p_libvlc_instance,
129                         p_e );
130
131     libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri, p_e );
132     free( psz_uri );
133     return;
134 }
135
136 /**************************************************************************
137  *       save (Public)
138  **************************************************************************/
139 void
140 libvlc_media_library_save( libvlc_media_library_t * p_mlib,
141                            libvlc_exception_t * p_e )
142 {
143     (void)p_mlib;
144     libvlc_exception_raise( p_e, "Not supported" );
145 }
146
147 /**************************************************************************
148  *        media_list (Public)
149  **************************************************************************/
150 libvlc_media_list_t *
151 libvlc_media_library_media_list( libvlc_media_library_t * p_mlib,
152                                      libvlc_exception_t * p_e )
153 {
154     (void)p_e;
155     if( p_mlib->p_mlist )
156         libvlc_media_list_retain( p_mlib->p_mlist );
157     return p_mlib->p_mlist;
158 }