1 /*****************************************************************************
2 * prefs.m: MacOS X plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: prefs.m,v 1.35 2003/11/11 23:50:41 hartman Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <thedj at users.sf.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
29 #include <sys/param.h> /* for MAXPATHLEN */
36 /*****************************************************************************
37 * VLCPrefs implementation
38 *****************************************************************************/
39 @implementation VLCPrefs
47 o_empty_view = [[NSView alloc] init];
48 o_save_prefs = [[NSMutableDictionary alloc] init];
56 [o_empty_view release];
57 [o_save_prefs release];
63 p_intf = [NSApp getIntf];
64 b_advanced = config_GetInt( p_intf, "advanced" );
67 [o_advanced_ckb setState: b_advanced];
68 [o_prefs_view setBorderType: NSGrooveBorder];
69 [o_prefs_view setHasVerticalScroller: YES];
70 [o_prefs_view setDrawsBackground: NO];
71 [o_prefs_view setRulersVisible: NO];
72 [o_prefs_view setDocumentView: o_empty_view];
73 [o_tree selectRow:0 byExtendingSelection:NO];
78 [o_prefs_window setTitle: _NS("Preferences")];
79 [o_save_btn setTitle: _NS("Save")];
80 [o_cancel_btn setTitle: _NS("Cancel")];
81 [o_reset_btn setTitle: _NS("Reset All")];
82 [o_advanced_ckb setTitle: _NS("Advanced")];
87 [o_save_prefs release];
88 o_save_prefs = [[NSMutableDictionary alloc] init];
89 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
90 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
91 [o_prefs_window center];
92 [o_prefs_window makeKeyAndOrderFront:self];
95 - (IBAction)savePrefs: (id)sender
100 o_enum = [o_save_prefs objectEnumerator];
101 while( ( o_vlc_config = [o_enum nextObject] ) )
103 int i_type = [o_vlc_config configType];
104 NSString *o_name = [o_vlc_config configName];
105 char *psz_name = (char *)[o_name UTF8String];
110 case CONFIG_ITEM_MODULE:
113 module_t *p_a_module;
114 int i_id = [[o_vlc_config selectedItem] tag];
116 p_a_module = (module_t *)vlc_object_get( p_intf, i_id );
117 if( p_a_module == NULL || p_a_module->i_object_type != VLC_OBJECT_MODULE )
122 psz_value = ( i_id == -1 ) ? "" : p_a_module->psz_object_name ;
123 config_PutPsz( p_intf, psz_name, strdup(psz_value) );
127 case CONFIG_ITEM_STRING:
128 case CONFIG_ITEM_FILE:
129 case CONFIG_ITEM_DIRECTORY:
132 NSString *o_value = [o_vlc_config stringValue];
133 psz_value = (char *)[o_value UTF8String];
135 config_PutPsz( p_intf, psz_name, psz_value );
139 case CONFIG_ITEM_INTEGER:
140 case CONFIG_ITEM_BOOL:
142 int i_value = [o_vlc_config intValue];
144 config_PutInt( p_intf, psz_name, i_value );
148 case CONFIG_ITEM_FLOAT:
150 float f_value = [o_vlc_config floatValue];
152 config_PutFloat( p_intf, psz_name, f_value );
156 case CONFIG_ITEM_KEY:
158 unsigned int i_key = config_GetInt( p_intf, psz_name );
159 unsigned int i_new_key = 0;
161 if( [o_vlc_config class] == [VLCMatrix class] )
164 NSButtonCell *o_current_cell;
165 NSArray *o_cells = [o_vlc_config cells];
166 i_new_key = (i_key & ~KEY_MODIFIER);
167 for( i = 0; i < [o_cells count]; i++ )
169 o_current_cell = [o_cells objectAtIndex:i];
170 if( [[o_current_cell title] isEqualToString:_NS("Command")] &&
171 [o_current_cell state] == NSOnState )
172 i_new_key |= KEY_MODIFIER_COMMAND;
173 if( [[o_current_cell title] isEqualToString:_NS("Control")] &&
174 [o_current_cell state] == NSOnState )
175 i_new_key |= KEY_MODIFIER_CTRL;
176 if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] &&
177 [o_current_cell state] == NSOnState )
178 i_new_key |= KEY_MODIFIER_ALT;
179 if( [[o_current_cell title] isEqualToString:_NS("Shift")] &&
180 [o_current_cell state] == NSOnState )
181 i_new_key |= KEY_MODIFIER_SHIFT;
186 i_new_key = (i_key & KEY_MODIFIER);
187 i_new_key |= StringToKey([[o_vlc_config stringValue] cString]);
189 config_PutInt( p_intf, psz_name, i_new_key );
194 config_SaveConfigFile( p_intf, NULL );
195 [o_prefs_window orderOut:self];
198 - (IBAction)closePrefs: (id)sender
200 [o_prefs_window orderOut:self];
203 - (IBAction)resetAll: (id)sender
205 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
206 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
207 _NS("Beware this will reset your VLC Media Player config file.\n"
208 "Are you sure you want to continue?") );
211 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
213 if( i_return == NSAlertAlternateReturn )
215 config_ResetAll( p_intf );
216 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
217 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
221 - (IBAction)advancedToggle: (id)sender
223 b_advanced = !b_advanced;
224 [o_advanced_ckb setState: b_advanced];
225 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
226 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
229 - (IBAction)openFileDialog: (id)sender
231 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
233 [o_open_panel setTitle: _NS("Select file or directory")];
234 [o_open_panel setPrompt: _NS("Select")];
235 [o_open_panel setAllowsMultipleSelection: NO];
236 [o_open_panel setCanChooseFiles: YES];
237 [o_open_panel setCanChooseDirectories: YES];
238 [o_open_panel beginSheetForDirectory:nil
241 modalForWindow:[sender window]
243 didEndSelector: @selector(pathChosenInPanel:
246 contextInfo: sender];
249 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info
251 if( i_return_code == NSOKButton )
253 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
254 VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */
255 [o_field setStringValue: o_path];
256 [self configChanged: o_field];
260 - (void)loadConfigTree
265 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
269 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
271 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
272 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
275 - (void)configChanged:(id)o_unknown
277 id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
278 [o_unknown object] : o_unknown;
280 NSString *o_name = [o_vlc_config configName];
281 [o_save_prefs setObject: o_vlc_config forKey: o_name];
284 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
288 module_config_t *p_item;
290 int i_pos, i_module_tag, i_index;
292 NSString *o_module_name;
293 NSRect s_rc; /* rect */
294 NSView *o_view; /* view */
295 NSRect s_vrc; /* view rect */
296 VLCTextField *o_text_field; /* input field / label */
298 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
300 /* Get a pointer to the module */
301 p_parser = (module_t *)vlc_object_get( p_intf, i_id );
302 if( p_parser->i_object_type != VLC_OBJECT_MODULE )
304 /* 0OOoo something went really bad */
308 /* Enumerate config options and add corresponding config boxes */
309 o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
310 p_item = p_parser->p_config;
317 #define Y_ORIGIN (X_ORIGIN - 10)
319 #define CHECK_VIEW_HEIGHT \
321 float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
322 if( f_new_pos > s_vrc.size.height ) \
324 s_vrc.size.height = f_new_pos; \
325 [o_view setFrame: s_vrc]; \
329 #define CONTROL_LABEL( label ) \
331 s_rc.origin.x += s_rc.size.width + 10; \
332 s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
333 o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
334 [o_text_field setDrawsBackground: NO]; \
335 [o_text_field setBordered: NO]; \
336 [o_text_field setEditable: NO]; \
337 [o_text_field setSelectable: NO]; \
340 [o_text_field setStringValue: \
341 [NSApp localizedString: label]]; \
343 [o_text_field sizeToFit]; \
344 [o_view addSubview: [o_text_field autorelease]]; \
347 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
349 char * psz_duptip = NULL; \
350 if ( p_item->psz_longtext != NULL ) \
351 psz_duptip = strdup( p_item->psz_longtext ); \
352 s_rc.size.height = 25; \
353 s_rc.size.width = w; \
354 s_rc.origin.y += 10; \
356 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
357 [o_text_field setAlignment: NSRightTextAlignment]; \
358 CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
359 [o_text_field msg: param]; \
360 if ( psz_duptip != NULL ) \
362 [o_text_field setToolTip: [NSApp wrapString: [NSApp localizedString: \
363 psz_duptip] toWidth: PREFS_WRAP ]]; \
366 [o_view addSubview: [o_text_field autorelease]]; \
367 [[NSNotificationCenter defaultCenter] addObserver: self \
368 selector: @selector(configChanged:) \
369 name: NSControlTextDidChangeNotification \
370 object: o_text_field]; \
371 CONTROL_LABEL( label ); \
372 s_rc.origin.y += s_rc.size.height; \
373 s_rc.origin.x = X_ORIGIN; \
376 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
377 INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
378 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
379 INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
380 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
381 INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
384 s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
385 o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
386 [o_view setAutoresizingMask: NSViewWidthSizable];
387 s_rc.origin.x = X_ORIGIN;
388 s_rc.origin.y = Y_ORIGIN;
389 BOOL b_right_cat = FALSE;
393 if( p_item->i_type == CONFIG_HINT_CATEGORY )
395 if( !strcmp( p_parser->psz_object_name, "main" ) &&
396 [o_item_name isEqualToString: [NSApp localizedString: p_item->psz_text]] )
399 } else if( strcmp( p_parser->psz_object_name, "main" ) )
402 } else b_right_cat = FALSE;
403 } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
408 if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
412 switch( p_item->i_type )
414 case CONFIG_ITEM_MODULE:
416 VLCPopUpButton *o_modules;
417 module_t *p_a_module;
418 char * psz_duptip = NULL;
420 if ( p_item->psz_longtext != NULL )
421 psz_duptip = strdup( p_item->psz_longtext );
423 s_rc.size.height = 25;
424 s_rc.size.width = 200;
429 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
430 CONTROL_CONFIG( o_modules, o_module_name,
431 CONFIG_ITEM_MODULE, p_item->psz_name );
432 [o_modules setTarget: self];
433 [o_modules setAction: @selector(configChanged:)];
434 [o_modules sendActionOn:NSLeftMouseUpMask];
436 if ( psz_duptip != NULL )
438 [o_modules setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
441 [o_view addSubview: [o_modules autorelease]];
443 [o_modules addItemWithTitle: _NS("Default")];
444 [[o_modules lastItem] setTag: -1];
445 [o_modules selectItem: [o_modules lastItem]];
447 /* build a list of available modules */
449 for( i_index = 0; i_index < p_list->i_count; i_index++ )
451 p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
453 if( !strcmp( p_a_module->psz_capability,
456 NSString *o_description = [NSApp
457 localizedString: p_a_module->psz_longname];
458 [o_modules addItemWithTitle: o_description];
459 [[o_modules lastItem] setTag: p_a_module->i_object_id];
461 if( p_item->psz_value &&
462 !strcmp( p_item->psz_value, p_a_module->psz_object_name ) )
464 [o_modules selectItem:[o_modules lastItem]];
470 CONTROL_LABEL( p_item->psz_text );
471 s_rc.origin.y += s_rc.size.height;
472 s_rc.origin.x = X_ORIGIN;
476 case CONFIG_ITEM_FILE:
477 case CONFIG_ITEM_DIRECTORY:
479 char *psz_duptip = NULL;
480 char *psz_value = p_item->psz_value ?
481 p_item->psz_value : "";
483 if ( p_item->psz_longtext != NULL )
484 psz_duptip = strdup( p_item->psz_longtext );
487 s_rc.size.width = - 10;
488 s_rc.size.height = 25;
490 CONTROL_LABEL( p_item->psz_text );
491 s_rc.origin.x = X_ORIGIN;
492 s_rc.origin.y += s_rc.size.height;
495 VLCButton *button = [[VLCButton alloc] initWithFrame: s_rc];
496 CONTROL_CONFIG( button, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
497 [button setButtonType: NSMomentaryPushInButton];
498 [button setBezelStyle: NSRoundedBezelStyle];
499 [button setTitle: _NS("Browse...")];
501 [button setAutoresizingMask:NSViewMinXMargin];
502 [button setFrameOrigin: NSMakePoint( s_vrc.size.width - ( 10 + [button frame].size.width), s_rc.origin.y)];
504 [button setTarget: self];
505 [button setAction: @selector(openFileDialog:)];
507 s_rc.size.height = 25;
508 s_rc.size.width = s_vrc.size.width - ( 35 + [button frame].size.width);
510 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
511 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
513 [o_text_field setStringValue: [NSApp localizedString: psz_value]];
514 if ( psz_duptip != NULL )
516 [o_text_field setToolTip: [NSApp wrapString: [NSApp localizedString:
517 psz_duptip] toWidth: PREFS_WRAP ]];
521 [[NSNotificationCenter defaultCenter] addObserver: self
522 selector: @selector(configChanged:)
523 name: NSControlTextDidChangeNotification
524 object: o_text_field];
525 [o_text_field setAutoresizingMask:NSViewWidthSizable];
526 [button setTag: (int) o_text_field ]; /* FIXME */
528 [o_view addSubview: [o_text_field autorelease]];
529 [o_view addSubview: [button autorelease]];
530 s_rc.origin.y += s_rc.size.height;
531 s_rc.origin.x = X_ORIGIN;
535 case CONFIG_ITEM_STRING:
537 if( !p_item->ppsz_list )
539 char *psz_value = p_item->psz_value ?
540 p_item->psz_value : "";
542 INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
543 [NSApp localizedString: psz_value],
544 p_item->psz_longtext );
549 VLCComboBox *o_combo_box;
550 char * psz_duptip = NULL;
551 if ( p_item->psz_longtext != NULL )
552 psz_duptip = strdup( p_item->psz_longtext );
554 s_rc.size.height = 25;
555 s_rc.size.width = 200;
560 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
561 CONTROL_CONFIG( o_combo_box, o_module_name,
562 CONFIG_ITEM_STRING, p_item->psz_name );
563 [o_combo_box setTarget: self];
564 [o_combo_box setAction: @selector(configChanged:)];
565 [o_combo_box sendActionOn:NSLeftMouseUpMask];
566 [[NSNotificationCenter defaultCenter] addObserver: self
567 selector: @selector(configChanged:)
568 name: NSControlTextDidChangeNotification
569 object: o_combo_box];
571 if ( psz_duptip != NULL )
573 [o_combo_box setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
576 [o_view addSubview: [o_combo_box autorelease]];
578 for( i=0; p_item->ppsz_list[i]; i++ )
580 [o_combo_box addItemWithObjectValue:
581 [NSApp localizedString: p_item->ppsz_list[i]]];
583 [o_combo_box setStringValue: [NSApp localizedString:
584 p_item->psz_value ? p_item->psz_value : ""]];
586 CONTROL_LABEL( p_item->psz_text );
588 s_rc.origin.y += s_rc.size.height;
589 s_rc.origin.x = X_ORIGIN;
595 case CONFIG_ITEM_INTEGER:
597 if( p_item->i_min == p_item->i_max )
599 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
600 p_item->i_value, p_item->psz_longtext );
606 char * psz_duptip = NULL;
607 if ( p_item->psz_longtext != NULL )
608 psz_duptip = strdup( p_item->psz_longtext );
610 s_rc.size.height = 27;
611 s_rc.size.width = 200;
616 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
617 [o_slider setMinValue: p_item->i_min];
618 [o_slider setMaxValue: p_item->i_max];
619 [o_slider setIntValue: p_item->i_value];
621 if ( psz_duptip != NULL )
623 [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
626 [o_slider setTarget: self];
627 [o_slider setAction: @selector(configChanged:)];
628 [o_slider sendActionOn:NSLeftMouseUpMask];
629 CONTROL_CONFIG( o_slider, o_module_name,
630 CONFIG_ITEM_INTEGER, p_item->psz_name );
631 [o_view addSubview: [o_slider autorelease]];
632 CONTROL_LABEL( p_item->psz_text );
634 s_rc.origin.y += s_rc.size.height;
635 s_rc.origin.x = X_ORIGIN;
640 case CONFIG_ITEM_FLOAT:
642 if( p_item->f_min == p_item->f_max )
644 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
645 p_item->f_value, p_item->psz_longtext );
649 /* create a slider */
651 char * psz_duptip = NULL;
652 if ( p_item->psz_longtext != NULL )
653 psz_duptip = strdup( p_item->psz_longtext );
655 s_rc.size.height = 27;
656 s_rc.size.width = 200;
661 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
662 [o_slider setMinValue: p_item->f_min];
663 [o_slider setMaxValue: p_item->f_max];
664 [o_slider setFloatValue: p_item->f_value];
666 if ( psz_duptip != NULL )
668 [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
671 [o_slider setTarget: self];
672 [o_slider setAction: @selector(configChanged:)];
673 [o_slider sendActionOn:NSLeftMouseUpMask];
674 CONTROL_CONFIG( o_slider, o_module_name,
675 CONFIG_ITEM_FLOAT, p_item->psz_name );
676 [o_view addSubview: [o_slider autorelease]];
677 CONTROL_LABEL( p_item->psz_text );
679 s_rc.origin.y += s_rc.size.height;
680 s_rc.origin.x = X_ORIGIN;
685 case CONFIG_ITEM_BOOL:
687 VLCButton *o_btn_bool;
688 char * psz_duptip = NULL;
690 if ( p_item->psz_longtext != NULL )
691 psz_duptip = strdup( p_item->psz_longtext );
693 s_rc.size.height = 27;
694 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
699 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
700 [o_btn_bool setButtonType: NSSwitchButton];
701 [o_btn_bool setIntValue: p_item->i_value];
702 [o_btn_bool setTitle: [NSApp localizedString: p_item->psz_text]];
703 if ( psz_duptip != NULL )
705 [o_btn_bool setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
708 [o_btn_bool setTarget: self];
709 [o_btn_bool setAction: @selector(configChanged:)];
710 CONTROL_CONFIG( o_btn_bool, o_module_name,
711 CONFIG_ITEM_BOOL, p_item->psz_name );
712 [o_view addSubview: [o_btn_bool autorelease]];
714 s_rc.origin.y += s_rc.size.height;
718 case CONFIG_ITEM_KEY:
721 char *psz_duptip = NULL;
722 VLCComboBox *o_combo_box;
724 if ( p_item->psz_longtext != NULL )
725 psz_duptip = strdup( p_item->psz_longtext );
728 s_rc.size.width = - 10;
729 s_rc.size.height = 20;
731 CONTROL_LABEL( p_item->psz_text );
732 s_rc.origin.x = X_ORIGIN;
733 s_rc.origin.y += s_rc.size.height;
734 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2;
736 VLCMatrix *o_matrix = [[VLCMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2];
737 NSArray *o_cells = [o_matrix cells];
738 for( i=0; i < [o_cells count]; i++ )
740 NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
741 [o_current_cell setButtonType: NSSwitchButton];
742 [o_current_cell setControlSize: NSSmallControlSize];
743 if( psz_duptip != NULL )
745 [o_matrix setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
750 [o_current_cell setTitle:_NS("Command")];
751 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
754 [o_current_cell setTitle:_NS("Control")];
755 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
758 [o_current_cell setTitle:_NS("Option/Alt")];
759 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
762 [o_current_cell setTitle:_NS("Shift")];
763 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
766 [o_current_cell setTarget: self];
767 [o_current_cell setAction: @selector(configChanged:)];
768 [o_current_cell sendActionOn:NSLeftMouseUpMask];
770 CONTROL_CONFIG( o_matrix, o_module_name,
771 CONFIG_ITEM_KEY, p_item->psz_name );
772 [o_matrix sizeToCells];
773 [o_view addSubview: [o_matrix autorelease]];
775 s_rc.origin.x += [o_matrix frame].size.width + 20;
776 s_rc.size.height = 25;
777 s_rc.size.width = 100;
781 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
782 CONTROL_CONFIG( o_combo_box, o_module_name,
783 CONFIG_ITEM_KEY, p_item->psz_name );
784 [o_combo_box setTarget: self];
785 [o_combo_box setAction: @selector(configChanged:)];
786 [o_combo_box sendActionOn:NSLeftMouseUpMask];
787 [[NSNotificationCenter defaultCenter] addObserver: self
788 selector: @selector(configChanged:)
789 name: NSControlTextDidChangeNotification
790 object: o_combo_box];
792 if ( psz_duptip != NULL )
794 [o_combo_box setToolTip: [NSApp wrapString: [NSApp localizedString: psz_duptip] toWidth: PREFS_WRAP]];
796 [o_view addSubview: [o_combo_box autorelease]];
798 for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
801 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
802 [o_combo_box addItemWithObjectValue: [NSApp localizedString:vlc_keys[i].psz_key_string]];
805 [o_combo_box setStringValue: [NSApp localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
807 s_rc.origin.y += s_rc.size.height;
808 s_rc.origin.x = X_ORIGIN;
809 if( psz_duptip ) free( psz_duptip );
815 #undef INPUT_FIELD_INTEGER
816 #undef INPUT_FIELD_FLOAT
817 #undef INPUT_FIELD_STRING
819 #undef CHECK_VIEW_HEIGHT
824 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
825 vlc_list_release( p_list );
827 [o_prefs_view setDocumentView: o_view];
828 [o_prefs_view setNeedsDisplay: TRUE];
834 @implementation VLCPrefs (NSTableDataSource)
836 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
837 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
840 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
841 return (item == nil) ? YES : ([item numberOfChildren] != -1);
844 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
845 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
848 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
849 return (item == nil) ? @"" : (id)[item getName];
854 @implementation VLCTreeItem
856 static VLCTreeItem *o_root_item = nil;
858 #define IsALeafNode ((id)-1)
860 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
866 o_name = [o_item_name copy];
868 o_parent = o_parent_item;
873 + (VLCTreeItem *)rootItem {
874 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
880 if (o_children != IsALeafNode) [o_children release];
885 /* Creates and returns the array of children
886 * Loads children incrementally */
887 - (NSArray *)children {
888 if (o_children == NULL) {
889 intf_thread_t *p_intf = [NSApp getIntf];
891 module_t *p_module = NULL;
892 module_config_t *p_item;
895 /* List the plugins */
896 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
897 if( !p_list ) return nil;
899 if( [[self getName] isEqualToString: @"main"] )
902 * Build a tree of the main options
904 for( i_index = 0; i_index < p_list->i_count; i_index++ )
906 p_module = (module_t *)p_list->p_values[i_index].p_object;
907 if( !strcmp( p_module->psz_object_name, "main" ) )
910 if( p_module == NULL )
912 msg_Err( p_intf, "Could not find the main module in our prefs" );
915 if( i_index < p_list->i_count )
917 /* We found the main module */
919 /* Enumerate config categories and store a reference so we can
920 * generate their config panel them when it is asked by the user. */
921 p_item = p_module->p_config;
922 o_children = [[NSMutableArray alloc] initWithCapacity:10];
926 NSString *o_child_name;
928 switch( p_item->i_type )
930 case CONFIG_HINT_CATEGORY:
931 o_child_name = [NSApp localizedString: p_item->psz_text];
932 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
933 ID: p_module->i_object_id parent:self]];
937 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
939 /* Add the plugins item */
940 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
945 o_children = IsALeafNode;
948 else if( [[self getName] isEqualToString: _NS("Modules")] )
950 /* Add the capabilities */
951 o_children = [[NSMutableArray alloc] initWithCapacity:10];
952 for( i_index = 0; i_index < p_list->i_count; i_index++ )
954 p_module = (module_t *)p_list->p_values[i_index].p_object;
956 /* Exclude the main module */
957 if( !strcmp( p_module->psz_object_name, "main" ) )
960 /* Exclude empty plugins */
961 p_item = p_module->p_config;
962 if( !p_item ) continue;
965 if( p_item->i_type & CONFIG_ITEM )
968 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
969 if( p_item->i_type == CONFIG_HINT_END ) continue;
971 /* Create the capability tree if it doesn't already exist */
972 NSString *o_capability;
973 o_capability = [NSApp localizedString: p_module->psz_capability];
974 if( !p_module->psz_capability || !*p_module->psz_capability )
976 /* Empty capability ? Let's look at the submodules */
977 module_t * p_submodule;
978 for( j = 0; j < p_module->i_children; j++ )
980 p_submodule = (module_t*)p_module->pp_children[ j ];
981 if( p_submodule->psz_capability && *p_submodule->psz_capability )
983 o_capability = [NSApp localizedString: p_submodule->psz_capability];
984 BOOL b_found = FALSE;
985 for( j = 0; j < (int)[o_children count]; j++ )
987 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
995 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1002 BOOL b_found = FALSE;
1003 for( j = 0; j < (int)[o_children count]; j++ )
1005 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1013 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1014 ID: 0 parent:self]];
1018 else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
1020 /* Now add the modules */
1021 o_children = [[NSMutableArray alloc] initWithCapacity:10];
1022 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1024 p_module = (module_t *)p_list->p_values[i_index].p_object;
1026 /* Exclude the main module */
1027 if( !strcmp( p_module->psz_object_name, "main" ) )
1030 /* Exclude empty plugins */
1031 p_item = p_module->p_config;
1032 if( !p_item ) continue;
1035 if( p_item->i_type & CONFIG_ITEM )
1038 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
1039 if( p_item->i_type == CONFIG_HINT_END ) continue;
1041 /* Check the capability */
1042 NSString *o_capability;
1043 o_capability = [NSApp localizedString: p_module->psz_capability];
1044 if( !p_module->psz_capability || !*p_module->psz_capability )
1046 /* Empty capability ? Let's look at the submodules */
1047 module_t * p_submodule;
1048 for( j = 0; j < p_module->i_children; j++ )
1050 p_submodule = (module_t*)p_module->pp_children[ j ];
1051 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1053 o_capability = [NSApp localizedString: p_submodule->psz_capability];
1054 if( [o_capability isEqualToString: [self getName]] )
1056 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1057 [NSApp localizedString: p_module->psz_object_name ]
1058 ID: p_module->i_object_id parent:self]];
1063 else if( [o_capability isEqualToString: [self getName]] )
1065 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1066 [NSApp localizedString: p_module->psz_object_name ]
1067 ID: p_module->i_object_id parent:self]];
1073 /* all the other stuff are leafs */
1074 o_children = IsALeafNode;
1085 - (NSString *)getName
1090 - (VLCTreeItem *)childAtIndex:(int)i_index {
1091 return [[self children] objectAtIndex:i_index];
1094 - (int)numberOfChildren {
1095 id i_tmp = [self children];
1096 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
1099 - (BOOL)hasPrefs:(NSString *)o_module_name
1101 intf_thread_t *p_intf = [NSApp getIntf];
1104 char *psz_module_name;
1107 psz_module_name = (char *)[o_module_name UTF8String];
1109 /* look for module */
1110 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1112 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1114 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1116 if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
1118 BOOL b_has_prefs = p_parser->i_config_items != 0;
1119 vlc_list_release( p_list );
1120 return( b_has_prefs );
1124 vlc_list_release( p_list );
1132 @implementation VLCFlippedView
1141 IMPL_CONTROL_CONFIG(Button);
1142 IMPL_CONTROL_CONFIG(PopUpButton);
1143 IMPL_CONTROL_CONFIG(ComboBox);
1144 IMPL_CONTROL_CONFIG(TextField);
1145 IMPL_CONTROL_CONFIG(Slider);
1146 IMPL_CONTROL_CONFIG(Matrix);