]> git.sesse.net Git - vlc/blobdiff - src/playlist/loadsave.c
Libvlc event: Support for event extra information passing. And register to "time...
[vlc] / src / playlist / loadsave.c
index 038b16dbf70581913c6e09614136ee4fa876ba18..e4c201acd5e5a6b8530a53a3a8ab4dc0d323e4cd 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 #include <vlc/vlc.h>
-#include <vlc/input.h>
-#include "vlc_playlist.h"
+#include <vlc_playlist.h>
 #include "playlist_internal.h"
-#include "charset.h"
-#include <errno.h>
-
-#if defined( WIN32 ) || defined( UNDER_CE )
-#   define DIR_SEP "\\"
-#else
-#   define DIR_SEP "/"
-#endif
+#include "modules/configuration.h"
+#include <vlc_charset.h>
 
-/**
- * Import a playlist file at a given point of a given 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_Import( playlist_t * p_playlist, const char *psz_filename,
-                     playlist_item_t *p_root, vlc_bool_t b_only_there )
-{
-    char *psz_uri, *psz_opt;
-    input_item_t *p_input;
-
-    asprintf( &psz_uri, "file/playlist://%s", psz_filename );
-    p_input = input_ItemNewExt( p_playlist, psz_uri, "playlist", 0, NULL, -1 );
-    if( b_only_there )
-    {
-        asprintf( &psz_opt, "parent-item=%i", p_root->i_id );
-        input_ItemAddOption( p_input, psz_opt );
-        free( psz_opt );
-    }
-    playlist_PlaylistAddInput( p_playlist, p_input, PLAYLIST_APPEND,
-                               PLAYLIST_END );
-    input_Read( p_playlist, p_input, VLC_TRUE );
-    free( psz_uri );
-    return VLC_SUCCESS;
-}
+#include <errno.h>
 
-/**
- * Export a node of the playlist to a certain type of playlistfile
- *
- * \param p_playlist the playlist to export
- * \param psz_filename the location where the exported file will be saved
- * \param p_export_root the root node to export
- * \param psz_type the type of playlist file to create.
- * \return VLC_SUCCESS on success
- */
 int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
                      playlist_item_t *p_export_root,const char *psz_type )
 {
@@ -127,7 +86,12 @@ int playlist_Export( playlist_t * p_playlist, const char *psz_filename ,
 
 int playlist_MLLoad( playlist_t *p_playlist )
 {
-    char *psz_uri, *psz_homedir =p_playlist->p_libvlc->psz_homedir;
+#if 0
+    FIXME: this code breaks streaming output (or streaming output breaks this,
+    whichever you prefer).
+
+    const char *psz_homedir = p_playlist->p_libvlc->psz_homedir;
+    char *psz_uri = NULL;
     input_item_t *p_input;
 
     if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
@@ -136,13 +100,21 @@ int playlist_MLLoad( playlist_t *p_playlist )
         msg_Err( p_playlist, "no home directory, cannot load media library") ;
         return VLC_EGENERIC;
     }
-    asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP CONFIG_DIR DIR_SEP
-                        "ml.xsp", psz_homedir );
+
+    if( asprintf( &psz_uri, "file/xspf-open://%s" DIR_SEP CONFIG_DIR DIR_SEP
+                        "ml.xsp", psz_homedir ) == -1 )
+    {
+        psz_uri = NULL;
+        goto error;
+    }
 
     p_input = input_ItemNewExt( p_playlist, psz_uri,
                                 _("Media Library"), 0, NULL, -1 );
-    p_playlist->p_ml_category->p_input = p_input;
-    p_playlist->p_ml_onelevel->p_input = p_input;
+    if( p_input == NULL )
+        goto error;
+
+    p_playlist->p_ml_onelevel->p_input =
+        p_playlist->p_ml_category->p_input = p_input;
 
     p_playlist->b_doing_ml = VLC_TRUE;
     stats_TimerStart( p_playlist, "ML Load", STATS_TIMER_ML_LOAD );
@@ -152,19 +124,34 @@ int playlist_MLLoad( playlist_t *p_playlist )
 
     free( psz_uri );
     return VLC_SUCCESS;
+
+error:
+    free( psz_uri );
+    return VLC_ENOMEM;
+#else
+    msg_Err( p_playlist, "Reloading playlist not implemented." );
+    return VLC_EGENERIC;
+#endif
 }
 
 int playlist_MLDump( playlist_t *p_playlist )
 {
-    char *psz_uri, *psz_homedir =p_playlist->p_libvlc->psz_homedir;
+    char *psz_uri, *psz_homedir = p_playlist->p_libvlc->psz_homedir;
     if( !config_GetInt( p_playlist, "media-library") ) return VLC_SUCCESS;
     if( !psz_homedir )
     {
-        msg_Err( p_playlist, "no home directory, cannot load media library") ;
+        msg_Err( p_playlist, "no home directory, cannot save media library") ;
         return VLC_EGENERIC;
     }
-    asprintf( &psz_uri, "%s" DIR_SEP CONFIG_DIR DIR_SEP
-                        "ml.xsp",  psz_homedir );
+
+    char psz_dirname[ strlen( psz_homedir ) + sizeof( DIR_SEP CONFIG_DIR ) ];
+    sprintf( psz_dirname, "%s" DIR_SEP CONFIG_DIR, psz_homedir );
+    if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) )
+    {
+        return VLC_EGENERIC;
+    }
+
+    asprintf( &psz_uri, "%s" DIR_SEP "%s", psz_dirname, "ml.xsp" );
     stats_TimerStart( p_playlist, "ML Dump", STATS_TIMER_ML_DUMP );
     playlist_Export( p_playlist, psz_uri, p_playlist->p_ml_category,
                      "export-xspf" );