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