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