]> git.sesse.net Git - vlc/blob - modules/gui/macosx/simple_prefs.m
macosx: remove "macosx-autosave-volume" as its already implemented in core
[vlc] / modules / gui / macosx / simple_prefs.m
1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008-2012 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_videodeco_ckb setTitle: _NS("Window decorations")];
310     [o_video_onTop_ckb setTitle: _NS("Always on top")];
311     [o_video_output_txt setStringValue: _NS("Output module")];
312     [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
313     [o_video_snap_box setTitle: _NS("Video snapshots")];
314     [o_video_snap_folder_btn setTitle: _NS("Browse...")];
315     [o_video_snap_folder_txt setStringValue: _NS("Folder")];
316     [o_video_snap_format_txt setStringValue: _NS("Format")];
317     [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
318     [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
319     [o_video_deinterlace_txt setStringValue: _NS("Deinterlace")];
320     [o_video_deinterlace_mode_txt setStringValue: _NS("Deinterlace mode")];
321     [o_video_video_box setTitle: _NS("Video")];
322
323     /* generic stuff */
324     [o_sprefs_showAll_btn setTitle: _NS("Show All")];
325     [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
326     [o_sprefs_reset_btn setTitle: _NS("Reset All")];
327     [o_sprefs_save_btn setTitle: _NS("Save")];
328     [o_sprefs_win setTitle: _NS("Preferences")];
329 }
330
331 /* TODO: move this part to core */
332 #define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
333 static inline char * __config_GetLabel( vlc_object_t *p_this, const char *psz_name )
334 {
335     module_config_t *p_config;
336
337     p_config = config_FindConfig( p_this, psz_name );
338
339     /* sanity checks */
340     if( !p_config )
341     {
342         msg_Err( p_this, "option %s does not exist", psz_name );
343         return NULL;
344     }
345
346     if ( p_config->psz_longtext )
347         return p_config->psz_longtext;
348     else if( p_config->psz_text )
349         return p_config->psz_text;
350     else
351         msg_Warn( p_this, "option %s does not include any help", psz_name );
352
353     return NULL;
354 }
355
356 #pragma mark -
357 #pragma mark Setup controls
358
359 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
360 {
361     module_config_t *p_item;
362
363     [object removeAllItems];
364     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
365
366     /* serious problem, if no item found */
367     assert( p_item );
368
369     for( int i = 0; i < p_item->i_list; i++ )
370     {
371         NSMenuItem *mi;
372         if( p_item->ppsz_list_text != NULL )
373             mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
374         else if( p_item->ppsz_list[i] && strcmp(p_item->ppsz_list[i],"") == 0 )
375         {
376             [[object menu] addItem: [NSMenuItem separatorItem]];
377             continue;
378         }
379         else if( p_item->ppsz_list[i] )
380             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
381         else
382             msg_Err( p_intf, "item %d of pref %s failed to be created", i, name );
383         [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
384         [[object menu] addItem: [mi autorelease]];
385         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
386             [object selectItem:[object lastItem]];
387     }
388     [object setToolTip: _NS( p_item->psz_longtext )];
389 }
390
391 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
392 {
393     module_config_t *p_item;
394
395     [object removeAllItems];
396     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
397
398     /* serious problem, if no item found */
399     assert( p_item );
400
401     for( int i = 0; i < p_item->i_list; i++ )
402     {
403         NSMenuItem *mi;
404         if( p_item->ppsz_list_text != NULL)
405             mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
406         else if( p_item->pi_list[i] )
407             mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
408         else
409             msg_Err( p_intf, "item %d of pref %s failed to be created", i, name);
410         [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
411         [[object menu] addItem: [mi autorelease]];
412         if( p_item->value.i == p_item->pi_list[i] )
413             [object selectItem:[object lastItem]];
414     }
415     [object setToolTip: _NS( p_item->psz_longtext )];
416 }
417
418 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
419 {
420     module_config_t *p_item;
421     module_t *p_parser, **p_list;
422     int y = 0;
423
424     [object removeAllItems];
425
426     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
427     p_list = module_list_get( NULL );
428     if( !p_item ||!p_list )
429     {
430         if( p_list ) module_list_free(p_list);
431         msg_Err( p_intf, "serious problem, item or list not found" );
432         return;
433     }
434
435     [object addItemWithTitle: _NS("Default")];
436     for( size_t i_index = 0; p_list[i_index]; i_index++ )
437     {
438         p_parser = p_list[i_index];
439         if( module_provides( p_parser, p_item->psz_type ) )
440         {
441             [object addItemWithTitle: [NSString stringWithUTF8String: _(module_GetLongName( p_parser )) ?: ""]];
442             if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
443                 [object selectItem: [object lastItem]];
444         }
445     }
446     module_list_free( p_list );
447     [object setToolTip: _NS(p_item->psz_longtext)];
448 }
449
450 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
451 {
452     [object setState: config_GetInt( p_intf, name )];
453     [object setToolTip: _NS(config_GetLabel( p_intf, name ) ?: "")];
454 }
455
456 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
457 {
458     char *psz_tmp = config_GetPsz( p_intf, psz_option );
459     [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
460     [o_object setToolTip: _NS(config_GetLabel( p_intf, psz_option ))];
461     free( psz_tmp );
462 }
463
464 - (void)resetControls
465 {
466     module_config_t *p_item;
467     int i, y = 0;
468     char *psz_tmp;
469
470     /**********************
471      * interface settings *
472      **********************/
473     [self setupButton: o_intf_lang_pop forStringList: "language"];
474     [self setupButton: o_intf_art_pop forIntList: "album-art"];
475
476     [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
477
478     [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
479     BOOL b_correct_sdk = NO;
480 #ifdef MAC_OS_X_VERSION_10_7
481     b_correct_sdk = YES;
482 #endif
483     if( !( b_correct_sdk && OSX_LION ))
484     {
485         [o_intf_nativefullscreen_ckb setState: NSOffState];
486         [o_intf_nativefullscreen_ckb setEnabled: NO];
487     }
488
489     [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
490
491     [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
492
493     [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
494     if( [[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL )
495         [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
496     else
497         [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
498     psz_tmp = config_GetPsz( p_intf, "control" );
499     if (psz_tmp) {
500         [o_intf_enableGrowl_ckb setState: (NSInteger)strstr( psz_tmp, "growl")];
501         free( psz_tmp );
502     }
503     else
504         [o_intf_enableGrowl_ckb setState: NSOffState];
505     if (config_GetInt( p_intf, "macosx-interfacestyle" ))
506     {
507         [o_intf_style_dark_bcell setState: YES];
508         [o_intf_style_bright_bcell setState: NO];
509     }
510     else
511     {
512         [o_intf_style_dark_bcell setState: NO];
513         [o_intf_style_bright_bcell setState: YES];
514     }
515     [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
516     [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
517
518     /******************
519      * audio settings *
520      ******************/
521     [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
522
523     if ( config_GetInt( p_intf, "volume-save" ))
524     {
525         [o_audio_autosavevol_yes_bcell setState: NSOnState];
526         [o_audio_autosavevol_no_bcell setState: NSOffState];
527         [o_audio_vol_fld setEnabled: NO];
528         [o_audio_vol_sld setEnabled: NO];
529
530         [o_audio_vol_sld setIntValue: 100];
531         [o_audio_vol_fld setIntValue: 100];
532     }
533     else
534     {
535         [o_audio_autosavevol_yes_bcell setState: NSOffState];
536         [o_audio_autosavevol_no_bcell setState: NSOnState];
537         [o_audio_vol_fld setEnabled: YES];
538         [o_audio_vol_sld setEnabled: YES];
539
540         i = config_GetInt( p_intf, "volume" );
541         i = i * 200 / AOUT_VOLUME_MAX;
542         [o_audio_vol_sld setIntValue: i];
543         [o_audio_vol_fld setIntValue: i];
544     }
545
546     [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
547
548     [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
549     [self setupField: o_audio_lang_fld forOption: "audio-language"];
550
551     [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
552
553     /* Last.FM is optional */
554     if( module_exists( "audioscrobbler" ) )
555     {
556         [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
557         [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
558
559         if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
560         {
561             [o_audio_last_ckb setState: NSOnState];
562             [o_audio_lastuser_fld setEnabled: YES];
563             [o_audio_lastpwd_sfld setEnabled: YES];
564         }
565         else
566         {
567             [o_audio_last_ckb setState: NSOffState];
568             [o_audio_lastuser_fld setEnabled: NO];
569             [o_audio_lastpwd_sfld setEnabled: NO];
570         }
571     }
572     else
573         [o_audio_last_ckb setEnabled: NO];
574
575     /******************
576      * video settings *
577      ******************/
578     [self setupButton: o_video_enable_ckb forBoolValue: "video"];
579     [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
580     [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
581     [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
582     [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
583     [self setupButton: o_video_videodeco_ckb forBoolValue: "video-deco"];
584
585     [self setupButton: o_video_output_pop forModuleList: "vout"];
586
587     [o_video_device_pop removeAllItems];
588     i = 0;
589     y = [[NSScreen screens] count];
590     [o_video_device_pop addItemWithTitle: _NS("Default")];
591     [[o_video_device_pop lastItem] setTag: 0];
592     while( i < y )
593     {
594         NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
595         [o_video_device_pop addItemWithTitle:
596          [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
597                    (int)s_rect.size.width, (int)s_rect.size.height]];
598         [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
599         i++;
600     }
601     [o_video_device_pop selectItemAtIndex: 0];
602     [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
603
604     [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
605     [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
606     [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
607     [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
608     [self setupButton: o_video_deinterlace_pop forIntList: "deinterlace"];
609     [self setupButton: o_video_deinterlace_mode_pop forStringList: "deinterlace-mode"];
610
611     /***************************
612      * input & codecs settings *
613      ***************************/
614     [self setupField: o_input_record_fld forOption:"input-record-path"];
615     [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
616     [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
617     [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "postproc-q")];
618     [o_input_postproc_fld setToolTip: _NS(config_GetLabel( p_intf, "postproc-q"))];
619
620     [self setupButton: o_input_avi_pop forIntList: "avi-index"];
621
622     [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
623     [self setupButton: o_input_skipLoop_pop forIntList: "avcodec-skiploopfilter"];
624
625     [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
626
627     [o_input_cachelevel_pop removeAllItems];
628     [o_input_cachelevel_pop addItemsWithTitles:
629         [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
630             _NS("High latency"), _NS("Higher latency"), nil]];
631     [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
632     [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
633     [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
634     [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
635     [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
636     [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
637
638     #define TestCaC( name, factor ) \
639     b_cache_equal =  b_cache_equal && \
640     ( i_cache * factor == config_GetInt( p_intf, name ) );
641
642     /* Select the accurate value of the PopupButton */
643     bool b_cache_equal = true;
644     int i_cache = config_GetInt( p_intf, "file-caching");
645
646     TestCaC( "network-caching", 10/3 );
647     TestCaC( "disc-caching", 1 );
648     TestCaC( "live-caching", 1 );
649     if( b_cache_equal )
650     {
651         [o_input_cachelevel_pop selectItemWithTag: i_cache];
652         [o_input_cachelevel_custom_txt setHidden: YES];
653     }
654     else
655     {
656         [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
657         [o_input_cachelevel_custom_txt setHidden: NO];
658     }
659     #undef TestCaC
660
661     /*********************
662      * subtitle settings *
663      *********************/
664     [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
665
666     [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
667     [self setupField: o_osd_lang_fld forOption: "sub-language" ];
668
669     [self setupField: o_osd_font_fld forOption: "freetype-font"];
670     [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
671     [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
672     i = config_GetInt( p_intf, "freetype-opacity" );
673     [o_osd_opacity_fld setIntValue: i];
674     [o_osd_opacity_sld setIntValue: i];
675     [o_osd_opacity_sld setToolTip: _NS(config_GetLabel( p_intf, "freetype-opacity"))];
676     [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
677     [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
678     [self setupButton: o_osd_outline_color_pop forIntList: "freetype-outline-color"];
679     [self setupButton: o_osd_outline_thickness_pop forIntList: "freetype-outline-thickness"];
680
681     /********************
682      * hotkeys settings *
683      ********************/
684     const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
685     [o_hotkeySettings release];
686     o_hotkeySettings = [[NSMutableArray alloc] init];
687     NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
688     NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
689
690     /* Get the main Module */
691     module_t *p_main = module_get_main();
692     assert( p_main );
693     unsigned confsize;
694     module_config_t *p_config;
695
696     p_config = module_config_get (p_main, &confsize);
697
698     for (size_t i = 0; i < confsize; i++)
699     {
700         module_config_t *p_item = p_config + i;
701
702         if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
703            && !strncmp( p_item->psz_name , "key-", 4 )
704            && !EMPTY_STR( p_item->psz_text ) )
705         {
706             [o_tempArray_desc addObject: _NS( p_item->psz_text )];
707             [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
708             if (p_item->value.psz)
709                 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
710             else
711                 [o_hotkeySettings addObject: [NSString string]];
712         }
713     }
714     module_config_free (p_config);
715
716     [o_hotkeyDescriptions release];
717     o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
718     [o_tempArray_desc release];
719     [o_hotkeyNames release];
720     o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
721     [o_tempArray_names release];
722     [o_hotkeys_listbox reloadData];
723 }
724
725 #pragma mark -
726 #pragma mark General actions
727
728 - (void)showSimplePrefs
729 {
730     /* we want to show the interface settings, if no category was chosen */
731     if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
732     {
733         [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
734         [self showInterfaceSettings];
735     }
736
737     [self resetControls];
738
739     [o_sprefs_win center];
740     [o_sprefs_win makeKeyAndOrderFront: self];
741 }
742
743 - (IBAction)buttonAction:(id)sender
744 {
745     if( sender == o_sprefs_cancel_btn )
746     {
747         [[NSFontPanel sharedFontPanel] close];
748         [o_sprefs_win orderOut: sender];
749     }
750     else if( sender == o_sprefs_save_btn )
751     {
752         [self saveChangedSettings];
753         [[NSFontPanel sharedFontPanel] close];
754         [o_sprefs_win orderOut: sender];
755     }
756     else if( sender == o_sprefs_reset_btn )
757         NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
758                                         _NS("Continue"), nil, o_sprefs_win, self,
759                                         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
760                                         _NS("Beware this will reset the VLC media player preferences.\n"
761                                             "Are you sure you want to continue?") );
762     else if( sender == o_sprefs_showAll_btn )
763     {
764         [o_sprefs_win orderOut: self];
765         [[[VLCMain sharedInstance] preferences] showPrefs];
766     }
767     else
768         msg_Warn( p_intf, "unknown buttonAction sender" );
769 }
770
771 - (void)sheetDidEnd:(NSWindow *)o_sheet
772          returnCode:(int)i_return
773         contextInfo:(void *)o_context
774 {
775     if( i_return == NSAlertAlternateReturn )
776     {
777         config_ResetAll( p_intf );
778         [self resetControls];
779         config_SaveConfigFile( p_intf );
780     }
781 }
782
783 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
784 {
785     NSNumber *p_valueobject;
786     module_config_t *p_item;
787     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
788     p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
789     assert([p_valueobject isKindOfClass:[NSNumber class]]);
790     if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
791 }
792
793 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
794 {
795     NSString *p_stringobject;
796     module_config_t *p_item;
797     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
798     p_stringobject = (NSString *)[[object selectedItem] representedObject];
799     assert([p_stringobject isKindOfClass:[NSString class]]);
800     if( p_stringobject )
801     {
802         config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
803     }
804 }
805
806 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
807 {
808     module_config_t *p_item;
809     module_t *p_parser, **p_list;
810     NSString * objectTitle = [[object selectedItem] title];
811
812     p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
813
814     p_list = module_list_get( NULL );
815     for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
816     {
817         p_parser = p_list[i_module_index];
818
819         if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
820         {
821             if( [objectTitle isEqualToString: _NS( module_GetLongName( p_parser ) )] )
822             {
823                 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
824                 break;
825             }
826         }
827     }
828     module_list_free( p_list );
829     if( [objectTitle isEqualToString: _NS( "Default" )] )
830         config_PutPsz( p_intf, name, "" );
831 }
832
833 - (void)saveChangedSettings
834 {
835     NSString *tmpString;
836     NSRange tmpRange;
837
838 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
839
840 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
841
842 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
843
844 #define getString( name ) [NSString stringWithFormat:@"%s", config_GetPsz( p_intf, name )]
845
846     /**********************
847      * interface settings *
848      **********************/
849     if( b_intfSettingChanged )
850     {
851         SaveStringList( o_intf_lang_pop, "language" );
852         SaveIntList( o_intf_art_pop, "album-art" );
853
854         config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
855         config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
856
857         config_PutInt( p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state] );
858         config_PutInt( p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state] );
859         config_PutInt( p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state] );
860         config_PutInt( p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state] );
861         config_PutInt( p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state] );
862         config_PutInt( p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state] );
863         if( [o_intf_enableGrowl_ckb state] == NSOnState )
864         {
865             tmpString = getString( "control" );
866             tmpRange = [tmpString rangeOfString:@"growl"];
867             if( [tmpString length] > 0 && tmpRange.location == NSNotFound )
868             {
869                 tmpString = [tmpString stringByAppendingString: @":growl"];
870                 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
871             }
872             else
873                 config_PutPsz( p_intf, "control", "growl" );
874         }
875         else
876         {
877             tmpString = getString( "control" );
878             if(! [tmpString isEqualToString:@""] )
879             {
880                 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
881                 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
882                 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
883                 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
884             }
885         }
886
887         /* activate stuff without restart */
888         if( [o_intf_appleremote_ckb state] == YES )
889             [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
890         else
891             [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
892         b_intfSettingChanged = NO;
893     }
894
895     /******************
896      * audio settings *
897      ******************/
898     if( b_audioSettingChanged )
899     {
900         config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
901         if( [o_audio_vol_fld isEnabled] )
902             config_PutInt( p_intf, "volume", [o_audio_vol_fld intValue] * AOUT_VOLUME_MAX / 200 );
903         config_PutInt( p_intf, "volume-save", [o_audio_autosavevol_yes_bcell state] );
904         config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
905
906         SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
907
908         config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
909
910         SaveModuleList( o_audio_visual_pop, "audio-visual" );
911
912         /* Last.FM is optional */
913         if( module_exists( "audioscrobbler" ) )
914         {
915             [o_audio_last_ckb setEnabled: YES];
916             if( [o_audio_last_ckb state] == NSOnState )
917                 config_AddIntf( p_intf, "audioscrobbler" );
918             else
919                 config_RemoveIntf( p_intf, "audioscrobbler" );
920
921             config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
922             config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
923         }
924         else
925             [o_audio_last_ckb setEnabled: NO];
926         b_audioSettingChanged = NO;
927     }
928
929     /******************
930      * video settings *
931      ******************/
932     if( b_videoSettingChanged )
933     {
934         config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
935         config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
936         config_PutInt( p_intf, "video-deco", [o_video_videodeco_ckb state] );
937         config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
938         config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
939         config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
940
941         SaveModuleList( o_video_output_pop, "vout" );
942         config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
943
944         config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
945         config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
946         config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
947         SaveStringList( o_video_snap_format_pop, "snapshot-format" );
948         SaveIntList( o_video_deinterlace_pop, "deinterlace" );
949         SaveStringList( o_video_deinterlace_mode_pop, "deinterlace-mode" );
950         b_videoSettingChanged = NO;
951     }
952
953     /***************************
954      * input & codecs settings *
955      ***************************/
956     if( b_inputSettingChanged )
957     {
958         config_PutPsz( p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String] );
959         config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
960         config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
961         config_PutInt( p_intf, "postproc-q", [o_input_postproc_fld intValue] );
962
963         SaveIntList( o_input_avi_pop, "avi-index" );
964
965         config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
966         SaveIntList( o_input_skipLoop_pop, "avcodec-skiploopfilter" );
967
968         config_PutInt( p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state] );
969
970         #define CaC( name, factor ) config_PutInt( p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor )
971         if ( [[o_input_cachelevel_pop selectedItem] tag] == 0 )
972         {
973             msg_Dbg( p_intf, "Custom chosen, not adjusting cache values" );
974         }
975         else
976         {
977             msg_Dbg( p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag] );
978             CaC( "file-caching", 1 );
979             CaC( "network-caching", 10/3 );
980             CaC( "disc-caching", 1 );
981             CaC( "live-caching", 1 );
982         }
983         #undef CaC
984         b_inputSettingChanged = NO;
985     }
986
987     /**********************
988      * subtitles settings *
989      **********************/
990     if( b_osdSettingChanged )
991     {
992         config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
993
994         if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
995             SaveStringList( o_osd_encoding_pop, "subsdec-encoding" );
996         else
997             config_PutPsz( p_intf, "subsdec-encoding", "" );
998
999         config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
1000
1001         config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
1002         SaveIntList( o_osd_font_color_pop, "freetype-color" );
1003         SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
1004         config_PutInt( p_intf, "freetype-opacity", [o_osd_opacity_sld intValue] );
1005         config_PutInt( p_intf, "freetype-bold", [o_osd_forcebold_ckb state] );
1006         SaveIntList( o_osd_outline_color_pop, "freetype-outline-color" );
1007         SaveIntList( o_osd_outline_thickness_pop, "freetype-outline-thickness" );
1008         b_osdSettingChanged = NO;
1009     }
1010
1011     /********************
1012      * hotkeys settings *
1013      ********************/
1014     if( b_hotkeyChanged )
1015     {
1016         NSUInteger hotKeyCount = [o_hotkeySettings count];
1017         for( NSUInteger i = 0; i < hotKeyCount; i++ )
1018             config_PutPsz( p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String] );
1019         b_hotkeyChanged = NO;
1020     }
1021
1022     [[VLCCoreInteraction sharedInstance] fixPreferences];
1023
1024     /* okay, let's save our changes to vlcrc */
1025     config_SaveConfigFile( p_intf );
1026
1027     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1028                                                             object: nil
1029                                                           userInfo: nil];
1030 }
1031
1032 - (void)showSettingsForCategory: (id)o_new_category_view
1033 {
1034     NSRect o_win_rect, o_view_rect, o_old_view_rect;
1035     o_win_rect = [o_sprefs_win frame];
1036     o_view_rect = [o_new_category_view frame];
1037
1038     if( o_currentlyShownCategoryView != nil )
1039     {
1040         /* restore our window's height, if we've shown another category previously */
1041         o_old_view_rect = [o_currentlyShownCategoryView frame];
1042         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
1043         o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
1044     }
1045
1046     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
1047
1048     [o_new_category_view setFrame: NSMakeRect( 0,
1049                                                [o_sprefs_controls_box frame].size.height,
1050                                                o_view_rect.size.width,
1051                                                o_view_rect.size.height )];
1052     [o_new_category_view setAutoresizesSubviews: YES];
1053     if (o_currentlyShownCategoryView)
1054     {
1055         [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
1056         [o_currentlyShownCategoryView release];
1057         [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
1058     }
1059     else
1060     {
1061         [[o_sprefs_win contentView] addSubview: o_new_category_view];
1062         [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
1063     }
1064
1065     /* keep our current category for further reference */
1066     o_currentlyShownCategoryView = o_new_category_view;
1067     [o_currentlyShownCategoryView retain];
1068 }
1069
1070 #pragma mark -
1071 #pragma mark Specific actions
1072
1073 - (IBAction)interfaceSettingChanged:(id)sender
1074 {
1075     if( sender == o_intf_embedded_ckb && [o_intf_embedded_ckb state] == NSOffState )
1076         [o_intf_nativefullscreen_ckb setState: NSOffState];
1077
1078     if( sender == o_intf_nativefullscreen_ckb && [o_intf_nativefullscreen_ckb state] == NSOnState )
1079         [o_intf_embedded_ckb setState: NSOnState];
1080
1081     if( sender == o_intf_embedded_ckb )
1082         [[VLCCoreInteraction sharedInstance] stop];
1083
1084     b_intfSettingChanged = YES;
1085 }
1086
1087 - (void)showInterfaceSettings
1088 {
1089     [self showSettingsForCategory: o_intf_view];
1090 }
1091
1092 - (IBAction)audioSettingChanged:(id)sender
1093 {
1094     if( sender == o_audio_vol_sld )
1095         [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1096
1097     if( sender == o_audio_vol_fld )
1098         [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1099
1100     if( sender == o_audio_last_ckb )
1101     {
1102         if( [o_audio_last_ckb state] == NSOnState )
1103         {
1104             [o_audio_lastpwd_sfld setEnabled: YES];
1105             [o_audio_lastuser_fld setEnabled: YES];
1106         }
1107         else
1108         {
1109             [o_audio_lastpwd_sfld setEnabled: NO];
1110             [o_audio_lastuser_fld setEnabled: NO];
1111         }
1112     }
1113
1114     if( sender == o_audio_autosavevol_matrix )
1115     {
1116         BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1117         [o_audio_vol_fld setEnabled: enableVolumeSlider];
1118         [o_audio_vol_sld setEnabled: enableVolumeSlider];
1119     }
1120
1121     b_audioSettingChanged = YES;
1122 }
1123
1124 - (void)showAudioSettings
1125 {
1126     [self showSettingsForCategory: o_audio_view];
1127 }
1128
1129 - (IBAction)videoSettingChanged:(id)sender
1130 {
1131     if( sender == o_video_snap_folder_btn )
1132     {
1133         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1134         [o_selectFolderPanel setCanChooseDirectories: YES];
1135         [o_selectFolderPanel setCanChooseFiles: NO];
1136         [o_selectFolderPanel setResolvesAliases: YES];
1137         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1138         [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1139         [o_selectFolderPanel setCanCreateDirectories: YES];
1140         [o_selectFolderPanel setPrompt: _NS("Choose")];
1141         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1142                                       modalDelegate: self
1143                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1144                                         contextInfo: o_video_snap_folder_btn];
1145     }
1146     else
1147         b_videoSettingChanged = YES;
1148 }
1149
1150 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1151 {
1152     if( returnCode == NSOKButton )
1153     {
1154         if( contextInfo == o_video_snap_folder_btn )
1155         {
1156             [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1157             b_videoSettingChanged = YES;
1158         }
1159         else if( contextInfo == o_input_record_btn )
1160         {
1161             [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1162             b_inputSettingChanged = YES;
1163         }
1164     }
1165
1166     [o_selectFolderPanel release];
1167 }
1168
1169 - (void)showVideoSettings
1170 {
1171     [self showSettingsForCategory: o_video_view];
1172 }
1173
1174 - (IBAction)osdSettingChanged:(id)sender
1175 {
1176     if( sender == o_osd_opacity_fld )
1177         [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1178
1179     if( sender == o_osd_opacity_sld )
1180         [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1181
1182     b_osdSettingChanged = YES;
1183 }
1184
1185 - (void)showOSDSettings
1186 {
1187     [self showSettingsForCategory: o_osd_view];
1188 }
1189
1190 - (void)controlTextDidChange:(NSNotification *)o_notification
1191 {
1192     id notificationObject = [o_notification object];
1193     if( notificationObject == o_audio_lang_fld ||
1194        notificationObject ==  o_audio_lastpwd_sfld ||
1195        notificationObject ==  o_audio_lastuser_fld ||
1196        notificationObject == o_audio_vol_fld )
1197         b_audioSettingChanged = YES;
1198     else if( notificationObject == o_input_record_fld ||
1199              notificationObject == o_input_httpproxy_fld ||
1200             notificationObject == o_input_httpproxypwd_sfld ||
1201             notificationObject == o_input_postproc_fld )
1202         b_inputSettingChanged = YES;
1203     else if( notificationObject == o_osd_font_fld ||
1204             notificationObject == o_osd_lang_fld ||
1205             notificationObject == o_osd_opacity_fld)
1206         b_osdSettingChanged = YES;
1207     else if( notificationObject == o_video_snap_folder_fld ||
1208             notificationObject == o_video_snap_prefix_fld )
1209         b_videoSettingChanged = YES;
1210 }
1211
1212 - (IBAction)showFontPicker:(id)sender
1213 {
1214     char * font = config_GetPsz( p_intf, "freetype-font" );
1215     NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1216     free(font);
1217     if( fontFamilyName )
1218     {
1219         NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1220         NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1221         [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1222     }
1223     [[NSFontManager sharedFontManager] setTarget: self];
1224     [[NSFontPanel sharedFontPanel] orderFront:self];
1225 }
1226
1227 - (void)changeFont:(id)sender
1228 {
1229     NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1230     [o_osd_font_fld setStringValue:[font fontName]];
1231     [self osdSettingChanged:self];
1232 }
1233
1234 - (IBAction)inputSettingChanged:(id)sender
1235 {
1236     if( sender == o_input_cachelevel_pop )
1237     {
1238         if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1239             [o_input_cachelevel_custom_txt setHidden: NO];
1240         else
1241             [o_input_cachelevel_custom_txt setHidden: YES];
1242     }
1243     else if( sender == o_input_record_btn )
1244     {
1245         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1246         [o_selectFolderPanel setCanChooseDirectories: YES];
1247         [o_selectFolderPanel setCanChooseFiles: YES];
1248         [o_selectFolderPanel setResolvesAliases: YES];
1249         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1250         [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1251         [o_selectFolderPanel setCanCreateDirectories: YES];
1252         [o_selectFolderPanel setPrompt: _NS("Choose")];
1253         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1254                                       modalDelegate: self
1255                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1256                                         contextInfo: o_input_record_btn];
1257         return;
1258     }
1259
1260     b_inputSettingChanged = YES;
1261 }
1262
1263 - (void)showInputSettings
1264 {
1265     [self showSettingsForCategory: o_input_view];
1266 }
1267
1268 #pragma mark -
1269 #pragma mark Hotkey actions
1270
1271 - (void)hotkeyTableDoubleClick:(id)object
1272 {
1273     // -1 is header
1274     if( [o_hotkeys_listbox clickedRow] >= 0 )
1275         [self hotkeySettingChanged:o_hotkeys_listbox];
1276 }
1277
1278 - (IBAction)hotkeySettingChanged:(id)sender
1279 {
1280     if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1281     {
1282         [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1283                                                [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1284         [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1285         [o_hotkeys_change_taken_lbl setStringValue: @""];
1286         [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1287         [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1288         [NSApp runModalForWindow: o_hotkeys_change_win];
1289     }
1290     else if( sender == o_hotkeys_change_cancel_btn )
1291     {
1292         [NSApp stopModal];
1293         [o_hotkeys_change_win close];
1294     }
1295     else if( sender == o_hotkeys_change_ok_btn )
1296     {
1297         NSInteger i_returnValue;
1298         if(! o_keyInTransition )
1299         {
1300             [NSApp stopModal];
1301             [o_hotkeys_change_win close];
1302             msg_Err( p_intf, "internal error prevented the hotkey switch" );
1303             return;
1304         }
1305
1306         b_hotkeyChanged = YES;
1307
1308         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1309         if( i_returnValue != NSNotFound )
1310             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1311         NSString *tempString;
1312         tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1313         i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1314         if( i_returnValue != NSNotFound )
1315             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1316
1317         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1318
1319         [NSApp stopModal];
1320         [o_hotkeys_change_win close];
1321
1322         [o_hotkeys_listbox reloadData];
1323     }
1324     else if( sender == o_hotkeys_clear_btn )
1325     {
1326         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1327         [o_hotkeys_listbox reloadData];
1328         b_hotkeyChanged = YES;
1329     }
1330
1331     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1332                                                         object: nil
1333                                                       userInfo: nil];
1334 }
1335
1336 - (void)showHotkeySettings
1337 {
1338     [self showSettingsForCategory: o_hotkeys_view];
1339 }
1340
1341 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1342 {
1343     return [o_hotkeySettings count];
1344 }
1345
1346 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1347 {
1348     NSString * identifier = [aTableColumn identifier];
1349
1350     if( [identifier isEqualToString: @"action"] )
1351         return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1352     else if( [identifier isEqualToString: @"shortcut"] )
1353         return [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1354     else
1355     {
1356         msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [identifier UTF8String] );
1357         return NULL;
1358     }
1359 }
1360
1361 - (BOOL)changeHotkeyTo: (NSString *)theKey
1362 {
1363     NSInteger i_returnValue, i_returnValue2;
1364     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1365
1366     if( i_returnValue != NSNotFound || [theKey isEqualToString:@""] )
1367     {
1368         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1369         [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1370         [o_hotkeys_change_ok_btn setEnabled: NO];
1371         return NO;
1372     }
1373     else
1374     {
1375         [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:theKey]];
1376
1377         i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1378         i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1379         if( i_returnValue != NSNotFound )
1380             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1381                                                          _NS("This combination is already taken by \"%@\"."),
1382                                                          [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1383         else if( i_returnValue2 != NSNotFound )
1384             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1385                                                          _NS("This combination is already taken by \"%@\"."),
1386                                                          [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1387         else
1388             [o_hotkeys_change_taken_lbl setStringValue: @""];
1389
1390         [o_hotkeys_change_ok_btn setEnabled: YES];
1391         [o_keyInTransition release];
1392         o_keyInTransition = theKey;
1393         [o_keyInTransition retain];
1394         return YES;
1395     }
1396 }
1397
1398 @end
1399
1400 /********************
1401  * hotkeys settings *
1402  ********************/
1403
1404 @implementation VLCHotkeyChangeWindow
1405
1406 - (BOOL)acceptsFirstResponder
1407 {
1408     return YES;
1409 }
1410
1411 - (BOOL)becomeFirstResponder
1412 {
1413     return YES;
1414 }
1415
1416 - (BOOL)resignFirstResponder
1417 {
1418     /* We need to stay the first responder or we'll miss the user's input */
1419     return NO;
1420 }
1421
1422 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1423 {
1424     NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1425     NSString *keyString = [o_theEvent characters];
1426
1427     unichar key = [keyString characterAtIndex:0];
1428     NSUInteger i_modifiers = [o_theEvent modifierFlags];
1429
1430     /* modifiers */
1431     if( i_modifiers & NSControlKeyMask )
1432         [tempString appendString:@"Ctrl-"];
1433     if( i_modifiers & NSAlternateKeyMask  )
1434         [tempString appendString:@"Alt-"];
1435     if( i_modifiers & NSShiftKeyMask )
1436         [tempString appendString:@"Shift-"];
1437     if( i_modifiers & NSCommandKeyMask )
1438         [tempString appendString:@"Command-"];
1439
1440     /* non character keys */
1441     if( key == NSUpArrowFunctionKey )
1442         [tempString appendString:@"Up"];
1443     else if( key == NSDownArrowFunctionKey )
1444         [tempString appendString:@"Down"];
1445     else if( key == NSLeftArrowFunctionKey )
1446         [tempString appendString:@"Left"];
1447     else if( key == NSRightArrowFunctionKey )
1448         [tempString appendString:@"Right"];
1449     else if( key == NSF1FunctionKey )
1450         [tempString appendString:@"F1"];
1451     else if( key == NSF2FunctionKey )
1452         [tempString appendString:@"F2"];
1453     else if( key == NSF3FunctionKey )
1454         [tempString appendString:@"F3"];
1455     else if( key == NSF4FunctionKey )
1456         [tempString appendString:@"F4"];
1457     else if( key == NSF5FunctionKey )
1458         [tempString appendString:@"F5"];
1459     else if( key == NSF6FunctionKey )
1460         [tempString appendString:@"F6"];
1461     else if( key == NSF7FunctionKey )
1462         [tempString appendString:@"F7"];
1463     else if( key == NSF8FunctionKey )
1464         [tempString appendString:@"F8"];
1465     else if( key == NSF9FunctionKey )
1466         [tempString appendString:@"F9"];
1467     else if( key == NSF10FunctionKey )
1468         [tempString appendString:@"F10"];
1469     else if( key == NSF11FunctionKey )
1470         [tempString appendString:@"F11"];
1471     else if( key == NSF12FunctionKey )
1472         [tempString appendString:@"F12"];
1473     else if( key == NSInsertFunctionKey )
1474         [tempString appendString:@"Insert"];
1475     else if( key == NSHomeFunctionKey )
1476         [tempString appendString:@"Home"];
1477     else if( key == NSEndFunctionKey )
1478         [tempString appendString:@"End"];
1479     else if( key == NSPageUpFunctionKey )
1480         [tempString appendString:@"Pageup"];
1481     else if( key == NSPageDownFunctionKey )
1482         [tempString appendString:@"Pagedown"];
1483     else if( key == NSMenuFunctionKey )
1484         [tempString appendString:@"Menu"];
1485     else if( key == NSTabCharacter )
1486         [tempString appendString:@"Tab"];
1487     else if( key == NSCarriageReturnCharacter )
1488         [tempString appendString:@"Enter"];
1489     else if( key == NSEnterCharacter )
1490         [tempString appendString:@"Enter"];
1491     else if( key == NSDeleteCharacter )
1492         [tempString appendString:@"Delete"];
1493     else if( key == NSBackspaceCharacter )
1494         [tempString appendString:@"Backspace"];
1495     else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1496         [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1497     else
1498         return NO;
1499
1500     return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1501 }
1502
1503 @end
1504
1505 @implementation VLCSimplePrefsWindow
1506
1507 - (BOOL)acceptsFirstResponder
1508 {
1509     return YES;
1510 }
1511
1512 - (void)changeFont:(id)sender
1513 {
1514     [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];
1515 }
1516 @end