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