1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008-2009 the VideoLAN team
7 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
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.
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.
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 *****************************************************************************/
24 #import "simple_prefs.h"
27 #import <vlc_interface.h>
28 #import <vlc_dialog.h>
31 #import "AppleRemote.h"
32 #import <Sparkle/Sparkle.h> //for o_intf_last_update_lbl
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";
42 @implementation VLCSimplePrefs
44 static VLCSimplePrefs *_o_sharedInstance = nil;
46 + (VLCSimplePrefs *)sharedInstance
48 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
53 if (_o_sharedInstance) {
56 _o_sharedInstance = [super init];
60 return _o_sharedInstance;
65 [o_currentlyShownCategoryView release];
67 [o_hotkeySettings release];
68 [o_hotkeyDescriptions release];
69 [o_hotkeysNonUseableKeys release];
71 [o_keyInTransition release];
77 - (NSString *)OSXKeyToString:(int)val
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"]];
89 const char *base = KeyToString( val & ~KEY_MODIFIER );
91 [o_temp_str appendString: [NSString stringWithUTF8String: base]];
93 o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
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];
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|'?'],
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 )
152 NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
154 [o_toolbarItem setLabel: o_name];
155 [o_toolbarItem setPaletteLabel: o_desc];
157 [o_toolbarItem setToolTip: o_desc];
158 [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
160 [o_toolbarItem setTarget: target];
161 [o_toolbarItem setAction: selector];
163 [o_toolbarItem setEnabled: YES];
164 [o_toolbarItem setAutovalidates: YES];
166 return o_toolbarItem;
169 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
170 itemForItemIdentifier: (NSString *)o_itemIdent
171 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
173 NSToolbarItem *o_toolbarItem = nil;
175 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
177 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
179 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
181 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
183 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
185 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
187 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
189 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
191 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
193 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
195 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
197 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
200 return o_toolbarItem;
203 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
205 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
206 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
209 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
211 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
212 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
215 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
217 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
218 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
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")];
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")];
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")];
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: @""];
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")];
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")];
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")];
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 )
315 module_config_t *p_config;
317 p_config = config_FindConfig( p_this, psz_name );
322 msg_Err( p_this, "option %s does not exist", psz_name );
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;
331 msg_Warn( p_this, "option %s does not include any help" );
336 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
338 module_config_t *p_item;
340 [object removeAllItems];
341 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
343 /* serious problem, if no item found */
346 for( int i = 0; i < p_item->i_list; i++ )
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 )
353 [[object menu] addItem: [NSMenuItem separatorItem]];
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]];
364 [object setToolTip: _NS( p_item->psz_longtext )];
367 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
369 module_config_t *p_item;
371 [object removeAllItems];
372 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
374 /* serious problem, if no item found */
377 for( int i = 0; i < p_item->i_list; i++ )
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]];
390 [object setToolTip: _NS( p_item->psz_longtext )];
393 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
395 module_config_t *p_item;
396 module_t *p_parser, **p_list;
399 [object removeAllItems];
401 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
402 p_list = module_list_get( NULL );
403 if( !p_item ||!p_list )
405 if( p_list ) module_list_free(p_list);
406 NSLog( @"serious problem, item or list not found" );
410 [object addItemWithTitle: _NS("Default")];
411 for( size_t i_index = 0; p_list[i_index]; i_index++ )
413 p_parser = p_list[i_index];
414 if( module_provides( p_parser, p_item->psz_type ) )
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]];
421 module_list_free( p_list );
422 [object setToolTip: _NS(p_item->psz_longtext)];
425 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
427 [object setState: config_GetInt( p_intf, name )];
428 [object setToolTip: [NSString stringWithUTF8String: config_GetLabel( p_intf, name )]];
431 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
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 )]];
439 - (void)resetControls
441 module_config_t *p_item;
445 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
446 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
448 /**********************
449 * interface settings *
450 **********************/
451 [self setupButton: o_intf_lang_pop forStringList: "language"];
452 [self setupButton: o_intf_art_pop forIntList: "album-art"];
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]]]];
463 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
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];
475 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
477 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
478 [self setupField: o_audio_lang_fld forOption: "audio-language"];
480 [self setupButton: o_audio_headphone_ckb forBoolValue: "headphone-dolby"];
482 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
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]];
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")]];
493 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
495 /* Last.FM is optional */
496 if( module_exists( "audioscrobbler" ) )
498 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
499 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
501 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
503 [o_audio_last_ckb setState: NSOnState];
504 [o_audio_lastuser_fld setEnabled: YES];
505 [o_audio_lastpwd_sfld setEnabled: YES];
509 [o_audio_last_ckb setState: NSOffState];
510 [o_audio_lastuser_fld setEnabled: NO];
511 [o_audio_lastpwd_sfld setEnabled: NO];
515 [o_audio_last_ckb setEnabled: NO];
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"];
526 [self setupButton: o_video_output_pop forModuleList: "vout"];
528 [o_video_device_pop removeAllItems];
530 y = [[NSScreen screens] count];
531 [o_video_device_pop addItemWithTitle: _NS("Default")];
532 [[o_video_device_pop lastItem] setTag: 0];
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]];
542 [o_video_device_pop selectItemAtIndex: 0];
543 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
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"];
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")]];
560 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
562 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
563 [self setupButton: o_input_skipLoop_pop forIntList: "ffmpeg-skiploopfilter"];
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];
576 #define TestCaC( name ) \
577 b_cache_equal = b_cache_equal && \
578 ( i_cache == config_GetInt( p_intf, name ) )
580 #define TestCaCi( name, int ) \
581 b_cache_equal = b_cache_equal && \
582 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
584 /* Select the accurate value of the PopupButton */
585 bool b_cache_equal = true;
586 int i_cache = config_GetInt( p_intf, "file-caching");
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 );
606 [o_input_cachelevel_pop selectItemWithTag: i_cache];
607 [o_input_cachelevel_custom_txt setHidden: YES];
611 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
612 [o_input_cachelevel_custom_txt setHidden: NO];
615 /*********************
616 * subtitle settings *
617 *********************/
618 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
620 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
621 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
623 if( module_exists( "quartztext" ) )
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"];
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];
640 /********************
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];
651 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
655 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
656 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
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];
666 - (void)showSimplePrefs
668 /* we want to show the interface settings, if no category was chosen */
669 if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
671 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
672 [self showInterfaceSettings];
675 [self resetControls];
677 [o_sprefs_win center];
678 [o_sprefs_win makeKeyAndOrderFront: self];
681 - (IBAction)buttonAction:(id)sender
683 if( sender == o_sprefs_cancel_btn )
684 [o_sprefs_win orderOut: sender];
685 else if( sender == o_sprefs_save_btn )
687 [self saveChangedSettings];
688 [o_sprefs_win orderOut: sender];
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 )
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];
704 msg_Warn( p_intf, "unknown buttonAction sender" );
707 - (void)sheetDidEnd:(NSWindow *)o_sheet
708 returnCode:(int)i_return
709 contextInfo:(void *)o_context
711 if( i_return == NSAlertAlternateReturn )
713 config_ResetAll( p_intf );
714 [self resetControls];
715 config_SaveConfigFile( p_intf, NULL );
719 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
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] );
729 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
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]]);
738 config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
739 [p_stringobject release];
743 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
745 module_config_t *p_item;
746 module_t *p_parser, **p_list;
748 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
750 p_list = module_list_get( NULL );
751 for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
753 p_parser = p_list[i_module_index];
755 if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
757 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
759 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
764 module_list_free( p_list );
765 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
766 config_PutPsz( p_intf, name, "" );
769 - (void)saveChangedSettings
774 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
776 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
778 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
780 /**********************
781 * interface settings *
782 **********************/
783 if( b_intfSettingChanged )
785 SaveStringList( o_intf_lang_pop, "language" );
786 SaveIntList( o_intf_art_pop, "album-art" );
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] );
794 /* activate stuff without restart */
795 if( [o_intf_appleremote_ckb state] == YES )
796 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
798 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
799 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
803 /* okay, let's save our changes to vlcrc */
804 i = config_SaveConfigFile( p_intf, "main" );
805 i = i + config_SaveConfigFile( p_intf, "macosx" );
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 );
815 b_intfSettingChanged = NO;
821 if( b_audioSettingChanged )
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] );
828 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
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] );
833 if( [o_audio_norm_ckb state] == NSOnState )
835 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
837 config_PutPsz( p_intf, "audio-filter", "volnorm" );
838 else if( (NSInteger)strstr( psz_tmp, "normvol" ) == NO )
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 );
848 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
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 );
858 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
860 SaveModuleList( o_audio_visual_pop, "audio-visual" );
862 /* Last.FM is optional */
863 if( module_exists( "audioscrobbler" ) )
865 [o_audio_last_ckb setEnabled: YES];
866 if( [o_audio_last_ckb state] == NSOnState )
867 config_AddIntf( p_intf, "audioscrobbler" );
869 config_RemoveIntf( p_intf, "audioscrobbler" );
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] );
875 [o_audio_last_ckb setEnabled: NO];
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" );
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 );
890 b_audioSettingChanged = NO;
896 if( b_videoSettingChanged )
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] );
904 SaveModuleList( o_video_output_pop, "vout" );
905 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
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" );
912 i = config_SaveConfigFile( p_intf, "main" );
913 i = i + config_SaveConfigFile( p_intf, "macosx" );
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 );
922 b_videoSettingChanged = NO;
925 /***************************
926 * input & codecs settings *
927 ***************************/
928 if( b_inputSettingChanged )
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] );
935 SaveIntList( o_input_avi_pop, "avi-index" );
937 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
938 SaveIntList( o_input_skipLoop_pop, "ffmpeg-skiploopfilter" );
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" ) )
946 CaC( "dvdread-caching" );
947 i = i + config_SaveConfigFile( p_intf, "dvdread" );
949 if( module_exists ( "dvdnav" ) )
951 CaC( "dvdnav-caching" );
952 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
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" ) )
961 CaCi( "realrtsp-caching", 10 );
962 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
964 CaCi( "mms-caching", 19 );
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" );
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 );
988 b_inputSettingChanged = NO;
991 /**********************
992 * subtitles settings *
993 **********************/
994 if( b_osdSettingChanged )
996 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
998 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
999 SaveStringList( o_osd_encoding_pop, "subsdec-encoding" );
1001 config_PutPsz( p_intf, "subsdec-encoding", "" );
1003 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
1005 if( module_exists( "quartztext" ) )
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" );
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" );
1019 i = config_SaveConfigFile( p_intf, NULL );
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 );
1028 b_osdSettingChanged = NO;
1031 /********************
1032 * hotkeys settings *
1033 ********************/
1034 if( b_hotkeyChanged )
1036 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
1038 while( i < [o_hotkeySettings count] )
1040 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
1044 i = config_SaveConfigFile( p_intf, "main" );
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 );
1053 b_hotkeyChanged = NO;
1057 - (void)showSettingsForCategory: (id)o_new_category_view
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];
1063 if( o_currentlyShownCategoryView != nil )
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;
1070 /* remove our previous category view */
1071 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
1074 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
1076 [o_sprefs_win displayIfNeeded];
1077 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
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];
1087 /* keep our current category for further reference */
1088 [o_currentlyShownCategoryView release];
1089 o_currentlyShownCategoryView = o_new_category_view;
1090 [o_currentlyShownCategoryView retain];
1093 - (IBAction)interfaceSettingChanged:(id)sender
1095 if( sender == o_intf_mediakeys_ckb )
1096 [o_intf_mediakeys_bg_ckb setEnabled: [o_intf_mediakeys_ckb state]];
1097 b_intfSettingChanged = YES;
1100 - (void)showInterfaceSettings
1102 [self showSettingsForCategory: o_intf_view];
1105 - (IBAction)audioSettingChanged:(id)sender
1107 if( sender == o_audio_vol_sld )
1108 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1110 if( sender == o_audio_vol_fld )
1111 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1113 if( sender == o_audio_norm_ckb )
1115 [o_audio_norm_stepper setEnabled: [o_audio_norm_ckb state]];
1116 [o_audio_norm_fld setEnabled: [o_audio_norm_ckb state]];
1119 if( sender == o_audio_last_ckb )
1121 if( [o_audio_last_ckb state] == NSOnState )
1123 [o_audio_lastpwd_sfld setEnabled: YES];
1124 [o_audio_lastuser_fld setEnabled: YES];
1128 [o_audio_lastpwd_sfld setEnabled: NO];
1129 [o_audio_lastuser_fld setEnabled: NO];
1133 b_audioSettingChanged = YES;
1136 - (void)showAudioSettings
1138 [self showSettingsForCategory: o_audio_view];
1141 - (IBAction)videoSettingChanged:(id)sender
1143 if( sender == o_video_snap_folder_btn )
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
1155 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1156 contextInfo: o_video_snap_folder_btn];
1159 b_videoSettingChanged = YES;
1162 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1164 if( returnCode == NSOKButton )
1166 if( contextInfo == o_video_snap_folder_btn )
1168 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1169 b_videoSettingChanged = YES;
1173 [o_selectFolderPanel release];
1176 - (void)showVideoSettings
1178 [self showSettingsForCategory: o_video_view];
1181 - (IBAction)osdSettingChanged:(id)sender
1183 b_osdSettingChanged = YES;
1186 - (void)showOSDSettings
1188 [self showSettingsForCategory: o_osd_view];
1191 - (IBAction)showFontPicker:(id)sender
1193 if( module_exists( "quartztext" ) )
1195 char * font = config_GetPsz( p_intf, "quartztext-font" );
1196 NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1198 if( fontFamilyName )
1200 NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1201 NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1202 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1204 [[NSFontManager sharedFontManager] setTarget: self];
1205 [[NSFontPanel sharedFontPanel] orderFront:self];
1209 - (void)changeFont:(id)sender
1211 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1212 [o_osd_font_fld setStringValue:[font familyName]];
1213 [self osdSettingChanged:self];
1216 - (IBAction)inputSettingChanged:(id)sender
1218 if( sender == o_input_cachelevel_pop )
1220 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1221 [o_input_cachelevel_custom_txt setHidden: NO];
1223 [o_input_cachelevel_custom_txt setHidden: YES];
1226 b_inputSettingChanged = YES;
1229 - (void)showInputSettings
1231 [self showSettingsForCategory: o_input_view];
1234 - (IBAction)hotkeySettingChanged:(id)sender
1236 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
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];
1246 else if( sender == o_hotkeys_change_cancel_btn )
1249 [o_hotkeys_change_win close];
1251 else if( sender == o_hotkeys_change_ok_btn )
1253 NSInteger i_returnValue;
1254 if(! o_keyInTransition )
1257 [o_hotkeys_change_win close];
1258 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1262 b_hotkeyChanged = YES;
1264 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1265 if( i_returnValue != NSNotFound )
1266 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1268 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1271 [o_hotkeys_change_win close];
1273 [o_hotkeys_listbox reloadData];
1275 else if( sender == o_hotkeys_clear_btn )
1277 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1278 [o_hotkeys_listbox reloadData];
1279 b_hotkeyChanged = YES;
1283 - (void)showHotkeySettings
1285 [self showSettingsForCategory: o_hotkeys_view];
1288 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1290 return [o_hotkeySettings count];
1293 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
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]];
1301 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1306 - (BOOL)changeHotkeyTo: (int)i_theNewKey
1308 NSInteger i_returnValue;
1309 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1310 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
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];
1320 if( o_keyInTransition )
1321 [o_keyInTransition release];
1322 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1324 o_temp = [self OSXKeyToString: i_theNewKey];
1326 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
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]]];
1334 [o_hotkeys_change_taken_lbl setStringValue: @""];
1336 [o_hotkeys_change_ok_btn setEnabled: YES];
1343 /********************
1344 * hotkeys settings *
1345 ********************/
1347 @implementation VLCHotkeyChangeWindow
1349 - (BOOL)acceptsFirstResponder
1354 - (BOOL)becomeFirstResponder
1359 - (BOOL)resignFirstResponder
1361 /* We need to stay the first responder or we'll miss the user's input */
1365 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1370 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1371 i_key |= KEY_MODIFIER_CTRL;
1373 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1374 i_key |= KEY_MODIFIER_ALT;
1376 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1377 i_key |= KEY_MODIFIER_SHIFT;
1379 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1380 i_key |= KEY_MODIFIER_COMMAND;
1382 key = [[[o_theEvent charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
1385 i_key |= CocoaKeyToVLC( key );
1386 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: i_key];
1393 @implementation VLCSimplePrefsWindow
1395 - (BOOL)acceptsFirstResponder
1400 - (void)changeFont:(id)sender
1402 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];