]> git.sesse.net Git - vlc/blob - modules/gui/macosx/simple_prefs.m
Implement the full/basic switch correctly and completely. Additionally, fixed a rare...
[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         _o_sharedInstance = [super init];
52         p_intf = VLCIntf;
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     /* video */
278     [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
279     [o_video_device_txt setStringValue: _NS("Display device")];
280     [o_video_display_box setTitle: _NS("Display")];
281     [o_video_enable_ckb setTitle: _NS("Enable Video")];
282     [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
283     [o_video_onTop_ckb setTitle: _NS("Always on top")];
284     [o_video_output_txt setStringValue: _NS("Output module")];
285     [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
286     [o_video_snap_box setTitle: _NS("Video snapshots")];
287     [o_video_snap_folder_btn setTitle: _NS("Browse...")];
288     [o_video_snap_folder_txt setStringValue: _NS("Folder")];
289     [o_video_snap_format_txt setStringValue: _NS("Format")];
290     [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
291     [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
292     
293     /* generic stuff */
294     [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
295     [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
296     [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
297     [o_sprefs_reset_btn setTitle: _NS("Reset Preferences")];
298     [o_sprefs_save_btn setTitle: _NS("Save")];
299     [o_sprefs_win setTitle: _NS("Preferences")];
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     [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
360     [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
361     
362     /**********************
363      * interface settings *
364      **********************/
365     SetupStringList( o_intf_lang_pop, "language" );
366     SetupIntList( o_intf_art_pop, "album-art" );
367
368     [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
369     [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
370     [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
371
372     /******************
373      * audio settings *
374      ******************/
375     [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
376     [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
377     [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
378
379     [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
380
381     SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
382
383     [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
384
385     [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
386     
387     psz_tmp = config_GetPsz( p_intf, "audio-filter" );
388     if( psz_tmp )
389         [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
390     [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
391
392     SetupModuleList( o_audio_visual_pop, "audio-visual" );
393
394     /* Last.FM is optional */
395     if( module_Exists( p_intf, "audioscrobbler" ) )
396     {
397         [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
398         [o_audio_lastpwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
399
400         if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
401         {
402             [o_audio_last_ckb setState: NSOnState];
403             [o_audio_lastuser_fld setEnabled: YES];
404             [o_audio_lastpwd_sfld setEnabled: YES];
405         }
406         else
407         {
408             [o_audio_last_ckb setState: NSOffState];
409             [o_audio_lastuser_fld setEnabled: NO];
410             [o_audio_lastpwd_sfld setEnabled: NO];
411         }
412     }
413     else
414         [o_audio_last_ckb setEnabled: NO];
415
416     /******************
417      * video settings *
418      ******************/
419     [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
420     [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
421     [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
422     [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
423     [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
424
425     SetupModuleList( o_video_output_pop, "vout" );
426
427     [o_video_device_pop removeAllItems];
428     i = 0;
429     y = [[NSScreen screens] count];
430     [o_video_device_pop addItemWithTitle: _NS("Default")];
431     [[o_video_device_pop lastItem] setTag: 0];
432     while( i < y )
433     {
434         NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
435         [o_video_device_pop addItemWithTitle: 
436          [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
437                    (int)s_rect.size.width, (int)s_rect.size.height]];
438         [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
439         i++;
440     }
441     [o_video_device_pop selectItemAtIndex: 0];
442     [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
443
444     if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
445         [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
446     [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
447     [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
448     
449     p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
450     for( i = 0; p_item->ppsz_list[i] != nil; i++ )
451     {
452         [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
453         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
454             y = i;
455     }
456     [o_video_snap_format_pop selectItemAtIndex: y];
457
458     /***************************
459      * input & codecs settings *
460      ***************************/
461     [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
462     if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
463         [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
464     if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
465         [o_input_httpproxypwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy-pwd" )]];
466     [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
467
468     SetupIntList( o_input_avi_pop, "avi-index" );
469
470     [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
471
472     psz_tmp = config_GetPsz( p_intf, "access-filter" );
473     if( psz_tmp )
474     {
475         [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
476         [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
477         [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
478         [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
479     }
480
481     [o_input_cachelevel_pop removeAllItems];
482     [o_input_cachelevel_pop addItemsWithTitles: 
483         [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
484             _NS("High latency"), _NS("Higher latency"), nil]];
485     [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
486     [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
487     [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
488     [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
489     [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
490     [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
491     
492 #define TestCaC( name ) \
493     b_cache_equal =  b_cache_equal && \
494         ( i_cache == config_GetInt( p_intf, name ) )
495
496 #define TestCaCi( name, int ) \
497         b_cache_equal = b_cache_equal &&  \
498         ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
499
500     /* Select the accurate value of the PopupButton */
501     bool b_cache_equal = true;
502     int i_cache = config_GetInt( p_intf, "file-caching");
503     
504     TestCaC( "udp-caching" );
505     if( module_Exists (p_intf, "dvdread") )
506         TestCaC( "dvdread-caching" );
507     if( module_Exists (p_intf, "dvdnav") )
508         TestCaC( "dvdnav-caching" );
509     TestCaC( "tcp-caching" );
510     TestCaC( "fake-caching" );
511     TestCaC( "cdda-caching" );
512     TestCaC( "screen-caching" );
513     TestCaC( "vcd-caching" );
514     TestCaCi( "rtsp-caching", 4 );
515     TestCaCi( "ftp-caching", 2 );
516     TestCaCi( "http-caching", 4 );
517     if(module_Exists (p_intf, "access_realrtsp"))
518         TestCaCi( "realrtsp-caching", 10 );
519     TestCaCi( "mms-caching", 19 );
520     if( b_cache_equal )
521     {
522         [o_input_cachelevel_pop selectItemWithTag: i_cache];
523         [o_input_cachelevel_custom_txt setHidden: YES];
524     }
525     else
526     {
527         [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
528         [o_input_cachelevel_custom_txt setHidden: NO];
529     }
530
531     /*********************
532      * subtitle settings *
533      *********************/
534     [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
535     
536     [o_osd_encoding_pop removeAllItems];
537     y = 0;
538     p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
539     for( i = 0; p_item->ppsz_list[i] != nil; i++ )
540     {
541         if( p_item->ppsz_list[i] != "" )
542             [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
543         else
544             [o_osd_encoding_pop addItemWithTitle: @" "];
545
546         if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
547             y = i;
548     }
549     [o_osd_encoding_pop selectItemAtIndex: y];
550     
551     [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
552     if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
553         [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
554
555     SetupIntList( o_osd_font_color_pop, "freetype-color" );
556     SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
557     SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
558
559     /********************
560      * hotkeys settings *
561      ********************/
562     struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
563     o_hotkeySettings = [[NSMutableArray alloc] init];
564     NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
565     i = 1;
566
567     while( i < 100 )
568     {
569         p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
570         if( !p_item )
571             break;
572
573         [o_tempArray_desc addObject: _NS( p_item->psz_text )];
574         [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
575
576         i++;
577     }
578     o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
579     [o_tempArray_desc release];
580     [o_hotkeys_listbox reloadData];
581 }
582
583 - (void)showSimplePrefs
584 {
585     /* we want to show the interface settings, if no category was chosen */
586     if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
587     {
588         [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
589         [self showInterfaceSettings];
590     }
591     
592     [self resetControls];
593
594     [o_sprefs_win center];
595     [o_sprefs_win makeKeyAndOrderFront: self];
596 }
597
598 - (IBAction)buttonAction:(id)sender
599 {
600     if( sender == o_sprefs_cancel_btn )
601         [o_sprefs_win orderOut: sender];
602     else if( sender == o_sprefs_save_btn )
603     {
604         [self saveChangedSettings];
605         [o_sprefs_win orderOut: sender];
606     }
607     else if( sender == o_sprefs_reset_btn )
608         NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
609                                         _NS("Continue"), nil, o_sprefs_win, self,
610                                         @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
611                                         _NS("Beware this will reset the VLC media player preferences.\n"
612                                             "Are you sure you want to continue?") );
613     else if( sender == o_sprefs_basicFull_matrix )
614     {
615         [o_sprefs_win orderOut: self];
616         [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
617         [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
618         [[[VLCMain sharedInstance] getPreferences] showPrefs];
619     }
620     else
621         msg_Err( p_intf, "unknown buttonAction sender" );
622 }
623
624 - (void)sheetDidEnd:(NSWindow *)o_sheet 
625          returnCode:(int)i_return
626         contextInfo:(void *)o_context
627 {
628     if( i_return == NSAlertAlternateReturn )
629     {
630         config_ResetAll( p_intf );
631         b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
632         [self resetControls];
633     }
634 }
635
636 - (void)saveChangedSettings
637 {
638     module_config_t *p_item;
639     vlc_list_t *p_list;
640     module_t *p_parser;
641     char *psz_tmp;
642     int i;
643     
644 #define SaveIntList( object, name ) \
645     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
646     if( [object indexOfSelectedItem] >= 0 ) \
647         config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
648     else \
649         config_PutInt( p_intf, name, [object intValue] ) \
650                     
651 #define SaveStringList( object, name ) \
652     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
653     if( [object indexOfSelectedItem] >= 0 ) \
654         config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
655     else \
656         config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
657
658 #define SaveModuleList( object, name ) \
659     p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
660     \
661     p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
662     for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
663     { \
664         p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
665         \
666         if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
667         { \
668             if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
669             { \
670                 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
671                 break; \
672             } \
673         } \
674     } \
675     vlc_list_release( p_list ); \
676     if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
677         config_PutPsz( p_intf, name, "" )
678
679     /**********************
680      * interface settings *
681      **********************/
682     if( b_intfSettingChanged )
683     {
684         SaveStringList( o_intf_lang_pop, "language" );
685         SaveIntList( o_intf_art_pop, "album-art" );
686
687         config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
688         config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
689         config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
690
691         /* okay, let's save our changes to vlcrc */
692         i = config_SaveConfigFile( p_intf, "main" );
693         i = config_SaveConfigFile( p_intf, "macosx" );
694
695         if( i != 0 )
696         {
697             msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
698             i = 0;
699         }
700
701         b_intfSettingChanged = NO;
702     }
703     
704     /******************
705      * audio settings *
706      ******************/
707     if( b_audioSettingChanged )
708     {
709         config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
710         config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
711         config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
712
713         SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
714
715         config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
716         config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
717
718         psz_tmp = config_GetPsz( p_intf, "audio-filter" );
719         if(! psz_tmp)
720             config_PutPsz( p_intf, "audio-filter", "volnorm" );
721         else if( (int)strstr( psz_tmp, "normvol" ) == NO )
722         {
723             /* work-around a GCC 4.0.1 bug */
724             psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
725             config_PutPsz( p_intf, "audio-filter", psz_tmp );
726         }
727         else
728         {
729             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
730             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
731             psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
732             config_PutPsz( p_intf, "audio-filter", psz_tmp );
733         }
734         config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
735
736         SaveModuleList( o_audio_visual_pop, "audio-visual" );
737
738         /* Last.FM is optional */
739         if( module_Exists( p_intf, "audioscrobbler" ) )
740         {   
741             [o_audio_last_ckb setEnabled: YES];
742             if( [o_audio_last_ckb state] == NSOnState )
743                 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
744             else
745                 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
746
747             config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
748             config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
749         }
750         else
751             [o_audio_last_ckb setEnabled: NO];
752
753         /* okay, let's save our changes to vlcrc */
754         i = config_SaveConfigFile( p_intf, "main" );
755         i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
756         i = i + config_SaveConfigFile( p_intf, "volnorm" );
757
758         if( i != 0 )
759         {
760             msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
761             i = 0;
762         }
763         b_audioSettingChanged = NO;
764     }
765     
766     /******************
767      * video settings *
768      ******************/
769     if( b_videoSettingChanged )
770     {
771         config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
772         config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
773         config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
774         config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
775         config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
776
777         SaveModuleList( o_video_output_pop, "vout" );
778         config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
779
780         config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
781         config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
782         config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
783
784         if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
785             config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
786
787         i = config_SaveConfigFile( p_intf, "main" );
788         i = i + config_SaveConfigFile( p_intf, "macosx" );
789
790         if( i != 0 )
791         {
792             msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
793             i = 0;
794         }
795         b_videoSettingChanged = NO;
796     }
797     
798     /***************************
799      * input & codecs settings *
800      ***************************/
801     if( b_inputSettingChanged )
802     {
803         config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
804         config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
805         config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
806         config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
807
808         SaveIntList( o_input_avi_pop, "avi-index" );
809
810         config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
811
812         #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
813         #define CaC( name ) CaCi( name, 1 )
814         msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
815         CaC( "udp-caching" );
816         if( module_Exists (p_intf, "dvdread" ) )
817         {
818             CaC( "dvdread-caching" );
819             i = i + config_SaveConfigFile( p_intf, "dvdread" );
820         }
821         if( module_Exists (p_intf, "dvdnav" ) )
822         {
823             CaC( "dvdnav-caching" );
824             i = i + config_SaveConfigFile( p_intf, "dvdnav" );
825         }
826         CaC( "tcp-caching" ); CaC( "vcd-caching" );
827         CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
828         CaC( "screen-caching" );
829         CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
830         CaCi( "http-caching", 4 );
831         if( module_Exists (p_intf, "access_realrtsp" ) )
832         {
833             CaCi( "realrtsp-caching", 10 );
834             i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
835         }
836         CaCi( "mms-caching", 19 );
837
838         #define SaveAccessFilter( object, name ) \
839         if( [object state] == NSOnState ) \
840         { \
841             if( b_first ) \
842             { \
843                 [o_temp appendString: name]; \
844                 b_first = NO; \
845             } \
846             else \
847                 [o_temp appendFormat: @":%@", name]; \
848         }
849
850         BOOL b_first = YES;
851         NSMutableString *o_temp = [[NSMutableString alloc] init];
852         SaveAccessFilter( o_input_record_ckb, @"record" );
853         SaveAccessFilter( o_input_dump_ckb, @"dump" );
854         SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
855         SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
856         config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
857         [o_temp release];
858
859         i = config_SaveConfigFile( p_intf, "main" );
860         i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
861         i = i + config_SaveConfigFile( p_intf, "access_http" );
862         i = i + config_SaveConfigFile( p_intf, "access_file" );
863         i = i + config_SaveConfigFile( p_intf, "access_tcp" );
864         i = i + config_SaveConfigFile( p_intf, "access_fake" );
865         i = i + config_SaveConfigFile( p_intf, "cdda" );
866         i = i + config_SaveConfigFile( p_intf, "screen" );
867         i = i + config_SaveConfigFile( p_intf, "vcd" );
868         i = i + config_SaveConfigFile( p_intf, "access_ftp" );
869         i = i + config_SaveConfigFile( p_intf, "access_mms" );
870         i = i + config_SaveConfigFile( p_intf, "live555" );
871
872         if( i != 0 )
873         {
874             msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
875             i = 0;
876         }
877         b_inputSettingChanged = NO;
878     }
879     
880     /**********************
881      * subtitles settings *
882      **********************/
883     if( b_osdSettingChanged )
884     {
885         config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
886
887         if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
888             config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
889
890         config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
891         config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
892
893         SaveIntList( o_osd_font_color_pop, "freetype-color" );
894         SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
895         SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
896
897         i = config_SaveConfigFile( p_intf, NULL );
898
899         if( i != 0 )
900         {
901             msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
902             i = 0;
903         }
904         b_osdSettingChanged = NO;
905     }
906     
907     /********************
908      * hotkeys settings *
909      ********************/
910     if( b_hotkeyChanged )
911     {
912         struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
913         i = 1;
914         while( i < [o_hotkeySettings count] )
915         {
916             config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
917             i++;
918         }        
919
920         i = config_SaveConfigFile( p_intf, "main" );
921
922         if( i != 0 )
923         {
924             msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
925             i = 0;
926         }
927         b_hotkeyChanged = NO;
928     }
929 }
930
931 - (void)showSettingsForCategory: (id)o_new_category_view
932 {
933     NSRect o_win_rect, o_view_rect, o_old_view_rect;
934     o_win_rect = [o_sprefs_win frame];
935     o_view_rect = [o_new_category_view frame];
936     
937     if( o_currentlyShownCategoryView != nil )
938     {
939         /* restore our window's height, if we've shown another category previously */
940         o_old_view_rect = [o_currentlyShownCategoryView frame];
941         o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
942         o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
943
944         /* remove our previous category view */
945         [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
946     }
947     
948     o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
949     
950     [o_sprefs_win displayIfNeeded];
951     [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
952     
953     [o_new_category_view setFrame: NSMakeRect( 0, 
954                                                [o_sprefs_controls_box frame].size.height, 
955                                                o_view_rect.size.width, 
956                                                o_view_rect.size.height )];
957     [o_new_category_view setNeedsDisplay: YES];
958     [o_new_category_view setAutoresizesSubviews: YES];
959     [[o_sprefs_win contentView] addSubview: o_new_category_view];
960     
961     /* keep our current category for further reference */
962     [o_currentlyShownCategoryView release];
963     o_currentlyShownCategoryView = o_new_category_view;
964     [o_currentlyShownCategoryView retain];
965 }
966
967 - (IBAction)interfaceSettingChanged:(id)sender
968 {
969     b_intfSettingChanged = YES;
970 }
971
972 - (void)showInterfaceSettings
973 {
974     msg_Dbg( p_intf, "showing interface settings" );
975     [self showSettingsForCategory: o_intf_view];
976 }
977
978 - (IBAction)audioSettingChanged:(id)sender
979 {
980     if( sender == o_audio_vol_sld )
981         [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
982
983     if( sender == o_audio_vol_fld )
984         [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
985
986     if( sender == o_audio_last_ckb )
987     {
988         if( [o_audio_last_ckb state] == NSOnState )
989         {
990             [o_audio_lastpwd_sfld setEnabled: YES];
991             [o_audio_lastuser_fld setEnabled: YES];
992         }
993         else
994         {
995             [o_audio_lastpwd_sfld setEnabled: NO];
996             [o_audio_lastuser_fld setEnabled: NO];
997         }
998     }
999
1000     b_audioSettingChanged = YES;
1001 }
1002
1003 - (void)showAudioSettings
1004 {
1005     msg_Dbg( p_intf, "showing audio settings" );
1006     [self showSettingsForCategory: o_audio_view];
1007 }
1008
1009 - (IBAction)videoSettingChanged:(id)sender
1010 {
1011     if( sender == o_video_snap_folder_btn )
1012     {
1013         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1014         [o_selectFolderPanel setCanChooseDirectories: YES];
1015         [o_selectFolderPanel setCanChooseFiles: NO];
1016         [o_selectFolderPanel setResolvesAliases: YES];
1017         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1018         [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1019         [o_selectFolderPanel setCanCreateDirectories: YES];
1020         [o_selectFolderPanel setPrompt: _NS("Choose")];
1021         [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win 
1022                                       modalDelegate: self 
1023                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1024                                         contextInfo: o_video_snap_folder_btn];
1025     }
1026     else
1027         b_videoSettingChanged = YES;
1028 }
1029
1030 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1031 {
1032     if( returnCode == NSOKButton )
1033     {
1034         if( contextInfo == o_video_snap_folder_btn )
1035         {
1036             [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1037             b_videoSettingChanged = YES;
1038         }
1039         else if( contextInfo == o_osd_font_btn )
1040         {
1041             [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1042             b_osdSettingChanged = YES;
1043         }
1044     }
1045
1046     [o_selectFolderPanel release];
1047 }
1048
1049 - (void)showVideoSettings
1050 {
1051     msg_Dbg( p_intf, "showing video settings" );
1052     [self showSettingsForCategory: o_video_view];
1053 }
1054
1055 - (IBAction)osdSettingChanged:(id)sender
1056 {
1057     if( sender == o_osd_font_btn )
1058     {
1059         o_selectFolderPanel = [[NSOpenPanel alloc] init];
1060         [o_selectFolderPanel setCanChooseDirectories: NO];
1061         [o_selectFolderPanel setCanChooseFiles: YES];
1062         [o_selectFolderPanel setResolvesAliases: YES];
1063         [o_selectFolderPanel setAllowsMultipleSelection: NO];
1064         [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1065         [o_selectFolderPanel setCanCreateDirectories: NO];
1066         [o_selectFolderPanel setPrompt: _NS("Choose")];
1067         [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1068         [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win 
1069                                       modalDelegate: self 
1070                                      didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1071                                         contextInfo: o_osd_font_btn];
1072     }
1073     else
1074         b_osdSettingChanged = YES;
1075 }
1076
1077 - (void)showOSDSettings
1078 {
1079     msg_Dbg( p_intf, "showing OSD settings" );
1080     [self showSettingsForCategory: o_osd_view];
1081 }
1082
1083 - (IBAction)inputSettingChanged:(id)sender
1084 {
1085     if( sender == o_input_cachelevel_pop )
1086     {
1087         if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1088             [o_input_cachelevel_custom_txt setHidden: NO];
1089         else
1090             [o_input_cachelevel_custom_txt setHidden: YES];
1091     }
1092
1093     b_inputSettingChanged = YES;
1094 }
1095
1096 - (void)showInputSettings
1097 {
1098     msg_Dbg( p_intf, "showing Input Settings" );
1099     [self showSettingsForCategory: o_input_view];
1100 }
1101
1102 - (IBAction)hotkeySettingChanged:(id)sender
1103 {
1104     if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1105     {
1106         [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""), 
1107                                                [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1108         [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1109         [o_hotkeys_change_taken_lbl setStringValue: @""];
1110         [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1111         [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1112         [NSApp runModalForWindow: o_hotkeys_change_win];
1113     }
1114     else if( sender == o_hotkeys_change_cancel_btn )
1115     {
1116         [NSApp stopModal];
1117         [o_hotkeys_change_win close];
1118     }
1119     else if( sender == o_hotkeys_change_ok_btn )
1120     {
1121         int i_returnValue;
1122         if(! o_keyInTransition )
1123         {
1124             [NSApp stopModal];
1125             [o_hotkeys_change_win close];
1126             msg_Err( p_intf, "internal error prevented the hotkey switch" );
1127             return;
1128         }
1129
1130         b_hotkeyChanged = YES;
1131
1132         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1133         if( i_returnValue != NSNotFound )
1134             [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1135
1136         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1137
1138         [NSApp stopModal];
1139         [o_hotkeys_change_win close];
1140
1141         [o_hotkeys_listbox reloadData];
1142     }
1143     else if( sender == o_hotkeys_clear_btn )
1144     {
1145         [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1146         [o_hotkeys_listbox reloadData];
1147         b_hotkeyChanged = YES;
1148     }
1149 }
1150
1151 - (void)showHotkeySettings
1152 {
1153     msg_Dbg( p_intf, "showing HotKey Settings" );
1154     [self showSettingsForCategory: o_hotkeys_view];
1155 }
1156
1157 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1158 {
1159     return [o_hotkeySettings count];
1160 }
1161
1162 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1163 {
1164     if( [[aTableColumn identifier] isEqualToString: @"action"] )
1165         return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1166     else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1167         return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1168     else
1169     {
1170         msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1171         return NULL;
1172     }
1173 }
1174
1175 - (void)changeHotkeyTo: (int)i_theNewKey
1176 {
1177     int i_returnValue;
1178     i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1179     if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1180     {
1181         [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1182         [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1183         [o_hotkeys_change_ok_btn setEnabled: NO];
1184     }
1185     else
1186     {
1187         NSString *o_temp;
1188         if( o_keyInTransition )
1189             [o_keyInTransition release];
1190         o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1191
1192         o_temp = [self OSXKeyToString: i_theNewKey];
1193
1194         [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1195
1196         i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1197         if( i_returnValue != NSNotFound )
1198             [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1199                                                          _NS("This combination is already taken by \"%@\"."),
1200                                                          [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1201         else
1202             [o_hotkeys_change_taken_lbl setStringValue: @""];
1203
1204         [o_hotkeys_change_ok_btn setEnabled: YES];
1205     }
1206 }
1207     
1208 @end
1209
1210 /********************
1211  * hotkeys settings *
1212  ********************/
1213
1214 @implementation VLCHotkeyChangeWindow
1215
1216 - (BOOL)resignFirstResponder
1217 {
1218     /* We need to stay the first responder or we'll miss the user's input */
1219     return NO;
1220 }
1221
1222 - (void)keyDown:(NSEvent *)o_theEvent
1223 {
1224     int i_nonReadableKey = 0;
1225
1226     if( [o_theEvent modifierFlags] & NSControlKeyMask )
1227         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1228
1229     if( [o_theEvent modifierFlags] & NSAlternateKeyMask  )
1230         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1231
1232     if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1233         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1234
1235     if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1236         i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1237
1238     if( [o_theEvent modifierFlags] & NSFunctionKeyMask  )
1239     {
1240         unichar key = 0;
1241         key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1242         
1243         switch( key )
1244         {
1245             case 0x1b:
1246                 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1247                 break;
1248             case NSF1FunctionKey:
1249                 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1250                 break;
1251             case NSF2FunctionKey:
1252                 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1253                 break;
1254             case NSF3FunctionKey:
1255                 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1256                 break;
1257             case NSF4FunctionKey:
1258                 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1259                 break;
1260             case NSF5FunctionKey:
1261                 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1262                 break;
1263             case NSF6FunctionKey:
1264                 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1265                 break;
1266             case NSF7FunctionKey:
1267                 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1268                 break;
1269             case NSF8FunctionKey:
1270                 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1271                 break;
1272             case NSF9FunctionKey:
1273                 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1274                 break;
1275             case NSF10FunctionKey:
1276                 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1277                 break;
1278             case NSF11FunctionKey:
1279                 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1280                 break;
1281             case NSF12FunctionKey:
1282                 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1283                 break;
1284             case NSInsertFunctionKey:
1285                 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1286                 break;
1287             case NSHomeFunctionKey:
1288                 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1289                 break;
1290             case NSEndFunctionKey:
1291                 i_nonReadableKey = i_nonReadableKey | KEY_END;
1292                 break;
1293             case NSPageUpFunctionKey:
1294                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1295                 break;
1296             case NSPageDownFunctionKey:
1297                 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1298                 break;
1299             case NSMenuFunctionKey:
1300                 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1301                 break;
1302             case NSTabCharacter:
1303                 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1304                 break;
1305             case NSDeleteCharacter:
1306                 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1307                 break;
1308             case NSBackspaceCharacter:
1309                 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1310                 break;
1311             case NSUpArrowFunctionKey:
1312                 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1313                 break;
1314             case NSDownArrowFunctionKey:
1315                 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1316                 break;
1317             case NSRightArrowFunctionKey:
1318                 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1319                 break;
1320             case NSLeftArrowFunctionKey:
1321                 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1322                 break;
1323             case NSEnterCharacter:
1324                 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1325                 break;
1326             default:
1327             {
1328                 msg_Warn( VLCIntf, "user pressed unknown function key" );
1329                 i_nonReadableKey = 0;
1330                 break;
1331             }
1332         }
1333     }
1334     else
1335     {
1336         if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1337             i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1338         else
1339             i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1340     }
1341
1342     [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];
1343 }
1344
1345 @end