]> git.sesse.net Git - vlc/blobdiff - src/playlist/loadsave.c
* 2nd review of /src/* \ libvlc.h (refs #438)
[vlc] / src / playlist / loadsave.c
index 52596af765e62f59a8d9b2b65077c4ed7e8b1f4c..2fae7bdf8ab19c240e0c13402e7d8b6ab1e69c2a 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * loadsave.c : Playlist loading / saving functions
  *****************************************************************************
- * Copyright (C) 1999-2004 VideoLAN
- * $Id: loadsave.c,v 1.11 2004/03/03 20:39:53 gbazin Exp $
+ * Copyright (C) 1999-2004 the VideoLAN team
+ * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #include <stdlib.h>                                      /* free(), strtol() */
 #include <stdio.h>                                              /* sprintf() */
 #include <string.h>                                            /* strerror() */
+#include <errno.h>
 
 #include <vlc/vlc.h>
 #include <vlc/vout.h>
 #include <vlc/sout.h>
-
-#ifdef HAVE_ERRNO_H
-#   include <errno.h>
-#endif
-
-#include "stream_control.h"
-#include "input_ext-intf.h"
+#include <vlc/input.h>
 
 #include "vlc_playlist.h"
+#include "charset.h"
 
 #define PLAYLIST_FILE_HEADER  "# vlc playlist file version 0.5"
 
-
 /**
- * Import a certain playlist file into the playlist
+ * Import a certain playlist file into the library
+ * This file will get inserted as a new category
  *
+ * XXX: TODO
  * \param p_playlist the playlist to which the new items will be added
  * \param psz_filename the name of the playlistfile to import
  * \return VLC_SUCCESS on success
@@ -53,22 +50,57 @@ int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
     char *psz_uri;
     int i_id;
 
-    msg_Dbg( p_playlist, "clearing playlist");
+    msg_Info( p_playlist, "clearing playlist");
     playlist_Clear( p_playlist );
 
 
     psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
     sprintf( psz_uri, "file/playlist://%s", psz_filename);
 
-    vlc_mutex_lock( &p_playlist->object_lock );
     i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
-                  PLAYLIST_INSERT | PLAYLIST_GO , PLAYLIST_END);
+                  PLAYLIST_INSERT  , PLAYLIST_END);
 
+    vlc_mutex_lock( &p_playlist->object_lock );
     p_item = playlist_ItemGetById( p_playlist, i_id );
     p_item->b_autodeletion = VLC_TRUE;
+    vlc_mutex_unlock( &p_playlist->object_lock );
+
+    playlist_Play(p_playlist);
+
+    return VLC_SUCCESS;
+}
 
+/**
+ * Load a certain playlist file into the playlist
+ * This file will replace the contents of the "current" view
+ *
+ * \param p_playlist the playlist to which the new items will be added
+ * \param psz_filename the name of the playlistfile to import
+ * \return VLC_SUCCESS on success
+ */
+int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
+{
+    playlist_item_t *p_item;
+    char *psz_uri;
+    int i_id;
+
+    msg_Info( p_playlist, "clearing playlist");
+    playlist_Clear( p_playlist );
+
+
+    psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
+    sprintf( psz_uri, "file/playlist://%s", psz_filename);
+
+    i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
+                  PLAYLIST_INSERT  , PLAYLIST_END);
+
+    vlc_mutex_lock( &p_playlist->object_lock );
+    p_item = playlist_ItemGetById( p_playlist, i_id );
+    p_item->b_autodeletion = VLC_TRUE;
     vlc_mutex_unlock( &p_playlist->object_lock );
 
+    playlist_Play(p_playlist);
+
     return VLC_SUCCESS;
 }
 
@@ -95,16 +127,14 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
         msg_Err( p_playlist, "out of memory");
         return VLC_ENOMEM;
     }
-    p_export->p_file = fopen( psz_filename, "wt" );
+    p_export->psz_filename = NULL;
+    if ( psz_filename )
+        p_export->psz_filename = strdup( psz_filename );
+    p_export->p_file = utf8_fopen( psz_filename, "wt" );
     if( !p_export->p_file )
     {
-#ifdef HAVE_ERRNO_H
         msg_Err( p_playlist , "could not create playlist file %s"
                  " (%s)", psz_filename, strerror(errno) );
-#else
-        msg_Err( p_playlist , "could not create playlist file %s"
-                 , psz_filename );
-#endif
         return VLC_EGENERIC;
     }
 
@@ -116,14 +146,18 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
     p_module = module_Need( p_playlist, "playlist export", psz_type, VLC_TRUE);
     if( !p_module )
     {
-        msg_Warn( p_playlist, "failed to export playlist" );
+        msg_Warn( p_playlist, "exporting playlist failed" );
         vlc_mutex_unlock( &p_playlist->object_lock );
         return VLC_ENOOBJ;
     }
     module_Unneed( p_playlist , p_module );
 
+    /* Clean up */
     fclose( p_export->p_file );
-
+    if ( p_export->psz_filename )
+        free( p_export->psz_filename );
+    free ( p_export );
+    p_playlist->p_private = NULL;
     vlc_mutex_unlock( &p_playlist->object_lock );
 
     return VLC_SUCCESS;