1 /*****************************************************************************
2 * prefs.m: MacOS X module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2004 VideoLAN
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videolan dot org>
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
41 static VLCPrefs *_o_sharedMainInstance = nil;
43 + (VLCPrefs *)sharedInstance
45 return _o_sharedMainInstance ? _o_sharedMainInstance : [[self alloc] init];
50 if( _o_sharedMainInstance) {
53 _o_sharedMainInstance = [super init];
56 return _o_sharedMainInstance;
62 [NSBundle loadNibNamed:@"Preferences" owner:self];
64 /* from "init" > r8571 */
65 o_empty_view = [[NSView alloc] init];
66 o_save_prefs = [[NSMutableDictionary alloc] init];
68 /* from "awakeFromNib" > r8571 */
70 b_advanced = config_GetInt( p_intf, "advanced" );
73 [o_advanced_ckb setState: b_advanced];
74 [o_prefs_view setBorderType: NSGrooveBorder];
75 [o_prefs_view setHasVerticalScroller: YES];
76 [o_prefs_view setDrawsBackground: NO];
77 [o_prefs_view setRulersVisible: NO];
78 [o_prefs_view setDocumentView: o_empty_view];
79 [o_tree selectRow:0 byExtendingSelection:NO];
80 /* end of the previous "awakeFromNib" method */
82 [o_save_prefs release];
83 o_save_prefs = [[NSMutableDictionary alloc] init];
84 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
85 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
86 [o_prefs_window center];
87 [o_prefs_window makeKeyAndOrderFront:self];
92 [o_prefs_window setTitle: _NS("Preferences")];
93 [o_save_btn setTitle: _NS("Save")];
94 [o_cancel_btn setTitle: _NS("Cancel")];
95 [o_reset_btn setTitle: _NS("Reset All")];
96 [o_advanced_ckb setTitle: _NS("Advanced")];
99 - (IBAction)savePrefs: (id)sender
102 NSEnumerator *o_enum;
104 o_enum = [o_save_prefs objectEnumerator];
105 while( ( o_vlc_config = [o_enum nextObject] ) )
107 int i_type = [o_vlc_config configType];
108 NSString *o_name = [o_vlc_config configName];
109 char *psz_name = (char *)[o_name UTF8String];
114 case CONFIG_ITEM_MODULE:
117 module_t *p_a_module;
118 int i_id = [[o_vlc_config selectedItem] tag];
120 p_a_module = (module_t *)vlc_object_get( p_intf, i_id );
121 if( p_a_module == NULL || p_a_module->i_object_type != VLC_OBJECT_MODULE )
126 psz_value = ( i_id == -1 ) ? "" : p_a_module->psz_object_name ;
127 config_PutPsz( p_intf, psz_name, strdup(psz_value) );
131 case CONFIG_ITEM_STRING:
134 NSString *o_value = [o_vlc_config stringValue];
135 psz_value = (char *)[o_value UTF8String];
137 config_PutPsz( p_intf, psz_name, psz_value );
141 case CONFIG_ITEM_FILE:
142 case CONFIG_ITEM_DIRECTORY:
145 NSString *o_value = [o_vlc_config stringValue];
146 psz_value = (char *)[o_value fileSystemRepresentation];
148 config_PutPsz( p_intf, psz_name, psz_value );
152 case CONFIG_ITEM_INTEGER:
153 case CONFIG_ITEM_BOOL:
155 int i_value = [o_vlc_config intValue];
157 config_PutInt( p_intf, psz_name, i_value );
161 case CONFIG_ITEM_FLOAT:
163 float f_value = [o_vlc_config floatValue];
165 config_PutFloat( p_intf, psz_name, f_value );
169 case CONFIG_ITEM_KEY:
171 unsigned int i_key = config_GetInt( p_intf, psz_name );
172 unsigned int i_new_key = 0;
174 if( [o_vlc_config class] == [VLCMatrix class] )
177 NSButtonCell *o_current_cell;
178 NSArray *o_cells = [o_vlc_config cells];
179 i_new_key = (i_key & ~KEY_MODIFIER);
180 for( i = 0; i < [o_cells count]; i++ )
182 o_current_cell = [o_cells objectAtIndex:i];
183 if( [[o_current_cell title] isEqualToString:_NS("Command")] &&
184 [o_current_cell state] == NSOnState )
185 i_new_key |= KEY_MODIFIER_COMMAND;
186 if( [[o_current_cell title] isEqualToString:_NS("Control")] &&
187 [o_current_cell state] == NSOnState )
188 i_new_key |= KEY_MODIFIER_CTRL;
189 if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] &&
190 [o_current_cell state] == NSOnState )
191 i_new_key |= KEY_MODIFIER_ALT;
192 if( [[o_current_cell title] isEqualToString:_NS("Shift")] &&
193 [o_current_cell state] == NSOnState )
194 i_new_key |= KEY_MODIFIER_SHIFT;
199 i_new_key = (i_key & KEY_MODIFIER);
200 i_new_key |= StringToKey([[o_vlc_config stringValue] cString]);
202 config_PutInt( p_intf, psz_name, i_new_key );
207 config_SaveConfigFile( p_intf, NULL );
208 [o_prefs_window orderOut:self];
211 - (IBAction)closePrefs: (id)sender
213 [o_prefs_window orderOut:self];
216 - (IBAction)resetAll: (id)sender
218 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
219 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
220 _NS("Beware this will reset your VLC media player preferences.\n"
221 "Are you sure you want to continue?") );
224 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
226 if( i_return == NSAlertAlternateReturn )
228 config_ResetAll( p_intf );
229 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
230 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
234 - (IBAction)advancedToggle: (id)sender
236 b_advanced = !b_advanced;
237 [o_advanced_ckb setState: b_advanced];
238 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
239 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
242 - (IBAction)openFileDialog: (id)sender
244 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
246 [o_open_panel setTitle: _NS("Select file or directory")];
247 [o_open_panel setPrompt: _NS("Select")];
248 [o_open_panel setAllowsMultipleSelection: NO];
249 [o_open_panel setCanChooseFiles: YES];
250 [o_open_panel setCanChooseDirectories: YES];
251 [o_open_panel beginSheetForDirectory:nil
254 modalForWindow:[sender window]
256 didEndSelector: @selector(pathChosenInPanel:
259 contextInfo: sender];
262 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info
264 if( i_return_code == NSOKButton )
266 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
267 VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */
268 [o_field setStringValue: o_path];
269 [self configChanged: o_field];
273 - (void)loadConfigTree
278 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
282 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
284 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
285 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
288 - (void)configChanged:(id)o_unknown
290 id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
291 [o_unknown object] : o_unknown;
293 NSString *o_name = [o_vlc_config configName];
294 [o_save_prefs setObject: o_vlc_config forKey: o_name];
297 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
301 module_config_t *p_item;
303 int i_pos, i_module_tag, i_index;
305 NSString *o_module_name;
306 NSRect s_rc; /* rect */
307 NSView *o_view; /* view */
308 NSRect s_vrc; /* view rect */
309 VLCTextField *o_text_field; /* input field / label */
311 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
313 /* Get a pointer to the module */
314 p_parser = (module_t *)vlc_object_get( p_intf, i_id );
315 if( p_parser->i_object_type != VLC_OBJECT_MODULE )
317 /* 0OOoo something went really bad */
318 vlc_list_release( p_list );
322 /* Enumerate config options and add corresponding config boxes */
323 o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
324 p_item = p_parser->p_config;
331 #define Y_ORIGIN (X_ORIGIN - 10)
333 #define CHECK_VIEW_HEIGHT \
335 float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
336 if( f_new_pos > s_vrc.size.height ) \
338 s_vrc.size.height = f_new_pos; \
339 [o_view setFrame: s_vrc]; \
343 #define CONTROL_LABEL( label ) \
345 s_rc.origin.x += s_rc.size.width + 10; \
346 s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
347 o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
348 [o_text_field setDrawsBackground: NO]; \
349 [o_text_field setBordered: NO]; \
350 [o_text_field setEditable: NO]; \
351 [o_text_field setSelectable: NO]; \
354 [o_text_field setStringValue: \
355 [[VLCMain sharedInstance] localizedString: label]]; \
357 [o_text_field sizeToFit]; \
358 [o_view addSubview: [o_text_field autorelease]]; \
361 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
363 char * psz_duptip = NULL; \
364 if ( p_item->psz_longtext != NULL ) \
365 psz_duptip = strdup( p_item->psz_longtext ); \
366 s_rc.size.height = 25; \
367 s_rc.size.width = w; \
368 s_rc.origin.y += 10; \
370 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
371 [o_text_field setAlignment: NSRightTextAlignment]; \
372 CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
373 [o_text_field msg: param]; \
374 if ( psz_duptip != NULL ) \
376 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: \
377 psz_duptip] toWidth: PREFS_WRAP ]]; \
380 [o_view addSubview: [o_text_field autorelease]]; \
381 [[NSNotificationCenter defaultCenter] addObserver: self \
382 selector: @selector(configChanged:) \
383 name: NSControlTextDidChangeNotification \
384 object: o_text_field]; \
385 CONTROL_LABEL( label ); \
386 s_rc.origin.y += s_rc.size.height; \
387 s_rc.origin.x = X_ORIGIN; \
390 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
391 INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
392 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
393 INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
394 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
395 INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
398 s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
399 o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
400 [o_view setAutoresizingMask: NSViewWidthSizable];
401 s_rc.origin.x = X_ORIGIN;
402 s_rc.origin.y = Y_ORIGIN;
403 BOOL b_right_cat = TRUE;
407 if( p_item->i_type == CONFIG_HINT_CATEGORY )
409 if( !strcmp( p_parser->psz_object_name, "main" ) &&
410 [o_item_name isEqualToString: [[VLCMain sharedInstance] localizedString: p_item->psz_text]] )
413 } else if( strcmp( p_parser->psz_object_name, "main" ) )
416 } else b_right_cat = FALSE;
417 } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
422 if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
426 switch( p_item->i_type )
428 case CONFIG_ITEM_MODULE:
430 VLCPopUpButton *o_modules;
431 module_t *p_a_module;
432 char * psz_duptip = NULL;
434 if ( p_item->psz_longtext != NULL )
435 psz_duptip = strdup( p_item->psz_longtext );
437 s_rc.size.height = 25;
438 s_rc.size.width = 200;
443 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
444 CONTROL_CONFIG( o_modules, o_module_name,
445 CONFIG_ITEM_MODULE, p_item->psz_name );
446 [o_modules setTarget: self];
447 [o_modules setAction: @selector(configChanged:)];
448 [o_modules sendActionOn:NSLeftMouseUpMask];
450 if ( psz_duptip != NULL )
452 [o_modules setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
455 [o_view addSubview: [o_modules autorelease]];
457 [o_modules addItemWithTitle: _NS("Default")];
458 [[o_modules lastItem] setTag: -1];
459 [o_modules selectItem: [o_modules lastItem]];
461 /* build a list of available modules */
463 for( i_index = 0; i_index < p_list->i_count; i_index++ )
465 p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
467 if( !strcmp( p_a_module->psz_capability,
470 NSString *o_description = [[VLCMain sharedInstance]
471 localizedString: p_a_module->psz_longname];
472 [o_modules addItemWithTitle: o_description];
473 [[o_modules lastItem] setTag: p_a_module->i_object_id];
475 if( p_item->psz_value &&
476 !strcmp( p_item->psz_value, p_a_module->psz_object_name ) )
478 [o_modules selectItem:[o_modules lastItem]];
484 CONTROL_LABEL( p_item->psz_text );
485 s_rc.origin.y += s_rc.size.height;
486 s_rc.origin.x = X_ORIGIN;
490 case CONFIG_ITEM_FILE:
491 case CONFIG_ITEM_DIRECTORY:
493 char *psz_duptip = NULL;
494 char *psz_value = p_item->psz_value ?
495 p_item->psz_value : "";
497 if ( p_item->psz_longtext != NULL )
498 psz_duptip = strdup( p_item->psz_longtext );
501 s_rc.size.width = - 10;
502 s_rc.size.height = 25;
504 CONTROL_LABEL( p_item->psz_text );
505 s_rc.origin.x = X_ORIGIN;
506 s_rc.origin.y += s_rc.size.height;
509 VLCButton *button = [[VLCButton alloc] initWithFrame: s_rc];
510 CONTROL_CONFIG( button, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
511 [button setButtonType: NSMomentaryPushInButton];
512 [button setBezelStyle: NSRoundedBezelStyle];
513 [button setTitle: _NS("Browse...")];
515 [button setAutoresizingMask:NSViewMinXMargin];
516 [button setFrameOrigin: NSMakePoint( s_vrc.size.width - ( 10 + [button frame].size.width), s_rc.origin.y)];
518 [button setTarget: self];
519 [button setAction: @selector(openFileDialog:)];
521 s_rc.size.height = 25;
522 s_rc.size.width = s_vrc.size.width - ( 35 + [button frame].size.width);
524 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
525 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
527 [o_text_field setStringValue: [[VLCMain sharedInstance] localizedString: psz_value]];
528 if ( psz_duptip != NULL )
530 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString:
531 psz_duptip] toWidth: PREFS_WRAP ]];
535 [[NSNotificationCenter defaultCenter] addObserver: self
536 selector: @selector(configChanged:)
537 name: NSControlTextDidChangeNotification
538 object: o_text_field];
539 [o_text_field setAutoresizingMask:NSViewWidthSizable];
540 [button setTag: (int) o_text_field ]; /* FIXME */
542 [o_view addSubview: [o_text_field autorelease]];
543 [o_view addSubview: [button autorelease]];
544 s_rc.origin.y += s_rc.size.height;
545 s_rc.origin.x = X_ORIGIN;
549 case CONFIG_ITEM_STRING:
551 if( !p_item->ppsz_list )
553 char *psz_value = p_item->psz_value ?
554 p_item->psz_value : "";
556 INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
557 [[VLCMain sharedInstance] localizedString: psz_value],
558 p_item->psz_longtext );
563 VLCComboBox *o_combo_box;
564 char * psz_duptip = NULL;
565 if ( p_item->psz_longtext != NULL )
566 psz_duptip = strdup( p_item->psz_longtext );
568 s_rc.size.height = 25;
569 s_rc.size.width = 200;
574 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
575 CONTROL_CONFIG( o_combo_box, o_module_name,
576 CONFIG_ITEM_STRING, p_item->psz_name );
577 [o_combo_box setTarget: self];
578 [o_combo_box setAction: @selector(configChanged:)];
579 [o_combo_box sendActionOn:NSLeftMouseUpMask];
580 [[NSNotificationCenter defaultCenter] addObserver: self
581 selector: @selector(configChanged:)
582 name: NSControlTextDidChangeNotification
583 object: o_combo_box];
585 if ( psz_duptip != NULL )
587 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
590 [o_view addSubview: [o_combo_box autorelease]];
592 for( i=0; p_item->ppsz_list[i]; i++ )
594 [o_combo_box addItemWithObjectValue:
595 [[VLCMain sharedInstance] localizedString: p_item->ppsz_list[i]]];
597 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:
598 p_item->psz_value ? p_item->psz_value : ""]];
600 CONTROL_LABEL( p_item->psz_text );
602 s_rc.origin.y += s_rc.size.height;
603 s_rc.origin.x = X_ORIGIN;
609 case CONFIG_ITEM_INTEGER:
611 if( p_item->i_min == p_item->i_max )
613 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
614 p_item->i_value, p_item->psz_longtext );
620 char * psz_duptip = NULL;
621 if ( p_item->psz_longtext != NULL )
622 psz_duptip = strdup( p_item->psz_longtext );
624 s_rc.size.height = 27;
625 s_rc.size.width = 200;
630 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
631 [o_slider setMinValue: p_item->i_min];
632 [o_slider setMaxValue: p_item->i_max];
633 [o_slider setIntValue: p_item->i_value];
635 if ( psz_duptip != NULL )
637 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
640 [o_slider setTarget: self];
641 [o_slider setAction: @selector(configChanged:)];
642 [o_slider sendActionOn:NSLeftMouseUpMask];
643 CONTROL_CONFIG( o_slider, o_module_name,
644 CONFIG_ITEM_INTEGER, p_item->psz_name );
645 [o_view addSubview: [o_slider autorelease]];
646 CONTROL_LABEL( p_item->psz_text );
648 s_rc.origin.y += s_rc.size.height;
649 s_rc.origin.x = X_ORIGIN;
654 case CONFIG_ITEM_FLOAT:
656 if( p_item->f_min == p_item->f_max )
658 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
659 p_item->f_value, p_item->psz_longtext );
663 /* create a slider */
665 char * psz_duptip = NULL;
666 if ( p_item->psz_longtext != NULL )
667 psz_duptip = strdup( p_item->psz_longtext );
669 s_rc.size.height = 27;
670 s_rc.size.width = 200;
675 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
676 [o_slider setMinValue: p_item->f_min];
677 [o_slider setMaxValue: p_item->f_max];
678 [o_slider setFloatValue: p_item->f_value];
680 if ( psz_duptip != NULL )
682 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
685 [o_slider setTarget: self];
686 [o_slider setAction: @selector(configChanged:)];
687 [o_slider sendActionOn:NSLeftMouseUpMask];
688 CONTROL_CONFIG( o_slider, o_module_name,
689 CONFIG_ITEM_FLOAT, p_item->psz_name );
690 [o_view addSubview: [o_slider autorelease]];
691 CONTROL_LABEL( p_item->psz_text );
693 s_rc.origin.y += s_rc.size.height;
694 s_rc.origin.x = X_ORIGIN;
699 case CONFIG_ITEM_BOOL:
701 VLCButton *o_btn_bool;
702 char * psz_duptip = NULL;
704 if ( p_item->psz_longtext != NULL )
705 psz_duptip = strdup( p_item->psz_longtext );
707 s_rc.size.height = 27;
708 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
713 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
714 [o_btn_bool setButtonType: NSSwitchButton];
715 [o_btn_bool setIntValue: p_item->i_value];
716 [o_btn_bool setTitle: [[VLCMain sharedInstance] localizedString: p_item->psz_text]];
717 if ( psz_duptip != NULL )
719 [o_btn_bool setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
722 [o_btn_bool setTarget: self];
723 [o_btn_bool setAction: @selector(configChanged:)];
724 CONTROL_CONFIG( o_btn_bool, o_module_name,
725 CONFIG_ITEM_BOOL, p_item->psz_name );
726 [o_view addSubview: [o_btn_bool autorelease]];
728 s_rc.origin.y += s_rc.size.height;
732 case CONFIG_ITEM_KEY:
735 char *psz_duptip = NULL;
736 VLCComboBox *o_combo_box;
738 if ( p_item->psz_longtext != NULL )
739 psz_duptip = strdup( p_item->psz_longtext );
742 s_rc.size.width = - 10;
743 s_rc.size.height = 20;
745 CONTROL_LABEL( p_item->psz_text );
746 s_rc.origin.x = X_ORIGIN;
747 s_rc.origin.y += s_rc.size.height;
748 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2;
750 VLCMatrix *o_matrix = [[VLCMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2];
751 NSArray *o_cells = [o_matrix cells];
752 for( i=0; i < [o_cells count]; i++ )
754 NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
755 [o_current_cell setButtonType: NSSwitchButton];
756 [o_current_cell setControlSize: NSSmallControlSize];
757 if( psz_duptip != NULL )
759 [o_matrix setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
764 [o_current_cell setTitle:_NS("Command")];
765 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
768 [o_current_cell setTitle:_NS("Control")];
769 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
772 [o_current_cell setTitle:_NS("Option/Alt")];
773 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
776 [o_current_cell setTitle:_NS("Shift")];
777 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
780 [o_current_cell setTarget: self];
781 [o_current_cell setAction: @selector(configChanged:)];
782 [o_current_cell sendActionOn:NSLeftMouseUpMask];
784 CONTROL_CONFIG( o_matrix, o_module_name,
785 CONFIG_ITEM_KEY, p_item->psz_name );
786 [o_matrix sizeToCells];
787 [o_view addSubview: [o_matrix autorelease]];
789 s_rc.origin.x += [o_matrix frame].size.width + 20;
790 s_rc.size.height = 25;
791 s_rc.size.width = 100;
795 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
796 CONTROL_CONFIG( o_combo_box, o_module_name,
797 CONFIG_ITEM_KEY, p_item->psz_name );
798 [o_combo_box setTarget: self];
799 [o_combo_box setAction: @selector(configChanged:)];
800 [o_combo_box sendActionOn:NSLeftMouseUpMask];
801 [[NSNotificationCenter defaultCenter] addObserver: self
802 selector: @selector(configChanged:)
803 name: NSControlTextDidChangeNotification
804 object: o_combo_box];
806 if ( psz_duptip != NULL )
808 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
810 [o_view addSubview: [o_combo_box autorelease]];
812 for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
815 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
816 [o_combo_box addItemWithObjectValue: [[VLCMain sharedInstance] localizedString:vlc_keys[i].psz_key_string]];
819 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
821 s_rc.origin.y += s_rc.size.height;
822 s_rc.origin.x = X_ORIGIN;
823 if( psz_duptip ) free( psz_duptip );
829 #undef INPUT_FIELD_INTEGER
830 #undef INPUT_FIELD_FLOAT
831 #undef INPUT_FIELD_STRING
833 #undef CHECK_VIEW_HEIGHT
838 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
839 vlc_object_release( p_parser );
840 vlc_list_release( p_list );
842 [o_prefs_view setDocumentView: o_view];
843 [o_prefs_view setNeedsDisplay: TRUE];
849 @implementation VLCPrefs (NSTableDataSource)
851 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
852 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
855 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
856 return (item == nil) ? YES : ([item numberOfChildren] != -1);
859 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
860 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
863 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
864 return (item == nil) ? @"" : (id)[item getName];
869 @implementation VLCTreeItem
871 static VLCTreeItem *o_root_item = nil;
873 #define IsALeafNode ((id)-1)
875 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
881 o_name = [o_item_name copy];
883 o_parent = o_parent_item;
888 + (VLCTreeItem *)rootItem {
889 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
895 if (o_children != IsALeafNode) [o_children release];
900 /* Creates and returns the array of children
901 * Loads children incrementally */
902 - (NSArray *)children {
903 if (o_children == NULL) {
904 intf_thread_t *p_intf = VLCIntf;
906 module_t *p_module = NULL;
907 module_config_t *p_item;
910 /* List the modules */
911 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
912 if( !p_list ) return nil;
914 if( [[self getName] isEqualToString: @"main"] )
917 * Build a tree of the main options
919 for( i_index = 0; i_index < p_list->i_count; i_index++ )
921 p_module = (module_t *)p_list->p_values[i_index].p_object;
922 if( !strcmp( p_module->psz_object_name, "main" ) )
925 if( p_module == NULL )
927 msg_Err( p_intf, "could not find the main module in our preferences" );
930 if( i_index < p_list->i_count )
932 /* We found the main module */
934 /* Enumerate config categories and store a reference so we can
935 * generate their config panel them when it is asked by the user. */
936 p_item = p_module->p_config;
937 o_children = [[NSMutableArray alloc] initWithCapacity:10];
941 NSString *o_child_name;
943 switch( p_item->i_type )
945 case CONFIG_HINT_CATEGORY:
946 o_child_name = [[VLCMain sharedInstance] localizedString: p_item->psz_text];
947 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
948 ID: p_module->i_object_id parent:self]];
952 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
954 /* Add the modules item */
955 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
960 o_children = IsALeafNode;
963 else if( [[self getName] isEqualToString: _NS("Modules")] )
965 /* Add the capabilities */
966 o_children = [[NSMutableArray alloc] initWithCapacity:10];
967 for( i_index = 0; i_index < p_list->i_count; i_index++ )
969 p_module = (module_t *)p_list->p_values[i_index].p_object;
971 /* Exclude the main module */
972 if( !strcmp( p_module->psz_object_name, "main" ) )
975 /* Exclude empty modules */
976 p_item = p_module->p_config;
977 if( !p_item ) continue;
980 if( p_item->i_type & CONFIG_ITEM )
983 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
984 if( p_item->i_type == CONFIG_HINT_END ) continue;
986 /* Create the capability tree if it doesn't already exist */
987 NSString *o_capability;
988 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
989 if( !p_module->psz_capability || !*p_module->psz_capability )
991 /* Empty capability ? Let's look at the submodules */
992 module_t * p_submodule;
993 for( j = 0; j < p_module->i_children; j++ )
995 p_submodule = (module_t*)p_module->pp_children[ j ];
996 if( p_submodule->psz_capability && *p_submodule->psz_capability )
998 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
999 BOOL b_found = FALSE;
1000 for( j = 0; j < (int)[o_children count]; j++ )
1002 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1010 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1011 ID: 0 parent:self]];
1017 BOOL b_found = FALSE;
1018 for( j = 0; j < (int)[o_children count]; j++ )
1020 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1028 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1029 ID: 0 parent:self]];
1033 else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
1035 /* Now add the modules */
1036 o_children = [[NSMutableArray alloc] initWithCapacity:10];
1037 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1039 p_module = (module_t *)p_list->p_values[i_index].p_object;
1041 /* Exclude the main module */
1042 if( !strcmp( p_module->psz_object_name, "main" ) )
1045 /* Exclude empty modules */
1046 p_item = p_module->p_config;
1047 if( !p_item ) continue;
1050 if( p_item->i_type & CONFIG_ITEM )
1053 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
1054 if( p_item->i_type == CONFIG_HINT_END ) continue;
1056 /* Check the capability */
1057 NSString *o_capability;
1058 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
1059 if( !p_module->psz_capability || !*p_module->psz_capability )
1061 /* Empty capability ? Let's look at the submodules */
1062 module_t * p_submodule;
1063 for( j = 0; j < p_module->i_children; j++ )
1065 p_submodule = (module_t*)p_module->pp_children[ j ];
1066 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1068 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
1069 if( [o_capability isEqualToString: [self getName]] )
1071 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1072 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1073 ID: p_module->i_object_id parent:self]];
1078 else if( [o_capability isEqualToString: [self getName]] )
1080 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1081 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1082 ID: p_module->i_object_id parent:self]];
1088 /* all the other stuff are leafs */
1089 o_children = IsALeafNode;
1091 vlc_list_release( p_list );
1101 - (NSString *)getName
1106 - (VLCTreeItem *)childAtIndex:(int)i_index {
1107 return [[self children] objectAtIndex:i_index];
1110 - (int)numberOfChildren {
1111 id i_tmp = [self children];
1112 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
1115 - (BOOL)hasPrefs:(NSString *)o_module_name
1117 intf_thread_t *p_intf = VLCIntf;
1120 char *psz_module_name;
1123 psz_module_name = (char *)[o_module_name UTF8String];
1125 /* look for module */
1126 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1128 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1130 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1132 if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
1134 BOOL b_has_prefs = p_parser->i_config_items != 0;
1135 vlc_list_release( p_list );
1136 return( b_has_prefs );
1140 vlc_list_release( p_list );
1148 @implementation VLCFlippedView
1157 IMPL_CONTROL_CONFIG(Button);
1158 IMPL_CONTROL_CONFIG(PopUpButton);
1159 IMPL_CONTROL_CONFIG(ComboBox);
1160 IMPL_CONTROL_CONFIG(TextField);
1161 IMPL_CONTROL_CONFIG(Slider);
1162 IMPL_CONTROL_CONFIG(Matrix);