]> git.sesse.net Git - vlc/blob - modules/gui/macosx/simple_prefs.m
For some reason, the OSX interface uses intf_UserFatal...
[vlc] / modules / gui / macosx / simple_prefs.m
1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
5 * $Id$
6 *
7 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
23
24 #import "simple_prefs.h"
25 #import "prefs.h"
26 #import <vlc_keys.h>
27 #import <vlc_interface.h>
28 #import <vlc_dialog.h>
29 #import "misc.h"
30
31 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
32 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
33 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
34 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
35 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
36 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
37 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
38
39 @implementation VLCSimplePrefs
40
41 static VLCSimplePrefs *_o_sharedInstance = nil;
42
43 + (VLCSimplePrefs *)sharedInstance
44 {
45     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
46 }
47
48 - (id)init
49 {
50     if (_o_sharedInstance) {
51         [self dealloc];
52     } else {
53         _o_sharedInstance = [super init];
54         p_intf = VLCIntf;
55     }
56
57     return _o_sharedInstance;
58 }
59
60 - (void)dealloc
61 {
62     [o_currentlyShownCategoryView release];
63
64     [o_hotkeySettings release];
65     [o_hotkeyDescriptions release];
66     [o_hotkeysNonUseableKeys release];
67
68     [o_keyInTransition release];
69
70     [super dealloc];
71 }
72
73
74 - (NSString *)OSXKeyToString:(int)val
75 {
76     NSMutableString *o_temp_str = [[[NSMutableString alloc] init] autorelease];
77     if( val & KEY_MODIFIER_CTRL )
78         [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
79     if( val & KEY_MODIFIER_ALT )
80         [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
81     if( val & KEY_MODIFIER_SHIFT )
82         [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
83     if( val & KEY_MODIFIER_COMMAND )
84         [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
85
86     const char *base = KeyToString( val & ~KEY_MODIFIER );
87     if( base )
88         [o_temp_str appendString: [NSString stringWithUTF8String: base]];
89     else
90         o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
91     return o_temp_str;
92 }
93
94 - (void)awakeFromNib
95 {
96     [self initStrings];
97     
98     /* setup the toolbar */
99     NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
100     [o_sprefs_toolbar setAllowsUserCustomization: NO];
101     [o_sprefs_toolbar setAutosavesConfiguration: NO];
102     [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
103     [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
104     [o_sprefs_toolbar setDelegate: self];
105     [o_sprefs_win setToolbar: o_sprefs_toolbar];
106     
107     /* setup useful stuff */
108     o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
109                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
110                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
111                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
112                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
113                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
114                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
115                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
116                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
117                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
118                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
119                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
120                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
121                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
122                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
123                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
124                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
125                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
126                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
127                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
128                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
129                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
130                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
131                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
132                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
133                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
134                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
135                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
136                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
137                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
138                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
139                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
140                                 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
141                                 nil] retain];
142 }
143
144 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
145     o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
146 static inline NSToolbarItem *
147 create_toolbar_item( NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector )
148 {
149     NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
150
151     [o_toolbarItem setLabel: o_name];
152     [o_toolbarItem setPaletteLabel: o_desc];
153
154     [o_toolbarItem setToolTip: o_desc];
155     [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
156
157     [o_toolbarItem setTarget: target];
158     [o_toolbarItem setAction: selector];
159
160     [o_toolbarItem setEnabled: YES];
161     [o_toolbarItem setAutovalidates: YES];
162
163     return o_toolbarItem;
164 }
165
166 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar 
167       itemForItemIdentifier: (NSString *)o_itemIdent 
168   willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
169 {
170     NSToolbarItem *o_toolbarItem = nil;
171
172     if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
173     {
174         CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
175     }
176     else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
177     {
178         CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
179     }
180     else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
181     {
182         CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
183     }
184     else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
185     {
186         CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
187     }
188     else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
189     {
190         CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
191     }
192     else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
193     {
194         CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
195     }
196
197     return o_toolbarItem;
198 }
199
200 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
201 {
202     return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier, 
203         VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
204 }
205
206 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
207 {
208     return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier, 
209         VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
210 }
211
212 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
213 {
214     return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier, 
215         VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
216 }
217
218 - (void)initStrings
219 {
220     /* audio */
221     [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
222     [o_audio_effects_box setTitle: _NS("Effects")];
223     [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
224     [o_audio_general_box setTitle: _NS("General Audio")];
225     [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
226     [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
227     [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
228     [o_audio_lastpwd_txt setStringValue: _NS("Password")];
229     [o_audio_lastuser_txt setStringValue: _NS("User name")];
230     [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
231     [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
232     [o_audio_visual_txt setStringValue: _NS("Visualization")];
233     [o_audio_vol_txt setStringValue: _NS("Default Volume")];
234
235     /* hotkeys */
236     [o_hotkeys_change_btn setTitle: _NS("Change")];
237     [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
238     [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
239     [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
240     [o_hotkeys_clear_btn setTitle: _NS("Clear")];
241     [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
242     [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
243     [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
244
245     /* input */
246     [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
247     [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
248     [o_input_caching_box setTitle: _NS("Caching")];
249     [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
250     [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
251     [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
252     [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
253     [o_input_net_box setTitle: _NS("Network")];
254     [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
255     [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
256     [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
257
258     /* interface */
259     [o_intf_art_txt setStringValue: _NS("Album art download policy")];
260     [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
261     [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
262     [o_intf_lang_txt setStringValue: _NS("Language")];
263     [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
264     
265     /* Subtitles and OSD */
266     [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
267     [o_osd_font_box setTitle: _NS("Display Settings")];
268     [o_osd_font_btn setTitle: _NS("Choose...")];
269     [o_osd_font_color_txt setStringValue: _NS("Font Color")];
270     [o_osd_font_size_txt setStringValue: _NS("Font Size")];
271     [o_osd_font_txt setStringValue: _NS("Font")];
272     [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
273     [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
274     [o_osd_osd_box setTitle: _NS("On Screen Display")];
275     [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
276
277     /* video */
278     [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
279     [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
280     [o_video_display_box setTitle: _NS("Display")];
281     [o_video_enable_ckb setTitle: _NS("Enable Video")];
282     [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
283     [o_video_onTop_ckb setTitle: _NS("Always on top")];
284     [o_video_output_txt setStringValue: _NS("Output module")];
285     [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
286     [o_video_snap_box setTitle: _NS("Video snapshots")];
287     [o_video_snap_folder_btn setTitle: _NS("Browse...")];
288     [o_video_snap_folder_txt setStringValue: _NS("Folder")];
289     [o_video_snap_format_txt setStringValue: _NS("Format")];
290     [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
291     [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
292     
293     /* generic stuff */
294     [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
295     [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
296     [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
297     [o_sprefs_reset_btn setTitle: _NS("Reset All")];
298     [o_sprefs_save_btn setTitle: _NS("Save")];
299     [o_sprefs_win setTitle: _NS("Preferences")];
300 }
301
302 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
303 {
304     module_config_t *p_item;
305
306     [object removeAllItems];
307     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
308
309     /* serious problem, if no item found */
310     assert( p_item );
311
312     for( int i = 0; i < p_item->i_list; i++ )
313     {
314         NSMenuItem *mi;
315         if( p_item->ppsz_list_text != NULL )
316             mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
317         else if( p_item->ppsz_list[i] && p_item->ppsz_list[i] == "" )
318         {
319             [[object menu] addItem: [NSMenuItem separatorItem]];
320             continue;
321         }
322         else if( p_item->ppsz_list[i] )
323             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
324         else NSLog( @"item %d of pref %s failed to be created", i, name);
325         [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
326         [[object menu] addItem: [mi autorelease]];
327         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
328             [object selectItem:[object lastItem]];
329     }
330     [object setToolTip: _NS( p_item->psz_longtext )];
331 }
332
333 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
334 {
335     module_config_t *p_item;
336
337     [object removeAllItems];
338     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
339
340     /* serious problem, if no item found */
341     assert( p_item );
342
343     for( int i = 0; i < p_item->i_list; i++ )
344     {
345         NSMenuItem *mi;
346         if( p_item->ppsz_list_text != NULL)
347             mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
348         else if( p_item->pi_list[i] )
349             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
350         else NSLog( @"item %d of pref %s failed to be created", i, name);
351         [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
352         [[object menu] addItem: [mi autorelease]];
353         if( p_item->value.i == p_item->pi_list[i] )
354             [object selectItem:[object lastItem]];
355     }
356     [object setToolTip: _NS( p_item->psz_longtext )];
357 }
358
359 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
360 {
361     module_config_t *p_item;
362     module_t *p_parser, **p_list;
363     int y = 0;
364     
365     [object removeAllItems];
366     
367     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
368     p_list = module_list_get( NULL );
369     if( !p_item ||!p_list )
370     {
371         if( p_list ) module_list_free(p_list);
372         NSLog( @"serious problem, item or list not found" );
373         return;
374     }
375
376     [object addItemWithTitle: _NS("Default")];
377     for( size_t i_index = 0; p_list[i_index]; i_index++ )
378     {
379         p_parser = p_list[i_index];
380         if( module_provides( p_parser, p_item->psz_type ) )
381         {
382             [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
383             if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
384                 [object selectItem: [object lastItem]];
385         }
386     }
387     module_list_free( p_list );
388     [object setToolTip: _NS(p_item->psz_longtext)];
389 }
390
391 - (void)resetControls
392 {
393     module_config_t *p_item;
394     int i, y = 0;
395     char *psz_tmp;
396
397     [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
398     [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
399     
400     /**********************
401      * interface settings *
402      **********************/
403     [self setupButton: o_intf_lang_pop forStringList: "language"];
404     [self setupButton: o_intf_art_pop forIntList: "album-art"];
405
406     [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
407     [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
408
409     /******************
410      * audio settings *
411      ******************/
412     [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
413     [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
414     [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
415
416     [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
417
418     [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
419
420     [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" ) ?: ""]];
421
422     [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
423     
424     psz_tmp = config_GetPsz( p_intf, "audio-filter" );
425     if( psz_tmp )
426     {
427         [o_audio_norm_ckb setState: (NSInteger)strstr( psz_tmp, "volnorm" )];
428         [o_audio_norm_fld setEnabled: [o_audio_norm_ckb state]];
429         [o_audio_norm_stepper setEnabled: [o_audio_norm_ckb state]];
430     }
431     [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
432
433     [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
434
435     /* Last.FM is optional */
436     if( module_exists( "audioscrobbler" ) )
437     {
438         [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" ) ?: ""]];
439         [o_audio_lastpwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" ) ?: ""]];
440
441         if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
442         {
443             [o_audio_last_ckb setState: NSOnState];
444             [o_audio_lastuser_fld setEnabled: YES];
445             [o_audio_lastpwd_sfld setEnabled: YES];
446         }
447         else
448         {
449             [o_audio_last_ckb setState: NSOffState];
450             [o_audio_lastuser_fld setEnabled: NO];
451             [o_audio_lastpwd_sfld setEnabled: NO];
452         }
453     }
454     else
455         [o_audio_last_ckb setEnabled: NO];
456
457     /******************
458      * video settings *
459      ******************/
460     [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
461     [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
462     [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
463     [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
464     [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
465
466     [self setupButton: o_video_output_pop forModuleList: "vout"];
467
468     [o_video_device_pop removeAllItems];
469     i = 0;
470     y = [[NSScreen screens] count];
471     [o_video_device_pop addItemWithTitle: _NS("Default")];
472     [[o_video_device_pop lastItem] setTag: 0];
473     while( i < y )
474     {
475         NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
476         [o_video_device_pop addItemWithTitle: 
477          [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
478                    (int)s_rect.size.width, (int)s_rect.size.height]];
479         [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
480         i++;
481     }
482     [o_video_device_pop selectItemAtIndex: 0];
483     [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
484
485     [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" ) ?: ""]];
486     [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" ) ?: ""]];
487     [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
488     [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
489
490     /***************************
491      * input & codecs settings *
492      ***************************/
493     [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
494     if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
495         [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" ) ?: ""]];
496     if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
497         [o_input_httpproxypwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy-pwd" ) ?: ""]];
498     [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
499
500     [self setupButton: o_input_avi_pop forIntList: "avi-index"];
501
502     [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
503
504     [o_input_cachelevel_pop removeAllItems];
505     [o_input_cachelevel_pop addItemsWithTitles: 
506         [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
507             _NS("High latency"), _NS("Higher latency"), nil]];
508     [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
509     [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
510     [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
511     [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
512     [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
513     [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
514     
515 #define TestCaC( name ) \
516     b_cache_equal =  b_cache_equal && \
517         ( i_cache == config_GetInt( p_intf, name ) )
518
519 #define TestCaCi( name, int ) \
520         b_cache_equal = b_cache_equal &&  \
521         ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
522
523     /* Select the accurate value of the PopupButton */
524     bool b_cache_equal = true;
525     int i_cache = config_GetInt( p_intf, "file-caching");
526     
527     TestCaC( "udp-caching" );
528     if( module_exists ("dvdread") )
529         TestCaC( "dvdread-caching" );
530     if( module_exists ("dvdnav") )
531         TestCaC( "dvdnav-caching" );
532     TestCaC( "tcp-caching" );
533     TestCaC( "fake-caching" );
534     TestCaC( "cdda-caching" );
535     TestCaC( "screen-caching" );
536     TestCaC( "vcd-caching" );
537     TestCaCi( "rtsp-caching", 4 );
538     TestCaCi( "ftp-caching", 2 );
539     TestCaCi( "http-caching", 4 );
540     if(module_exists ("access_realrtsp"))
541         TestCaCi( "realrtsp-caching", 10 );
542     TestCaCi( "mms-caching", 19 );
543     if( b_cache_equal )
544     {
545         [o_input_cachelevel_pop selectItemWithTag: i_cache];
546         [o_input_cachelevel_custom_txt setHidden: YES];
547     }
548     else
549     {
550         [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
551         [o_input_cachelevel_custom_txt setHidden: NO];
552     }
553
554     /*********************
555      * subtitle settings *
556      *********************/
557     [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
558     
559     [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
560     
561     [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" ) ?: ""]];
562     if( config_GetPsz( p_intf, "quartztext-font" ) != NULL )
563         [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "quartztext-font" ) ?: ""]];
564
565     [self setupButton: o_osd_font_color_pop forIntList: "quartztext-color"];
566     [self setupButton: o_osd_font_size_pop forIntList: "quartztext-rel-fontsize"];
567
568     /********************
569      * hotkeys settings *
570      ********************/
571     struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
572     o_hotkeySettings = [[NSMutableArray alloc] init];
573     NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
574     i = 1;
575
576     while( i < 100 )
577     {
578         p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
579         if( !p_item )
580             break;
581
582         [o_tempArray_desc addObject: _NS( p_item->psz_text )];
583         [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
584
585         i++;
586     }
587     o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
588     [o_tempArray_desc release];
589     [o_hotkeys_listbox reloadData];
590 }
591
592 - (void)showSimplePrefs
593 {
594     /* we want to show the interface settings, if no category was chosen */
595     if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
596     {
597         [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
598         [self showInterfaceSettings];
599     }
600     
601     [self resetControls];
602
603     [o_sprefs_win center];
604     [o_sprefs_win makeKeyAndOrderFront: self];
605 }
606
607 - (IBAction)buttonAction:(id)sender
608 {
609     if( sender == o_sprefs_cancel_btn )
610         [o_sprefs_win orderOut: sender];
611     else if( sender == o_sprefs_save_btn )
612     {
613         [self saveChangedSettings];
614         [o_sprefs_win orderOut: sender];
615     }
616     else if( sender == o_sprefs_reset_btn )
617         NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
618                                         _NS("Continue"), nil, o_sprefs_win, self,
619                                         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
620                                         _NS("Beware this will reset the VLC media player preferences.\n"
621                                             "Are you sure you want to continue?") );
622     else if( sender == o_sprefs_basicFull_matrix )
623     {
624         [o_sprefs_win orderOut: self];
625         [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
626         [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
627         [[[VLCMain sharedInstance] getPreferences] showPrefs];
628     }
629     else
630         msg_Warn( p_intf, "unknown buttonAction sender" );
631 }
632
633 - (void)sheetDidEnd:(NSWindow *)o_sheet 
634          returnCode:(int)i_return
635         contextInfo:(void *)o_context
636 {
637     if( i_return == NSAlertAlternateReturn )
638     {
639         config_ResetAll( p_intf );
640         [self resetControls];
641         config_SaveConfigFile( p_intf, NULL );
642     }
643 }
644
645 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
646 {
647     NSNumber *p_valueobject;
648     module_config_t *p_item;
649     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
650     p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
651     assert([p_valueobject isKindOfClass:[NSNumber class]]);
652     if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
653 }
654
655 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
656 {
657     NSString *p_stringobject;
658     module_config_t *p_item;
659     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
660     p_stringobject = (NSString *)[[object selectedItem] representedObject];
661     assert([p_stringobject isKindOfClass:[NSString class]]);
662     if( p_stringobject ) config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
663 }
664
665 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
666 {
667     module_config_t *p_item;
668     module_t *p_parser, **p_list;
669
670     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
671
672     p_list = module_list_get( NULL );
673     for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
674     {
675         p_parser = p_list[i_module_index];
676
677         if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
678         {
679             if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
680             {
681                 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
682                 break;
683             }
684         }
685     }
686     module_list_free( p_list );
687     if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
688         config_PutPsz( p_intf, name, "" );
689 }
690
691 - (void)saveChangedSettings
692 {
693     char *psz_tmp;
694     int i;
695     NSString *p_stringobject;
696     
697 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
698                     
699 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
700
701 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
702
703     /**********************
704      * interface settings *
705      **********************/
706     if( b_intfSettingChanged )
707     {
708         SaveStringList( o_intf_lang_pop, "language" );
709         SaveIntList( o_intf_art_pop, "album-art" );
710
711         config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
712         config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
713
714         /* okay, let's save our changes to vlcrc */
715         i = config_SaveConfigFile( p_intf, "main" );
716         i = i + config_SaveConfigFile( p_intf, "macosx" );
717
718         if( i != 0 )
719         {
720             msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
721             dialog_Fatal( p_intf, _("Interface Settings not saved"),
722                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
723             i = 0;
724         }
725
726         b_intfSettingChanged = NO;
727     }
728     
729     /******************
730      * audio settings *
731      ******************/
732     if( b_audioSettingChanged )
733     {
734         config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
735         config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
736         config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
737
738         SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
739
740         config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
741         config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
742
743         if( [o_audio_norm_ckb state] == NSOnState )
744         {
745             psz_tmp = config_GetPsz( p_intf, "audio-filter" );
746             if(! psz_tmp)
747                 config_PutPsz( p_intf, "audio-filter", "volnorm" );
748             else if( (NSInteger)strstr( psz_tmp, "normvol" ) == NO )
749             {
750                 /* work-around a GCC 4.0.1 bug */
751                 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
752                 config_PutPsz( p_intf, "audio-filter", psz_tmp );
753             }
754         }
755         else
756         {
757             psz_tmp = config_GetPsz( p_intf, "audio-filter" );
758             if( psz_tmp )
759             {
760                 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
761                 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
762                 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
763                 config_PutPsz( p_intf, "audio-filter", psz_tmp );
764             }
765         }
766         config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
767
768         SaveModuleList( o_audio_visual_pop, "audio-visual" );
769
770         /* Last.FM is optional */
771         if( module_exists( "audioscrobbler" ) )
772         {   
773             [o_audio_last_ckb setEnabled: YES];
774             if( [o_audio_last_ckb state] == NSOnState )
775                 config_AddIntf( p_intf, "audioscrobbler" );
776             else
777                 config_RemoveIntf( p_intf, "audioscrobbler" );
778
779             config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
780             config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
781         }
782         else
783             [o_audio_last_ckb setEnabled: NO];
784
785         /* okay, let's save our changes to vlcrc */
786         i = config_SaveConfigFile( p_intf, "main" );
787         i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
788         i = i + config_SaveConfigFile( p_intf, "volnorm" );
789
790         if( i != 0 )
791         {
792             msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
793             dialog_Fatal( p_intf, _("Audio Settings not saved"),
794                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
795             
796             i = 0;
797         }
798         b_audioSettingChanged = NO;
799     }
800     
801     /******************
802      * video settings *
803      ******************/
804     if( b_videoSettingChanged )
805     {
806         config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
807         config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
808         config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
809         config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
810         config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
811
812         SaveModuleList( o_video_output_pop, "vout" );
813         config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
814
815         config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
816         config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
817         config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
818         SaveStringList( o_video_snap_format_pop, "snapshot-format" );
819
820         i = config_SaveConfigFile( p_intf, "main" );
821         i = i + config_SaveConfigFile( p_intf, "macosx" );
822
823         if( i != 0 )
824         {
825             msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
826             dialog_Fatal( p_intf, _("Video Settings not saved"),
827                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
828             i = 0;
829         }
830         b_videoSettingChanged = NO;
831     }
832     
833     /***************************
834      * input & codecs settings *
835      ***************************/
836     if( b_inputSettingChanged )
837     {
838         config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
839         config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
840         config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
841         config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
842
843         SaveIntList( o_input_avi_pop, "avi-index" );
844
845         config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
846
847         #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
848         #define CaC( name ) CaCi( name, 1 )
849         msg_Dbg( p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag] );
850         CaC( "udp-caching" );
851         if( module_exists ( "dvdread" ) )
852         {
853             CaC( "dvdread-caching" );
854             i = i + config_SaveConfigFile( p_intf, "dvdread" );
855         }
856         if( module_exists ( "dvdnav" ) )
857         {
858             CaC( "dvdnav-caching" );
859             i = i + config_SaveConfigFile( p_intf, "dvdnav" );
860         }
861         CaC( "tcp-caching" ); CaC( "vcd-caching" );
862         CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
863         CaC( "screen-caching" );
864         CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
865         CaCi( "http-caching", 4 );
866         if( module_exists ( "access_realrtsp" ) )
867         {
868             CaCi( "realrtsp-caching", 10 );
869             i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
870         }
871         CaCi( "mms-caching", 19 );
872
873         i = config_SaveConfigFile( p_intf, "main" );
874         i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
875         i = i + config_SaveConfigFile( p_intf, "access_http" );
876         i = i + config_SaveConfigFile( p_intf, "access_file" );
877         i = i + config_SaveConfigFile( p_intf, "access_tcp" );
878         i = i + config_SaveConfigFile( p_intf, "access_fake" );
879         i = i + config_SaveConfigFile( p_intf, "cdda" );
880         i = i + config_SaveConfigFile( p_intf, "screen" );
881         i = i + config_SaveConfigFile( p_intf, "vcd" );
882         i = i + config_SaveConfigFile( p_intf, "access_ftp" );
883         i = i + config_SaveConfigFile( p_intf, "access_mms" );
884         i = i + config_SaveConfigFile( p_intf, "live555" );
885         i = i + config_SaveConfigFile( p_intf, "avi" );
886
887         if( i != 0 )
888         {
889             msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
890             dialog_Fatal( p_intf, _("Input Settings not saved"),
891                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
892             i = 0;
893         }
894         b_inputSettingChanged = NO;
895     }
896     
897     /**********************
898      * subtitles settings *
899      **********************/
900     if( b_osdSettingChanged )
901     {
902         config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
903
904         if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
905             config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
906
907         config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
908         config_PutPsz( p_intf, "quartztext-font", [[o_osd_font_fld stringValue] UTF8String] );
909
910         SaveIntList( o_osd_font_color_pop, "quartztext-color" );
911         SaveIntList( o_osd_font_size_pop, "quartztext-rel-fontsize" );
912
913         i = config_SaveConfigFile( p_intf, NULL );
914
915         if( i != 0 )
916         {
917             msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
918             dialog_Fatal( p_intf, _("On Screen Display/Subtitle Settings not saved"),
919                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
920             i = 0;
921         }
922         b_osdSettingChanged = NO;
923     }
924     
925     /********************
926      * hotkeys settings *
927      ********************/
928     if( b_hotkeyChanged )
929     {
930         struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
931         i = 1;
932         while( i < [o_hotkeySettings count] )
933         {
934             config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
935             i++;
936         }        
937
938         i = config_SaveConfigFile( p_intf, "main" );
939
940         if( i != 0 )
941         {
942             msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
943             dialog_Fatal( p_intf, _("Hotkeys not saved"),
944                         _("An error occured while saving your settings via SimplePrefs (%i)."), i );
945             i = 0;
946         }
947         b_hotkeyChanged = NO;
948     }
949 }
950
951 - (void)showSettingsForCategory: (id)o_new_category_view
952 {
953     NSRect o_win_rect, o_view_rect, o_old_view_rect;
954     o_win_rect = [o_sprefs_win frame];
955     o_view_rect = [o_new_category_view frame];
956     
957     if( o_currentlyShownCategoryView != nil )
958     {
959         /* restore our window's height, if we've shown another category previously */
960         o_old_view_rect = [o_currentlyShownCategoryView frame];
961         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
962         o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
963
964         /* remove our previous category view */
965         [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
966     }
967     
968     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
969     
970     [o_sprefs_win displayIfNeeded];
971     [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
972     
973     [o_new_category_view setFrame: NSMakeRect( 0, 
974                                                [o_sprefs_controls_box frame].size.height, 
975                                                o_view_rect.size.width, 
976                                                o_view_rect.size.height )];
977     [o_new_category_view setNeedsDisplay: YES];
978     [o_new_category_view setAutoresizesSubviews: YES];
979     [[o_sprefs_win contentView] addSubview: o_new_category_view];
980     
981     /* keep our current category for further reference */
982     [o_currentlyShownCategoryView release];
983     o_currentlyShownCategoryView = o_new_category_view;
984     [o_currentlyShownCategoryView retain];
985 }
986
987 - (IBAction)interfaceSettingChanged:(id)sender
988 {
989     b_intfSettingChanged = YES;
990 }
991
992 - (void)showInterfaceSettings
993 {
994     [self showSettingsForCategory: o_intf_view];
995 }
996
997 - (IBAction)audioSettingChanged:(id)sender
998 {
999     if( sender == o_audio_vol_sld )
1000         [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1001
1002     if( sender == o_audio_vol_fld )
1003         [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1004
1005     if( sender == o_audio_norm_ckb )
1006     {
1007         [o_audio_norm_stepper setEnabled: [o_audio_norm_ckb state]];
1008         [o_audio_norm_fld setEnabled: [o_audio_norm_ckb state]];
1009     }    
1010     
1011     if( sender == o_audio_last_ckb )
1012     {
1013         if( [o_audio_last_ckb state] == NSOnState )
1014         {
1015             [o_audio_lastpwd_sfld setEnabled: YES];
1016             [o_audio_lastuser_fld setEnabled: YES];
1017         }
1018         else
1019         {
1020             [o_audio_lastpwd_sfld setEnabled: NO];
1021             [o_audio_lastuser_fld setEnabled: NO];
1022         }
1023     }
1024
1025     b_audioSettingChanged = YES;
1026 }
1027
1028 - (void)showAudioSettings
1029 {
1030     [self showSettingsForCategory: o_audio_view];
1031 }
1032
1033 - (IBAction)videoSettingChanged:(id)sender
1034 {
1035     if( sender == o_video_snap_folder_btn )
1036     {
1037         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1038         [o_selectFolderPanel setCanChooseDirectories: YES];
1039         [o_selectFolderPanel setCanChooseFiles: NO];
1040         [o_selectFolderPanel setResolvesAliases: YES];
1041         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1042         [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1043         [o_selectFolderPanel setCanCreateDirectories: YES];
1044         [o_selectFolderPanel setPrompt: _NS("Choose")];
1045         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win 
1046                                       modalDelegate: self 
1047                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1048                                         contextInfo: o_video_snap_folder_btn];
1049     }
1050     else
1051         b_videoSettingChanged = YES;
1052 }
1053
1054 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1055 {
1056     if( returnCode == NSOKButton )
1057     {
1058         if( contextInfo == o_video_snap_folder_btn )
1059         {
1060             [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1061             b_videoSettingChanged = YES;
1062         }
1063     }
1064
1065     [o_selectFolderPanel release];
1066 }
1067
1068 - (void)showVideoSettings
1069 {
1070     [self showSettingsForCategory: o_video_view];
1071 }
1072
1073 - (IBAction)osdSettingChanged:(id)sender
1074 {
1075     b_osdSettingChanged = YES;
1076 }
1077
1078 - (void)showOSDSettings
1079 {
1080     [self showSettingsForCategory: o_osd_view];
1081 }
1082
1083 - (IBAction)showFontPicker:(id)sender
1084 {
1085     char * font = config_GetPsz( p_intf, "quartztext-font" );
1086     NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1087     free(font);
1088     if( fontFamilyName )
1089     {
1090         NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1091         NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1092         [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1093     }
1094     [[NSFontManager sharedFontManager] setTarget: self];
1095     [[NSFontPanel sharedFontPanel] orderFront:self];
1096 }
1097
1098 - (void)changeFont:(id)sender
1099 {
1100     NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1101     [o_osd_font_fld setStringValue:[font familyName]];
1102     [self osdSettingChanged:self];
1103 }
1104
1105 - (IBAction)inputSettingChanged:(id)sender
1106 {
1107     if( sender == o_input_cachelevel_pop )
1108     {
1109         if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1110             [o_input_cachelevel_custom_txt setHidden: NO];
1111         else
1112             [o_input_cachelevel_custom_txt setHidden: YES];
1113     }
1114
1115     b_inputSettingChanged = YES;
1116 }
1117
1118 - (void)showInputSettings
1119 {
1120     [self showSettingsForCategory: o_input_view];
1121 }
1122
1123 - (IBAction)hotkeySettingChanged:(id)sender
1124 {
1125     if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1126     {
1127         [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""), 
1128                                                [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1129         [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1130         [o_hotkeys_change_taken_lbl setStringValue: @""];
1131         [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1132         [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1133         [NSApp runModalForWindow: o_hotkeys_change_win];
1134     }
1135     else if( sender == o_hotkeys_change_cancel_btn )
1136     {
1137         [NSApp stopModal];
1138         [o_hotkeys_change_win close];
1139     }
1140     else if( sender == o_hotkeys_change_ok_btn )
1141     {
1142         NSInteger i_returnValue;
1143         if(! o_keyInTransition )
1144         {
1145             [NSApp stopModal];
1146             [o_hotkeys_change_win close];
1147             msg_Err( p_intf, "internal error prevented the hotkey switch" );
1148             return;
1149         }
1150
1151         b_hotkeyChanged = YES;
1152
1153         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1154         if( i_returnValue != NSNotFound )
1155             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1156
1157         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1158
1159         [NSApp stopModal];
1160         [o_hotkeys_change_win close];
1161
1162         [o_hotkeys_listbox reloadData];
1163     }
1164     else if( sender == o_hotkeys_clear_btn )
1165     {
1166         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1167         [o_hotkeys_listbox reloadData];
1168         b_hotkeyChanged = YES;
1169     }
1170 }
1171
1172 - (void)showHotkeySettings
1173 {
1174     [self showSettingsForCategory: o_hotkeys_view];
1175 }
1176
1177 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1178 {
1179     return [o_hotkeySettings count];
1180 }
1181
1182 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1183 {
1184     if( [[aTableColumn identifier] isEqualToString: @"action"] )
1185         return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1186     else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1187         return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1188     else
1189     {
1190         msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1191         return NULL;
1192     }
1193 }
1194
1195 - (BOOL)changeHotkeyTo: (int)i_theNewKey
1196 {
1197     NSInteger i_returnValue;
1198     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1199     if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1200     {
1201         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1202         [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1203         [o_hotkeys_change_ok_btn setEnabled: NO];
1204         return NO;
1205     }
1206     else
1207     {
1208         NSString *o_temp;
1209         if( o_keyInTransition )
1210             [o_keyInTransition release];
1211         o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1212
1213         o_temp = [self OSXKeyToString: i_theNewKey];
1214
1215         [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1216
1217         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1218         if( i_returnValue != NSNotFound )
1219             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1220                                                          _NS("This combination is already taken by \"%@\"."),
1221                                                          [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1222         else
1223             [o_hotkeys_change_taken_lbl setStringValue: @""];
1224
1225         [o_hotkeys_change_ok_btn setEnabled: YES];
1226         return YES;
1227     }
1228 }
1229     
1230 @end
1231
1232 /********************
1233  * hotkeys settings *
1234  ********************/
1235
1236 @implementation VLCHotkeyChangeWindow
1237
1238 - (BOOL)acceptsFirstResponder
1239 {
1240     return YES;
1241 }
1242
1243 - (BOOL)becomeFirstResponder
1244 {
1245     return YES;
1246 }
1247
1248 - (BOOL)resignFirstResponder
1249 {
1250     /* We need to stay the first responder or we'll miss the user's input */
1251     return NO;
1252 }
1253
1254 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1255 {
1256     unichar key;
1257     int i_key = 0;
1258
1259     if( [o_theEvent modifierFlags] & NSControlKeyMask )
1260         i_key |= KEY_MODIFIER_CTRL;
1261
1262     if( [o_theEvent modifierFlags] & NSAlternateKeyMask  )
1263         i_key |= KEY_MODIFIER_ALT;
1264
1265     if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1266         i_key |= KEY_MODIFIER_SHIFT;
1267
1268     if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1269         i_key |= KEY_MODIFIER_COMMAND;
1270
1271     key = [[[o_theEvent charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
1272     if( key )
1273     {
1274         i_key |= CocoaKeyToVLC( key );
1275         return [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_key];
1276     }
1277     return FALSE;
1278 }
1279
1280 @end
1281
1282 @implementation VLCSimplePrefsWindow
1283
1284 - (BOOL)acceptsFirstResponder
1285 {
1286     return YES;
1287 }
1288
1289 - (void)changeFont:(id)sender
1290 {
1291     [[[VLCMain sharedInstance] getSimplePreferences] changeFont: sender];
1292 }
1293 @end