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