1 /*****************************************************************************
2 * prefs.m: MacOS X module for vlc
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
5 * $Id: prefs.m,v 1.39 2004/02/02 08:50:41 titer Exp $
7 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8 * Derk-Jan Hartman <hartman at videolan.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() */
37 #define GENERAL_ID 1242
38 #define MODULE_ID 1243
39 #define CAPABILITY_ID 1244
41 /*****************************************************************************
42 * GetCapabilityHelp: Display the help for one capability.
43 *****************************************************************************/
44 static char * GetCapabilityHelp( char *psz_capability, int i_type)
46 if( psz_capability == NULL) return "";
48 if( !strcasecmp(psz_capability,"access") )
49 return i_type == 1 ? ACCESS_TITLE : ACCESS_HELP;
50 if( !strcasecmp(psz_capability,"audio filter") )
51 return i_type == 1 ? AUDIO_FILTER_TITLE : AUDIO_FILTER_HELP;
52 if( !strcasecmp(psz_capability,"audio output") )
53 return i_type == 1 ? AOUT_TITLE : AOUT_HELP;
54 if( !strcasecmp(psz_capability,"audio encoder") )
55 return i_type == 1 ? AOUT_ENC_TITLE : AOUT_ENC_HELP;
56 if( !strcasecmp(psz_capability,"chroma") )
57 return i_type == 1 ? CHROMA_TITLE : CHROMA_HELP;
58 if( !strcasecmp(psz_capability,"decoder") )
59 return i_type == 1 ? DECODER_TITLE : DECODER_HELP;
60 if( !strcasecmp(psz_capability,"demux") )
61 return i_type == 1 ? DEMUX_TITLE : DEMUX_HELP;
62 if( !strcasecmp(psz_capability,"interface") )
63 return i_type == 1 ? INTERFACE_TITLE : INTERFACE_HELP;
64 if( !strcasecmp(psz_capability,"sout access") )
65 return i_type == 1 ? SOUT_TITLE : SOUT_HELP;
66 if( !strcasecmp(psz_capability,"subtitle demux") )
67 return i_type == 1 ? SUBTITLE_DEMUX_TITLE : SUBTITLE_DEMUX_HELP;
68 if( !strcasecmp(psz_capability,"text renderer") )
69 return i_type == 1 ? TEXT_TITLE : TEXT_HELP;
70 if( !strcasecmp(psz_capability,"video output") )
71 return i_type == 1 ? VOUT__TITLE : VOUT_HELP;
72 if( !strcasecmp(psz_capability,"video filter") )
73 return i_type == 1 ? VIDEO_FILTER_TITLE : VIDEO_FILTER_HELP;
78 /*****************************************************************************
79 * VLCPrefs implementation
80 *****************************************************************************/
81 @implementation VLCPrefs
89 o_empty_view = [[[NSView alloc] init] retain];
97 [o_empty_view release];
103 p_intf = [NSApp getIntf];
104 b_advanced = config_GetInt( p_intf, "advanced" );
107 [o_advanced_ckb setState: b_advanced];
108 [o_prefs_view setBorderType: NSGrooveBorder];
109 [o_prefs_view setHasVerticalScroller: YES];
110 [o_prefs_view setDrawsBackground: NO];
111 [o_prefs_view setRulersVisible: NO];
112 [o_prefs_view setDocumentView: o_empty_view];
113 [o_tree selectRow:0 byExtendingSelection:NO];
114 [o_tree expandItem:[o_tree itemAtRow:0]];
119 [o_prefs_window setTitle: _NS("Preferences")];
120 [o_save_btn setTitle: _NS("Save")];
121 [o_cancel_btn setTitle: _NS("Cancel")];
122 [o_reset_btn setTitle: _NS("Reset All")];
123 [o_advanced_ckb setTitle: _NS("Advanced")];
128 // show first tree item
129 [[o_prefs_view window] center];
130 [[o_prefs_view window] makeKeyAndOrderFront:self];
133 - (IBAction)savePrefs: (id)sender
135 // walk trough all treeitems and tell them all to save
136 config_SaveConfigFile( p_intf, NULL );
137 [o_prefs_window orderOut:self];
140 - (IBAction)closePrefs: (id)sender
142 [o_prefs_window orderOut:self];
145 - (IBAction)resetAll: (id)sender
147 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"), _NS("Continue"),
148 nil, o_prefs_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
149 _NS("Beware this will reset your VLC media player preferences.\n"
150 "Are you sure you want to continue?") );
153 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context
155 if( i_return == NSAlertAlternateReturn )
157 config_ResetAll( p_intf );
158 // show first config treeitem
162 - (IBAction)advancedToggle: (id)sender
164 b_advanced = !b_advanced;
165 [o_advanced_ckb setState: b_advanced];
166 // walk trough all treeitems and set advanced state
169 - (void)outlineViewSelectionDidChange:(NSNotification *)o_notification
171 // a tree item will be shown
174 - (void)showViewForID:(int)i_id
180 @implementation VLCPrefs (NSTableDataSource)
182 - (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
183 return (item == nil) ? [[VLCTreeItem rootItem] numberOfChildren] : [item numberOfChildren];
186 - (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
187 return (item == nil) ? YES : ([item numberOfChildren] >= 0);
190 - (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item {
191 return (item == nil) ? [[VLCTreeItem rootItem] childAtIndex:index] : [item childAtIndex:index];
194 - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
195 return (item == nil) ? @"" : (id)[item name];
200 @implementation VLCTreeItem
202 static VLCTreeItem *o_root_item = nil;
204 #define IsALeafNode ((id)-1)
206 - (id)initWithID: (int)i_id parent: (VLCTreeItem *)o_parent_item
213 o_parent = o_parent_item;
218 + (VLCTreeItem *)rootItem {
219 if (o_root_item == nil) o_root_item = [[VLCTreeItem alloc] initWithID: ROOT_ID parent:nil];
225 if( psz_help ) free( psz_help );
226 if( psz_section ) free( psz_section );
227 if (o_name) [o_name release];
228 if (o_children != IsALeafNode) [o_children release];
232 /* Creates and returns the array of children
233 * Loads children incrementally */
234 - (NSArray *)children
236 if (o_children == NULL)
238 intf_thread_t *p_intf = [NSApp getIntf];
239 vlc_list_t *p_list = NULL;
240 module_t *p_module = NULL;
241 module_config_t *p_item = NULL;
244 /* List the modules */
245 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
246 if( !p_list ) return nil;
248 if( [self objectID] == ROOT_ID )
250 /* Create the General Settings and Modules items */
251 o_children = [[NSMutableArray alloc] initWithCapacity:2];
253 [o_children addObject:[[VLCTreeItem alloc] initWithID: GENERAL_ID parent:self]];
254 [o_children addObject:[[VLCTreeItem alloc] initWithID: MODULE_ID parent:self]];
257 else if( [self objectID] == GENERAL_ID )
260 * Build a tree of the main options
262 o_name = [_NS("General Settings") copy];
263 psz_help = strdup( GENERAL_HELP );
264 psz_section = strdup( GENERAL_TITLE );
266 for( i_index = 0; i_index < p_list->i_count; i_index++ )
268 p_module = (module_t *)p_list->p_values[i_index].p_object;
269 if( !strcmp( p_module->psz_object_name, "main" ) )
272 if( p_module == NULL )
274 msg_Err( p_intf, "could not find the main module in our preferences" );
277 if( i_index < p_list->i_count )
279 /* Enumerate config categories and store a reference so we can
280 * generate their config panel them when it is asked by the user. */
281 p_item = p_module->p_config;
282 o_children = [[NSMutableArray alloc] initWithCapacity:10];
288 switch( p_item->i_type )
290 case CONFIG_HINT_CATEGORY:
291 o_now = [[VLCTreeItem alloc] initWithID: p_module->i_object_id parent:self];
292 [o_now setName: [[NSApp localizedString: p_item->psz_text] retain]];
293 [o_children addObject: o_now];
297 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
299 //[o_children sortUsingSelector:@selector(caseInsensitiveCompare:)];
302 else if( [self objectID] == MODULE_ID )
308 /* Build a list of the capabilities */
309 o_name = [_NS("Modules") copy];
310 psz_help = strdup( PLUGIN_HELP );
311 psz_section = strdup( PLUGIN_TITLE );
313 o_children = [[NSMutableArray alloc] initWithCapacity:10];
314 for( i_index = 0; i_index < p_list->i_count; i_index++ )
316 p_module = (module_t *)p_list->p_values[i_index].p_object;
318 /* Exclude the main module */
319 if( !strcmp( p_module->psz_object_name, "main" ) )
322 /* Exclude empty modules */
323 if( p_module->b_submodule )
324 p_item = ((module_t *)p_module->p_parent)->p_config;
326 p_item = p_module->p_config;
328 if( !p_item ) continue;
331 if( p_item->i_type & CONFIG_ITEM )
334 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
335 if( p_item->i_type == CONFIG_HINT_END ) continue;
337 i_total = [o_children count];
340 for( i_counter = 0; i_counter < i_total; i_counter++ )
342 if( [[[o_children objectAtIndex: i_counter] name] isEqualToString:
343 [NSApp localizedString: p_module->psz_capability]] )
352 VLCTreeItem *o_now = [[VLCTreeItem alloc] initWithID: CAPABILITY_ID parent:self];
353 [o_now setName: [NSApp localizedString: p_module->psz_capability]];
354 [o_children addObject:o_now];
358 //[o_children sortUsingSelector:@selector(caseInsensitiveCompare:)];
360 else if( [self objectID] == CAPABILITY_ID )
362 /* add the modules */
363 o_children = [[NSMutableArray alloc] initWithCapacity:3];
364 for( i_index = 0; i_index < p_list->i_count; i_index++ )
366 p_module = (module_t *)p_list->p_values[i_index].p_object;
368 /* Exclude the main module */
369 if( !strcmp( p_module->psz_object_name, "main" ) )
372 /* Exclude empty modules */
373 if( p_module->b_submodule )
374 p_item = ((module_t *)p_module->p_parent)->p_config;
376 p_item = p_module->p_config;
378 if( !p_item ) continue;
381 if( p_item->i_type & CONFIG_ITEM )
384 while( p_item->i_type != CONFIG_HINT_END && p_item++ );
385 if( p_item->i_type == CONFIG_HINT_END ) continue;
387 if( [[self name] isEqualToString:
388 [NSApp localizedString: p_module->psz_capability]] )
390 VLCTreeItem *o_now = [[VLCTreeItem alloc] initWithID: p_module->i_object_id parent:self];
391 psz_help = strdup(GetCapabilityHelp( p_module->psz_capability, 1));
392 psz_section = strdup(GetCapabilityHelp( p_module->psz_capability, 2));
393 [o_now setName: [[NSApp localizedString:p_module->psz_object_name] retain]];
394 [o_children addObject:o_now];
401 /* all the other stuff are leafs */
402 o_children = IsALeafNode;
415 if( o_name ) return o_name;
418 - (void)setName:(NSString *)a_name;
420 if( o_name ) [o_name release];
421 o_name = [a_name copy];
424 - (VLCTreeItem *)childAtIndex:(int)i_index
426 return [[self children] objectAtIndex:i_index];
429 - (int)numberOfChildren
431 id i_tmp = [self children];
432 return (i_tmp == IsALeafNode) ? (-1) : (int)[i_tmp count];