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
47 o_empty_view = [[NSView alloc] init];
48 o_save_prefs = [[NSMutableDictionary alloc] init];
56 [o_empty_view release];
57 [o_save_prefs release];
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:
130 NSString *o_value = [o_vlc_config stringValue];
131 psz_value = (char *)[o_value UTF8String];
133 config_PutPsz( p_intf, psz_name, psz_value );
137 case CONFIG_ITEM_FILE:
138 case CONFIG_ITEM_DIRECTORY:
141 NSString *o_value = [o_vlc_config stringValue];
142 psz_value = (char *)[o_value fileSystemRepresentation];
144 config_PutPsz( p_intf, psz_name, psz_value );
148 case CONFIG_ITEM_INTEGER:
149 case CONFIG_ITEM_BOOL:
151 int i_value = [o_vlc_config intValue];
153 config_PutInt( p_intf, psz_name, i_value );
157 case CONFIG_ITEM_FLOAT:
159 float f_value = [o_vlc_config floatValue];
161 config_PutFloat( p_intf, psz_name, f_value );
165 case CONFIG_ITEM_KEY:
167 unsigned int i_key = config_GetInt( p_intf, psz_name );
168 unsigned int i_new_key = 0;
170 if( [o_vlc_config class] == [VLCMatrix class] )
173 NSButtonCell *o_current_cell;
174 NSArray *o_cells = [o_vlc_config cells];
175 i_new_key = (i_key & ~KEY_MODIFIER);
176 for( i = 0; i < [o_cells count]; i++ )
178 o_current_cell = [o_cells objectAtIndex:i];
179 if( [[o_current_cell title] isEqualToString:_NS("Command")] &&
180 [o_current_cell state] == NSOnState )
181 i_new_key |= KEY_MODIFIER_COMMAND;
182 if( [[o_current_cell title] isEqualToString:_NS("Control")] &&
183 [o_current_cell state] == NSOnState )
184 i_new_key |= KEY_MODIFIER_CTRL;
185 if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] &&
186 [o_current_cell state] == NSOnState )
187 i_new_key |= KEY_MODIFIER_ALT;
188 if( [[o_current_cell title] isEqualToString:_NS("Shift")] &&
189 [o_current_cell state] == NSOnState )
190 i_new_key |= KEY_MODIFIER_SHIFT;
195 i_new_key = (i_key & KEY_MODIFIER);
196 i_new_key |= StringToKey([[o_vlc_config stringValue] cString]);
198 config_PutInt( p_intf, psz_name, i_new_key );
203 config_SaveConfigFile( p_intf, NULL );
204 [o_prefs_window orderOut:self];
207 - (IBAction)closePrefs: (id)sender
209 [o_prefs_window orderOut:self];
212 - (IBAction)resetAll: (id)sender
214 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
215 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
216 _NS("Beware this will reset your VLC media player preferences.\n"
217 "Are you sure you want to continue?") );
220 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
222 if( i_return == NSAlertAlternateReturn )
224 config_ResetAll( p_intf );
225 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
226 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
230 - (IBAction)advancedToggle: (id)sender
232 b_advanced = !b_advanced;
233 [o_advanced_ckb setState: b_advanced];
234 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
235 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
238 - (IBAction)openFileDialog: (id)sender
240 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
242 [o_open_panel setTitle: _NS("Select file or directory")];
243 [o_open_panel setPrompt: _NS("Select")];
244 [o_open_panel setAllowsMultipleSelection: NO];
245 [o_open_panel setCanChooseFiles: YES];
246 [o_open_panel setCanChooseDirectories: YES];
247 [o_open_panel beginSheetForDirectory:nil
250 modalForWindow:[sender window]
252 didEndSelector: @selector(pathChosenInPanel:
255 contextInfo: sender];
258 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info
260 if( i_return_code == NSOKButton )
262 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
263 VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */
264 [o_field setStringValue: o_path];
265 [self configChanged: o_field];
269 - (void)loadConfigTree
274 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
278 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
280 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
281 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
284 - (void)configChanged:(id)o_unknown
286 id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
287 [o_unknown object] : o_unknown;
289 NSString *o_name = [o_vlc_config configName];
290 [o_save_prefs setObject: o_vlc_config forKey: o_name];
293 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
297 module_config_t *p_item;
299 int i_pos, i_module_tag, i_index;
301 NSString *o_module_name;
302 NSRect s_rc; /* rect */
303 NSView *o_view; /* view */
304 NSRect s_vrc; /* view rect */
305 VLCTextField *o_text_field; /* input field / label */
307 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
309 /* Get a pointer to the module */
310 p_parser = (module_t *)vlc_object_get( p_intf, i_id );
311 if( p_parser->i_object_type != VLC_OBJECT_MODULE )
313 /* 0OOoo something went really bad */
314 vlc_list_release( p_list );
318 /* Enumerate config options and add corresponding config boxes */
319 o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
320 p_item = p_parser->p_config;
327 #define Y_ORIGIN (X_ORIGIN - 10)
329 #define CHECK_VIEW_HEIGHT \
331 float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
332 if( f_new_pos > s_vrc.size.height ) \
334 s_vrc.size.height = f_new_pos; \
335 [o_view setFrame: s_vrc]; \
339 #define CONTROL_LABEL( label ) \
341 s_rc.origin.x += s_rc.size.width + 10; \
342 s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
343 o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
344 [o_text_field setDrawsBackground: NO]; \
345 [o_text_field setBordered: NO]; \
346 [o_text_field setEditable: NO]; \
347 [o_text_field setSelectable: NO]; \
350 [o_text_field setStringValue: \
351 [[VLCMain sharedInstance] localizedString: label]]; \
353 [o_text_field sizeToFit]; \
354 [o_view addSubview: [o_text_field autorelease]]; \
357 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
359 char * psz_duptip = NULL; \
360 if ( p_item->psz_longtext != NULL ) \
361 psz_duptip = strdup( p_item->psz_longtext ); \
362 s_rc.size.height = 25; \
363 s_rc.size.width = w; \
364 s_rc.origin.y += 10; \
366 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
367 [o_text_field setAlignment: NSRightTextAlignment]; \
368 CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
369 [o_text_field msg: param]; \
370 if ( psz_duptip != NULL ) \
372 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: \
373 psz_duptip] toWidth: PREFS_WRAP ]]; \
376 [o_view addSubview: [o_text_field autorelease]]; \
377 [[NSNotificationCenter defaultCenter] addObserver: self \
378 selector: @selector(configChanged:) \
379 name: NSControlTextDidChangeNotification \
380 object: o_text_field]; \
381 CONTROL_LABEL( label ); \
382 s_rc.origin.y += s_rc.size.height; \
383 s_rc.origin.x = X_ORIGIN; \
386 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
387 INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
388 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
389 INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
390 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
391 INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
394 s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
395 o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
396 [o_view setAutoresizingMask: NSViewWidthSizable];
397 s_rc.origin.x = X_ORIGIN;
398 s_rc.origin.y = Y_ORIGIN;
399 BOOL b_right_cat = TRUE;
403 if( p_item->i_type == CONFIG_HINT_CATEGORY )
405 if( !strcmp( p_parser->psz_object_name, "main" ) &&
406 [o_item_name isEqualToString: [[VLCMain sharedInstance] localizedString: p_item->psz_text]] )
409 } else if( strcmp( p_parser->psz_object_name, "main" ) )
412 } else b_right_cat = FALSE;
413 } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
418 if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
422 switch( p_item->i_type )
424 case CONFIG_ITEM_MODULE:
426 VLCPopUpButton *o_modules;
427 module_t *p_a_module;
428 char * psz_duptip = NULL;
430 if ( p_item->psz_longtext != NULL )
431 psz_duptip = strdup( p_item->psz_longtext );
433 s_rc.size.height = 25;
434 s_rc.size.width = 200;
439 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
440 CONTROL_CONFIG( o_modules, o_module_name,
441 CONFIG_ITEM_MODULE, p_item->psz_name );
442 [o_modules setTarget: self];
443 [o_modules setAction: @selector(configChanged:)];
444 [o_modules sendActionOn:NSLeftMouseUpMask];
446 if ( psz_duptip != NULL )
448 [o_modules setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
451 [o_view addSubview: [o_modules autorelease]];
453 [o_modules addItemWithTitle: _NS("Default")];
454 [[o_modules lastItem] setTag: -1];
455 [o_modules selectItem: [o_modules lastItem]];
457 /* build a list of available modules */
459 for( i_index = 0; i_index < p_list->i_count; i_index++ )
461 p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
463 if( !strcmp( p_a_module->psz_capability,
466 NSString *o_description = [[VLCMain sharedInstance]
467 localizedString: p_a_module->psz_longname];
468 [o_modules addItemWithTitle: o_description];
469 [[o_modules lastItem] setTag: p_a_module->i_object_id];
471 if( p_item->psz_value &&
472 !strcmp( p_item->psz_value, p_a_module->psz_object_name ) )
474 [o_modules selectItem:[o_modules lastItem]];
480 CONTROL_LABEL( p_item->psz_text );
481 s_rc.origin.y += s_rc.size.height;
482 s_rc.origin.x = X_ORIGIN;
486 case CONFIG_ITEM_FILE:
487 case CONFIG_ITEM_DIRECTORY:
489 char *psz_duptip = NULL;
490 char *psz_value = p_item->psz_value ?
491 p_item->psz_value : "";
493 if ( p_item->psz_longtext != NULL )
494 psz_duptip = strdup( p_item->psz_longtext );
497 s_rc.size.width = - 10;
498 s_rc.size.height = 25;
500 CONTROL_LABEL( p_item->psz_text );
501 s_rc.origin.x = X_ORIGIN;
502 s_rc.origin.y += s_rc.size.height;
505 VLCButton *button = [[VLCButton alloc] initWithFrame: s_rc];
506 CONTROL_CONFIG( button, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
507 [button setButtonType: NSMomentaryPushInButton];
508 [button setBezelStyle: NSRoundedBezelStyle];
509 [button setTitle: _NS("Browse...")];
511 [button setAutoresizingMask:NSViewMinXMargin];
512 [button setFrameOrigin: NSMakePoint( s_vrc.size.width - ( 10 + [button frame].size.width), s_rc.origin.y)];
514 [button setTarget: self];
515 [button setAction: @selector(openFileDialog:)];
517 s_rc.size.height = 25;
518 s_rc.size.width = s_vrc.size.width - ( 35 + [button frame].size.width);
520 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
521 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
523 [o_text_field setStringValue: [[VLCMain sharedInstance] localizedString: psz_value]];
524 if ( psz_duptip != NULL )
526 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString:
527 psz_duptip] toWidth: PREFS_WRAP ]];
531 [[NSNotificationCenter defaultCenter] addObserver: self
532 selector: @selector(configChanged:)
533 name: NSControlTextDidChangeNotification
534 object: o_text_field];
535 [o_text_field setAutoresizingMask:NSViewWidthSizable];
536 [button setTag: (int) o_text_field ]; /* FIXME */
538 [o_view addSubview: [o_text_field autorelease]];
539 [o_view addSubview: [button autorelease]];
540 s_rc.origin.y += s_rc.size.height;
541 s_rc.origin.x = X_ORIGIN;
545 case CONFIG_ITEM_STRING:
547 if( !p_item->ppsz_list )
549 char *psz_value = p_item->psz_value ?
550 p_item->psz_value : "";
552 INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
553 [[VLCMain sharedInstance] localizedString: psz_value],
554 p_item->psz_longtext );
559 VLCComboBox *o_combo_box;
560 char * psz_duptip = NULL;
561 if ( p_item->psz_longtext != NULL )
562 psz_duptip = strdup( p_item->psz_longtext );
564 s_rc.size.height = 25;
565 s_rc.size.width = 200;
570 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
571 CONTROL_CONFIG( o_combo_box, o_module_name,
572 CONFIG_ITEM_STRING, p_item->psz_name );
573 [o_combo_box setTarget: self];
574 [o_combo_box setAction: @selector(configChanged:)];
575 [o_combo_box sendActionOn:NSLeftMouseUpMask];
576 [[NSNotificationCenter defaultCenter] addObserver: self
577 selector: @selector(configChanged:)
578 name: NSControlTextDidChangeNotification
579 object: o_combo_box];
581 if ( psz_duptip != NULL )
583 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
586 [o_view addSubview: [o_combo_box autorelease]];
588 for( i=0; p_item->ppsz_list[i]; i++ )
590 [o_combo_box addItemWithObjectValue:
591 [[VLCMain sharedInstance] localizedString: p_item->ppsz_list[i]]];
593 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:
594 p_item->psz_value ? p_item->psz_value : ""]];
596 CONTROL_LABEL( p_item->psz_text );
598 s_rc.origin.y += s_rc.size.height;
599 s_rc.origin.x = X_ORIGIN;
605 case CONFIG_ITEM_INTEGER:
607 if( p_item->i_min == p_item->i_max )
609 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
610 p_item->i_value, p_item->psz_longtext );
616 char * psz_duptip = NULL;
617 if ( p_item->psz_longtext != NULL )
618 psz_duptip = strdup( p_item->psz_longtext );
620 s_rc.size.height = 27;
621 s_rc.size.width = 200;
626 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
627 [o_slider setMinValue: p_item->i_min];
628 [o_slider setMaxValue: p_item->i_max];
629 [o_slider setIntValue: p_item->i_value];
631 if ( psz_duptip != NULL )
633 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
636 [o_slider setTarget: self];
637 [o_slider setAction: @selector(configChanged:)];
638 [o_slider sendActionOn:NSLeftMouseUpMask];
639 CONTROL_CONFIG( o_slider, o_module_name,
640 CONFIG_ITEM_INTEGER, p_item->psz_name );
641 [o_view addSubview: [o_slider autorelease]];
642 CONTROL_LABEL( p_item->psz_text );
644 s_rc.origin.y += s_rc.size.height;
645 s_rc.origin.x = X_ORIGIN;
650 case CONFIG_ITEM_FLOAT:
652 if( p_item->f_min == p_item->f_max )
654 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
655 p_item->f_value, p_item->psz_longtext );
659 /* create a slider */
661 char * psz_duptip = NULL;
662 if ( p_item->psz_longtext != NULL )
663 psz_duptip = strdup( p_item->psz_longtext );
665 s_rc.size.height = 27;
666 s_rc.size.width = 200;
671 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
672 [o_slider setMinValue: p_item->f_min];
673 [o_slider setMaxValue: p_item->f_max];
674 [o_slider setFloatValue: p_item->f_value];
676 if ( psz_duptip != NULL )
678 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
681 [o_slider setTarget: self];
682 [o_slider setAction: @selector(configChanged:)];
683 [o_slider sendActionOn:NSLeftMouseUpMask];
684 CONTROL_CONFIG( o_slider, o_module_name,
685 CONFIG_ITEM_FLOAT, p_item->psz_name );
686 [o_view addSubview: [o_slider autorelease]];
687 CONTROL_LABEL( p_item->psz_text );
689 s_rc.origin.y += s_rc.size.height;
690 s_rc.origin.x = X_ORIGIN;
695 case CONFIG_ITEM_BOOL:
697 VLCButton *o_btn_bool;
698 char * psz_duptip = NULL;
700 if ( p_item->psz_longtext != NULL )
701 psz_duptip = strdup( p_item->psz_longtext );
703 s_rc.size.height = 27;
704 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
709 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
710 [o_btn_bool setButtonType: NSSwitchButton];
711 [o_btn_bool setIntValue: p_item->i_value];
712 [o_btn_bool setTitle: [[VLCMain sharedInstance] localizedString: p_item->psz_text]];
713 if ( psz_duptip != NULL )
715 [o_btn_bool setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
718 [o_btn_bool setTarget: self];
719 [o_btn_bool setAction: @selector(configChanged:)];
720 CONTROL_CONFIG( o_btn_bool, o_module_name,
721 CONFIG_ITEM_BOOL, p_item->psz_name );
722 [o_view addSubview: [o_btn_bool autorelease]];
724 s_rc.origin.y += s_rc.size.height;
728 case CONFIG_ITEM_KEY:
731 char *psz_duptip = NULL;
732 VLCComboBox *o_combo_box;
734 if ( p_item->psz_longtext != NULL )
735 psz_duptip = strdup( p_item->psz_longtext );
738 s_rc.size.width = - 10;
739 s_rc.size.height = 20;
741 CONTROL_LABEL( p_item->psz_text );
742 s_rc.origin.x = X_ORIGIN;
743 s_rc.origin.y += s_rc.size.height;
744 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2;
746 VLCMatrix *o_matrix = [[VLCMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2];
747 NSArray *o_cells = [o_matrix cells];
748 for( i=0; i < [o_cells count]; i++ )
750 NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
751 [o_current_cell setButtonType: NSSwitchButton];
752 [o_current_cell setControlSize: NSSmallControlSize];
753 if( psz_duptip != NULL )
755 [o_matrix setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
760 [o_current_cell setTitle:_NS("Command")];
761 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
764 [o_current_cell setTitle:_NS("Control")];
765 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
768 [o_current_cell setTitle:_NS("Option/Alt")];
769 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
772 [o_current_cell setTitle:_NS("Shift")];
773 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
776 [o_current_cell setTarget: self];
777 [o_current_cell setAction: @selector(configChanged:)];
778 [o_current_cell sendActionOn:NSLeftMouseUpMask];
780 CONTROL_CONFIG( o_matrix, o_module_name,
781 CONFIG_ITEM_KEY, p_item->psz_name );
782 [o_matrix sizeToCells];
783 [o_view addSubview: [o_matrix autorelease]];
785 s_rc.origin.x += [o_matrix frame].size.width + 20;
786 s_rc.size.height = 25;
787 s_rc.size.width = 100;
791 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
792 CONTROL_CONFIG( o_combo_box, o_module_name,
793 CONFIG_ITEM_KEY, p_item->psz_name );
794 [o_combo_box setTarget: self];
795 [o_combo_box setAction: @selector(configChanged:)];
796 [o_combo_box sendActionOn:NSLeftMouseUpMask];
797 [[NSNotificationCenter defaultCenter] addObserver: self
798 selector: @selector(configChanged:)
799 name: NSControlTextDidChangeNotification
800 object: o_combo_box];
802 if ( psz_duptip != NULL )
804 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
806 [o_view addSubview: [o_combo_box autorelease]];
808 for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
811 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
812 [o_combo_box addItemWithObjectValue: [[VLCMain sharedInstance] localizedString:vlc_keys[i].psz_key_string]];
815 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
817 s_rc.origin.y += s_rc.size.height;
818 s_rc.origin.x = X_ORIGIN;
819 if( psz_duptip ) free( psz_duptip );
825 #undef INPUT_FIELD_INTEGER
826 #undef INPUT_FIELD_FLOAT
827 #undef INPUT_FIELD_STRING
829 #undef CHECK_VIEW_HEIGHT
834 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
835 vlc_object_release( p_parser );
836 vlc_list_release( p_list );
838 [o_prefs_view setDocumentView: o_view];
839 [o_prefs_view setNeedsDisplay: TRUE];
845 @implementation VLCPrefs (NSTableDataSource)
847 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
848 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
851 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
852 return (item == nil) ? YES : ([item numberOfChildren] != -1);
855 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
856 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
859 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
860 return (item == nil) ? @"" : (id)[item getName];
865 @implementation VLCTreeItem
867 static VLCTreeItem *o_root_item = nil;
869 #define IsALeafNode ((id)-1)
871 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
877 o_name = [o_item_name copy];
879 o_parent = o_parent_item;
884 + (VLCTreeItem *)rootItem {
885 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
891 if (o_children != IsALeafNode) [o_children release];
896 /* Creates and returns the array of children
897 * Loads children incrementally */
898 - (NSArray *)children {
899 if (o_children == NULL) {
900 intf_thread_t *p_intf = VLCIntf;
902 module_t *p_module = NULL;
903 module_config_t *p_item;
906 /* List the modules */
907 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
908 if( !p_list ) return nil;
910 if( [[self getName] isEqualToString: @"main"] )
913 * Build a tree of the main options
915 for( i_index = 0; i_index < p_list->i_count; i_index++ )
917 p_module = (module_t *)p_list->p_values[i_index].p_object;
918 if( !strcmp( p_module->psz_object_name, "main" ) )
921 if( p_module == NULL )
923 msg_Err( p_intf, "could not find the main module in our preferences" );
926 if( i_index < p_list->i_count )
928 /* We found the main module */
930 /* Enumerate config categories and store a reference so we can
931 * generate their config panel them when it is asked by the user. */
932 p_item = p_module->p_config;
933 o_children = [[NSMutableArray alloc] initWithCapacity:10];
937 NSString *o_child_name;
939 switch( p_item->i_type )
941 case CONFIG_HINT_CATEGORY:
942 o_child_name = [[VLCMain sharedInstance] localizedString: p_item->psz_text];
943 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
944 ID: p_module->i_object_id parent:self]];
948 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
950 /* Add the modules item */
951 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
956 o_children = IsALeafNode;
959 else if( [[self getName] isEqualToString: _NS("Modules")] )
961 /* Add the capabilities */
962 o_children = [[NSMutableArray alloc] initWithCapacity:10];
963 for( i_index = 0; i_index < p_list->i_count; i_index++ )
965 p_module = (module_t *)p_list->p_values[i_index].p_object;
967 /* Exclude the main module */
968 if( !strcmp( p_module->psz_object_name, "main" ) )
971 /* Exclude empty modules */
972 p_item = p_module->p_config;
973 if( !p_item ) continue;
976 if( p_item->i_type & CONFIG_ITEM )
979 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
980 if( p_item->i_type == CONFIG_HINT_END ) continue;
982 /* Create the capability tree if it doesn't already exist */
983 NSString *o_capability;
984 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
985 if( !p_module->psz_capability || !*p_module->psz_capability )
987 /* Empty capability ? Let's look at the submodules */
988 module_t * p_submodule;
989 for( j = 0; j < p_module->i_children; j++ )
991 p_submodule = (module_t*)p_module->pp_children[ j ];
992 if( p_submodule->psz_capability && *p_submodule->psz_capability )
994 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
995 BOOL b_found = FALSE;
996 for( j = 0; j < (int)[o_children count]; j++ )
998 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1006 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1007 ID: 0 parent:self]];
1013 BOOL b_found = FALSE;
1014 for( j = 0; j < (int)[o_children count]; j++ )
1016 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1024 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1025 ID: 0 parent:self]];
1029 else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
1031 /* Now add the modules */
1032 o_children = [[NSMutableArray alloc] initWithCapacity:10];
1033 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1035 p_module = (module_t *)p_list->p_values[i_index].p_object;
1037 /* Exclude the main module */
1038 if( !strcmp( p_module->psz_object_name, "main" ) )
1041 /* Exclude empty modules */
1042 p_item = p_module->p_config;
1043 if( !p_item ) continue;
1046 if( p_item->i_type & CONFIG_ITEM )
1049 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
1050 if( p_item->i_type == CONFIG_HINT_END ) continue;
1052 /* Check the capability */
1053 NSString *o_capability;
1054 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
1055 if( !p_module->psz_capability || !*p_module->psz_capability )
1057 /* Empty capability ? Let's look at the submodules */
1058 module_t * p_submodule;
1059 for( j = 0; j < p_module->i_children; j++ )
1061 p_submodule = (module_t*)p_module->pp_children[ j ];
1062 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1064 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
1065 if( [o_capability isEqualToString: [self getName]] )
1067 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1068 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1069 ID: p_module->i_object_id parent:self]];
1074 else if( [o_capability isEqualToString: [self getName]] )
1076 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1077 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1078 ID: p_module->i_object_id parent:self]];
1084 /* all the other stuff are leafs */
1085 o_children = IsALeafNode;
1087 vlc_list_release( p_list );
1097 - (NSString *)getName
1102 - (VLCTreeItem *)childAtIndex:(int)i_index {
1103 return [[self children] objectAtIndex:i_index];
1106 - (int)numberOfChildren {
1107 id i_tmp = [self children];
1108 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
1111 - (BOOL)hasPrefs:(NSString *)o_module_name
1113 intf_thread_t *p_intf = VLCIntf;
1116 char *psz_module_name;
1119 psz_module_name = (char *)[o_module_name UTF8String];
1121 /* look for module */
1122 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1124 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1126 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1128 if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
1130 BOOL b_has_prefs = p_parser->i_config_items != 0;
1131 vlc_list_release( p_list );
1132 return( b_has_prefs );
1136 vlc_list_release( p_list );
1144 @implementation VLCFlippedView
1153 IMPL_CONTROL_CONFIG(Button);
1154 IMPL_CONTROL_CONFIG(PopUpButton);
1155 IMPL_CONTROL_CONFIG(ComboBox);
1156 IMPL_CONTROL_CONFIG(TextField);
1157 IMPL_CONTROL_CONFIG(Slider);
1158 IMPL_CONTROL_CONFIG(Matrix);