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