root/src/control/media_library.c
| Revision 146dad54bff773b990752e44b92aa35f87cbc678, 4.5 kB (checked in by Rémi Denis-Courmont <rem@videolan.org>, 5 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 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 | #include "libvlc_internal.h" |
| 25 | #include <vlc/libvlc.h> |
| 26 | #include "libvlc.h" |
| 27 | #include "vlc_arrays.h" |
| 28 | |
| 29 | /* |
| 30 | * Private functions |
| 31 | */ |
| 32 | |
| 33 | /* |
| 34 | * Public libvlc functions |
| 35 | */ |
| 36 | |
| 37 | /************************************************************************** |
| 38 | * new (Public) |
| 39 | **************************************************************************/ |
| 40 | libvlc_media_library_t * |
| 41 | libvlc_media_library_new( libvlc_instance_t * p_inst, |
| 42 | libvlc_exception_t * p_e ) |
| 43 | { |
| 44 | (void)p_e; |
| 45 | libvlc_media_library_t * p_mlib; |
| 46 | |
| 47 | p_mlib = malloc(sizeof(libvlc_media_library_t)); |
| 48 | |
| 49 | if( !p_mlib ) |
| 50 | return NULL; |
| 51 | |
| 52 | p_mlib->p_libvlc_instance = p_inst; |
| 53 | p_mlib->i_refcount = 1; |
| 54 | p_mlib->p_mlist = NULL; |
| 55 | |
| 56 | p_mlib->p_event_manager = libvlc_event_manager_new( p_mlib, p_inst, p_e ); |
| 57 | |
| 58 | return p_mlib; |
| 59 | } |
| 60 | |
| 61 | /************************************************************************** |
| 62 | * release (Public) |
| 63 | **************************************************************************/ |
| 64 | void libvlc_media_library_release( libvlc_media_library_t * p_mlib ) |
| 65 | { |
| 66 | p_mlib->i_refcount--; |
| 67 | |
| 68 | if( p_mlib->i_refcount > 0 ) |
| 69 | return; |
| 70 | |
| 71 | libvlc_event_manager_release( p_mlib->p_event_manager ); |
| 72 | free( p_mlib ); |
| 73 | } |
| 74 | |
| 75 | /************************************************************************** |
| 76 | * retain (Public) |
| 77 | **************************************************************************/ |
| 78 | void libvlc_media_library_retain( libvlc_media_library_t * p_mlib ) |
| 79 | { |
| 80 | p_mlib->i_refcount++; |
| 81 | } |
| 82 | |
| 83 | /************************************************************************** |
| 84 | * load (Public) |
| 85 | * |
| 86 | * It doesn't yet load the playlists |
| 87 | **************************************************************************/ |
| 88 | void |
| 89 | libvlc_media_library_load( libvlc_media_library_t * p_mlib, |
| 90 | libvlc_exception_t * p_e ) |
| 91 | { |
| 92 | char *psz_datadir = config_GetUserDataDir(); |
| 93 | char * psz_uri; |
| 94 | |
| 95 | if( !psz_datadir ) /* XXX: i doubt that this can ever happen */ |
| 96 | { |
| 97 | libvlc_exception_raise( p_e, "Can't get data directory" ); |
| 98 | return; |
| 99 | } |
| 100 | |
| 101 | if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP "ml.xsp", |
| 102 | psz_datadir ) == -1 ) |
| 103 | { |
| 104 | free( psz_datadir ); |
| 105 | libvlc_exception_raise( p_e, "Can't get create the path" ); |
| 106 | return; |
| 107 | } |
| 108 | free( psz_datadir ); |
| 109 | if( p_mlib->p_mlist ) |
| 110 | libvlc_media_list_release( p_mlib->p_mlist ); |
| 111 | |
| 112 | p_mlib->p_mlist = libvlc_media_list_new( |
| 113 | p_mlib->p_libvlc_instance, |
| 114 | p_e ); |
| 115 | |
| 116 | libvlc_media_list_add_file_content( p_mlib->p_mlist, psz_uri, p_e ); |
| 117 | free( psz_uri ); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | /************************************************************************** |
| 122 | * save (Public) |
| 123 | **************************************************************************/ |
| 124 | void |
| 125 | libvlc_media_library_save( libvlc_media_library_t * p_mlib, |
| 126 | libvlc_exception_t * p_e ) |
| 127 | { |
| 128 | (void)p_mlib; |
| 129 | libvlc_exception_raise( p_e, "Not supported" ); |
| 130 | } |
| 131 | |
| 132 | /************************************************************************** |
| 133 | * media_list (Public) |
| 134 | **************************************************************************/ |
| 135 | libvlc_media_list_t * |
| 136 | libvlc_media_library_media_list( libvlc_media_library_t * p_mlib, |
| 137 | libvlc_exception_t * p_e ) |
| 138 | { |
| 139 | (void)p_e; |
| 140 | if( p_mlib->p_mlist ) |
| 141 | libvlc_media_list_retain( p_mlib->p_mlist ); |
| 142 | return p_mlib->p_mlist; |
| 143 | } |
Note: See TracBrowser for help on using the browser.
