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