inhibit/dbus: fix flawed logic
[vlc.git] / lib / media_library.c
blobf2bf77a77fced2e1c1fb75ae60a1bd06f57781ea
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$
8 * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
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.
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.
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 *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
29 #include <vlc/vlc.h>
31 #include <vlc_common.h>
33 #include "libvlc_internal.h"
35 struct libvlc_media_library_t
37 libvlc_event_manager_t event_manager;
38 libvlc_instance_t * p_libvlc_instance;
39 int i_refcount;
40 libvlc_media_list_t * p_mlist;
45 * Private functions
49 * Public libvlc functions
52 /**************************************************************************
53 * new (Public)
54 **************************************************************************/
55 libvlc_media_library_t *
56 libvlc_media_library_new( libvlc_instance_t * p_inst )
58 libvlc_media_library_t * p_mlib;
60 p_mlib = malloc(sizeof(libvlc_media_library_t));
62 if( !p_mlib )
64 libvlc_printerr( "Not enough memory" );
65 return NULL;
68 p_mlib->p_libvlc_instance = p_inst;
69 p_mlib->i_refcount = 1;
70 p_mlib->p_mlist = NULL;
72 libvlc_event_manager_init( &p_mlib->event_manager, p_mlib );
73 libvlc_retain( p_inst );
74 return p_mlib;
77 /**************************************************************************
78 * release (Public)
79 **************************************************************************/
80 void libvlc_media_library_release( libvlc_media_library_t * p_mlib )
82 p_mlib->i_refcount--;
84 if( p_mlib->i_refcount > 0 )
85 return;
87 libvlc_event_manager_destroy( &p_mlib->event_manager );
88 libvlc_release( p_mlib->p_libvlc_instance );
89 free( p_mlib );
92 /**************************************************************************
93 * retain (Public)
94 **************************************************************************/
95 void libvlc_media_library_retain( libvlc_media_library_t * p_mlib )
97 p_mlib->i_refcount++;
100 /**************************************************************************
101 * load (Public)
103 * It doesn't yet load the playlists
104 **************************************************************************/
105 int libvlc_media_library_load( libvlc_media_library_t * p_mlib )
107 char *psz_datadir = config_GetUserDir( VLC_DATA_DIR );
108 char * psz_uri;
110 if( psz_datadir == NULL
111 || asprintf( &psz_uri, "file/directory://%s" DIR_SEP "ml.xsp",
112 psz_datadir ) == -1 )
113 psz_uri = NULL;
114 free( psz_datadir );
116 if( psz_uri == NULL )
118 libvlc_printerr( "Not enough memory" );
119 return -1;
122 if( p_mlib->p_mlist )
123 libvlc_media_list_release( p_mlib->p_mlist );
125 p_mlib->p_mlist = libvlc_media_list_new( p_mlib->p_libvlc_instance );
127 int ret = libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri );
128 free( psz_uri );
129 return ret;
132 /**************************************************************************
133 * media_list (Public)
134 **************************************************************************/
135 libvlc_media_list_t *
136 libvlc_media_library_media_list( libvlc_media_library_t * p_mlib )
138 if( p_mlib->p_mlist )
139 libvlc_media_list_retain( p_mlib->p_mlist );
140 return p_mlib->p_mlist;