]> git.sesse.net Git - vlc/blob - modules/gui/macosx/simple_prefs.m
implemented the display device selector.
[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 makeKeyAndOrderFront: self];
582 }
583
584 - (IBAction)buttonAction:(id)sender
585 {
586     if( sender == o_sprefs_cancel_btn )
587         [o_sprefs_win orderOut: sender];
588     else if( sender == o_sprefs_save_btn )
589     {
590         [self saveChangedSettings];
591         [o_sprefs_win orderOut: sender];
592     }
593     else if( sender == o_sprefs_reset_btn )
594         NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
595                                         _NS("Continue"), nil, o_sprefs_win, self,
596                                         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
597                                         _NS("Beware this will reset the VLC media player preferences.\n"
598                                             "Are you sure you want to continue?") );
599     else if( sender == o_sprefs_basicFull_matrix )
600     {
601         [o_sprefs_win orderOut: self];
602         [[[VLCMain sharedInstance] getPreferences] showPrefs];
603         [self resetControls];
604     }
605     else
606         msg_Err( p_intf, "unknown buttonAction sender" );
607 }
608
609 - (void)sheetDidEnd:(NSWindow *)o_sheet 
610          returnCode:(int)i_return
611         contextInfo:(void *)o_context
612 {
613     if( i_return == NSAlertAlternateReturn )
614     {
615         config_ResetAll( p_intf );
616         b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
617         [self resetControls];
618     }
619 }
620
621 - (void)saveChangedSettings
622 {
623     module_config_t *p_item;
624     vlc_list_t *p_list;
625     module_t *p_parser;
626     char *psz_tmp;
627     int i;
628     
629 #define SaveIntList( object, name ) \
630     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
631     if( [object indexOfSelectedItem] >= 0 ) \
632         config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
633     else \
634         config_PutInt( p_intf, name, [object intValue] ) \
635                     
636 #define SaveStringList( object, name ) \
637     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
638     if( [object indexOfSelectedItem] >= 0 ) \
639         config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
640     else \
641         config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
642
643 #define SaveModuleList( object, name ) \
644     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
645     \
646     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
647     for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
648     { \
649         p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
650         \
651         if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
652         { \
653             if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
654             { \
655                 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
656                 break; \
657             } \
658         } \
659     } \
660     vlc_list_release( p_list ); \
661     if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
662         config_PutPsz( p_intf, name, "" )
663
664     /**********************
665      * interface settings *
666      **********************/
667     if( b_intfSettingChanged )
668     {
669         SaveStringList( o_intf_lang_pop, "language" );
670         SaveIntList( o_intf_art_pop, "album-art" );
671
672         config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
673         config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
674         config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
675
676         /* okay, let's save our changes to vlcrc */
677         i = config_SaveConfigFile( p_intf, "main" );
678         i = config_SaveConfigFile( p_intf, "macosx" );
679
680         if( i != 0 )
681         {
682             msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
683             i = 0;
684         }
685
686         b_intfSettingChanged = NO;
687     }
688     
689     /******************
690      * audio settings *
691      ******************/
692     if( b_audioSettingChanged )
693     {
694         config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
695         config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
696         config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
697
698         SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
699
700         config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
701         config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
702
703         psz_tmp = config_GetPsz( p_intf, "audio-filter" );
704         if(! psz_tmp)
705             config_PutPsz( p_intf, "audio-filter", "volnorm" );
706         else if( (int)strstr( psz_tmp, "normvol" ) == NO )
707         {
708             /* work-around a GCC 4.0.1 bug */
709             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
710             config_PutPsz( p_intf, "audio-filter", psz_tmp );
711         }
712         else
713         {
714             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
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             config_PutPsz( p_intf, "audio-filter", psz_tmp );
718         }
719         config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
720
721         SaveModuleList( o_audio_visual_pop, "audio-visual" );
722
723         /* Last.FM is optional */
724         if( module_Exists( p_intf, "audioscrobbler" ) )
725         {    
726             if( [o_audio_last_ckb state] == NSOnState )
727                 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
728             else
729                 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
730
731             config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
732             config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
733         }
734
735         /* okay, let's save our changes to vlcrc */
736         i = config_SaveConfigFile( p_intf, "main" );
737         i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
738         i = i + config_SaveConfigFile( p_intf, "volnorm" );
739
740         if( i != 0 )
741         {
742             msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
743             i = 0;
744         }
745         b_audioSettingChanged = NO;
746     }
747     
748     /******************
749      * video settings *
750      ******************/
751     if( b_videoSettingChanged )
752     {
753         config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
754         config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
755         config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
756         config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
757         config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
758
759         SaveModuleList( o_video_output_pop, "vout" );
760         config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
761
762         config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
763         config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
764         config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
765
766         if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
767             config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
768
769         i = config_SaveConfigFile( p_intf, "main" );
770         i = i + config_SaveConfigFile( p_intf, "macosx" );
771
772         if( i != 0 )
773         {
774             msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
775             i = 0;
776         }
777         b_videoSettingChanged = NO;
778     }
779     
780     /***************************
781      * input & codecs settings *
782      ***************************/
783     if( b_inputSettingChanged )
784     {
785         config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
786         config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
787         config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
788
789         SaveIntList( o_input_avi_pop, "avi-index" );
790
791         config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
792
793         #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
794         #define CaC( name ) CaCi( name, 1 )
795         msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
796         CaC( "udp-caching" );
797         if( module_Exists (p_intf, "dvdread" ) )
798         {
799             CaC( "dvdread-caching" );
800             i = i + config_SaveConfigFile( p_intf, "dvdread" );
801         }
802         if( module_Exists (p_intf, "dvdnav" ) )
803         {
804             CaC( "dvdnav-caching" );
805             i = i + config_SaveConfigFile( p_intf, "dvdnav" );
806         }
807         CaC( "tcp-caching" ); CaC( "vcd-caching" );
808         CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
809         CaC( "screen-caching" );
810         CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
811         CaCi( "http-caching", 4 );
812         if( module_Exists (p_intf, "access_realrtsp" ) )
813         {
814             CaCi( "realrtsp-caching", 10 );
815             i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
816         }
817         CaCi( "mms-caching", 19 );
818
819         #define SaveAccessFilter( object, name ) \
820         if( [object state] == NSOnState ) \
821         { \
822             if( b_first ) \
823             { \
824                 [o_temp appendString: name]; \
825                 b_first = NO; \
826             } \
827             else \
828                 [o_temp appendFormat: @":%@", name]; \
829         }
830
831         BOOL b_first = YES;
832         NSMutableString *o_temp = [[NSMutableString alloc] init];
833         SaveAccessFilter( o_input_record_ckb, @"record" );
834         SaveAccessFilter( o_input_dump_ckb, @"dump" );
835         SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
836         SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
837         config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
838         [o_temp release];
839
840         i = config_SaveConfigFile( p_intf, "main" );
841         i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
842         i = i + config_SaveConfigFile( p_intf, "access_http" );
843         i = i + config_SaveConfigFile( p_intf, "access_file" );
844         i = i + config_SaveConfigFile( p_intf, "access_tcp" );
845         i = i + config_SaveConfigFile( p_intf, "access_fake" );
846         i = i + config_SaveConfigFile( p_intf, "cdda" );
847         i = i + config_SaveConfigFile( p_intf, "screen" );
848         i = i + config_SaveConfigFile( p_intf, "vcd" );
849         i = i + config_SaveConfigFile( p_intf, "access_ftp" );
850         i = i + config_SaveConfigFile( p_intf, "access_mms" );
851         i = i + config_SaveConfigFile( p_intf, "live555" );
852
853         if( i != 0 )
854         {
855             msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
856             i = 0;
857         }
858         b_inputSettingChanged = NO;
859     }
860     
861     /**********************
862      * subtitles settings *
863      **********************/
864     if( b_osdSettingChanged )
865     {
866         config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
867
868         if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
869             config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
870
871         config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
872         config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
873
874         SaveIntList( o_osd_font_color_pop, "freetype-color" );
875         SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
876         SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
877
878         i = config_SaveConfigFile( p_intf, NULL );
879
880         if( i != 0 )
881         {
882             msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
883             i = 0;
884         }
885         b_osdSettingChanged = NO;
886     }
887     
888     /********************
889      * hotkeys settings *
890      ********************/
891     if( b_hotkeyChanged )
892     {
893         struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
894         i = 1;
895         while( i < [o_hotkeySettings count] )
896         {
897             config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
898             i++;
899         }        
900
901         i = config_SaveConfigFile( p_intf, "main" );
902
903         if( i != 0 )
904         {
905             msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
906             i = 0;
907         }
908         b_hotkeyChanged = NO;
909     }
910 }
911
912 - (void)showSettingsForCategory: (id)o_new_category_view
913 {
914     NSRect o_win_rect, o_view_rect, o_old_view_rect;
915     o_win_rect = [o_sprefs_win frame];
916     o_view_rect = [o_new_category_view frame];
917     
918     if( o_currentlyShownCategoryView != nil )
919     {
920         /* restore our window's height, if we've shown another category previously */
921         o_old_view_rect = [o_currentlyShownCategoryView frame];
922         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
923
924         /* remove our previous category view */
925         [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
926     }
927     
928     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
929     
930     [o_sprefs_win displayIfNeeded];
931     [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
932     
933     [o_new_category_view setFrame: NSMakeRect( 0, 
934                                                [o_sprefs_controls_box frame].size.height, 
935                                                o_view_rect.size.width, 
936                                                o_view_rect.size.height )];
937     [o_new_category_view setNeedsDisplay: YES];
938     [o_new_category_view setAutoresizesSubviews: YES];
939     [[o_sprefs_win contentView] addSubview: o_new_category_view];
940     
941     /* keep our current category for further reference */
942     [o_currentlyShownCategoryView release];
943     o_currentlyShownCategoryView = o_new_category_view;
944     [o_currentlyShownCategoryView retain];
945 }
946
947 - (IBAction)interfaceSettingChanged:(id)sender
948 {
949     b_intfSettingChanged = YES;
950 }
951
952 - (void)showInterfaceSettings
953 {
954     msg_Dbg( p_intf, "showing interface settings" );
955     [self showSettingsForCategory: o_intf_view];
956 }
957
958 - (IBAction)audioSettingChanged:(id)sender
959 {
960     if( sender == o_audio_vol_sld )
961         [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
962     
963     if( sender == o_audio_vol_fld )
964         [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
965     
966     b_audioSettingChanged = YES;
967 }
968
969 - (void)showAudioSettings
970 {
971     msg_Dbg( p_intf, "showing audio settings" );
972     [self showSettingsForCategory: o_audio_view];
973 }
974
975 - (IBAction)videoSettingChanged:(id)sender
976 {
977     if( sender == o_video_snap_folder_btn )
978     {
979         o_selectFolderPanel = [[NSOpenPanel alloc] init];
980         [o_selectFolderPanel setCanChooseDirectories: YES];
981         [o_selectFolderPanel setCanChooseFiles: NO];
982         [o_selectFolderPanel setResolvesAliases: YES];
983         [o_selectFolderPanel setAllowsMultipleSelection: NO];
984         [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
985         [o_selectFolderPanel setCanCreateDirectories: YES];
986         [o_selectFolderPanel setPrompt: _NS("Choose")];
987         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win 
988                                       modalDelegate: self 
989                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
990                                         contextInfo: o_video_snap_folder_btn];
991     }
992     else
993         b_videoSettingChanged = YES;
994 }
995
996 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
997 {
998     if( returnCode == NSOKButton )
999     {
1000         if( contextInfo == o_video_snap_folder_btn )
1001         {
1002             [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1003             b_videoSettingChanged = YES;
1004         }
1005         else if( contextInfo == o_osd_font_btn )
1006         {
1007             [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1008             b_osdSettingChanged = YES;
1009         }
1010     }
1011
1012     [o_selectFolderPanel release];
1013 }
1014
1015 - (void)showVideoSettings
1016 {
1017     msg_Dbg( p_intf, "showing video settings" );
1018     [self showSettingsForCategory: o_video_view];
1019 }
1020
1021 - (IBAction)osdSettingChanged:(id)sender
1022 {
1023     if( sender == o_osd_font_btn )
1024     {
1025         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1026         [o_selectFolderPanel setCanChooseDirectories: NO];
1027         [o_selectFolderPanel setCanChooseFiles: YES];
1028         [o_selectFolderPanel setResolvesAliases: YES];
1029         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1030         [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1031         [o_selectFolderPanel setCanCreateDirectories: NO];
1032         [o_selectFolderPanel setPrompt: _NS("Choose")];
1033         [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1034         [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win 
1035                                       modalDelegate: self 
1036                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1037                                         contextInfo: o_osd_font_btn];
1038     }
1039     else
1040         b_osdSettingChanged = YES;
1041 }
1042
1043 - (void)showOSDSettings
1044 {
1045     msg_Dbg( p_intf, "showing OSD settings" );
1046     [self showSettingsForCategory: o_osd_view];
1047 }
1048
1049 - (IBAction)inputSettingChanged:(id)sender
1050 {
1051     b_inputSettingChanged = YES;
1052 }
1053
1054 - (void)showInputSettings
1055 {
1056     msg_Dbg( p_intf, "showing Input Settings" );
1057     [self showSettingsForCategory: o_input_view];
1058 }
1059
1060 - (IBAction)hotkeySettingChanged:(id)sender
1061 {
1062     if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1063     {
1064         [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""), 
1065                                                [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1066         [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1067         [o_hotkeys_change_taken_lbl setStringValue: @""];
1068         [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1069         [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1070         [NSApp runModalForWindow: o_hotkeys_change_win];
1071     }
1072     else if( sender == o_hotkeys_change_cancel_btn )
1073     {
1074         [NSApp stopModal];
1075         [o_hotkeys_change_win close];
1076     }
1077     else if( sender == o_hotkeys_change_ok_btn )
1078     {
1079         int i_returnValue;
1080         if(! o_keyInTransition )
1081         {
1082             [NSApp stopModal];
1083             [o_hotkeys_change_win close];
1084             msg_Err( p_intf, "internal error prevented the hotkey switch" );
1085             return;
1086         }
1087
1088         b_hotkeyChanged = YES;
1089
1090         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1091         if( i_returnValue != NSNotFound )
1092             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1093
1094         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1095
1096         [NSApp stopModal];
1097         [o_hotkeys_change_win close];
1098
1099         [o_hotkeys_listbox reloadData];
1100     }
1101     else if( sender == o_hotkeys_clear_btn )
1102     {
1103         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1104         [o_hotkeys_listbox reloadData];
1105         b_hotkeyChanged = YES;
1106     }
1107 }
1108
1109 - (void)showHotkeySettings
1110 {
1111     msg_Dbg( p_intf, "showing HotKey Settings" );
1112     [self showSettingsForCategory: o_hotkeys_view];
1113 }
1114
1115 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1116 {
1117     return [o_hotkeySettings count];
1118 }
1119
1120 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1121 {
1122     if( [[aTableColumn identifier] isEqualToString: @"action"] )
1123         return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1124     else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1125         return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1126     else
1127     {
1128         msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1129         return NULL;
1130     }
1131 }
1132
1133 - (void)changeHotkeyTo: (int)i_theNewKey
1134 {
1135     int i_returnValue;
1136     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1137     if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1138     {
1139         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1140         [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1141         [o_hotkeys_change_ok_btn setEnabled: NO];
1142     }
1143     else
1144     {
1145         NSString *o_temp;
1146         if( o_keyInTransition )
1147             [o_keyInTransition release];
1148         o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1149
1150         o_temp = [self OSXKeyToString: i_theNewKey];
1151
1152         [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1153
1154         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1155         if( i_returnValue != NSNotFound )
1156             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1157                                                          _NS("This combination is already taken by \"%@\"."),
1158                                                          [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1159         else
1160             [o_hotkeys_change_taken_lbl setStringValue: @""];
1161
1162         [o_hotkeys_change_ok_btn setEnabled: YES];
1163     }
1164 }
1165     
1166 @end
1167
1168 /********************
1169  * hotkeys settings *
1170  ********************/
1171
1172 @implementation VLCHotkeyChangeWindow
1173
1174 - (BOOL)resignFirstResponder
1175 {
1176     /* We need to stay the first responder or we'll miss the user's input */
1177     return NO;
1178 }
1179
1180 - (void)keyDown:(NSEvent *)o_theEvent
1181 {
1182     int i_nonReadableKey = 0;
1183
1184     if( [o_theEvent modifierFlags] & NSControlKeyMask )
1185         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1186
1187     if( [o_theEvent modifierFlags] & NSAlternateKeyMask  )
1188         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1189
1190     if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1191         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1192
1193     if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1194         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1195
1196     if( [o_theEvent modifierFlags] & NSFunctionKeyMask  )
1197     {
1198         unichar key = 0;
1199         key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1200         
1201         switch( key )
1202         {
1203             case 0x1b:
1204                 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1205                 break;
1206             case NSF1FunctionKey:
1207                 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1208                 break;
1209             case NSF2FunctionKey:
1210                 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1211                 break;
1212             case NSF3FunctionKey:
1213                 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1214                 break;
1215             case NSF4FunctionKey:
1216                 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1217                 break;
1218             case NSF5FunctionKey:
1219                 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1220                 break;
1221             case NSF6FunctionKey:
1222                 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1223                 break;
1224             case NSF7FunctionKey:
1225                 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1226                 break;
1227             case NSF8FunctionKey:
1228                 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1229                 break;
1230             case NSF9FunctionKey:
1231                 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1232                 break;
1233             case NSF10FunctionKey:
1234                 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1235                 break;
1236             case NSF11FunctionKey:
1237                 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1238                 break;
1239             case NSF12FunctionKey:
1240                 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1241                 break;
1242             case NSInsertFunctionKey:
1243                 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1244                 break;
1245             case NSHomeFunctionKey:
1246                 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1247                 break;
1248             case NSEndFunctionKey:
1249                 i_nonReadableKey = i_nonReadableKey | KEY_END;
1250                 break;
1251             case NSPageUpFunctionKey:
1252                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1253                 break;
1254             case NSPageDownFunctionKey:
1255                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1256                 break;
1257             case NSMenuFunctionKey:
1258                 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1259                 break;
1260             case NSTabCharacter:
1261                 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1262                 break;
1263             case NSDeleteCharacter:
1264                 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1265                 break;
1266             case NSBackspaceCharacter:
1267                 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1268                 break;
1269             case NSUpArrowFunctionKey:
1270                 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1271                 break;
1272             case NSDownArrowFunctionKey:
1273                 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1274                 break;
1275             case NSRightArrowFunctionKey:
1276                 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1277                 break;
1278             case NSLeftArrowFunctionKey:
1279                 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1280                 break;
1281             case NSEnterCharacter:
1282                 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1283                 break;
1284             default:
1285             {
1286                 msg_Warn( VLCIntf, "user pressed unknown function key" );
1287                 i_nonReadableKey = 0;
1288                 break;
1289             }
1290         }
1291     }
1292     else
1293     {
1294         if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1295             i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1296         else
1297             i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1298     }
1299
1300     [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];
1301 }
1302
1303 @end