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