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;
61 [o_empty_view release];
62 [o_save_prefs release];
69 [NSBundle loadNibNamed:@"Preferences" owner:self];
71 /* from "init" =< r8571 */
72 o_empty_view = [[NSView alloc] init];
73 o_save_prefs = [[NSMutableDictionary alloc] init];
75 /* from "awakeFromNib" =< r8571 */
77 b_advanced = config_GetInt( p_intf, "advanced" );
80 [o_advanced_ckb setState: b_advanced];
81 [o_prefs_view setBorderType: NSGrooveBorder];
82 [o_prefs_view setHasVerticalScroller: YES];
83 [o_prefs_view setDrawsBackground: NO];
84 [o_prefs_view setRulersVisible: NO];
85 [o_prefs_view setDocumentView: o_empty_view];
86 [o_tree selectRow:0 byExtendingSelection:NO];
87 /* end of the previous "awakeFromNib" method */
89 [o_save_prefs release];
90 o_save_prefs = [[NSMutableDictionary alloc] init];
91 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
92 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
93 [o_prefs_window center];
94 [o_prefs_window makeKeyAndOrderFront:self];
99 [o_prefs_window setTitle: _NS("Preferences")];
100 [o_save_btn setTitle: _NS("Save")];
101 [o_cancel_btn setTitle: _NS("Cancel")];
102 [o_reset_btn setTitle: _NS("Reset All")];
103 [o_advanced_ckb setTitle: _NS("Advanced")];
106 - (IBAction)savePrefs: (id)sender
109 NSEnumerator *o_enum;
111 o_enum = [o_save_prefs objectEnumerator];
112 while( ( o_vlc_config = [o_enum nextObject] ) )
114 int i_type = [o_vlc_config configType];
115 NSString *o_name = [o_vlc_config configName];
116 char *psz_name = (char *)[o_name UTF8String];
121 case CONFIG_ITEM_MODULE:
124 module_t *p_a_module;
125 int i_id = [[o_vlc_config selectedItem] tag];
127 p_a_module = (module_t *)vlc_object_get( p_intf, i_id );
128 if( p_a_module == NULL || p_a_module->i_object_type != VLC_OBJECT_MODULE )
133 psz_value = ( i_id == -1 ) ? "" : p_a_module->psz_object_name ;
134 config_PutPsz( p_intf, psz_name, strdup(psz_value) );
138 case CONFIG_ITEM_STRING:
141 NSString *o_value = [o_vlc_config stringValue];
142 psz_value = (char *)[o_value UTF8String];
144 config_PutPsz( p_intf, psz_name, psz_value );
148 case CONFIG_ITEM_FILE:
149 case CONFIG_ITEM_DIRECTORY:
152 NSString *o_value = [o_vlc_config stringValue];
153 psz_value = (char *)[o_value fileSystemRepresentation];
155 config_PutPsz( p_intf, psz_name, psz_value );
159 case CONFIG_ITEM_INTEGER:
160 case CONFIG_ITEM_BOOL:
162 int i_value = [o_vlc_config intValue];
164 config_PutInt( p_intf, psz_name, i_value );
168 case CONFIG_ITEM_FLOAT:
170 float f_value = [o_vlc_config floatValue];
172 config_PutFloat( p_intf, psz_name, f_value );
176 case CONFIG_ITEM_KEY:
178 unsigned int i_key = config_GetInt( p_intf, psz_name );
179 unsigned int i_new_key = 0;
181 if( [o_vlc_config class] == [VLCMatrix class] )
184 NSButtonCell *o_current_cell;
185 NSArray *o_cells = [o_vlc_config cells];
186 i_new_key = (i_key & ~KEY_MODIFIER);
187 for( i = 0; i < [o_cells count]; i++ )
189 o_current_cell = [o_cells objectAtIndex:i];
190 if( [[o_current_cell title] isEqualToString:_NS("Command")] &&
191 [o_current_cell state] == NSOnState )
192 i_new_key |= KEY_MODIFIER_COMMAND;
193 if( [[o_current_cell title] isEqualToString:_NS("Control")] &&
194 [o_current_cell state] == NSOnState )
195 i_new_key |= KEY_MODIFIER_CTRL;
196 if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] &&
197 [o_current_cell state] == NSOnState )
198 i_new_key |= KEY_MODIFIER_ALT;
199 if( [[o_current_cell title] isEqualToString:_NS("Shift")] &&
200 [o_current_cell state] == NSOnState )
201 i_new_key |= KEY_MODIFIER_SHIFT;
206 i_new_key = (i_key & KEY_MODIFIER);
207 i_new_key |= StringToKey([[o_vlc_config stringValue] cString]);
209 config_PutInt( p_intf, psz_name, i_new_key );
214 config_SaveConfigFile( p_intf, NULL );
215 [o_prefs_window orderOut:self];
218 - (IBAction)closePrefs: (id)sender
220 [o_prefs_window orderOut:self];
223 - (IBAction)resetAll: (id)sender
225 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
226 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
227 _NS("Beware this will reset your VLC media player preferences.\n"
228 "Are you sure you want to continue?") );
231 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
233 if( i_return == NSAlertAlternateReturn )
235 config_ResetAll( p_intf );
236 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
237 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
241 - (IBAction)advancedToggle: (id)sender
243 b_advanced = !b_advanced;
244 [o_advanced_ckb setState: b_advanced];
245 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
246 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
249 - (IBAction)openFileDialog: (id)sender
251 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
253 [o_open_panel setTitle: _NS("Select file or directory")];
254 [o_open_panel setPrompt: _NS("Select")];
255 [o_open_panel setAllowsMultipleSelection: NO];
256 [o_open_panel setCanChooseFiles: YES];
257 [o_open_panel setCanChooseDirectories: YES];
258 [o_open_panel beginSheetForDirectory:nil
261 modalForWindow:[sender window]
263 didEndSelector: @selector(pathChosenInPanel:
266 contextInfo: sender];
269 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info
271 if( i_return_code == NSOKButton )
273 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
274 VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */
275 [o_field setStringValue: o_path];
276 [self configChanged: o_field];
280 - (void)loadConfigTree
285 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
289 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
291 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
292 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
295 - (void)configChanged:(id)o_unknown
297 id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
298 [o_unknown object] : o_unknown;
300 NSString *o_name = [o_vlc_config configName];
301 [o_save_prefs setObject: o_vlc_config forKey: o_name];
304 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
308 module_config_t *p_item;
310 int i_pos, i_module_tag, i_index;
312 NSString *o_module_name;
313 NSRect s_rc; /* rect */
314 NSView *o_view; /* view */
315 NSRect s_vrc; /* view rect */
316 VLCTextField *o_text_field; /* input field / label */
318 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
320 /* Get a pointer to the module */
321 p_parser = (module_t *)vlc_object_get( p_intf, i_id );
322 if( p_parser->i_object_type != VLC_OBJECT_MODULE )
324 /* 0OOoo something went really bad */
325 vlc_list_release( p_list );
329 /* Enumerate config options and add corresponding config boxes */
330 o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
331 p_item = p_parser->p_config;
338 #define Y_ORIGIN (X_ORIGIN - 10)
340 #define CHECK_VIEW_HEIGHT \
342 float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
343 if( f_new_pos > s_vrc.size.height ) \
345 s_vrc.size.height = f_new_pos; \
346 [o_view setFrame: s_vrc]; \
350 #define CONTROL_LABEL( label ) \
352 s_rc.origin.x += s_rc.size.width + 10; \
353 s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
354 o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
355 [o_text_field setDrawsBackground: NO]; \
356 [o_text_field setBordered: NO]; \
357 [o_text_field setEditable: NO]; \
358 [o_text_field setSelectable: NO]; \
361 [o_text_field setStringValue: \
362 [[VLCMain sharedInstance] localizedString: label]]; \
364 [o_text_field sizeToFit]; \
365 [o_view addSubview: [o_text_field autorelease]]; \
368 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
370 char * psz_duptip = NULL; \
371 if ( p_item->psz_longtext != NULL ) \
372 psz_duptip = strdup( p_item->psz_longtext ); \
373 s_rc.size.height = 25; \
374 s_rc.size.width = w; \
375 s_rc.origin.y += 10; \
377 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
378 [o_text_field setAlignment: NSRightTextAlignment]; \
379 CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
380 [o_text_field msg: param]; \
381 if ( psz_duptip != NULL ) \
383 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: \
384 psz_duptip] toWidth: PREFS_WRAP ]]; \
387 [o_view addSubview: [o_text_field autorelease]]; \
388 [[NSNotificationCenter defaultCenter] addObserver: self \
389 selector: @selector(configChanged:) \
390 name: NSControlTextDidChangeNotification \
391 object: o_text_field]; \
392 CONTROL_LABEL( label ); \
393 s_rc.origin.y += s_rc.size.height; \
394 s_rc.origin.x = X_ORIGIN; \
397 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
398 INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
399 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
400 INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
401 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
402 INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
405 s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
406 o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
407 [o_view setAutoresizingMask: NSViewWidthSizable];
408 s_rc.origin.x = X_ORIGIN;
409 s_rc.origin.y = Y_ORIGIN;
410 BOOL b_right_cat = TRUE;
414 if( p_item->i_type == CONFIG_HINT_CATEGORY )
416 if( !strcmp( p_parser->psz_object_name, "main" ) &&
417 [o_item_name isEqualToString: [[VLCMain sharedInstance] localizedString: p_item->psz_text]] )
420 } else if( strcmp( p_parser->psz_object_name, "main" ) )
423 } else b_right_cat = FALSE;
424 } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
429 if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
433 switch( p_item->i_type )
435 case CONFIG_ITEM_MODULE:
437 VLCPopUpButton *o_modules;
438 module_t *p_a_module;
439 char * psz_duptip = NULL;
441 if ( p_item->psz_longtext != NULL )
442 psz_duptip = strdup( p_item->psz_longtext );
444 s_rc.size.height = 25;
445 s_rc.size.width = 200;
450 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
451 CONTROL_CONFIG( o_modules, o_module_name,
452 CONFIG_ITEM_MODULE, p_item->psz_name );
453 [o_modules setTarget: self];
454 [o_modules setAction: @selector(configChanged:)];
455 [o_modules sendActionOn:NSLeftMouseUpMask];
457 if ( psz_duptip != NULL )
459 [o_modules setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
462 [o_view addSubview: [o_modules autorelease]];
464 [o_modules addItemWithTitle: _NS("Default")];
465 [[o_modules lastItem] setTag: -1];
466 [o_modules selectItem: [o_modules lastItem]];
468 /* build a list of available modules */
470 for( i_index = 0; i_index < p_list->i_count; i_index++ )
472 p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
474 if( !strcmp( p_a_module->psz_capability,
477 NSString *o_description = [[VLCMain sharedInstance]
478 localizedString: p_a_module->psz_longname];
479 [o_modules addItemWithTitle: o_description];
480 [[o_modules lastItem] setTag: p_a_module->i_object_id];
482 if( p_item->psz_value &&
483 !strcmp( p_item->psz_value, p_a_module->psz_object_name ) )
485 [o_modules selectItem:[o_modules lastItem]];
491 CONTROL_LABEL( p_item->psz_text );
492 s_rc.origin.y += s_rc.size.height;
493 s_rc.origin.x = X_ORIGIN;
497 case CONFIG_ITEM_FILE:
498 case CONFIG_ITEM_DIRECTORY:
500 char *psz_duptip = NULL;
501 char *psz_value = p_item->psz_value ?
502 p_item->psz_value : "";
504 if ( p_item->psz_longtext != NULL )
505 psz_duptip = strdup( p_item->psz_longtext );
508 s_rc.size.width = - 10;
509 s_rc.size.height = 25;
511 CONTROL_LABEL( p_item->psz_text );
512 s_rc.origin.x = X_ORIGIN;
513 s_rc.origin.y += s_rc.size.height;
516 VLCButton *button = [[VLCButton alloc] initWithFrame: s_rc];
517 CONTROL_CONFIG( button, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
518 [button setButtonType: NSMomentaryPushInButton];
519 [button setBezelStyle: NSRoundedBezelStyle];
520 [button setTitle: _NS("Browse...")];
522 [button setAutoresizingMask:NSViewMinXMargin];
523 [button setFrameOrigin: NSMakePoint( s_vrc.size.width - ( 10 + [button frame].size.width), s_rc.origin.y)];
525 [button setTarget: self];
526 [button setAction: @selector(openFileDialog:)];
528 s_rc.size.height = 25;
529 s_rc.size.width = s_vrc.size.width - ( 35 + [button frame].size.width);
531 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
532 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
534 [o_text_field setStringValue: [[VLCMain sharedInstance] localizedString: psz_value]];
535 if ( psz_duptip != NULL )
537 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString:
538 psz_duptip] toWidth: PREFS_WRAP ]];
542 [[NSNotificationCenter defaultCenter] addObserver: self
543 selector: @selector(configChanged:)
544 name: NSControlTextDidChangeNotification
545 object: o_text_field];
546 [o_text_field setAutoresizingMask:NSViewWidthSizable];
547 [button setTag: (int) o_text_field ]; /* FIXME */
549 [o_view addSubview: [o_text_field autorelease]];
550 [o_view addSubview: [button autorelease]];
551 s_rc.origin.y += s_rc.size.height;
552 s_rc.origin.x = X_ORIGIN;
556 case CONFIG_ITEM_STRING:
558 if( !p_item->ppsz_list )
560 char *psz_value = p_item->psz_value ?
561 p_item->psz_value : "";
563 INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
564 [[VLCMain sharedInstance] localizedString: psz_value],
565 p_item->psz_longtext );
570 VLCComboBox *o_combo_box;
571 char * psz_duptip = NULL;
572 if ( p_item->psz_longtext != NULL )
573 psz_duptip = strdup( p_item->psz_longtext );
575 s_rc.size.height = 25;
576 s_rc.size.width = 200;
581 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
582 CONTROL_CONFIG( o_combo_box, o_module_name,
583 CONFIG_ITEM_STRING, p_item->psz_name );
584 [o_combo_box setTarget: self];
585 [o_combo_box setAction: @selector(configChanged:)];
586 [o_combo_box sendActionOn:NSLeftMouseUpMask];
587 [[NSNotificationCenter defaultCenter] addObserver: self
588 selector: @selector(configChanged:)
589 name: NSControlTextDidChangeNotification
590 object: o_combo_box];
592 if ( psz_duptip != NULL )
594 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
597 [o_view addSubview: [o_combo_box autorelease]];
599 for( i=0; p_item->ppsz_list[i]; i++ )
601 [o_combo_box addItemWithObjectValue:
602 [[VLCMain sharedInstance] localizedString: p_item->ppsz_list[i]]];
604 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:
605 p_item->psz_value ? p_item->psz_value : ""]];
607 CONTROL_LABEL( p_item->psz_text );
609 s_rc.origin.y += s_rc.size.height;
610 s_rc.origin.x = X_ORIGIN;
616 case CONFIG_ITEM_INTEGER:
618 if( p_item->i_min == p_item->i_max )
620 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
621 p_item->i_value, p_item->psz_longtext );
627 char * psz_duptip = NULL;
628 if ( p_item->psz_longtext != NULL )
629 psz_duptip = strdup( p_item->psz_longtext );
631 s_rc.size.height = 27;
632 s_rc.size.width = 200;
637 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
638 [o_slider setMinValue: p_item->i_min];
639 [o_slider setMaxValue: p_item->i_max];
640 [o_slider setIntValue: p_item->i_value];
642 if ( psz_duptip != NULL )
644 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
647 [o_slider setTarget: self];
648 [o_slider setAction: @selector(configChanged:)];
649 [o_slider sendActionOn:NSLeftMouseUpMask];
650 CONTROL_CONFIG( o_slider, o_module_name,
651 CONFIG_ITEM_INTEGER, p_item->psz_name );
652 [o_view addSubview: [o_slider autorelease]];
653 CONTROL_LABEL( p_item->psz_text );
655 s_rc.origin.y += s_rc.size.height;
656 s_rc.origin.x = X_ORIGIN;
661 case CONFIG_ITEM_FLOAT:
663 if( p_item->f_min == p_item->f_max )
665 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
666 p_item->f_value, p_item->psz_longtext );
670 /* create a slider */
672 char * psz_duptip = NULL;
673 if ( p_item->psz_longtext != NULL )
674 psz_duptip = strdup( p_item->psz_longtext );
676 s_rc.size.height = 27;
677 s_rc.size.width = 200;
682 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
683 [o_slider setMinValue: p_item->f_min];
684 [o_slider setMaxValue: p_item->f_max];
685 [o_slider setFloatValue: p_item->f_value];
687 if ( psz_duptip != NULL )
689 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
692 [o_slider setTarget: self];
693 [o_slider setAction: @selector(configChanged:)];
694 [o_slider sendActionOn:NSLeftMouseUpMask];
695 CONTROL_CONFIG( o_slider, o_module_name,
696 CONFIG_ITEM_FLOAT, p_item->psz_name );
697 [o_view addSubview: [o_slider autorelease]];
698 CONTROL_LABEL( p_item->psz_text );
700 s_rc.origin.y += s_rc.size.height;
701 s_rc.origin.x = X_ORIGIN;
706 case CONFIG_ITEM_BOOL:
708 VLCButton *o_btn_bool;
709 char * psz_duptip = NULL;
711 if ( p_item->psz_longtext != NULL )
712 psz_duptip = strdup( p_item->psz_longtext );
714 s_rc.size.height = 27;
715 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
720 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
721 [o_btn_bool setButtonType: NSSwitchButton];
722 [o_btn_bool setIntValue: p_item->i_value];
723 [o_btn_bool setTitle: [[VLCMain sharedInstance] localizedString: p_item->psz_text]];
724 if ( psz_duptip != NULL )
726 [o_btn_bool setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
729 [o_btn_bool setTarget: self];
730 [o_btn_bool setAction: @selector(configChanged:)];
731 CONTROL_CONFIG( o_btn_bool, o_module_name,
732 CONFIG_ITEM_BOOL, p_item->psz_name );
733 [o_view addSubview: [o_btn_bool autorelease]];
735 s_rc.origin.y += s_rc.size.height;
739 case CONFIG_ITEM_KEY:
742 char *psz_duptip = NULL;
743 VLCComboBox *o_combo_box;
745 if ( p_item->psz_longtext != NULL )
746 psz_duptip = strdup( p_item->psz_longtext );
749 s_rc.size.width = - 10;
750 s_rc.size.height = 20;
752 CONTROL_LABEL( p_item->psz_text );
753 s_rc.origin.x = X_ORIGIN;
754 s_rc.origin.y += s_rc.size.height;
755 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2;
757 VLCMatrix *o_matrix = [[VLCMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2];
758 NSArray *o_cells = [o_matrix cells];
759 for( i=0; i < [o_cells count]; i++ )
761 NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
762 [o_current_cell setButtonType: NSSwitchButton];
763 [o_current_cell setControlSize: NSSmallControlSize];
764 if( psz_duptip != NULL )
766 [o_matrix setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
771 [o_current_cell setTitle:_NS("Command")];
772 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
775 [o_current_cell setTitle:_NS("Control")];
776 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
779 [o_current_cell setTitle:_NS("Option/Alt")];
780 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
783 [o_current_cell setTitle:_NS("Shift")];
784 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
787 [o_current_cell setTarget: self];
788 [o_current_cell setAction: @selector(configChanged:)];
789 [o_current_cell sendActionOn:NSLeftMouseUpMask];
791 CONTROL_CONFIG( o_matrix, o_module_name,
792 CONFIG_ITEM_KEY, p_item->psz_name );
793 [o_matrix sizeToCells];
794 [o_view addSubview: [o_matrix autorelease]];
796 s_rc.origin.x += [o_matrix frame].size.width + 20;
797 s_rc.size.height = 25;
798 s_rc.size.width = 100;
802 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
803 CONTROL_CONFIG( o_combo_box, o_module_name,
804 CONFIG_ITEM_KEY, p_item->psz_name );
805 [o_combo_box setTarget: self];
806 [o_combo_box setAction: @selector(configChanged:)];
807 [o_combo_box sendActionOn:NSLeftMouseUpMask];
808 [[NSNotificationCenter defaultCenter] addObserver: self
809 selector: @selector(configChanged:)
810 name: NSControlTextDidChangeNotification
811 object: o_combo_box];
813 if ( psz_duptip != NULL )
815 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
817 [o_view addSubview: [o_combo_box autorelease]];
819 for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
822 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
823 [o_combo_box addItemWithObjectValue: [[VLCMain sharedInstance] localizedString:vlc_keys[i].psz_key_string]];
826 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
828 s_rc.origin.y += s_rc.size.height;
829 s_rc.origin.x = X_ORIGIN;
830 if( psz_duptip ) free( psz_duptip );
836 #undef INPUT_FIELD_INTEGER
837 #undef INPUT_FIELD_FLOAT
838 #undef INPUT_FIELD_STRING
840 #undef CHECK_VIEW_HEIGHT
845 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
846 vlc_object_release( p_parser );
847 vlc_list_release( p_list );
849 [o_prefs_view setDocumentView: o_view];
850 [o_prefs_view setNeedsDisplay: TRUE];
856 @implementation VLCPrefs (NSTableDataSource)
858 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
859 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
862 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
863 return (item == nil) ? YES : ([item numberOfChildren] != -1);
866 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
867 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
870 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
871 return (item == nil) ? @"" : (id)[item getName];
876 @implementation VLCTreeItem
878 static VLCTreeItem *o_root_item = nil;
880 #define IsALeafNode ((id)-1)
882 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
888 o_name = [o_item_name copy];
890 o_parent = o_parent_item;
895 + (VLCTreeItem *)rootItem {
896 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
902 if (o_children != IsALeafNode) [o_children release];
907 /* Creates and returns the array of children
908 * Loads children incrementally */
909 - (NSArray *)children {
910 if (o_children == NULL) {
911 intf_thread_t *p_intf = VLCIntf;
913 module_t *p_module = NULL;
914 module_config_t *p_item;
917 /* List the modules */
918 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
919 if( !p_list ) return nil;
921 if( [[self getName] isEqualToString: @"main"] )
924 * Build a tree of the main options
926 for( i_index = 0; i_index < p_list->i_count; i_index++ )
928 p_module = (module_t *)p_list->p_values[i_index].p_object;
929 if( !strcmp( p_module->psz_object_name, "main" ) )
932 if( p_module == NULL )
934 msg_Err( p_intf, "could not find the main module in our preferences" );
937 if( i_index < p_list->i_count )
939 /* We found the main module */
941 /* Enumerate config categories and store a reference so we can
942 * generate their config panel them when it is asked by the user. */
943 p_item = p_module->p_config;
944 o_children = [[NSMutableArray alloc] initWithCapacity:10];
948 NSString *o_child_name;
950 switch( p_item->i_type )
952 case CONFIG_HINT_CATEGORY:
953 o_child_name = [[VLCMain sharedInstance] localizedString: p_item->psz_text];
954 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
955 ID: p_module->i_object_id parent:self]];
959 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
961 /* Add the modules item */
962 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
967 o_children = IsALeafNode;
970 else if( [[self getName] isEqualToString: _NS("Modules")] )
972 /* Add the capabilities */
973 o_children = [[NSMutableArray alloc] initWithCapacity:10];
974 for( i_index = 0; i_index < p_list->i_count; i_index++ )
976 p_module = (module_t *)p_list->p_values[i_index].p_object;
978 /* Exclude the main module */
979 if( !strcmp( p_module->psz_object_name, "main" ) )
982 /* Exclude empty modules */
983 p_item = p_module->p_config;
984 if( !p_item ) continue;
987 if( p_item->i_type & CONFIG_ITEM )
990 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
991 if( p_item->i_type == CONFIG_HINT_END ) continue;
993 /* Create the capability tree if it doesn't already exist */
994 NSString *o_capability;
995 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
996 if( !p_module->psz_capability || !*p_module->psz_capability )
998 /* Empty capability ? Let's look at the submodules */
999 module_t * p_submodule;
1000 for( j = 0; j < p_module->i_children; j++ )
1002 p_submodule = (module_t*)p_module->pp_children[ j ];
1003 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1005 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
1006 BOOL b_found = FALSE;
1007 for( j = 0; j < (int)[o_children count]; j++ )
1009 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1017 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1018 ID: 0 parent:self]];
1024 BOOL b_found = FALSE;
1025 for( j = 0; j < (int)[o_children count]; j++ )
1027 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1035 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1036 ID: 0 parent:self]];
1040 else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
1042 /* Now add the modules */
1043 o_children = [[NSMutableArray alloc] initWithCapacity:10];
1044 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1046 p_module = (module_t *)p_list->p_values[i_index].p_object;
1048 /* Exclude the main module */
1049 if( !strcmp( p_module->psz_object_name, "main" ) )
1052 /* Exclude empty modules */
1053 p_item = p_module->p_config;
1054 if( !p_item ) continue;
1057 if( p_item->i_type & CONFIG_ITEM )
1060 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
1061 if( p_item->i_type == CONFIG_HINT_END ) continue;
1063 /* Check the capability */
1064 NSString *o_capability;
1065 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
1066 if( !p_module->psz_capability || !*p_module->psz_capability )
1068 /* Empty capability ? Let's look at the submodules */
1069 module_t * p_submodule;
1070 for( j = 0; j < p_module->i_children; j++ )
1072 p_submodule = (module_t*)p_module->pp_children[ j ];
1073 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1075 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
1076 if( [o_capability isEqualToString: [self getName]] )
1078 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1079 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1080 ID: p_module->i_object_id parent:self]];
1085 else if( [o_capability isEqualToString: [self getName]] )
1087 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1088 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1089 ID: p_module->i_object_id parent:self]];
1095 /* all the other stuff are leafs */
1096 o_children = IsALeafNode;
1098 vlc_list_release( p_list );
1108 - (NSString *)getName
1113 - (VLCTreeItem *)childAtIndex:(int)i_index {
1114 return [[self children] objectAtIndex:i_index];
1117 - (int)numberOfChildren {
1118 id i_tmp = [self children];
1119 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
1122 - (BOOL)hasPrefs:(NSString *)o_module_name
1124 intf_thread_t *p_intf = VLCIntf;
1127 char *psz_module_name;
1130 psz_module_name = (char *)[o_module_name UTF8String];
1132 /* look for module */
1133 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1135 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1137 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1139 if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
1141 BOOL b_has_prefs = p_parser->i_config_items != 0;
1142 vlc_list_release( p_list );
1143 return( b_has_prefs );
1147 vlc_list_release( p_list );
1155 @implementation VLCFlippedView
1164 IMPL_CONTROL_CONFIG(Button);
1165 IMPL_CONTROL_CONFIG(PopUpButton);
1166 IMPL_CONTROL_CONFIG(ComboBox);
1167 IMPL_CONTROL_CONFIG(TextField);
1168 IMPL_CONTROL_CONFIG(Slider);
1169 IMPL_CONTROL_CONFIG(Matrix);