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