Commit c9c85bef authored by Yoann Peronneau's avatar Yoann Peronneau

* proof of concept of drag & dropping a subtitle file while playing a video file. (Refs: #645)

parent 92ee23d3
...@@ -506,4 +506,6 @@ VLC_EXPORT( decoder_t *, input_DecoderNew, ( input_thread_t *, es_format_t *, vl ...@@ -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_DecoderDelete, ( decoder_t * ) );
VLC_EXPORT( void, input_DecoderDecode,( decoder_t *, block_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 #endif
...@@ -513,6 +513,7 @@ struct module_symbols_t ...@@ -513,6 +513,7 @@ struct module_symbols_t
int (*__intf_UserOkayCancel_inner) (vlc_object_t*, const char*, const char*); int (*__intf_UserOkayCancel_inner) (vlc_object_t*, const char*, const char*);
int (*__intf_UserStringInput_inner) (vlc_object_t*, const char*, const char*, 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 **); 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__) # if defined (__PLUGIN__)
# define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner # define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
...@@ -980,6 +981,7 @@ struct module_symbols_t ...@@ -980,6 +981,7 @@ struct module_symbols_t
# define __intf_UserOkayCancel (p_symbols)->__intf_UserOkayCancel_inner # define __intf_UserOkayCancel (p_symbols)->__intf_UserOkayCancel_inner
# define __intf_UserStringInput (p_symbols)->__intf_UserStringInput_inner # define __intf_UserStringInput (p_symbols)->__intf_UserStringInput_inner
# define playlist_NodesCreateForSD (p_symbols)->playlist_NodesCreateForSD_inner # define playlist_NodesCreateForSD (p_symbols)->playlist_NodesCreateForSD_inner
# define input_AddSubtitles (p_symbols)->input_AddSubtitles_inner
# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__) # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
/****************************************************************** /******************************************************************
* STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access. * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
...@@ -1450,6 +1452,7 @@ struct module_symbols_t ...@@ -1450,6 +1452,7 @@ struct module_symbols_t
((p_symbols)->__intf_UserOkayCancel_inner) = __intf_UserOkayCancel; \ ((p_symbols)->__intf_UserOkayCancel_inner) = __intf_UserOkayCancel; \
((p_symbols)->__intf_UserStringInput_inner) = __intf_UserStringInput; \ ((p_symbols)->__intf_UserStringInput_inner) = __intf_UserStringInput; \
((p_symbols)->playlist_NodesCreateForSD_inner) = playlist_NodesCreateForSD; \ ((p_symbols)->playlist_NodesCreateForSD_inner) = playlist_NodesCreateForSD; \
((p_symbols)->input_AddSubtitles_inner) = input_AddSubtitles; \
(p_symbols)->net_ConvertIPv4_deprecated = NULL; \ (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
(p_symbols)->__playlist_ItemCopy_deprecated = NULL; \ (p_symbols)->__playlist_ItemCopy_deprecated = NULL; \
(p_symbols)->playlist_ItemAddParent_deprecated = NULL; \ (p_symbols)->playlist_ItemAddParent_deprecated = NULL; \
......
...@@ -1283,6 +1283,26 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord, ...@@ -1283,6 +1283,26 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
return FALSE; 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++ ) for( size_t i = 0; i < filenames.GetCount(); i++ )
{ {
char *psz_utf8 = wxDnDFromLocale( filenames[i] ); char *psz_utf8 = wxDnDFromLocale( filenames[i] );
......
...@@ -2431,3 +2431,44 @@ static void MRLSections( input_thread_t *p_input, char *psz_source, ...@@ -2431,3 +2431,44 @@ static void MRLSections( input_thread_t *p_input, char *psz_source,
psz_source, *pi_title_start, *pi_chapter_start, psz_source, *pi_title_start, *pi_chapter_start,
*pi_title_end, *pi_chapter_end ); *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;
}
...@@ -152,6 +152,8 @@ mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t ); ...@@ -152,6 +152,8 @@ mtime_t input_ClockGetTS( input_thread_t *, input_clock_t *, mtime_t );
/* Subtitles */ /* Subtitles */
char **subtitles_Detect( input_thread_t *, char* path, char *fname ); char **subtitles_Detect( input_thread_t *, char* path, char *fname );
int subtitles_Filter( const char *);
void MRLSplit( vlc_object_t *, char *, char **, char **, char ** ); void MRLSplit( vlc_object_t *, char *, char **, char **, char ** );
#endif #endif
...@@ -158,10 +158,11 @@ static int compare_sub_priority( const void *a, const void *b ) ...@@ -158,10 +158,11 @@ static int compare_sub_priority( const void *a, const void *b )
#endif #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, '.'); const char *tmp = strrchr( psz_dir_content, '.');
if( tmp == NULL ) if( tmp == NULL )
return 0; return 0;
...@@ -344,8 +345,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path, ...@@ -344,8 +345,8 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
continue; continue;
/* parse psz_src dir */ /* parse psz_src dir */
i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content, Filter, i_dir_content = utf8_scandir( psz_dir, &ppsz_dir_content,
NULL ); subtitles_Filter, NULL );
if( i_dir_content != -1 ) if( i_dir_content != -1 )
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment