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