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