Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

loadsave.c

00001 /*****************************************************************************
00002  * loadsave.c : Playlist loading / saving functions
00003  *****************************************************************************
00004  * Copyright (C) 1999-2004 the VideoLAN team
00005  * $Id: loadsave.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 #include <stdlib.h>                                      /* free(), strtol() */
00024 #include <stdio.h>                                              /* sprintf() */
00025 #include <string.h>                                            /* strerror() */
00026 #include <errno.h>
00027 
00028 #include <vlc/vlc.h>
00029 #include <vlc/vout.h>
00030 #include <vlc/sout.h>
00031 #include <vlc/input.h>
00032 
00033 #include "vlc_playlist.h"
00034 
00035 #define PLAYLIST_FILE_HEADER  "# vlc playlist file version 0.5"
00036 
00046 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
00047 {
00048     playlist_item_t *p_item;
00049     char *psz_uri;
00050     int i_id;
00051 
00052     msg_Info( p_playlist, "clearing playlist");
00053     playlist_Clear( p_playlist );
00054 
00055 
00056     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
00057     sprintf( psz_uri, "file/playlist://%s", psz_filename);
00058 
00059     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
00060                   PLAYLIST_INSERT  , PLAYLIST_END);
00061 
00062     vlc_mutex_lock( &p_playlist->object_lock );
00063     p_item = playlist_ItemGetById( p_playlist, i_id );
00064     p_item->b_autodeletion = VLC_TRUE;
00065     vlc_mutex_unlock( &p_playlist->object_lock );
00066 
00067     playlist_Play(p_playlist);
00068 
00069     return VLC_SUCCESS;
00070 }
00071 
00080 int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
00081 {
00082     playlist_item_t *p_item;
00083     char *psz_uri;
00084     int i_id;
00085 
00086     msg_Info( p_playlist, "clearing playlist");
00087     playlist_Clear( p_playlist );
00088 
00089 
00090     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
00091     sprintf( psz_uri, "file/playlist://%s", psz_filename);
00092 
00093     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
00094                   PLAYLIST_INSERT  , PLAYLIST_END);
00095 
00096     vlc_mutex_lock( &p_playlist->object_lock );
00097     p_item = playlist_ItemGetById( p_playlist, i_id );
00098     p_item->b_autodeletion = VLC_TRUE;
00099     vlc_mutex_unlock( &p_playlist->object_lock );
00100 
00101     playlist_Play(p_playlist);
00102 
00103     return VLC_SUCCESS;
00104 }
00105 
00114 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
00115                      const char *psz_type)
00116 {
00117     module_t *p_module;
00118     playlist_export_t *p_export;
00119 
00120     msg_Info( p_playlist, "saving playlist to file %s", psz_filename );
00121 
00122     /* Prepare the playlist_export_t structure */
00123     p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
00124     if( !p_export)
00125     {
00126         msg_Err( p_playlist, "out of memory");
00127         return VLC_ENOMEM;
00128     }
00129     p_export->p_file = fopen( psz_filename, "wt" );
00130     if( !p_export->p_file )
00131     {
00132         msg_Err( p_playlist , "could not create playlist file %s"
00133                  " (%s)", psz_filename, strerror(errno) );
00134         return VLC_EGENERIC;
00135     }
00136 
00137     p_playlist->p_private = (void *)p_export;
00138     /* Lock the playlist */
00139     vlc_mutex_lock( &p_playlist->object_lock );
00140 
00141     /* And call the module ! All work is done now */
00142     p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
00143     if( !p_module )
00144     {
00145         msg_Warn( p_playlist, "failed to export playlist" );
00146         vlc_mutex_unlock( &p_playlist->object_lock );
00147         return VLC_ENOOBJ;
00148     }
00149     module_Unneed( p_playlist , p_module );
00150 
00151     fclose( p_export->p_file );
00152 
00153     vlc_mutex_unlock( &p_playlist->object_lock );
00154 
00155     return VLC_SUCCESS;
00156 }

Generated on Tue Dec 20 10:15:01 2005 for vlc-0.8.4a by  doxygen 1.4.2