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