]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/mediadirs.c
mediadirs: display snapshots in the video widget
[vlc] / modules / services_discovery / mediadirs.c
index 897d894dc7e29e2dd608a11a0b0285de7ffd3737..6cd5e605d71079c3030f9fd27655f599a71be5ce 100644 (file)
@@ -32,7 +32,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_url.h>
-#include <vlc_charset.h>
+#include <vlc_fs.h>
 #include <vlc_services_discovery.h>
 
 #include <sys/stat.h>
@@ -69,21 +69,21 @@ vlc_module_begin ()
 
         set_shortname( N_("Video") )
         set_description( N_("My Videos") )
-        set_capability( "services_discovery", 10 )
+        set_capability( "services_discovery", 0 )
         set_callbacks( OpenVideo, Close )
         add_shortcut( "video_dir" )
 
     add_submodule ()
         set_shortname( N_("Audio") )
         set_description( N_("My Music") )
-        set_capability( "services_discovery", 10 )
+        set_capability( "services_discovery", 0 )
         set_callbacks( OpenAudio, Close )
         add_shortcut( "audio_dir" )
 
     add_submodule ()
         set_shortname( N_("Picture") )
         set_description( N_("My Pictures") )
-        set_capability( "services_discovery", 10 )
+        set_capability( "services_discovery", 0 )
         set_callbacks( OpenPicture, Close )
         add_shortcut( "picture_dir" )
 
@@ -186,15 +186,11 @@ static void *Run( void *data )
         /* make sure the directory exists */
         struct stat st;
         if( psz_dir == NULL            ||
-            utf8_stat( psz_dir, &st )  ||
+            vlc_stat( psz_dir, &st )  ||
             !S_ISDIR( st.st_mode ) )
             continue;
 
-        // TODO:  make_URI is only for file://, what about dir:// ?
-        // char* psz_uri = make_URI( psz_dir );
-        char* psz_uri;
-        if( asprintf( &psz_uri, "dir://%s",  psz_dir ) == -1 )
-            continue;
+        char* psz_uri = make_URI( psz_dir );
 
         input_item_t* p_root = input_item_New( p_sd, psz_uri, NULL );
         if( p_sys->i_type == Picture )
@@ -303,28 +299,34 @@ void formatSnapshotItem( input_item_t *p_item )
     if( !p_item )
         return;
 
-    if( !p_item->p_meta )
-        p_item->p_meta = vlc_meta_New();
+    char* psz_file = NULL;
+    char* psz_option = NULL;
+    char* psz_uri = input_item_GetURI( p_item );
+
+    if( !psz_uri )
+        goto end;
 
     /* copy the snapshot mrl as a ArtURL */
-    if( p_item->p_meta )
+    input_item_SetArtURL( p_item, psz_uri );
+
+    psz_file = make_path( psz_uri );
+    if( !psz_file )
+        goto end;
+
+    if( asprintf( &psz_option, "fake-file=%s", psz_file ) == -1 )
     {
-        char* psz_uri = NULL;
-        psz_uri = input_item_GetURI( p_item );
-        if( psz_uri )
-            input_item_SetArtURL( p_item, psz_uri );
-        free( psz_uri );
+        psz_option = NULL;
+        goto end;
     }
 
-    /**
-     * TODO: select the best mrl for displaying snapshots
-     *   - vlc://pause:10  => snapshot are displayed as Art
-     *   - file:///path/image.ext  => snapshot are displayed as videos
-     **/
-    input_item_SetURI( p_item, "vlc://pause:10" );
+    /* display still image as a video */
+    input_item_SetURI( p_item, "fake://" );
+    input_item_AddOption( p_item, psz_option, VLC_INPUT_OPTION_TRUSTED );
 
-    // input_item_AddOption( p_item, "fake-duration=10000",
-    //                       VLC_INPUT_OPTION_TRUSTED );
+end:
+    free( psz_option );
+    free( psz_file );
+    free( psz_uri );
 }
 
 
@@ -356,10 +358,10 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
     vlc_probe_t *probe = (vlc_probe_t *)obj;
 
     vlc_sd_probe_Add( probe, "video_dir{longname=\"My Videos\"}",
-                      N_("My Videos") );
+                      N_("My Videos"), SD_CAT_MYCOMPUTER );
     vlc_sd_probe_Add( probe, "audio_dir{longname=\"My Music\"}",
-                      N_("My Music") );
+                      N_("My Music"), SD_CAT_MYCOMPUTER );
     vlc_sd_probe_Add( probe, "picture_dir{longname=\"My Pictures\"}",
-                      N_("My Pictures") );
+                      N_("My Pictures"), SD_CAT_MYCOMPUTER );
     return VLC_PROBE_CONTINUE;
 }