]> git.sesse.net Git - vlc/blob - modules/gui/macosx/simple_prefs.m
removed trailing spaces, cough
[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     msg_Warn( p_intf, "localisation of the simple preferences is not implemented!" );
221 }
222
223 - (void)resetControls
224 {
225     module_config_t *p_item;
226     int i, y = 0;
227     char *psz_tmp;
228
229     #define SetupIntList( object, name ) \
230     [object removeAllItems]; \
231     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
232     for( i = 0; i < p_item->i_list; i++ ) \
233     { \
234         if( p_item->ppsz_list_text[i] != NULL) \
235             [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
236         else \
237             [object addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]]; \
238     } \
239     if( p_item->value.i < [object numberOfItems] ) \
240         [object selectItemAtIndex: p_item->value.i]; \
241     else \
242         [object selectItemAtIndex: 0]
243
244     #define SetupStringList( object, name ) \
245         [object removeAllItems]; \
246         y = 0; \
247         p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
248         for( i = 0; p_item->ppsz_list[i] != nil; i++ ) \
249         { \
250             [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
251             if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) ) \
252                 y = i; \
253         } \
254         [object selectItemAtIndex: y]
255
256     /**********************
257      * interface settings *
258      **********************/
259     SetupStringList( o_intf_lang_pop, "language" );
260     SetupIntList( o_intf_art_pop, "album-art" );
261
262     [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
263     [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
264     [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
265
266     /******************
267      * audio settings *
268      ******************/
269     [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
270     [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
271     [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
272
273     [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
274
275     SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
276
277     [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
278
279     [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
280     
281     psz_tmp = config_GetPsz( p_intf, "audio-filter" );
282     if( psz_tmp )
283         [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
284     [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
285     
286     // visualizer
287     msg_Warn( p_intf, "visualizer not implemented!" );
288     
289     /* Last.FM is optional */
290     if( module_Exists( p_intf, "audioscrobbler" ) )
291     {
292         [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
293         [o_audio_lastpwd_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
294
295         if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
296             [o_audio_last_ckb setState: NSOnState];
297         else
298             [o_audio_last_ckb setState: NSOffState];
299     }
300
301     /******************
302      * video settings *
303      ******************/
304     [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
305     [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
306     [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
307     [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
308     [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
309
310     msg_Warn( p_intf, "vout module and display device selectors not implemented!" );
311
312     if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
313         [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
314     [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
315     [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
316     
317     p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
318     for( i = 0; p_item->ppsz_list[i] != nil; i++ )
319     {
320         [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
321         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
322             y = i;
323     }
324     [o_video_snap_format_pop selectItemAtIndex: y];
325
326     /***************************
327      * input & codecs settings *
328      ***************************/
329     [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
330     if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
331         [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
332     [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
333
334     SetupIntList( o_input_avi_pop, "avi-index" );
335
336     [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
337
338     psz_tmp = config_GetPsz( p_intf, "access-filter" );
339     if( psz_tmp )
340     {
341         [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
342         [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
343         [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
344         [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
345     }
346
347     [o_input_cachelevel_pop removeAllItems];
348     [o_input_cachelevel_pop addItemsWithTitles: 
349         [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
350             _NS("High latency"), _NS("Higher latency"), nil]];
351     [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
352     [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
353     [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
354     [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
355     [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
356     [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
357     
358 #define TestCaC( name ) \
359     b_cache_equal =  b_cache_equal && \
360         ( i_cache == config_GetInt( p_intf, name ) )
361
362 #define TestCaCi( name, int ) \
363         b_cache_equal = b_cache_equal &&  \
364         ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
365
366     /* Select the accurate value of the PopupButton */
367     bool b_cache_equal = true;
368     int i_cache = config_GetInt( p_intf, "file-caching");
369     
370     TestCaC( "udp-caching" );
371     if( module_Exists (p_intf, "dvdread") )
372         TestCaC( "dvdread-caching" );
373     if( module_Exists (p_intf, "dvdnav") )
374         TestCaC( "dvdnav-caching" );
375     TestCaC( "tcp-caching" );
376     TestCaC( "fake-caching" );
377     TestCaC( "cdda-caching" );
378     TestCaC( "screen-caching" );
379     TestCaC( "vcd-caching" );
380     TestCaCi( "rtsp-caching", 4 );
381     TestCaCi( "ftp-caching", 2 );
382     TestCaCi( "http-caching", 4 );
383     if(module_Exists (p_intf, "access_realrtsp"))
384         TestCaCi( "realrtsp-caching", 10 );
385     TestCaCi( "mms-caching", 19 );
386     if( b_cache_equal )
387         [o_input_cachelevel_pop selectItemWithTag: i_cache];
388     else
389         [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
390
391     /*********************
392      * subtitle settings *
393      *********************/
394     [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
395     
396     [o_osd_encoding_pop removeAllItems];
397     y = 0;
398     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
399     for( i = 0; p_item->ppsz_list[i] != nil; i++ )
400     {
401         if( p_item->ppsz_list[i] != "" )
402             [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
403         else
404             [o_osd_encoding_pop addItemWithTitle: @" "];
405
406         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
407             y = i;
408     }
409     [o_osd_encoding_pop selectItemAtIndex: y];
410     
411     [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
412     if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
413         [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
414
415     SetupIntList( o_osd_font_color_pop, "freetype-color" );
416     SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
417     SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
418
419     /********************
420      * hotkeys settings *
421      ********************/
422     struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
423     o_hotkeySettings = [[NSMutableArray alloc] init];
424     NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
425     i = 1;
426
427     while( i < 100 )
428     {
429         p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
430         if( !p_item )
431             break;
432
433         [o_tempArray_desc addObject: _NS( p_item->psz_text )];
434         [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
435
436         i++;
437     }
438     o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
439     [o_tempArray_desc release];
440     [o_hotkeys_listbox reloadData];
441 }
442
443 - (void)showSimplePrefs
444 {
445     /* we want to show the interface settings, if no category was chosen */
446     if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
447     {
448         [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
449         [self showInterfaceSettings];
450     }
451     
452     [self resetControls];
453
454     [o_sprefs_win makeKeyAndOrderFront: self];
455 }
456
457 - (IBAction)buttonAction:(id)sender
458 {
459     if( sender == o_sprefs_cancel_btn )
460         [o_sprefs_win orderOut: sender];
461     else if( sender == o_sprefs_save_btn )
462     {
463         [self saveChangedSettings];
464         [o_sprefs_win orderOut: sender];
465     }
466     else if( sender == o_sprefs_reset_btn )
467         NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
468                                         _NS("Continue"), nil, o_sprefs_win, self,
469                                         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
470                                         _NS("Beware this will reset the VLC media player preferences.\n"
471                                             "Are you sure you want to continue?") );
472     else if( sender == o_sprefs_basicFull_matrix )
473     {
474         [o_sprefs_win orderOut: self];
475         [[[VLCMain sharedInstance] getPreferences] showPrefs];
476         [self resetControls];
477     }
478     else
479         msg_Err( p_intf, "unknown buttonAction sender" );
480 }
481
482 - (void)sheetDidEnd:(NSWindow *)o_sheet 
483          returnCode:(int)i_return
484         contextInfo:(void *)o_context
485 {
486     if( i_return == NSAlertAlternateReturn )
487     {
488         config_ResetAll( p_intf );
489         b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
490         [self resetControls];
491     }
492 }
493
494 - (void)saveChangedSettings
495 {
496     module_config_t *p_item;
497     char *psz_tmp;
498     int i;
499     
500 #define SaveIntList( object, name ) \
501     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
502     if( [object indexOfSelectedItem] >= 0 ) \
503         config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
504     else \
505         config_PutInt( p_intf, name, [object intValue] ) \
506                     
507 #define SaveStringList( object, name ) \
508     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
509     if( [object indexOfSelectedItem] >= 0 ) \
510         config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
511     else \
512         config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
513
514     /**********************
515      * interface settings *
516      **********************/
517     if( b_intfSettingChanged )
518     {
519         SaveStringList( o_intf_lang_pop, "language" );
520         SaveIntList( o_intf_art_pop, "album-art" );
521
522         config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
523         config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
524         config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
525
526         /* okay, let's save our changes to vlcrc */
527         i = config_SaveConfigFile( p_intf, "main" );
528         i = config_SaveConfigFile( p_intf, "macosx" );
529
530         if( i != 0 )
531         {
532             msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
533             i = 0;
534         }
535
536         b_intfSettingChanged = NO;
537     }
538     
539     /******************
540      * audio settings *
541      ******************/
542     if( b_audioSettingChanged )
543     {
544         config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
545         config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
546         config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
547
548         SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
549
550         config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
551         config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
552
553         psz_tmp = config_GetPsz( p_intf, "audio-filter" );
554         if(! psz_tmp)
555             config_PutPsz( p_intf, "audio-filter", "volnorm" );
556         else if( (int)strstr( psz_tmp, "normvol" ) == NO )
557         {
558             /* work-around a GCC 4.0.1 bug */
559             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
560             config_PutPsz( p_intf, "audio-filter", psz_tmp );
561         }
562         else
563         {
564             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
565             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
566             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
567             config_PutPsz( p_intf, "audio-filter", psz_tmp );
568         }
569         config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
570
571         msg_Warn( p_intf, "visualizer not implemented!" );
572
573         /* Last.FM is optional */
574         if( module_Exists( p_intf, "audioscrobbler" ) )
575         {    
576             if( [o_audio_last_ckb state] == NSOnState )
577                 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
578             else
579                 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
580
581             config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
582             config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
583         }
584
585         /* okay, let's save our changes to vlcrc */
586         i = config_SaveConfigFile( p_intf, "main" );
587         i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
588         i = i + config_SaveConfigFile( p_intf, "volnorm" );
589
590         if( i != 0 )
591         {
592             msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
593             i = 0;
594         }
595         b_audioSettingChanged = NO;
596     }
597     
598     /******************
599      * video settings *
600      ******************/
601     if( b_videoSettingChanged )
602     {
603         config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
604         config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
605         config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
606         config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
607         config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
608
609         msg_Warn( p_intf, "vout module and display device selectors not implemented!" );
610
611         config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
612         config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
613         config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
614
615         if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
616             config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
617
618         i = config_SaveConfigFile( p_intf, "main" );
619         i = i + config_SaveConfigFile( p_intf, "macosx" );
620
621         if( i != 0 )
622         {
623             msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
624             i = 0;
625         }
626         b_videoSettingChanged = NO;
627     }
628     
629     /***************************
630      * input & codecs settings *
631      ***************************/
632     if( b_inputSettingChanged )
633     {
634         config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
635         config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
636         config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
637
638         SaveIntList( o_input_avi_pop, "avi-index" );
639
640         config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
641
642         #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
643         #define CaC( name ) CaCi( name, 1 )
644         msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
645         CaC( "udp-caching" );
646         if( module_Exists (p_intf, "dvdread" ) )
647         {
648             CaC( "dvdread-caching" );
649             i = i + config_SaveConfigFile( p_intf, "dvdread" );
650         }
651         if( module_Exists (p_intf, "dvdnav" ) )
652         {
653             CaC( "dvdnav-caching" );
654             i = i + config_SaveConfigFile( p_intf, "dvdnav" );
655         }
656         CaC( "tcp-caching" ); CaC( "vcd-caching" );
657         CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
658         CaC( "screen-caching" );
659         CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
660         CaCi( "http-caching", 4 );
661         if( module_Exists (p_intf, "access_realrtsp" ) )
662         {
663             CaCi( "realrtsp-caching", 10 );
664             i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
665         }
666         CaCi( "mms-caching", 19 );
667
668         #define SaveAccessFilter( object, name ) \
669         if( [object state] == NSOnState ) \
670         { \
671             if( b_first ) \
672             { \
673                 [o_temp appendString: name]; \
674                 b_first = NO; \
675             } \
676             else \
677                 [o_temp appendFormat: @":%@", name]; \
678         }
679
680         BOOL b_first = YES;
681         NSMutableString *o_temp = [[NSMutableString alloc] init];
682         SaveAccessFilter( o_input_record_ckb, @"record" );
683         SaveAccessFilter( o_input_dump_ckb, @"dump" );
684         SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
685         SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
686         config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
687         [o_temp release];
688
689         i = config_SaveConfigFile( p_intf, "main" );
690         i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
691         i = i + config_SaveConfigFile( p_intf, "access_http" );
692         i = i + config_SaveConfigFile( p_intf, "access_file" );
693         i = i + config_SaveConfigFile( p_intf, "access_tcp" );
694         i = i + config_SaveConfigFile( p_intf, "access_fake" );
695         i = i + config_SaveConfigFile( p_intf, "cdda" );
696         i = i + config_SaveConfigFile( p_intf, "screen" );
697         i = i + config_SaveConfigFile( p_intf, "vcd" );
698         i = i + config_SaveConfigFile( p_intf, "access_ftp" );
699         i = i + config_SaveConfigFile( p_intf, "access_mms" );
700         i = i + config_SaveConfigFile( p_intf, "live555" );
701
702         if( i != 0 )
703         {
704             msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
705             i = 0;
706         }
707         b_inputSettingChanged = NO;
708     }
709     
710     /**********************
711      * subtitles settings *
712      **********************/
713     if( b_osdSettingChanged )
714     {
715         config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
716
717         if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
718             config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
719
720         config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
721         config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
722
723         SaveIntList( o_osd_font_color_pop, "freetype-color" );
724         SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
725         SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
726
727         i = config_SaveConfigFile( p_intf, NULL );
728
729         if( i != 0 )
730         {
731             msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
732             i = 0;
733         }
734         b_osdSettingChanged = NO;
735     }
736     
737     /********************
738      * hotkeys settings *
739      ********************/
740     if( b_hotkeyChanged )
741     {
742         struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
743         i = 1;
744         while( i < [o_hotkeySettings count] )
745         {
746             config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
747             i++;
748         }        
749
750         i = config_SaveConfigFile( p_intf, "main" );
751
752         if( i != 0 )
753         {
754             msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
755             i = 0;
756         }
757         b_hotkeyChanged = NO;
758     }
759 }
760
761 - (void)showSettingsForCategory: (id)o_new_category_view
762 {
763     NSRect o_win_rect, o_view_rect, o_old_view_rect;
764     o_win_rect = [o_sprefs_win frame];
765     o_view_rect = [o_new_category_view frame];
766     
767     if( o_currentlyShownCategoryView != nil )
768     {
769         /* restore our window's height, if we've shown another category previously */
770         o_old_view_rect = [o_currentlyShownCategoryView frame];
771         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
772
773         /* remove our previous category view */
774         [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
775     }
776     
777     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
778     
779     [o_sprefs_win displayIfNeeded];
780     [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
781     
782     [o_new_category_view setFrame: NSMakeRect( 0, 
783                                                [o_sprefs_controls_box frame].size.height, 
784                                                o_view_rect.size.width, 
785                                                o_view_rect.size.height )];
786     [o_new_category_view setNeedsDisplay: YES];
787     [o_new_category_view setAutoresizesSubviews: YES];
788     [[o_sprefs_win contentView] addSubview: o_new_category_view];
789     
790     /* keep our current category for further reference */
791     [o_currentlyShownCategoryView release];
792     o_currentlyShownCategoryView = o_new_category_view;
793     [o_currentlyShownCategoryView retain];
794 }
795
796 - (IBAction)interfaceSettingChanged:(id)sender
797 {
798     b_intfSettingChanged = YES;
799 }
800
801 - (void)showInterfaceSettings
802 {
803     msg_Dbg( p_intf, "showing interface settings" );
804     [self showSettingsForCategory: o_intf_view];
805 }
806
807 - (IBAction)audioSettingChanged:(id)sender
808 {
809     if( sender == o_audio_vol_sld )
810         [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
811     
812     if( sender == o_audio_vol_fld )
813         [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
814     
815     b_audioSettingChanged = YES;
816 }
817
818 - (void)showAudioSettings
819 {
820     msg_Dbg( p_intf, "showing audio settings" );
821     [self showSettingsForCategory: o_audio_view];
822 }
823
824 - (IBAction)videoSettingChanged:(id)sender
825 {
826     if( sender == o_video_snap_folder_btn )
827     {
828         o_selectFolderPanel = [[NSOpenPanel alloc] init];
829         [o_selectFolderPanel setCanChooseDirectories: YES];
830         [o_selectFolderPanel setCanChooseFiles: NO];
831         [o_selectFolderPanel setResolvesAliases: YES];
832         [o_selectFolderPanel setAllowsMultipleSelection: NO];
833         [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
834         [o_selectFolderPanel setCanCreateDirectories: YES];
835         [o_selectFolderPanel setPrompt: _NS("Choose")];
836         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win 
837                                       modalDelegate: self 
838                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
839                                         contextInfo: o_video_snap_folder_btn];
840     }
841     else
842         b_videoSettingChanged = YES;
843 }
844
845 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
846 {
847     if( returnCode == NSOKButton )
848     {
849         if( contextInfo == o_video_snap_folder_btn )
850         {
851             [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
852             b_videoSettingChanged = YES;
853         }
854         else if( contextInfo == o_osd_font_btn )
855         {
856             [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
857             b_osdSettingChanged = YES;
858         }
859     }
860
861     [o_selectFolderPanel release];
862 }
863
864 - (void)showVideoSettings
865 {
866     msg_Dbg( p_intf, "showing video settings" );
867     [self showSettingsForCategory: o_video_view];
868 }
869
870 - (IBAction)osdSettingChanged:(id)sender
871 {
872     if( sender == o_osd_font_btn )
873     {
874         o_selectFolderPanel = [[NSOpenPanel alloc] init];
875         [o_selectFolderPanel setCanChooseDirectories: NO];
876         [o_selectFolderPanel setCanChooseFiles: YES];
877         [o_selectFolderPanel setResolvesAliases: YES];
878         [o_selectFolderPanel setAllowsMultipleSelection: NO];
879         [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
880         [o_selectFolderPanel setCanCreateDirectories: NO];
881         [o_selectFolderPanel setPrompt: _NS("Choose")];
882         [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
883         [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win 
884                                       modalDelegate: self 
885                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
886                                         contextInfo: o_osd_font_btn];
887     }
888     else
889         b_osdSettingChanged = YES;
890 }
891
892 - (void)showOSDSettings
893 {
894     msg_Dbg( p_intf, "showing OSD settings" );
895     [self showSettingsForCategory: o_osd_view];
896 }
897
898 - (IBAction)inputSettingChanged:(id)sender
899 {
900     b_inputSettingChanged = YES;
901 }
902
903 - (void)showInputSettings
904 {
905     msg_Dbg( p_intf, "showing Input Settings" );
906     [self showSettingsForCategory: o_input_view];
907 }
908
909 - (IBAction)hotkeySettingChanged:(id)sender
910 {
911     if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
912     {
913         [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""), 
914                                                [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
915         [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
916         [o_hotkeys_change_taken_lbl setStringValue: @""];
917         [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
918         [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
919         [NSApp runModalForWindow: o_hotkeys_change_win];
920     }
921     else if( sender == o_hotkeys_change_cancel_btn )
922     {
923         [NSApp stopModal];
924         [o_hotkeys_change_win close];
925     }
926     else if( sender == o_hotkeys_change_ok_btn )
927     {
928         int i_returnValue;
929         if(! o_keyInTransition )
930         {
931             [NSApp stopModal];
932             [o_hotkeys_change_win close];
933             msg_Err( p_intf, "internal error prevented the hotkey switch" );
934             return;
935         }
936
937         b_hotkeyChanged = YES;
938
939         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
940         if( i_returnValue != NSNotFound )
941             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
942
943         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
944
945         [NSApp stopModal];
946         [o_hotkeys_change_win close];
947
948         [o_hotkeys_listbox reloadData];
949     }
950     else if( sender == o_hotkeys_clear_btn )
951     {
952         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
953         [o_hotkeys_listbox reloadData];
954         b_hotkeyChanged = YES;
955     }
956 }
957
958 - (void)showHotkeySettings
959 {
960     msg_Dbg( p_intf, "showing HotKey Settings" );
961     [self showSettingsForCategory: o_hotkeys_view];
962 }
963
964 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
965 {
966     return [o_hotkeySettings count];
967 }
968
969 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
970 {
971     if( [[aTableColumn identifier] isEqualToString: @"action"] )
972         return [o_hotkeyDescriptions objectAtIndex: rowIndex];
973     else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
974         return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
975     else
976     {
977         msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
978         return NULL;
979     }
980 }
981
982 - (void)changeHotkeyTo: (int)i_theNewKey
983 {
984     int i_returnValue;
985     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
986     if( i_returnValue != NSNotFound || i_theNewKey == 0 )
987     {
988         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
989         [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
990         [o_hotkeys_change_ok_btn setEnabled: NO];
991     }
992     else
993     {
994         NSString *o_temp;
995         if( o_keyInTransition )
996             [o_keyInTransition release];
997         o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
998
999         o_temp = [self OSXKeyToString: i_theNewKey];
1000
1001         [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1002
1003         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1004         if( i_returnValue != NSNotFound )
1005             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1006                                                          _NS("This combination is already taken by \"%@\"."),
1007                                                          [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1008         else
1009             [o_hotkeys_change_taken_lbl setStringValue: @""];
1010
1011         [o_hotkeys_change_ok_btn setEnabled: YES];
1012     }
1013 }
1014     
1015 @end
1016
1017 /********************
1018  * hotkeys settings *
1019  ********************/
1020
1021 @implementation VLCHotkeyChangeWindow
1022
1023 - (BOOL)resignFirstResponder
1024 {
1025     /* We need to stay the first responder or we'll miss the user's input */
1026     return NO;
1027 }
1028
1029 - (void)keyDown:(NSEvent *)o_theEvent
1030 {
1031     int i_nonReadableKey = 0;
1032
1033     if( [o_theEvent modifierFlags] & NSControlKeyMask )
1034         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1035
1036     if( [o_theEvent modifierFlags] & NSAlternateKeyMask  )
1037         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1038
1039     if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1040         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1041
1042     if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1043         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1044
1045     if( [o_theEvent modifierFlags] & NSFunctionKeyMask  )
1046     {
1047         unichar key = 0;
1048         key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1049         
1050         switch( key )
1051         {
1052             case 0x1b:
1053                 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1054                 break;
1055             case NSF1FunctionKey:
1056                 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1057                 break;
1058             case NSF2FunctionKey:
1059                 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1060                 break;
1061             case NSF3FunctionKey:
1062                 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1063                 break;
1064             case NSF4FunctionKey:
1065                 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1066                 break;
1067             case NSF5FunctionKey:
1068                 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1069                 break;
1070             case NSF6FunctionKey:
1071                 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1072                 break;
1073             case NSF7FunctionKey:
1074                 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1075                 break;
1076             case NSF8FunctionKey:
1077                 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1078                 break;
1079             case NSF9FunctionKey:
1080                 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1081                 break;
1082             case NSF10FunctionKey:
1083                 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1084                 break;
1085             case NSF11FunctionKey:
1086                 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1087                 break;
1088             case NSF12FunctionKey:
1089                 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1090                 break;
1091             case NSInsertFunctionKey:
1092                 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1093                 break;
1094             case NSHomeFunctionKey:
1095                 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1096                 break;
1097             case NSEndFunctionKey:
1098                 i_nonReadableKey = i_nonReadableKey | KEY_END;
1099                 break;
1100             case NSPageUpFunctionKey:
1101                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1102                 break;
1103             case NSPageDownFunctionKey:
1104                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1105                 break;
1106             case NSMenuFunctionKey:
1107                 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1108                 break;
1109             case NSTabCharacter:
1110                 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1111                 break;
1112             case NSDeleteCharacter:
1113                 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1114                 break;
1115             case NSBackspaceCharacter:
1116                 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1117                 break;
1118             case NSUpArrowFunctionKey:
1119                 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1120                 break;
1121             case NSDownArrowFunctionKey:
1122                 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1123                 break;
1124             case NSRightArrowFunctionKey:
1125                 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1126                 break;
1127             case NSLeftArrowFunctionKey:
1128                 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1129                 break;
1130             case NSEnterCharacter:
1131                 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1132                 break;
1133             default:
1134             {
1135                 msg_Warn( VLCIntf, "user pressed unknown function key" );
1136                 i_nonReadableKey = 0;
1137                 break;
1138             }
1139         }
1140     }
1141     else
1142     {
1143         if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1144             i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1145         else
1146             i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1147     }
1148
1149     [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];
1150 }
1151
1152 @end