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