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