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