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