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