]> git.sesse.net Git - vlc/blob - src/playlist/loadsave.c
Removed the default skin for the skins1 module
[vlc] / src / playlist / loadsave.c
1 /*****************************************************************************
2  * loadsave.c : Playlist loading / saving functions
3  *****************************************************************************
4  * Copyright (C) 1999-2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23 #include <stdlib.h>                                      /* free(), strtol() */
24 #include <stdio.h>                                              /* sprintf() */
25 #include <string.h>                                            /* strerror() */
26
27 #include <vlc/vlc.h>
28 #include <vlc/vout.h>
29 #include <vlc/sout.h>
30 #include <vlc/input.h>
31
32 #ifdef HAVE_ERRNO_H
33 #   include <errno.h>
34 #endif
35
36 #include "vlc_playlist.h"
37
38 #define PLAYLIST_FILE_HEADER  "# vlc playlist file version 0.5"
39
40
41 /**
42  * Import a certain playlist file into the playlist
43  *
44  * \param p_playlist the playlist to which the new items will be added
45  * \param psz_filename the name of the playlistfile to import
46  * \return VLC_SUCCESS on success
47  */
48 int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
49 {
50     playlist_item_t *p_item;
51     char *psz_uri;
52     int i_id;
53
54     msg_Dbg( p_playlist, "clearing playlist");
55     playlist_Clear( p_playlist );
56
57
58     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
59     sprintf( psz_uri, "file/playlist://%s", psz_filename);
60
61     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
62                   PLAYLIST_INSERT  , PLAYLIST_END);
63
64     vlc_mutex_lock( &p_playlist->object_lock );
65     p_item = playlist_ItemGetById( p_playlist, i_id );
66     p_item->b_autodeletion = VLC_TRUE;
67     vlc_mutex_unlock( &p_playlist->object_lock );
68
69     playlist_Play(p_playlist);
70
71     return VLC_SUCCESS;
72 }
73
74 /**
75  * Export a playlist to a certain type of playlistfile
76  *
77  * \param p_playlist the playlist to export
78  * \param psz_filename the location where the exported file will be saved
79  * \param psz_type the type of playlist file to create.
80  * \return VLC_SUCCESS on success
81  */
82 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
83                      const char *psz_type)
84 {
85     module_t *p_module;
86     playlist_export_t *p_export;
87
88     msg_Info( p_playlist, "saving playlist to file %s", psz_filename );
89
90     /* Prepare the playlist_export_t structure */
91     p_export = (playlist_export_t *)malloc( sizeof(playlist_export_t) );
92     if( !p_export)
93     {
94         msg_Err( p_playlist, "out of memory");
95         return VLC_ENOMEM;
96     }
97     p_export->p_file = fopen( psz_filename, "wt" );
98     if( !p_export->p_file )
99     {
100 #ifdef HAVE_ERRNO_H
101         msg_Err( p_playlist , "could not create playlist file %s"
102                  " (%s)", psz_filename, strerror(errno) );
103 #else
104         msg_Err( p_playlist , "could not create playlist file %s"
105                  , psz_filename );
106 #endif
107         return VLC_EGENERIC;
108     }
109
110     p_playlist->p_private = (void *)p_export;
111     /* Lock the playlist */
112     vlc_mutex_lock( &p_playlist->object_lock );
113
114     /* And call the module ! All work is done now */
115     p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
116     if( !p_module )
117     {
118         msg_Warn( p_playlist, "failed to export playlist" );
119         vlc_mutex_unlock( &p_playlist->object_lock );
120         return VLC_ENOOBJ;
121     }
122     module_Unneed( p_playlist , p_module );
123
124     fclose( p_export->p_file );
125
126     vlc_mutex_unlock( &p_playlist->object_lock );
127
128     return VLC_SUCCESS;
129 }