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