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