]> git.sesse.net Git - vlc/blobdiff - modules/services_discovery/mediadirs.c
services_discovery: implement SD categories and use in Qt interface
[vlc] / modules / services_discovery / mediadirs.c
index 4da0e3d7b2994ddabbce95fa72eaac3a34055144..c4b06cf58c2783e64d92190b6ff63702729fb4c8 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>
@@ -61,30 +61,33 @@ OPEN_MODULE( Picture )
 
 #undef OPEN_MODULE
 
+static int vlc_sd_probe_Open( vlc_object_t * );
+
 vlc_module_begin ()
     set_category( CAT_PLAYLIST )
     set_subcategory( SUBCAT_PLAYLIST_SD )
 
-        set_shortname( "Video" )
+        set_shortname( N_("Video") )
         set_description( N_("My Videos") )
         set_capability( "services_discovery", 10 )
         set_callbacks( OpenVideo, Close )
         add_shortcut( "video_dir" )
 
     add_submodule ()
-        set_shortname( "Audio" )
+        set_shortname( N_("Audio") )
         set_description( N_("My Music") )
         set_capability( "services_discovery", 10 )
         set_callbacks( OpenAudio, Close )
         add_shortcut( "audio_dir" )
 
     add_submodule ()
-        set_shortname( "Picture")
+        set_shortname( N_("Picture") )
         set_description( N_("My Pictures") )
         set_capability( "services_discovery", 10 )
         set_callbacks( OpenPicture, Close )
         add_shortcut( "picture_dir" )
 
+    VLC_SD_PROBE_SUBMODULE
 vlc_module_end ()
 
 
@@ -107,7 +110,7 @@ struct services_discovery_sys_t
     enum type_e i_type;
 
     char* psz_dir[2];
-    char* psz_var;
+    const char* psz_var;
 };
 
 /*****************************************************************************
@@ -129,21 +132,21 @@ static int Open( vlc_object_t *p_this, enum type_e i_type )
         p_sys->psz_dir[0] = config_GetUserDir( VLC_VIDEOS_DIR );
         p_sys->psz_dir[1] = var_CreateGetString( p_sd, "input-record-path" );
 
-        p_sys->psz_var = strdup( "record-file" );
+        p_sys->psz_var = "record-file";
     }
     else if( p_sys->i_type == Audio )
     {
         p_sys->psz_dir[0] = config_GetUserDir( VLC_MUSIC_DIR );
         p_sys->psz_dir[1] = var_CreateGetString( p_sd, "input-record-path" );
 
-        p_sys->psz_var = strdup( "record-file" );
+        p_sys->psz_var = "record-file";
     }
     else if( p_sys->i_type == Picture )
     {
         p_sys->psz_dir[0] = config_GetUserDir( VLC_PICTURES_DIR );
         p_sys->psz_dir[1] = var_CreateGetString( p_sd, "snapshot-path" );
 
-        p_sys->psz_var = strdup( "snapshot-file" );
+        p_sys->psz_var = "snapshot-file";
     }
     else
     {
@@ -156,7 +159,6 @@ static int Open( vlc_object_t *p_this, enum type_e i_type )
     if( vlc_clone( &p_sys->thread, Run, p_sd, VLC_THREAD_PRIORITY_LOW ) )
     {
         var_DelCallback( p_sd->p_libvlc, p_sys->psz_var, onNewFileAdded, p_sd );
-        free( p_sys->psz_var );
         free( p_sys->psz_dir[1] );
         free( p_sys->psz_dir[0] );
         free( p_sys );
@@ -184,7 +186,7 @@ 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;
 
@@ -199,7 +201,7 @@ static void *Run( void *data )
             input_item_AddOption( p_root, "ignore-filetypes=ini,db,lnk,txt",
                                   VLC_INPUT_OPTION_TRUSTED );
 
-        input_item_AddOption( p_root, "recursive=expand",
+        input_item_AddOption( p_root, "recursive=collapse",
                               VLC_INPUT_OPTION_TRUSTED );
 
 
@@ -207,7 +209,7 @@ static void *Run( void *data )
         vlc_event_attach( p_em, vlc_InputItemSubItemAdded,
                           input_item_subitem_added, p_sd );
 
-        input_Read( p_sd, p_root, true );
+        input_Read( p_sd, p_root );
 
         vlc_event_detach( p_em, vlc_InputItemSubItemAdded,
                           input_item_subitem_added, p_sd );
@@ -233,7 +235,6 @@ static void Close( vlc_object_t *p_this )
 
     var_DelCallback( p_sd->p_libvlc, p_sys->psz_var, onNewFileAdded, p_sd );
 
-    free( p_sys->psz_var );
     free( p_sys->psz_dir[1] );
     free( p_sys->psz_dir[0] );
     free( p_sys );
@@ -349,3 +350,16 @@ enum type_e fileType( services_discovery_t *p_sd, const char* psz_file )
     free( psz_dir );
     return i_ret;
 }
+
+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"), SD_CAT_MYCOMPUTER );
+    vlc_sd_probe_Add( probe, "audio_dir{longname=\"My Music\"}",
+                      N_("My Music"), SD_CAT_MYCOMPUTER );
+    vlc_sd_probe_Add( probe, "picture_dir{longname=\"My Pictures\"}",
+                      N_("My Pictures"), SD_CAT_MYCOMPUTER );
+    return VLC_PROBE_CONTINUE;
+}