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