-- (void)setupMenus:(input_thread_t *)p_input
-{
- unsigned int i, i_nb_items;
- NSMenuItem * o_item;
- NSString * o_menu_title;
- char psz_title[ 256 ];
-
- es_descriptor_t * p_audio_es = NULL;
- es_descriptor_t * p_spu_es = NULL;
-
- intf_thread_t * p_intf = [NSApp getIntf];
-
- p_intf->p_sys->b_chapter_update |= p_intf->p_sys->b_title_update;
- p_intf->p_sys->b_audio_update |= p_intf->p_sys->b_title_update |
- p_intf->p_sys->b_program_update;
- p_intf->p_sys->b_spu_update |= p_intf->p_sys->b_title_update |
- p_intf->p_sys->b_program_update;
-
- if( p_intf->p_sys->b_program_update )
- {
- NSMenu * o_program;
- SEL pf_toggle_program;
- pgrm_descriptor_t * p_pgrm;
-
- if( p_input->stream.p_new_program )
- {
- p_pgrm = p_input->stream.p_new_program;
- }
- else
- {
- p_pgrm = p_input->stream.p_selected_program;
- }
-
- o_program = [o_mi_program submenu];
- pf_toggle_program = @selector(toggleProgram:);
-
- /* remove previous program items */
- i_nb_items = [o_program numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_program removeItemAtIndex: 0];
- }
-
- /* make (un)sensitive */
- [o_mi_program setEnabled:
- p_input->stream.i_pgrm_number > 1];
-
- /* add program items */
- for( i = 0 ; i < p_input->stream.i_pgrm_number ; i++ )
- {
- snprintf( psz_title, sizeof(psz_title), "id %d",
- p_input->stream.pp_programs[i]->i_number );
- psz_title[sizeof(psz_title) - 1] = '\0';
-
- o_menu_title = [NSApp localizedString: psz_title];
-
- o_item = [o_program addItemWithTitle: o_menu_title
- action: pf_toggle_program keyEquivalent: @""];
- [o_item setTag: p_input->stream.pp_programs[i]->i_number];
- [o_item setTarget: o_controls];
-
- if( p_pgrm == p_input->stream.pp_programs[i] )
- {
- [o_item setState: NSOnState];
- }
- }
-
- p_intf->p_sys->b_program_update = 0;
- }
-
- if( p_intf->p_sys->b_title_update )
- {
- NSMenu * o_title;
- SEL pf_toggle_title;
-
- o_title = [o_mi_title submenu];
- pf_toggle_title = @selector(toggleTitle:);
-
- /* remove previous title items */
- i_nb_items = [o_title numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_title removeItemAtIndex: 0];
- }
-
- /* make (un)sensitive */
- [o_mi_title setEnabled:
- p_input->stream.i_area_nb > 1];
-
- /* add title items */
- for( i = 1 ; i < p_input->stream.i_area_nb ; i++ )
- {
- snprintf( psz_title, sizeof(psz_title), "Title %d (%d)", i,
- p_input->stream.pp_areas[i]->i_part_nb );
- psz_title[sizeof(psz_title) - 1] = '\0';
-
- o_menu_title = [NSApp localizedString: psz_title];
-
- o_item = [o_title addItemWithTitle: o_menu_title
- action: pf_toggle_title keyEquivalent: @""];
- [o_item setTag: i];
- [o_item setTarget: o_controls];
-
- if( ( p_input->stream.pp_areas[i] ==
- p_input->stream.p_selected_area ) )
- {
- [o_item setState: NSOnState];
- }
- }
-
- p_intf->p_sys->b_title_update = 0;
- }
-
- if( p_intf->p_sys->b_chapter_update )
- {
- NSMenu * o_chapter;
- SEL pf_toggle_chapter;
-
- o_chapter = [o_mi_chapter submenu];
- pf_toggle_chapter = @selector(toggleChapter:);
-
- /* remove previous chapter items */
- i_nb_items = [o_chapter numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_chapter removeItemAtIndex: 0];
- }
-
- /* make (un)sensitive */
- [o_mi_chapter setEnabled:
- p_input->stream.p_selected_area->i_part_nb > 1];
-
- /* add chapter items */
- for( i = 0 ; i < p_input->stream.p_selected_area->i_part_nb ; i++ )
- {
- snprintf( psz_title, sizeof(psz_title), "Chapter %d", i + 1 );
- psz_title[sizeof(psz_title) - 1] = '\0';
-
- o_menu_title = [NSApp localizedString: psz_title];
-
- o_item = [o_chapter addItemWithTitle: o_menu_title
- action: pf_toggle_chapter keyEquivalent: @""];
- [o_item setTag: i + 1];
- [o_item setTarget: o_controls];
-
- if( ( p_input->stream.p_selected_area->i_part == i + 1 ) )
- {
- [o_item setState: NSOnState];
- }
- }
-
- p_intf->p_sys->i_part =
- p_input->stream.p_selected_area->i_part;
-
- p_intf->p_sys->b_chapter_update = 0;
- }
-
- for( i = 0 ; i < p_input->stream.i_selected_es_number ; i++ )
- {
- if( p_input->stream.pp_selected_es[i]->i_cat == AUDIO_ES )
- {
- p_audio_es = p_input->stream.pp_selected_es[i];
- }
- else if( p_input->stream.pp_selected_es[i]->i_cat == SPU_ES )
- {
- p_spu_es = p_input->stream.pp_selected_es[i];
- }
- }
-
- if( p_intf->p_sys->b_audio_update )
- {
- [self setupLangMenu: p_input mi: o_mi_language es: p_audio_es
- category: AUDIO_ES selector: @selector(toggleLanguage:)];
-
- p_intf->p_sys->b_audio_update = 0;
- }
-
- if( p_intf->p_sys->b_spu_update )
- {
- [self setupLangMenu: p_input mi: o_mi_subtitle es: p_spu_es
- category: SPU_ES selector: @selector(toggleLanguage:)];
-
- p_intf->p_sys->b_spu_update = 0;
- }
-
- if ( p_intf->p_sys->b_aout_update )
- {
- aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
- FIND_ANYWHERE );
-
- if ( p_aout != NULL )
- {
- vlc_value_t val;
- val.b_bool = 0;
-
- var_Set( (vlc_object_t *)p_aout, "intf-change", val );
-
- [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
- var: "audio-channels" selector: @selector(toggleVar:)];
-
- [self setupVarMenu: o_mi_device target: (vlc_object_t *)p_aout
- var: "audio-device" selector: @selector(toggleVar:)];
-
- vlc_object_release( (vlc_object_t *)p_aout );
- }
-
- p_intf->p_sys->b_aout_update = 0;
- }
-
- if( p_intf->p_sys->b_vout_update )
- {
- vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
- FIND_ANYWHERE );
-
- if ( p_vout != NULL )
- {
- vlc_value_t val;
- val.b_bool = 0;
-
- var_Set( (vlc_object_t *)p_vout, "intf-change", val );
-
- [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
- var: "video-device" selector: @selector(toggleVar:)];
-
- vlc_object_release( (vlc_object_t *)p_vout );
-
- [o_mi_close_window setEnabled: TRUE];
- }
-
- p_intf->p_sys->b_vout_update = 0;
- }
-
-#undef p_input
-}
-
-- (void)setupLangMenu:(input_thread_t *)p_input
- mi:(NSMenuItem *)o_mi
- es:(es_descriptor_t *)p_es
- category:(int)i_cat
- selector:(SEL)pf_callback
-{
- unsigned int i, i_nb_items;
- NSMenu * o_menu = [o_mi submenu];
-
- /* remove previous language items */
- i_nb_items = [o_menu numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_menu removeItemAtIndex: 0];
- }
-
- /* make sensitive : we can't change it after we build the menu, and
- * before, we don't yet how many items we will have. So make it
- * always sensitive. --Meuuh */
- [o_mi setEnabled: TRUE];
-
-#if 0
- /* We do not use this code, because you need to start stop .avi for
- * it to work, so not very useful now --hartman */
- if ( o_mi == o_mi_subtitle ) {
- NSLog(@"testing");
- [o_mi setEnabled: TRUE ];
- NSMenuItem * o_lmi;
- NSString * o_title;
- o_title = _NS("Load from file..");
- o_lmi = [o_menu addItemWithTitle: o_title
- action: pf_callback keyEquivalent: @""];
- [o_lmi setTag: 2000];
- [o_lmi setTarget: o_controls];
- }
-#endif
-
-#define ES p_input->stream.pp_es[i]
- for( i = 0 ; i < p_input->stream.i_es_number ; i++ )
- {
- if( ( ES->i_cat == i_cat ) &&
- ( !ES->p_pgrm ||
- ES->p_pgrm ==
- p_input->stream.p_selected_program ) )
- {
- NSMenuItem * o_lmi;
- NSString * o_title;
-
- if( *ES->psz_desc )
- {
- o_title = [NSApp localizedString: ES->psz_desc];
- }
- else
- {
- char psz_title[ 256 ];
-
- snprintf( psz_title, sizeof(psz_title), _("Language 0x%x"),
- ES->i_id );
- psz_title[sizeof(psz_title) - 1] = '\0';
-
- o_title = [NSApp localizedString: psz_title];
- }
-
- o_lmi = [o_menu addItemWithTitle: o_title
- action: pf_callback keyEquivalent: @""];
- [o_lmi setRepresentedObject:
- [NSValue valueWithPointer: ES]];
- [o_lmi setTarget: o_controls];
- [o_lmi setTag: i_cat];
-
- if( /*p_es == ES*/ ES->p_decoder_fifo != NULL )
- {
- [o_lmi setState: NSOnState];
- }
- }
- }
-#undef ES
-}
-
-- (void)setupVarMenu:(NSMenuItem *)o_mi
- target:(vlc_object_t *)p_object
- var:(const char *)psz_variable
- selector:(SEL)pf_callback
-{
- int i, i_nb_items;
- NSMenu * o_menu = [o_mi submenu];
- vlc_value_t val;
- char * psz_value;
-
- /* remove previous items */
- i_nb_items = [o_menu numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_menu removeItemAtIndex: 0];
- }
-
- if ( var_Get( p_object, psz_variable, &val ) < 0 )
- {
- return;
- }
- psz_value = val.psz_string;
-
- if ( var_Change( p_object, psz_variable,
- VLC_VAR_GETLIST, &val ) < 0 )
- {
- free( psz_value );
- return;
- }
-
- /* make (un)sensitive */
- [o_mi setEnabled: ( val.p_list->i_count > 0 )];
-
- for ( i = 0; i < val.p_list->i_count; i++ )
- {
- NSMenuItem * o_lmi;
- NSString * o_title;
-
- o_title = [NSApp localizedString: val.p_list->p_values[i].psz_string];
- o_lmi = [o_menu addItemWithTitle: o_title
- action: pf_callback keyEquivalent: @""];
- /* FIXME: this isn't 64-bit clean ! */
- [o_lmi setTag: (int)psz_variable];
- [o_lmi setRepresentedObject:
- [NSValue valueWithPointer: p_object]];
- [o_lmi setTarget: o_controls];
-
- if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
- [o_lmi setState: NSOnState];
- }
-
- var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
- &val );
-
- free( psz_value );
-}
-