]> git.sesse.net Git - vlc/commitdiff
* proof of concept of drag & dropping a subtitle file while playing a video file...
authorYoann Peronneau <yoann@videolan.org>
Fri, 9 Jun 2006 04:38:16 +0000 (04:38 +0000)
committerYoann Peronneau <yoann@videolan.org>
Fri, 9 Jun 2006 04:38:16 +0000 (04:38 +0000)
include/vlc_input.h
include/vlc_symbols.h
modules/gui/wxwidgets/interface.cpp
src/input/input.c
src/input/input_internal.h
src/input/subtitles.c

index 9b9dc6a4312c13c76f776dc44746f03c5570f333..5333c82842a1285b0d4c6587c892a6aad74d13d2 100644 (file)
@@ -506,4 +506,6 @@ VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vl
 VLC_EXPORT( void, input_DecoderDelete, ( decoder_t * ) );
 VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_t * ) );
 
+VLC_EXPORT( vlc_bool_t, input_AddSubtitles, ( input_thread_t *, char *, vlc_bool_t ) );
+
 #endif
index ef754dcbf1cf47a760802c075d51a4464061996c..6974e56be325e872b2ad82654b5e722f16528dec 100644 (file)
@@ -513,6 +513,7 @@ struct module_symbols_t
     int (*__intf_UserOkayCancel_inner) (vlc_object_t*, const char*, const char*);
     int (*__intf_UserStringInput_inner) (vlc_object_t*, const char*, const char*, char **);
     void (*playlist_NodesCreateForSD_inner) (playlist_t *, char *, playlist_item_t **, playlist_item_t **);
+    vlc_bool_t (*input_AddSubtitles_inner) (input_thread_t *, char *, vlc_bool_t);
 };
 # if defined (__PLUGIN__)
 #  define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
@@ -980,6 +981,7 @@ struct module_symbols_t
 #  define __intf_UserOkayCancel (p_symbols)->__intf_UserOkayCancel_inner
 #  define __intf_UserStringInput (p_symbols)->__intf_UserStringInput_inner
 #  define playlist_NodesCreateForSD (p_symbols)->playlist_NodesCreateForSD_inner
+#  define input_AddSubtitles (p_symbols)->input_AddSubtitles_inner
 # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
 /******************************************************************
  * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
@@ -1450,6 +1452,7 @@ struct module_symbols_t
     ((p_symbols)->__intf_UserOkayCancel_inner) = __intf_UserOkayCancel; \
     ((p_symbols)->__intf_UserStringInput_inner) = __intf_UserStringInput; \
     ((p_symbols)->playlist_NodesCreateForSD_inner) = playlist_NodesCreateForSD; \
+    ((p_symbols)->input_AddSubtitles_inner) = input_AddSubtitles; \
     (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
     (p_symbols)->__playlist_ItemCopy_deprecated = NULL; \
     (p_symbols)->playlist_ItemAddParent_deprecated = NULL; \
index fe8fb736ff46ced9844b6de4998cd2857dc960cd..3ec4243e91e63aaedd01b60915125eb29282665f 100644 (file)
@@ -1283,6 +1283,26 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
         return FALSE;
     }
 
+    /* If we drag & drop a subtitle file, add it on the fly */
+    if( filenames.GetCount() == 1 )
+    {
+        char *psz_utf8 = wxDnDFromLocale( filenames[0] );
+        input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
+                                            VLC_OBJECT_INPUT, FIND_ANYWHERE );
+        if( p_input )
+        {
+            if( input_AddSubtitles( p_input, psz_utf8, VLC_TRUE ) )
+            {
+                vlc_object_release( p_input );
+                wxDnDLocaleFree( psz_utf8 );
+                vlc_object_release( p_playlist );
+                return TRUE;
+            }
+            vlc_object_release( p_input );
+        }
+        wxDnDLocaleFree( psz_utf8 );
+    }
+
     for( size_t i = 0; i < filenames.GetCount(); i++ )
     {
         char *psz_utf8 = wxDnDFromLocale( filenames[i] );
index 4d45125d48979d537f5a82a754218b38d4e81a7f..7b8cbcf030fe4baded4b71a48d981d6e9ae02a69 100644 (file)
@@ -2431,3 +2431,44 @@ static void MRLSections( input_thread_t *p_input, char *psz_source,
              psz_source, *pi_title_start, *pi_chapter_start,
              *pi_title_end, *pi_chapter_end );
 }
+
+/*****************************************************************************
+ * input_AddSubtitles: add a subtitles file and enable it
+ *****************************************************************************/
+vlc_bool_t input_AddSubtitles( input_thread_t *p_input, char *psz_subtitle,
+                               vlc_bool_t b_check_extension )
+{
+    input_source_t *sub;
+    vlc_value_t count;
+    vlc_value_t list;
+
+    if( b_check_extension && !subtitles_Filter( psz_subtitle ) )
+    {
+        return VLC_FALSE;
+    }
+
+    var_Change( p_input, "spu-es", VLC_VAR_CHOICESCOUNT, &count, NULL );
+
+    sub = InputSourceNew( p_input );
+    if( !InputSourceInit( p_input, sub, psz_subtitle, "subtitle", VLC_FALSE ) )
+    {
+        TAB_APPEND( p_input->i_slave, p_input->slave, sub );
+
+        /* Select the ES */
+        if( !var_Change( p_input, "spu-es", VLC_VAR_GETLIST, &list, NULL ) )
+        {
+            if( count.i_int == 0 )
+                count.i_int++;
+            /* if it was first one, there is disable too */
+
+            if( count.i_int < list.p_list->i_count )
+            {
+                input_ControlPush( p_input, INPUT_CONTROL_SET_ES,
+                                   &list.p_list->p_values[count.i_int] );
+            }
+            var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
+        }
+    }
+
+    return VLC_TRUE;
+}
index e6e51e85809ee51ef908d8d9c9de87d3b06afdbb..d1592fc07db1fcfb3424a6584983e42a4de971ef 100644 (file)
@@ -152,6 +152,8 @@ mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
 
 /* Subtitles */
 char **subtitles_Detect( input_thread_t *, char* path, char *fname );
+int subtitles_Filter( const char *);
+
 void MRLSplit( vlc_object_t *, char *, char **, char **, char ** );
 
 #endif
index 19bc365386ad5c4172f44a2a758091c5dc8eb488..b805a1ba32851461e9b353c6f86ea19cc3e5b081 100644 (file)
@@ -158,10 +158,11 @@ static int compare_sub_priority( const void *a, const void *b )
 #endif
 }
 
-/* Utility function for scandir */
-static int Filter( const char *psz_dir_content )
+/*
+ * Check if a file ends with a subtitle extension
+ */
+int subtitles_Filter( const char *psz_dir_content )
 {
-    /* does it end with a subtitle extension? */
     const char *tmp = strrchr( psz_dir_content, '.');
     if( tmp == NULL )
         return 0;
@@ -344,8 +345,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             continue;
 
         /* parse psz_src dir */
-        i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content, Filter,
-                                      NULL );
+        i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content,
+                                      subtitles_Filter, NULL );
 
         if( i_dir_content != -1 )
         {