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