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:
128 case CONFIG_ITEM_FILE:
129 case CONFIG_ITEM_DIRECTORY:
132 NSString *o_value = [o_vlc_config stringValue];
133 psz_value = (char *)[o_value UTF8String];
135 config_PutPsz( p_intf, psz_name, psz_value );
139 case CONFIG_ITEM_INTEGER:
140 case CONFIG_ITEM_BOOL:
142 int i_value = [o_vlc_config intValue];
144 config_PutInt( p_intf, psz_name, i_value );
148 case CONFIG_ITEM_FLOAT:
150 float f_value = [o_vlc_config floatValue];
152 config_PutFloat( p_intf, psz_name, f_value );
156 case CONFIG_ITEM_KEY:
158 unsigned int i_key = config_GetInt( p_intf, psz_name );
159 unsigned int i_new_key = 0;
161 if( [o_vlc_config class] == [VLCMatrix class] )
164 NSButtonCell *o_current_cell;
165 NSArray *o_cells = [o_vlc_config cells];
166 i_new_key = (i_key & ~KEY_MODIFIER);
167 for( i = 0; i < [o_cells count]; i++ )
169 o_current_cell = [o_cells objectAtIndex:i];
170 if( [[o_current_cell title] isEqualToString:_NS("Command")] &&
171 [o_current_cell state] == NSOnState )
172 i_new_key |= KEY_MODIFIER_COMMAND;
173 if( [[o_current_cell title] isEqualToString:_NS("Control")] &&
174 [o_current_cell state] == NSOnState )
175 i_new_key |= KEY_MODIFIER_CTRL;
176 if( [[o_current_cell title] isEqualToString:_NS("Option/Alt")] &&
177 [o_current_cell state] == NSOnState )
178 i_new_key |= KEY_MODIFIER_ALT;
179 if( [[o_current_cell title] isEqualToString:_NS("Shift")] &&
180 [o_current_cell state] == NSOnState )
181 i_new_key |= KEY_MODIFIER_SHIFT;
186 i_new_key = (i_key & KEY_MODIFIER);
187 i_new_key |= StringToKey([[o_vlc_config stringValue] cString]);
189 config_PutInt( p_intf, psz_name, i_new_key );
194 config_SaveConfigFile( p_intf, NULL );
195 [o_prefs_window orderOut:self];
198 - (IBAction)closePrefs: (id)sender
200 [o_prefs_window orderOut:self];
203 - (IBAction)resetAll: (id)sender
205 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
206 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
207 _NS("Beware this will reset your VLC media player preferences.\n"
208 "Are you sure you want to continue?") );
211 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
213 if( i_return == NSAlertAlternateReturn )
215 config_ResetAll( p_intf );
216 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
217 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
221 - (IBAction)advancedToggle: (id)sender
223 b_advanced = !b_advanced;
224 [o_advanced_ckb setState: b_advanced];
225 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
226 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
229 - (IBAction)openFileDialog: (id)sender
231 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
233 [o_open_panel setTitle: _NS("Select file or directory")];
234 [o_open_panel setPrompt: _NS("Select")];
235 [o_open_panel setAllowsMultipleSelection: NO];
236 [o_open_panel setCanChooseFiles: YES];
237 [o_open_panel setCanChooseDirectories: YES];
238 [o_open_panel beginSheetForDirectory:nil
241 modalForWindow:[sender window]
243 didEndSelector: @selector(pathChosenInPanel:
246 contextInfo: sender];
249 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet withReturn:(int)i_return_code contextInfo:(void *)o_context_info
251 if( i_return_code == NSOKButton )
253 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
254 VLCTextField *o_field = (VLCTextField *)[(VLCButton *)o_context_info tag]; /* FIXME */
255 [o_field setStringValue: o_path];
256 [self configChanged: o_field];
260 - (void)loadConfigTree
265 - (void)outlineViewSelectionIsChanging:(NSNotification *)o_notification
269 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
271 [self showViewForID: [[o_tree itemAtRow:[o_tree selectedRow]] getObjectID]
272 andName: [[o_tree itemAtRow:[o_tree selectedRow]] getName]];
275 - (void)configChanged:(id)o_unknown
277 id o_vlc_config = [o_unknown isKindOfClass: [NSNotification class]] ?
278 [o_unknown object] : o_unknown;
280 NSString *o_name = [o_vlc_config configName];
281 [o_save_prefs setObject: o_vlc_config forKey: o_name];
284 - (void)showViewForID: (int)i_id andName: (NSString *)o_item_name
288 module_config_t *p_item;
290 int i_pos, i_module_tag, i_index;
292 NSString *o_module_name;
293 NSRect s_rc; /* rect */
294 NSView *o_view; /* view */
295 NSRect s_vrc; /* view rect */
296 VLCTextField *o_text_field; /* input field / label */
298 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
300 /* Get a pointer to the module */
301 p_parser = (module_t *)vlc_object_get( p_intf, i_id );
302 if( p_parser->i_object_type != VLC_OBJECT_MODULE )
304 /* 0OOoo something went really bad */
305 vlc_list_release( p_list );
309 /* Enumerate config options and add corresponding config boxes */
310 o_module_name = [NSString stringWithUTF8String: p_parser->psz_object_name];
311 p_item = p_parser->p_config;
318 #define Y_ORIGIN (X_ORIGIN - 10)
320 #define CHECK_VIEW_HEIGHT \
322 float f_new_pos = s_rc.origin.y + s_rc.size.height + X_ORIGIN; \
323 if( f_new_pos > s_vrc.size.height ) \
325 s_vrc.size.height = f_new_pos; \
326 [o_view setFrame: s_vrc]; \
330 #define CONTROL_LABEL( label ) \
332 s_rc.origin.x += s_rc.size.width + 10; \
333 s_rc.size.width = s_vrc.size.width - s_rc.origin.x - X_ORIGIN - 20; \
334 o_text_field = [[NSTextField alloc] initWithFrame: s_rc]; \
335 [o_text_field setDrawsBackground: NO]; \
336 [o_text_field setBordered: NO]; \
337 [o_text_field setEditable: NO]; \
338 [o_text_field setSelectable: NO]; \
341 [o_text_field setStringValue: \
342 [[VLCMain sharedInstance] localizedString: label]]; \
344 [o_text_field sizeToFit]; \
345 [o_view addSubview: [o_text_field autorelease]]; \
348 #define INPUT_FIELD( ctype, cname, label, w, msg, param, tip ) \
350 char * psz_duptip = NULL; \
351 if ( p_item->psz_longtext != NULL ) \
352 psz_duptip = strdup( p_item->psz_longtext ); \
353 s_rc.size.height = 25; \
354 s_rc.size.width = w; \
355 s_rc.origin.y += 10; \
357 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc]; \
358 [o_text_field setAlignment: NSRightTextAlignment]; \
359 CONTROL_CONFIG( o_text_field, o_module_name, ctype, cname ); \
360 [o_text_field msg: param]; \
361 if ( psz_duptip != NULL ) \
363 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: \
364 psz_duptip] toWidth: PREFS_WRAP ]]; \
367 [o_view addSubview: [o_text_field autorelease]]; \
368 [[NSNotificationCenter defaultCenter] addObserver: self \
369 selector: @selector(configChanged:) \
370 name: NSControlTextDidChangeNotification \
371 object: o_text_field]; \
372 CONTROL_LABEL( label ); \
373 s_rc.origin.y += s_rc.size.height; \
374 s_rc.origin.x = X_ORIGIN; \
377 #define INPUT_FIELD_INTEGER( name, label, w, param, tip ) \
378 INPUT_FIELD( CONFIG_ITEM_INTEGER, name, label, w, setIntValue, param, tip )
379 #define INPUT_FIELD_FLOAT( name, label, w, param, tip ) \
380 INPUT_FIELD( CONFIG_ITEM_FLOAT, name, label, w, setFloatValue, param, tip )
381 #define INPUT_FIELD_STRING( name, label, w, param, tip ) \
382 INPUT_FIELD( CONFIG_ITEM_STRING, name, label, w, setStringValue, param, tip )
385 s_vrc = [[o_prefs_view contentView] bounds]; s_vrc.size.height -= 4;
386 o_view = [[VLCFlippedView alloc] initWithFrame: s_vrc];
387 [o_view setAutoresizingMask: NSViewWidthSizable];
388 s_rc.origin.x = X_ORIGIN;
389 s_rc.origin.y = Y_ORIGIN;
390 BOOL b_right_cat = TRUE;
394 if( p_item->i_type == CONFIG_HINT_CATEGORY )
396 if( !strcmp( p_parser->psz_object_name, "main" ) &&
397 [o_item_name isEqualToString: [[VLCMain sharedInstance] localizedString: p_item->psz_text]] )
400 } else if( strcmp( p_parser->psz_object_name, "main" ) )
403 } else b_right_cat = FALSE;
404 } else if( p_item->i_type == CONFIG_HINT_END && !strcmp( p_parser->psz_object_name, "main" ) )
409 if( (p_item->b_advanced && !b_advanced ) || !b_right_cat )
413 switch( p_item->i_type )
415 case CONFIG_ITEM_MODULE:
417 VLCPopUpButton *o_modules;
418 module_t *p_a_module;
419 char * psz_duptip = NULL;
421 if ( p_item->psz_longtext != NULL )
422 psz_duptip = strdup( p_item->psz_longtext );
424 s_rc.size.height = 25;
425 s_rc.size.width = 200;
430 o_modules = [[VLCPopUpButton alloc] initWithFrame: s_rc];
431 CONTROL_CONFIG( o_modules, o_module_name,
432 CONFIG_ITEM_MODULE, p_item->psz_name );
433 [o_modules setTarget: self];
434 [o_modules setAction: @selector(configChanged:)];
435 [o_modules sendActionOn:NSLeftMouseUpMask];
437 if ( psz_duptip != NULL )
439 [o_modules setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
442 [o_view addSubview: [o_modules autorelease]];
444 [o_modules addItemWithTitle: _NS("Default")];
445 [[o_modules lastItem] setTag: -1];
446 [o_modules selectItem: [o_modules lastItem]];
448 /* build a list of available modules */
450 for( i_index = 0; i_index < p_list->i_count; i_index++ )
452 p_a_module = (module_t *)p_list->p_values[i_index].p_object ;
454 if( !strcmp( p_a_module->psz_capability,
457 NSString *o_description = [[VLCMain sharedInstance]
458 localizedString: p_a_module->psz_longname];
459 [o_modules addItemWithTitle: o_description];
460 [[o_modules lastItem] setTag: p_a_module->i_object_id];
462 if( p_item->psz_value &&
463 !strcmp( p_item->psz_value, p_a_module->psz_object_name ) )
465 [o_modules selectItem:[o_modules lastItem]];
471 CONTROL_LABEL( p_item->psz_text );
472 s_rc.origin.y += s_rc.size.height;
473 s_rc.origin.x = X_ORIGIN;
477 case CONFIG_ITEM_FILE:
478 case CONFIG_ITEM_DIRECTORY:
480 char *psz_duptip = NULL;
481 char *psz_value = p_item->psz_value ?
482 p_item->psz_value : "";
484 if ( p_item->psz_longtext != NULL )
485 psz_duptip = strdup( p_item->psz_longtext );
488 s_rc.size.width = - 10;
489 s_rc.size.height = 25;
491 CONTROL_LABEL( p_item->psz_text );
492 s_rc.origin.x = X_ORIGIN;
493 s_rc.origin.y += s_rc.size.height;
496 VLCButton *button = [[VLCButton alloc] initWithFrame: s_rc];
497 CONTROL_CONFIG( button, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
498 [button setButtonType: NSMomentaryPushInButton];
499 [button setBezelStyle: NSRoundedBezelStyle];
500 [button setTitle: _NS("Browse...")];
502 [button setAutoresizingMask:NSViewMinXMargin];
503 [button setFrameOrigin: NSMakePoint( s_vrc.size.width - ( 10 + [button frame].size.width), s_rc.origin.y)];
505 [button setTarget: self];
506 [button setAction: @selector(openFileDialog:)];
508 s_rc.size.height = 25;
509 s_rc.size.width = s_vrc.size.width - ( 35 + [button frame].size.width);
511 o_text_field = [[VLCTextField alloc] initWithFrame: s_rc];
512 CONTROL_CONFIG( o_text_field, o_module_name, CONFIG_ITEM_STRING , p_item->psz_name );
514 [o_text_field setStringValue: [[VLCMain sharedInstance] localizedString: psz_value]];
515 if ( psz_duptip != NULL )
517 [o_text_field setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString:
518 psz_duptip] toWidth: PREFS_WRAP ]];
522 [[NSNotificationCenter defaultCenter] addObserver: self
523 selector: @selector(configChanged:)
524 name: NSControlTextDidChangeNotification
525 object: o_text_field];
526 [o_text_field setAutoresizingMask:NSViewWidthSizable];
527 [button setTag: (int) o_text_field ]; /* FIXME */
529 [o_view addSubview: [o_text_field autorelease]];
530 [o_view addSubview: [button autorelease]];
531 s_rc.origin.y += s_rc.size.height;
532 s_rc.origin.x = X_ORIGIN;
536 case CONFIG_ITEM_STRING:
538 if( !p_item->ppsz_list )
540 char *psz_value = p_item->psz_value ?
541 p_item->psz_value : "";
543 INPUT_FIELD_STRING( p_item->psz_name, p_item->psz_text, 200,
544 [[VLCMain sharedInstance] localizedString: psz_value],
545 p_item->psz_longtext );
550 VLCComboBox *o_combo_box;
551 char * psz_duptip = NULL;
552 if ( p_item->psz_longtext != NULL )
553 psz_duptip = strdup( p_item->psz_longtext );
555 s_rc.size.height = 25;
556 s_rc.size.width = 200;
561 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
562 CONTROL_CONFIG( o_combo_box, o_module_name,
563 CONFIG_ITEM_STRING, p_item->psz_name );
564 [o_combo_box setTarget: self];
565 [o_combo_box setAction: @selector(configChanged:)];
566 [o_combo_box sendActionOn:NSLeftMouseUpMask];
567 [[NSNotificationCenter defaultCenter] addObserver: self
568 selector: @selector(configChanged:)
569 name: NSControlTextDidChangeNotification
570 object: o_combo_box];
572 if ( psz_duptip != NULL )
574 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
577 [o_view addSubview: [o_combo_box autorelease]];
579 for( i=0; p_item->ppsz_list[i]; i++ )
581 [o_combo_box addItemWithObjectValue:
582 [[VLCMain sharedInstance] localizedString: p_item->ppsz_list[i]]];
584 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:
585 p_item->psz_value ? p_item->psz_value : ""]];
587 CONTROL_LABEL( p_item->psz_text );
589 s_rc.origin.y += s_rc.size.height;
590 s_rc.origin.x = X_ORIGIN;
596 case CONFIG_ITEM_INTEGER:
598 if( p_item->i_min == p_item->i_max )
600 INPUT_FIELD_INTEGER( p_item->psz_name, p_item->psz_text, 70,
601 p_item->i_value, p_item->psz_longtext );
607 char * psz_duptip = NULL;
608 if ( p_item->psz_longtext != NULL )
609 psz_duptip = strdup( p_item->psz_longtext );
611 s_rc.size.height = 27;
612 s_rc.size.width = 200;
617 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
618 [o_slider setMinValue: p_item->i_min];
619 [o_slider setMaxValue: p_item->i_max];
620 [o_slider setIntValue: p_item->i_value];
622 if ( psz_duptip != NULL )
624 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
627 [o_slider setTarget: self];
628 [o_slider setAction: @selector(configChanged:)];
629 [o_slider sendActionOn:NSLeftMouseUpMask];
630 CONTROL_CONFIG( o_slider, o_module_name,
631 CONFIG_ITEM_INTEGER, p_item->psz_name );
632 [o_view addSubview: [o_slider autorelease]];
633 CONTROL_LABEL( p_item->psz_text );
635 s_rc.origin.y += s_rc.size.height;
636 s_rc.origin.x = X_ORIGIN;
641 case CONFIG_ITEM_FLOAT:
643 if( p_item->f_min == p_item->f_max )
645 INPUT_FIELD_FLOAT( p_item->psz_name, p_item->psz_text, 70,
646 p_item->f_value, p_item->psz_longtext );
650 /* create a slider */
652 char * psz_duptip = NULL;
653 if ( p_item->psz_longtext != NULL )
654 psz_duptip = strdup( p_item->psz_longtext );
656 s_rc.size.height = 27;
657 s_rc.size.width = 200;
662 o_slider = [[VLCSlider alloc] initWithFrame: s_rc];
663 [o_slider setMinValue: p_item->f_min];
664 [o_slider setMaxValue: p_item->f_max];
665 [o_slider setFloatValue: p_item->f_value];
667 if ( psz_duptip != NULL )
669 [o_slider setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
672 [o_slider setTarget: self];
673 [o_slider setAction: @selector(configChanged:)];
674 [o_slider sendActionOn:NSLeftMouseUpMask];
675 CONTROL_CONFIG( o_slider, o_module_name,
676 CONFIG_ITEM_FLOAT, p_item->psz_name );
677 [o_view addSubview: [o_slider autorelease]];
678 CONTROL_LABEL( p_item->psz_text );
680 s_rc.origin.y += s_rc.size.height;
681 s_rc.origin.x = X_ORIGIN;
686 case CONFIG_ITEM_BOOL:
688 VLCButton *o_btn_bool;
689 char * psz_duptip = NULL;
691 if ( p_item->psz_longtext != NULL )
692 psz_duptip = strdup( p_item->psz_longtext );
694 s_rc.size.height = 27;
695 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2 - 20;
700 o_btn_bool = [[VLCButton alloc] initWithFrame: s_rc];
701 [o_btn_bool setButtonType: NSSwitchButton];
702 [o_btn_bool setIntValue: p_item->i_value];
703 [o_btn_bool setTitle: [[VLCMain sharedInstance] localizedString: p_item->psz_text]];
704 if ( psz_duptip != NULL )
706 [o_btn_bool setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
709 [o_btn_bool setTarget: self];
710 [o_btn_bool setAction: @selector(configChanged:)];
711 CONTROL_CONFIG( o_btn_bool, o_module_name,
712 CONFIG_ITEM_BOOL, p_item->psz_name );
713 [o_view addSubview: [o_btn_bool autorelease]];
715 s_rc.origin.y += s_rc.size.height;
719 case CONFIG_ITEM_KEY:
722 char *psz_duptip = NULL;
723 VLCComboBox *o_combo_box;
725 if ( p_item->psz_longtext != NULL )
726 psz_duptip = strdup( p_item->psz_longtext );
729 s_rc.size.width = - 10;
730 s_rc.size.height = 20;
732 CONTROL_LABEL( p_item->psz_text );
733 s_rc.origin.x = X_ORIGIN;
734 s_rc.origin.y += s_rc.size.height;
735 s_rc.size.width = s_vrc.size.width - X_ORIGIN * 2;
737 VLCMatrix *o_matrix = [[VLCMatrix alloc] initWithFrame: s_rc mode: NSHighlightModeMatrix cellClass: [NSButtonCell class] numberOfRows:2 numberOfColumns:2];
738 NSArray *o_cells = [o_matrix cells];
739 for( i=0; i < [o_cells count]; i++ )
741 NSButtonCell *o_current_cell = [o_cells objectAtIndex:i];
742 [o_current_cell setButtonType: NSSwitchButton];
743 [o_current_cell setControlSize: NSSmallControlSize];
744 if( psz_duptip != NULL )
746 [o_matrix setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP] forCell: o_current_cell];
751 [o_current_cell setTitle:_NS("Command")];
752 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_COMMAND];
755 [o_current_cell setTitle:_NS("Control")];
756 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_CTRL];
759 [o_current_cell setTitle:_NS("Option/Alt")];
760 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_ALT];
763 [o_current_cell setTitle:_NS("Shift")];
764 [o_current_cell setState: p_item->i_value & KEY_MODIFIER_SHIFT];
767 [o_current_cell setTarget: self];
768 [o_current_cell setAction: @selector(configChanged:)];
769 [o_current_cell sendActionOn:NSLeftMouseUpMask];
771 CONTROL_CONFIG( o_matrix, o_module_name,
772 CONFIG_ITEM_KEY, p_item->psz_name );
773 [o_matrix sizeToCells];
774 [o_view addSubview: [o_matrix autorelease]];
776 s_rc.origin.x += [o_matrix frame].size.width + 20;
777 s_rc.size.height = 25;
778 s_rc.size.width = 100;
782 o_combo_box = [[VLCComboBox alloc] initWithFrame: s_rc];
783 CONTROL_CONFIG( o_combo_box, o_module_name,
784 CONFIG_ITEM_KEY, p_item->psz_name );
785 [o_combo_box setTarget: self];
786 [o_combo_box setAction: @selector(configChanged:)];
787 [o_combo_box sendActionOn:NSLeftMouseUpMask];
788 [[NSNotificationCenter defaultCenter] addObserver: self
789 selector: @selector(configChanged:)
790 name: NSControlTextDidChangeNotification
791 object: o_combo_box];
793 if ( psz_duptip != NULL )
795 [o_combo_box setToolTip: [[VLCMain sharedInstance] wrapString: [[VLCMain sharedInstance] localizedString: psz_duptip] toWidth: PREFS_WRAP]];
797 [o_view addSubview: [o_combo_box autorelease]];
799 for( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++ )
802 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
803 [o_combo_box addItemWithObjectValue: [[VLCMain sharedInstance] localizedString:vlc_keys[i].psz_key_string]];
806 [o_combo_box setStringValue: [[VLCMain sharedInstance] localizedString:KeyToString(( ((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
808 s_rc.origin.y += s_rc.size.height;
809 s_rc.origin.x = X_ORIGIN;
810 if( psz_duptip ) free( psz_duptip );
816 #undef INPUT_FIELD_INTEGER
817 #undef INPUT_FIELD_FLOAT
818 #undef INPUT_FIELD_STRING
820 #undef CHECK_VIEW_HEIGHT
825 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
826 vlc_object_release( p_parser );
827 vlc_list_release( p_list );
829 [o_prefs_view setDocumentView: o_view];
830 [o_prefs_view setNeedsDisplay: TRUE];
836 @implementation VLCPrefs (NSTableDataSource)
838 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
839 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
842 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
843 return (item == nil) ? YES : ([item numberOfChildren] != -1);
846 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
847 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
850 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
851 return (item == nil) ? @"" : (id)[item getName];
856 @implementation VLCTreeItem
858 static VLCTreeItem *o_root_item = nil;
860 #define IsALeafNode ((id)-1)
862 - (id)initWithName: (NSString *)o_item_name ID: (int)i_id parent:(VLCTreeItem *)o_parent_item
868 o_name = [o_item_name copy];
870 o_parent = o_parent_item;
875 + (VLCTreeItem *)rootItem {
876 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithName:@"main" ID: 0 parent:nil];
882 if (o_children != IsALeafNode) [o_children release];
887 /* Creates and returns the array of children
888 * Loads children incrementally */
889 - (NSArray *)children {
890 if (o_children == NULL) {
891 intf_thread_t *p_intf = VLCIntf;
893 module_t *p_module = NULL;
894 module_config_t *p_item;
897 /* List the modules */
898 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
899 if( !p_list ) return nil;
901 if( [[self getName] isEqualToString: @"main"] )
904 * Build a tree of the main options
906 for( i_index = 0; i_index < p_list->i_count; i_index++ )
908 p_module = (module_t *)p_list->p_values[i_index].p_object;
909 if( !strcmp( p_module->psz_object_name, "main" ) )
912 if( p_module == NULL )
914 msg_Err( p_intf, "could not find the main module in our preferences" );
917 if( i_index < p_list->i_count )
919 /* We found the main module */
921 /* Enumerate config categories and store a reference so we can
922 * generate their config panel them when it is asked by the user. */
923 p_item = p_module->p_config;
924 o_children = [[NSMutableArray alloc] initWithCapacity:10];
928 NSString *o_child_name;
930 switch( p_item->i_type )
932 case CONFIG_HINT_CATEGORY:
933 o_child_name = [[VLCMain sharedInstance] localizedString: p_item->psz_text];
934 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_child_name
935 ID: p_module->i_object_id parent:self]];
939 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
941 /* Add the modules item */
942 [o_children addObject:[[VLCTreeItem alloc] initWithName: _NS("Modules")
947 o_children = IsALeafNode;
950 else if( [[self getName] isEqualToString: _NS("Modules")] )
952 /* Add the capabilities */
953 o_children = [[NSMutableArray alloc] initWithCapacity:10];
954 for( i_index = 0; i_index < p_list->i_count; i_index++ )
956 p_module = (module_t *)p_list->p_values[i_index].p_object;
958 /* Exclude the main module */
959 if( !strcmp( p_module->psz_object_name, "main" ) )
962 /* Exclude empty modules */
963 p_item = p_module->p_config;
964 if( !p_item ) continue;
967 if( p_item->i_type & CONFIG_ITEM )
970 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
971 if( p_item->i_type == CONFIG_HINT_END ) continue;
973 /* Create the capability tree if it doesn't already exist */
974 NSString *o_capability;
975 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
976 if( !p_module->psz_capability || !*p_module->psz_capability )
978 /* Empty capability ? Let's look at the submodules */
979 module_t * p_submodule;
980 for( j = 0; j < p_module->i_children; j++ )
982 p_submodule = (module_t*)p_module->pp_children[ j ];
983 if( p_submodule->psz_capability && *p_submodule->psz_capability )
985 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
986 BOOL b_found = FALSE;
987 for( j = 0; j < (int)[o_children count]; j++ )
989 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
997 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1004 BOOL b_found = FALSE;
1005 for( j = 0; j < (int)[o_children count]; j++ )
1007 if( [[[o_children objectAtIndex:j] getName] isEqualToString: o_capability] )
1015 [o_children addObject:[[VLCTreeItem alloc] initWithName: o_capability
1016 ID: 0 parent:self]];
1020 else if( [[o_parent getName] isEqualToString: _NS("Modules")] )
1022 /* Now add the modules */
1023 o_children = [[NSMutableArray alloc] initWithCapacity:10];
1024 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1026 p_module = (module_t *)p_list->p_values[i_index].p_object;
1028 /* Exclude the main module */
1029 if( !strcmp( p_module->psz_object_name, "main" ) )
1032 /* Exclude empty modules */
1033 p_item = p_module->p_config;
1034 if( !p_item ) continue;
1037 if( p_item->i_type & CONFIG_ITEM )
1040 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
1041 if( p_item->i_type == CONFIG_HINT_END ) continue;
1043 /* Check the capability */
1044 NSString *o_capability;
1045 o_capability = [[VLCMain sharedInstance] localizedString: p_module->psz_capability];
1046 if( !p_module->psz_capability || !*p_module->psz_capability )
1048 /* Empty capability ? Let's look at the submodules */
1049 module_t * p_submodule;
1050 for( j = 0; j < p_module->i_children; j++ )
1052 p_submodule = (module_t*)p_module->pp_children[ j ];
1053 if( p_submodule->psz_capability && *p_submodule->psz_capability )
1055 o_capability = [[VLCMain sharedInstance] localizedString: p_submodule->psz_capability];
1056 if( [o_capability isEqualToString: [self getName]] )
1058 [o_children addObject:[[VLCTreeItem alloc] initWithName:
1059 [[VLCMain sharedInstance] localizedString: p_module->psz_object_name ]
1060 ID: p_module->i_object_id parent:self]];
1065 else 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]];
1075 /* all the other stuff are leafs */
1076 o_children = IsALeafNode;
1078 vlc_list_release( p_list );
1088 - (NSString *)getName
1093 - (VLCTreeItem *)childAtIndex:(int)i_index {
1094 return [[self children] objectAtIndex:i_index];
1097 - (int)numberOfChildren {
1098 id i_tmp = [self children];
1099 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];
1102 - (BOOL)hasPrefs:(NSString *)o_module_name
1104 intf_thread_t *p_intf = VLCIntf;
1107 char *psz_module_name;
1110 psz_module_name = (char *)[o_module_name UTF8String];
1112 /* look for module */
1113 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1115 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1117 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1119 if( !strcmp( p_parser->psz_object_name, psz_module_name ) )
1121 BOOL b_has_prefs = p_parser->i_config_items != 0;
1122 vlc_list_release( p_list );
1123 return( b_has_prefs );
1127 vlc_list_release( p_list );
1135 @implementation VLCFlippedView
1144 IMPL_CONTROL_CONFIG(Button);
1145 IMPL_CONTROL_CONFIG(PopUpButton);
1146 IMPL_CONTROL_CONFIG(ComboBox);
1147 IMPL_CONTROL_CONFIG(TextField);
1148 IMPL_CONTROL_CONFIG(Slider);
1149 IMPL_CONTROL_CONFIG(Matrix);