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