]> git.sesse.net Git - vlc/blob - src/control/media_library.c
041a2412d141fa33ab688571da80bfd1fd8a0d79
[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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc/libvlc.h>
30 #include <vlc/libvlc_media.h>
31 #include <vlc/libvlc_media_list.h>
32 #include <vlc/libvlc_media_library.h>
33 #include <vlc/libvlc_events.h>
34
35 #include <vlc_common.h>
36
37 #include "libvlc_internal.h"
38
39 struct libvlc_media_library_t
40 {
41     libvlc_event_manager_t * p_event_manager;
42     libvlc_instance_t *      p_libvlc_instance;
43     int                      i_refcount;
44     libvlc_media_list_t *    p_mlist;
45 };
46
47
48 /*
49  * Private functions
50  */
51
52 /*
53  * Public libvlc functions
54  */
55
56 /**************************************************************************
57  *       new (Public)
58  **************************************************************************/
59 libvlc_media_library_t *
60 libvlc_media_library_new( libvlc_instance_t * p_inst,
61                           libvlc_exception_t * p_e )
62 {
63     libvlc_media_library_t * p_mlib;
64
65     p_mlib = malloc(sizeof(libvlc_media_library_t));
66
67     if( !p_mlib )
68         return NULL;
69
70     p_mlib->p_libvlc_instance = p_inst;
71     p_mlib->i_refcount = 1;
72     p_mlib->p_mlist = NULL;
73
74     p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e );
75
76     return p_mlib;
77 }
78
79 /**************************************************************************
80  *       release (Public)
81  **************************************************************************/
82 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
83 {
84     p_mlib->i_refcount--;
85
86     if( p_mlib->i_refcount > 0 )
87         return;
88
89     libvlc_event_manager_release( p_mlib->p_event_manager );
90     free( p_mlib );
91 }
92
93 /**************************************************************************
94  *       retain (Public)
95  **************************************************************************/
96 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
97 {
98     p_mlib->i_refcount++;
99 }
100
101 /**************************************************************************
102  *       load (Public)
103  *
104  * It doesn't yet load the playlists
105  **************************************************************************/
106 void
107 libvlc_media_library_load( libvlc_media_library_t * p_mlib,
108                            libvlc_exception_t * p_e )
109 {
110     char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
111     char * psz_uri;
112
113     if( psz_datadir == NULL
114      || asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp",
115                   psz_datadir ) == -1 )
116         psz_uri = NULL;
117     free( psz_datadir );
118
119     if( psz_uri == NULL )
120     {
121         libvlc_exception_raise( p_e );
122         libvlc_printerr( "Not enough memory" );
123         return;
124     }
125
126     if( p_mlib->p_mlist )
127         libvlc_media_list_release( p_mlib->p_mlist );
128
129     p_mlib->p_mlist = libvlc_media_list_new(
130                         p_mlib->p_libvlc_instance,
131                         p_e );
132
133     libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri, p_e );
134     free( psz_uri );
135     return;
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                                      libvlc_exception_t * p_e )
144 {
145     (void)p_e;
146     if( p_mlib->p_mlist )
147         libvlc_media_list_retain( p_mlib->p_mlist );
148     return p_mlib->p_mlist;
149 }