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