-- (void)setupVarMenuItem:(NSMenuItem *)o_mi
- target:(vlc_object_t *)p_object
- var:(const char *)psz_variable
- selector:(SEL)pf_callback
-{
- vlc_value_t val, text;
- int i_type = var_Type( p_object, psz_variable );
-
- switch( i_type & VLC_VAR_TYPE )
- {
- case VLC_VAR_VOID:
- case VLC_VAR_BOOL:
- case VLC_VAR_VARIABLE:
- case VLC_VAR_STRING:
- case VLC_VAR_INTEGER:
- break;
- default:
- /* Variable doesn't exist or isn't handled */
- return;
- }
-
- /* Make sure we want to display the variable */
- if( i_type & VLC_VAR_HASCHOICE )
- {
- var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
- if( val.i_int == 0 ) return;
- if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
- return;
- }
-
- /* Get the descriptive name of the variable */
- var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
- [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
- text.psz_string : psz_variable ]];
-
- if( i_type & VLC_VAR_HASCHOICE )
- {
- NSMenu *o_menu = [o_mi submenu];
-
- [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
- var:psz_variable selector:pf_callback];
-
- free( text.psz_string );
- return;
- }
- if( var_Get( p_object, psz_variable, &val ) < 0 )
- {
- return;
- }
-
- VLCAutoGeneratedMenuContent *o_data;
- switch( i_type & VLC_VAR_TYPE )
- {
- case VLC_VAR_VOID:
- o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
- andValue: val ofType: i_type];
- [o_mi setRepresentedObject: [o_data autorelease]];
- break;
-
- case VLC_VAR_BOOL:
- o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
- andValue: val ofType: i_type];
- [o_mi setRepresentedObject: [o_data autorelease]];
- if( !( i_type & VLC_VAR_ISCOMMAND ) )
- [o_mi setState: val.b_bool ? TRUE : FALSE ];
- break;
-
- default:
- break;
- }
-
- if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
- free( text.psz_string );
-}
-
-
-- (void)setupVarMenu:(NSMenu *)o_menu
- forMenuItem: (NSMenuItem *)o_parent
- target:(vlc_object_t *)p_object
- var:(const char *)psz_variable
- selector:(SEL)pf_callback
-{
- vlc_value_t val, val_list, text_list;
- int i_type, i, i_nb_items;
-
- /* remove previous items */
- i_nb_items = [o_menu numberOfItems];
- for( i = 0; i < i_nb_items; i++ )
- {
- [o_menu removeItemAtIndex: 0];
- }
-
- /* Check the type of the object variable */
- i_type = var_Type( p_object, psz_variable );
-
- /* Make sure we want to display the variable */
- if( i_type & VLC_VAR_HASCHOICE )
- {
- var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
- if( val.i_int == 0 ) return;
- if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
- return;
- }
- else
- {
- return;
- }
-
- switch( i_type & VLC_VAR_TYPE )
- {
- case VLC_VAR_VOID:
- case VLC_VAR_BOOL:
- case VLC_VAR_VARIABLE:
- case VLC_VAR_STRING:
- case VLC_VAR_INTEGER:
- break;
- default:
- /* Variable doesn't exist or isn't handled */
- return;
- }
-
- if( var_Get( p_object, psz_variable, &val ) < 0 )
- {
- return;
- }
-
- if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
- &val_list, &text_list ) < 0 )
- {
- if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
- return;
- }
-
- /* make (un)sensitive */
- [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
-
- /* Aspect Ratio */
- if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
- {
- NSMenuItem *o_lmi_tmp2;
- o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
- [o_lmi_tmp2 setTarget: self];
- [o_lmi_tmp2 setEnabled: YES];
- [o_lmi_tmp2 setState: b_lockAspectRatio];
- [o_parent setEnabled: YES];
- [o_menu addItem: [NSMenuItem separatorItem]];
- }
-
- /* special case for the subtitles items */
- if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
- {
- NSMenuItem * o_lmi_tmp;
- o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
- [o_lmi_tmp setTarget: self];
- [o_lmi_tmp setEnabled: YES];
- [o_parent setEnabled: YES];
- [o_menu addItem: [NSMenuItem separatorItem]];
- }
-
- for( i = 0; i < val_list.p_list->i_count; i++ )
- {
- NSMenuItem * o_lmi;
- NSString *o_title = @"";
- VLCAutoGeneratedMenuContent *o_data;
-
- switch( i_type & VLC_VAR_TYPE )
- {
- case VLC_VAR_STRING:
-
- o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
- text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
-
- o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
- o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
- andValue: val_list.p_list->p_values[i] ofType: i_type];
- [o_lmi setRepresentedObject: [o_data autorelease]];
- [o_lmi setTarget: self];
-
- if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
- [o_lmi setState: TRUE ];
-
- break;
-
- case VLC_VAR_INTEGER:
-
- o_title = text_list.p_list->p_values[i].psz_string ?
- [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
- [NSString stringWithFormat: @"%"PRId64,
- val_list.p_list->p_values[i].i_int];
-
- o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
- o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
- andValue: val_list.p_list->p_values[i] ofType: i_type];
- [o_lmi setRepresentedObject: [o_data autorelease]];
- [o_lmi setTarget: self];
-
- if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
- [o_lmi setState: TRUE ];
- break;
-
- default:
- break;
- }
- }
-
- /* special case for the subtitles sub-menu
- * In case that we don't have any subs, we don't want a separator item at the end */
- if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
- {
- if( [o_menu numberOfItems] == 2 )
- [o_menu removeItemAtIndex: 1];
- }
-
- /* clean up everything */
- if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
- var_FreeList( &val_list, &text_list );
-}
-
-- (IBAction)toggleVar:(id)sender
-{
- NSMenuItem *o_mi = (NSMenuItem *)sender;
- VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
- [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
- toTarget: self withObject: o_data];
-
- return;
-}
-
-- (int)toggleVarThread: (id)data
-{
- vlc_object_t *p_object;
- NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
-
- assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
- VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
-
- vlc_thread_set_priority( VLCIntf , VLC_THREAD_PRIORITY_LOW );
-
- p_object = [menuContent vlcObject];
-
- if( p_object != NULL )
- {
- var_Set( p_object, [menuContent name], [menuContent value] );
- vlc_object_release( p_object );
- [o_pool release];
- return true;
- }
- [o_pool release];
- return VLC_EGENERIC;
-}
-