1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008-2011 VLC authors and VideoLAN
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 *****************************************************************************/
27 #import "CompatibilityFixes.h"
28 #import "simple_prefs.h"
31 #import <vlc_interface.h>
32 #import <vlc_aout_intf.h>
33 #import <vlc_dialog.h>
34 #import <vlc_modules.h>
35 #import <vlc_config_cat.h>
38 #import "AppleRemote.h"
40 #import <Sparkle/Sparkle.h> //for o_intf_last_update_lbl
42 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
43 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
44 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
45 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
46 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
47 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
48 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
50 @implementation VLCSimplePrefs
52 static VLCSimplePrefs *_o_sharedInstance = nil;
54 #pragma mark Initialisation
56 + (VLCSimplePrefs *)sharedInstance
58 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
63 if (_o_sharedInstance) {
66 _o_sharedInstance = [super init];
70 return _o_sharedInstance;
75 [o_currentlyShownCategoryView release];
77 [o_hotkeySettings release];
78 [o_hotkeyDescriptions release];
79 [o_hotkeyNames release];
80 [o_hotkeysNonUseableKeys release];
82 [o_keyInTransition release];
87 - (NSString *)OSXStringKeyToString:(NSString *)theString
89 if (![theString isEqualToString:@""]) {
91 if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
92 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
95 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
96 theString = [NSString stringWithFormat:@"%@+", theString];
98 if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
99 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
102 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
103 theString = [NSString stringWithFormat:@"%@-", theString];
106 theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
107 theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
108 theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
109 theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
110 /* show non-character keys correctly */
111 theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
112 theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
113 theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
114 theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
115 theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
116 theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
117 theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]]; /* capitalize plain characters to suit the menubar's look */
118 theString = [theString capitalizedString];
121 theString = [NSString stringWithString:_NS("Not Set")];
129 /* setup the toolbar */
130 NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
131 [o_sprefs_toolbar setAllowsUserCustomization: NO];
132 [o_sprefs_toolbar setAutosavesConfiguration: NO];
133 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
134 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
135 [o_sprefs_toolbar setDelegate: self];
136 [o_sprefs_win setToolbar: o_sprefs_toolbar];
139 [o_sprefs_win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
141 [o_hotkeys_listbox setTarget:self];
142 [o_hotkeys_listbox setDoubleAction:@selector(hotkeyTableDoubleClick:)];
144 /* setup useful stuff */
145 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects: @"Command-c", @"Command-x", @"Command-v", @"Command-a", @"Command-," , @"Command-h", @"Command-Alt-h", @"Command-Shift-o", @"Command-o", @"Command-d", @"Command-n", @"Command-s", @"Command-z", @"Command-l", @"Command-r", @"Command-3", @"Command-m", @"Command-w", @"Command-Shift-w", @"Command-Shift-c", @"Command-Shift-p", @"Command-i", @"Command-e", @"Command-Shift-e", @"Command-b", @"Command-Shift-m", @"Command-Ctrl-m", @"Command-?", @"Command-Alt-?", nil] retain];
148 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
149 o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
150 static inline NSToolbarItem *
151 create_toolbar_item( NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector )
153 NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
155 [o_toolbarItem setLabel: o_name];
156 [o_toolbarItem setPaletteLabel: o_desc];
158 [o_toolbarItem setToolTip: o_desc];
159 [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
161 [o_toolbarItem setTarget: target];
162 [o_toolbarItem setAction: selector];
164 [o_toolbarItem setEnabled: YES];
165 [o_toolbarItem setAutovalidates: YES];
167 return o_toolbarItem;
170 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
171 itemForItemIdentifier: (NSString *)o_itemIdent
172 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
174 NSToolbarItem *o_toolbarItem = nil;
176 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
178 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
180 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
182 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
184 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
186 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
188 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
190 CreateToolbarItem( _NS(SUBPIC_TITLE), _NS("Subtitles & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
192 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
194 CreateToolbarItem( _NS(INPUT_TITLE), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
196 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
198 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
201 return o_toolbarItem;
204 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
206 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
207 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
210 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
212 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
213 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
216 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
218 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
219 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
225 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
226 [o_audio_effects_box setTitle: _NS("Effects")];
227 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
228 [o_audio_general_box setTitle: _NS("General Audio")];
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_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
234 [o_audio_visual_txt setStringValue: _NS("Visualization")];
235 [o_audio_autosavevol_yes_bcell setTitle: _NS("Keep audio level between sessions")];
236 [o_audio_autosavevol_no_bcell setTitle: _NS("Always reset audio start level to:")];
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_record_box setTitle: _NS("Record directory or filename")];
250 [o_input_record_btn setTitle: _NS("Browse...")];
251 [o_input_record_btn setToolTip: _NS("Directory or filename where the records will be stored")];
252 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
253 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
254 [o_input_caching_box setTitle: _NS("Caching")];
255 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
256 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
257 [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
258 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
259 [o_input_net_box setTitle: _NS("Network")];
260 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
261 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
262 [o_input_skipLoop_txt setStringValue: _NS("Skip the loop filter for H.264 decoding")];
263 [o_input_mkv_preload_dir_ckb setTitle: _NS("Preload MKV files in the same directory")];
266 [o_intf_style_txt setStringValue: _NS("Interface style")];
267 [o_intf_style_dark_bcell setTitle: _NS("Dark")];
268 [o_intf_style_bright_bcell setTitle: _NS("Bright")];
269 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
270 [o_intf_embedded_ckb setTitle: _NS("Show video within the main window")];
271 [o_intf_nativefullscreen_ckb setTitle: _NS("Use the native fullscreen mode on OS X Lion")];
272 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
273 [o_intf_lang_txt setStringValue: _NS("Language")];
274 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
276 [o_intf_appleremote_ckb setTitle: _NS("Control playback with the Apple Remote")];
278 [o_intf_mediakeys_ckb setTitle: _NS("Control playback with media keys")];
279 [o_intf_update_ckb setTitle: _NS("Automatically check for updates")];
280 [o_intf_last_update_lbl setStringValue: @""];
281 [o_intf_enableGrowl_ckb setTitle: _NS("Enable Growl notifications (on playlist item change)")];
282 [o_intf_autoresize_ckb setTitle: _NS("Resize interface to the native video size")];
283 [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
285 /* Subtitles and OSD */
286 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
287 [o_osd_font_box setTitle: _NS("Display Settings")];
288 [o_osd_font_btn setTitle: _NS("Choose...")];
289 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
290 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
291 [o_osd_font_txt setStringValue: _NS("Font")];
292 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
293 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
294 [o_osd_osd_box setTitle: _NS("On Screen Display")];
295 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
296 [o_osd_opacity_txt setStringValue: _NS("Opacity")];
297 [o_osd_forcebold_ckb setTitle: _NS("Force Bold")];
298 [o_osd_moreoptions_txt setStringValue: _NS("More options on background, shadow and outline are available in the advanced preferences.")];
301 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
302 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
303 [o_video_display_box setTitle: _NS("Display")];
304 [o_video_enable_ckb setTitle: _NS("Enable Video")];
305 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
306 [o_video_onTop_ckb setTitle: _NS("Always on top")];
307 [o_video_output_txt setStringValue: _NS("Output module")];
308 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
309 [o_video_snap_box setTitle: _NS("Video snapshots")];
310 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
311 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
312 [o_video_snap_format_txt setStringValue: _NS("Format")];
313 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
314 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
317 [o_sprefs_showAll_btn setTitle: _NS("Show All")];
318 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
319 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
320 [o_sprefs_save_btn setTitle: _NS("Save")];
321 [o_sprefs_win setTitle: _NS("Preferences")];
324 /* TODO: move this part to core */
325 #define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
326 static inline char * __config_GetLabel( vlc_object_t *p_this, const char *psz_name )
328 module_config_t *p_config;
330 p_config = config_FindConfig( p_this, psz_name );
335 msg_Err( p_this, "option %s does not exist", psz_name );
339 if ( p_config->psz_longtext )
340 return p_config->psz_longtext;
341 else if( p_config->psz_text )
342 return p_config->psz_text;
344 msg_Warn( p_this, "option %s does not include any help", psz_name );
350 #pragma mark Setup controls
352 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
354 module_config_t *p_item;
356 [object removeAllItems];
357 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
359 /* serious problem, if no item found */
362 for( int i = 0; i < p_item->i_list; i++ )
365 if( p_item->ppsz_list_text != NULL )
366 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
367 else if( p_item->ppsz_list[i] && strcmp(p_item->ppsz_list[i],"") == 0 )
369 [[object menu] addItem: [NSMenuItem separatorItem]];
372 else if( p_item->ppsz_list[i] )
373 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
375 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name );
376 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
377 [[object menu] addItem: [mi autorelease]];
378 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
379 [object selectItem:[object lastItem]];
381 [object setToolTip: _NS( p_item->psz_longtext )];
384 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
386 module_config_t *p_item;
388 [object removeAllItems];
389 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
391 /* serious problem, if no item found */
394 for( int i = 0; i < p_item->i_list; i++ )
397 if( p_item->ppsz_list_text != NULL)
398 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
399 else if( p_item->pi_list[i] )
400 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
402 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name);
403 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
404 [[object menu] addItem: [mi autorelease]];
405 if( p_item->value.i == p_item->pi_list[i] )
406 [object selectItem:[object lastItem]];
408 [object setToolTip: _NS( p_item->psz_longtext )];
411 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
413 module_config_t *p_item;
414 module_t *p_parser, **p_list;
417 [object removeAllItems];
419 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
420 p_list = module_list_get( NULL );
421 if( !p_item ||!p_list )
423 if( p_list ) module_list_free(p_list);
424 msg_Err( p_intf, "serious problem, item or list not found" );
428 [object addItemWithTitle: _NS("Default")];
429 for( size_t i_index = 0; p_list[i_index]; i_index++ )
431 p_parser = p_list[i_index];
432 if( module_provides( p_parser, p_item->psz_type ) )
434 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
435 if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
436 [object selectItem: [object lastItem]];
439 module_list_free( p_list );
440 [object setToolTip: _NS(p_item->psz_longtext)];
443 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
445 [object setState: config_GetInt( p_intf, name )];
446 [object setToolTip: _NS(config_GetLabel( p_intf, name ) ?: "")];
449 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
451 char *psz_tmp = config_GetPsz( p_intf, psz_option );
452 [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
453 [o_object setToolTip: _NS(config_GetLabel( p_intf, psz_option ))];
457 - (void)resetControls
459 module_config_t *p_item;
463 /**********************
464 * interface settings *
465 **********************/
466 [self setupButton: o_intf_lang_pop forStringList: "language"];
467 [self setupButton: o_intf_art_pop forIntList: "album-art"];
469 [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
471 [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
472 BOOL b_correct_sdk = NO;
473 #ifdef MAC_OS_X_VERSION_10_7
476 if( !( b_correct_sdk && OSX_LION ))
478 [o_intf_nativefullscreen_ckb setState: NSOffState];
479 [o_intf_nativefullscreen_ckb setEnabled: NO];
482 [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
484 [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
486 [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
487 if( [[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL )
488 [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
490 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
491 psz_tmp = config_GetPsz( p_intf, "control" );
493 [o_intf_enableGrowl_ckb setState: (NSInteger)strstr( psz_tmp, "growl")];
497 [o_intf_enableGrowl_ckb setState: NSOffState];
498 if (config_GetInt( p_intf, "macosx-interfacestyle" ))
500 [o_intf_style_dark_bcell setState: YES];
501 [o_intf_style_bright_bcell setState: NO];
505 [o_intf_style_dark_bcell setState: NO];
506 [o_intf_style_bright_bcell setState: YES];
508 [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
509 [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
514 [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
516 if ( config_GetInt( p_intf, "macosx-autosave-volume" ))
518 [o_audio_autosavevol_yes_bcell setState: NSOnState];
519 [o_audio_autosavevol_no_bcell setState: NSOffState];
520 [o_audio_vol_fld setEnabled: NO];
521 [o_audio_vol_sld setEnabled: NO];
523 [o_audio_vol_sld setIntValue: 100];
524 [o_audio_vol_fld setIntValue: 100];
528 [o_audio_autosavevol_yes_bcell setState: NSOffState];
529 [o_audio_autosavevol_no_bcell setState: NSOnState];
530 [o_audio_vol_fld setEnabled: YES];
531 [o_audio_vol_sld setEnabled: YES];
533 i = config_GetInt( p_intf, "volume" );
534 i = i * 200 / AOUT_VOLUME_MAX;
535 [o_audio_vol_sld setIntValue: i];
536 [o_audio_vol_fld setIntValue: i];
539 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
541 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
542 [self setupField: o_audio_lang_fld forOption: "audio-language"];
544 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
546 /* Last.FM is optional */
547 if( module_exists( "audioscrobbler" ) )
549 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
550 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
552 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
554 [o_audio_last_ckb setState: NSOnState];
555 [o_audio_lastuser_fld setEnabled: YES];
556 [o_audio_lastpwd_sfld setEnabled: YES];
560 [o_audio_last_ckb setState: NSOffState];
561 [o_audio_lastuser_fld setEnabled: NO];
562 [o_audio_lastpwd_sfld setEnabled: NO];
566 [o_audio_last_ckb setEnabled: NO];
571 [self setupButton: o_video_enable_ckb forBoolValue: "video"];
572 [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
573 [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
574 [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
575 [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
577 [self setupButton: o_video_output_pop forModuleList: "vout"];
579 [o_video_device_pop removeAllItems];
581 y = [[NSScreen screens] count];
582 [o_video_device_pop addItemWithTitle: _NS("Default")];
583 [[o_video_device_pop lastItem] setTag: 0];
586 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
587 [o_video_device_pop addItemWithTitle:
588 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
589 (int)s_rect.size.width, (int)s_rect.size.height]];
590 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
593 [o_video_device_pop selectItemAtIndex: 0];
594 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
596 [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
597 [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
598 [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
599 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
601 /***************************
602 * input & codecs settings *
603 ***************************/
604 [self setupField: o_input_record_fld forOption:"input-record-path"];
605 [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
606 [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
607 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "postproc-q")];
608 [o_input_postproc_fld setToolTip: _NS(config_GetLabel( p_intf, "postproc-q"))];
610 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
612 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
613 [self setupButton: o_input_skipLoop_pop forIntList: "ffmpeg-skiploopfilter"];
615 [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
617 [o_input_cachelevel_pop removeAllItems];
618 [o_input_cachelevel_pop addItemsWithTitles:
619 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
620 _NS("High latency"), _NS("Higher latency"), nil]];
621 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
622 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
623 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
624 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
625 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
626 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
628 #define TestCaC( name, factor ) \
629 b_cache_equal = b_cache_equal && \
630 ( i_cache * factor == config_GetInt( p_intf, name ) );
632 /* Select the accurate value of the PopupButton */
633 bool b_cache_equal = true;
634 int i_cache = config_GetInt( p_intf, "file-caching");
636 TestCaC( "network-caching", 10/3 );
637 TestCaC( "disc-caching", 1 );
638 TestCaC( "live-caching", 1 );
641 [o_input_cachelevel_pop selectItemWithTag: i_cache];
642 [o_input_cachelevel_custom_txt setHidden: YES];
646 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
647 [o_input_cachelevel_custom_txt setHidden: NO];
651 /*********************
652 * subtitle settings *
653 *********************/
654 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
656 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
657 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
659 [self setupField: o_osd_font_fld forOption: "freetype-font"];
660 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
661 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
662 i = config_GetInt( p_intf, "freetype-opacity" );
663 [o_osd_opacity_fld setIntValue: i];
664 [o_osd_opacity_sld setIntValue: i];
665 [o_osd_opacity_sld setToolTip: _NS(config_GetLabel( p_intf, "freetype-opacity"))];
666 [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
667 [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
669 /********************
671 ********************/
672 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
673 [o_hotkeySettings release];
674 o_hotkeySettings = [[NSMutableArray alloc] init];
675 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
676 NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
678 /* Get the main Module */
679 module_t *p_main = module_get_main();
682 module_config_t *p_config;
684 p_config = module_config_get (p_main, &confsize);
686 for (size_t i = 0; i < confsize; i++)
688 module_config_t *p_item = p_config + i;
690 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
691 && !strncmp( p_item->psz_name , "key-", 4 )
692 && !EMPTY_STR( p_item->psz_text ) )
694 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
695 [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
696 if (p_item->value.psz)
697 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
699 [o_hotkeySettings addObject: [NSString string]];
702 module_config_free (p_config);
704 [o_hotkeyDescriptions release];
705 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
706 [o_tempArray_desc release];
707 [o_hotkeyNames release];
708 o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
709 [o_tempArray_names release];
710 [o_hotkeys_listbox reloadData];
714 #pragma mark General actions
716 - (void)showSimplePrefs
718 /* we want to show the interface settings, if no category was chosen */
719 if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
721 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
722 [self showInterfaceSettings];
725 [self resetControls];
727 [o_sprefs_win center];
728 [o_sprefs_win makeKeyAndOrderFront: self];
731 - (IBAction)buttonAction:(id)sender
733 if( sender == o_sprefs_cancel_btn )
734 [o_sprefs_win orderOut: sender];
735 else if( sender == o_sprefs_save_btn )
737 [self saveChangedSettings];
738 [o_sprefs_win orderOut: sender];
740 else if( sender == o_sprefs_reset_btn )
741 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
742 _NS("Continue"), nil, o_sprefs_win, self,
743 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
744 _NS("Beware this will reset the VLC media player preferences.\n"
745 "Are you sure you want to continue?") );
746 else if( sender == o_sprefs_showAll_btn )
748 [o_sprefs_win orderOut: self];
749 [[[VLCMain sharedInstance] preferences] showPrefs];
752 msg_Warn( p_intf, "unknown buttonAction sender" );
755 - (void)sheetDidEnd:(NSWindow *)o_sheet
756 returnCode:(int)i_return
757 contextInfo:(void *)o_context
759 if( i_return == NSAlertAlternateReturn )
761 config_ResetAll( p_intf );
762 [self resetControls];
763 config_SaveConfigFile( p_intf );
767 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
769 NSNumber *p_valueobject;
770 module_config_t *p_item;
771 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
772 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
773 assert([p_valueobject isKindOfClass:[NSNumber class]]);
774 if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
777 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
779 NSString *p_stringobject;
780 module_config_t *p_item;
781 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
782 p_stringobject = (NSString *)[[object selectedItem] representedObject];
783 assert([p_stringobject isKindOfClass:[NSString class]]);
786 config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
790 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
792 module_config_t *p_item;
793 module_t *p_parser, **p_list;
795 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
797 p_list = module_list_get( NULL );
798 for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
800 p_parser = p_list[i_module_index];
802 if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
804 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
806 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
811 module_list_free( p_list );
812 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
813 config_PutPsz( p_intf, name, "" );
816 - (void)saveChangedSettings
821 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
823 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
825 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
827 #define getString( name ) [NSString stringWithFormat:@"%s", config_GetPsz( p_intf, name )]
829 /**********************
830 * interface settings *
831 **********************/
832 if( b_intfSettingChanged )
834 SaveStringList( o_intf_lang_pop, "language" );
835 SaveIntList( o_intf_art_pop, "album-art" );
837 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
838 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
840 config_PutInt( p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state] );
841 config_PutInt( p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state] );
842 config_PutInt( p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state] );
843 config_PutInt( p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state] );
844 config_PutInt( p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state] );
845 config_PutInt( p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state] );
846 if( [o_intf_enableGrowl_ckb state] == NSOnState )
848 tmpString = getString( "control" );
849 tmpRange = [tmpString rangeOfString:@"growl"];
850 if( [tmpString length] > 0 && tmpRange.location == NSNotFound )
852 tmpString = [tmpString stringByAppendingString: @":growl"];
853 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
856 config_PutPsz( p_intf, "control", "growl" );
860 tmpString = getString( "control" );
861 if(! [tmpString isEqualToString:@""] )
863 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
864 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
865 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
866 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
870 /* activate stuff without restart */
871 if( [o_intf_appleremote_ckb state] == YES )
872 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
874 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
875 b_intfSettingChanged = NO;
881 if( b_audioSettingChanged )
883 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
884 if( [o_audio_vol_fld isEnabled] )
885 config_PutInt( p_intf, "volume", [o_audio_vol_fld intValue] * AOUT_VOLUME_MAX / 200 );
886 config_PutInt( p_intf, "macosx-autosave-volume", [o_audio_autosavevol_yes_bcell state] );
887 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
889 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
891 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
893 SaveModuleList( o_audio_visual_pop, "audio-visual" );
895 /* Last.FM is optional */
896 if( module_exists( "audioscrobbler" ) )
898 [o_audio_last_ckb setEnabled: YES];
899 if( [o_audio_last_ckb state] == NSOnState )
900 config_AddIntf( p_intf, "audioscrobbler" );
902 config_RemoveIntf( p_intf, "audioscrobbler" );
904 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
905 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
908 [o_audio_last_ckb setEnabled: NO];
909 b_audioSettingChanged = NO;
915 if( b_videoSettingChanged )
917 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
918 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
919 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
920 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
921 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
923 SaveModuleList( o_video_output_pop, "vout" );
924 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
926 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
927 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
928 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
929 SaveStringList( o_video_snap_format_pop, "snapshot-format" );
930 b_videoSettingChanged = NO;
933 /***************************
934 * input & codecs settings *
935 ***************************/
936 if( b_inputSettingChanged )
938 config_PutPsz( p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String] );
939 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
940 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
941 config_PutInt( p_intf, "postproc-q", [o_input_postproc_fld intValue] );
943 SaveIntList( o_input_avi_pop, "avi-index" );
945 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
946 SaveIntList( o_input_skipLoop_pop, "ffmpeg-skiploopfilter" );
948 config_PutInt( p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state] );
950 #define CaC( name, factor ) config_PutInt( p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor )
951 if ( [[o_input_cachelevel_pop selectedItem] tag] == 0 )
953 msg_Dbg( p_intf, "Custom chosen, not adjusting cache values" );
957 msg_Dbg( p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag] );
958 CaC( "file-caching", 1 );
959 CaC( "network-caching", 10/3 );
960 CaC( "disc-caching", 1 );
961 CaC( "live-caching", 1 );
964 b_inputSettingChanged = NO;
967 /**********************
968 * subtitles settings *
969 **********************/
970 if( b_osdSettingChanged )
972 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
974 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
975 SaveStringList( o_osd_encoding_pop, "subsdec-encoding" );
977 config_PutPsz( p_intf, "subsdec-encoding", "" );
979 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
981 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
982 SaveIntList( o_osd_font_color_pop, "freetype-color" );
983 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
984 config_PutInt( p_intf, "freetype-opacity", [o_osd_opacity_sld intValue] );
985 config_PutInt( p_intf, "freetype-bold", [o_osd_forcebold_ckb state] );
986 b_osdSettingChanged = NO;
989 /********************
991 ********************/
992 if( b_hotkeyChanged )
994 NSUInteger hotKeyCount = [o_hotkeySettings count];
995 for( NSUInteger i = 0; i < hotKeyCount; i++ )
996 config_PutPsz( p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String] );
997 b_hotkeyChanged = NO;
1000 /* okay, let's save our changes to vlcrc */
1001 config_SaveConfigFile( p_intf );
1003 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1008 - (void)showSettingsForCategory: (id)o_new_category_view
1010 NSRect o_win_rect, o_view_rect, o_old_view_rect;
1011 o_win_rect = [o_sprefs_win frame];
1012 o_view_rect = [o_new_category_view frame];
1014 if( o_currentlyShownCategoryView != nil )
1016 /* restore our window's height, if we've shown another category previously */
1017 o_old_view_rect = [o_currentlyShownCategoryView frame];
1018 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
1019 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
1022 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
1024 [o_new_category_view setFrame: NSMakeRect( 0,
1025 [o_sprefs_controls_box frame].size.height,
1026 o_view_rect.size.width,
1027 o_view_rect.size.height )];
1028 [o_new_category_view setAutoresizesSubviews: YES];
1029 if (o_currentlyShownCategoryView)
1031 [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
1032 [o_currentlyShownCategoryView release];
1033 [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
1037 [[o_sprefs_win contentView] addSubview: o_new_category_view];
1038 [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
1041 /* keep our current category for further reference */
1042 o_currentlyShownCategoryView = o_new_category_view;
1043 [o_currentlyShownCategoryView retain];
1047 #pragma mark Specific actions
1049 - (IBAction)interfaceSettingChanged:(id)sender
1051 if( sender == o_intf_embedded_ckb && [o_intf_embedded_ckb state] == NSOffState )
1052 [o_intf_nativefullscreen_ckb setState: NSOffState];
1054 if( sender == o_intf_nativefullscreen_ckb && [o_intf_nativefullscreen_ckb state] == NSOnState )
1055 [o_intf_embedded_ckb setState: NSOnState];
1057 b_intfSettingChanged = YES;
1060 - (void)showInterfaceSettings
1062 [self showSettingsForCategory: o_intf_view];
1065 - (IBAction)audioSettingChanged:(id)sender
1067 if( sender == o_audio_vol_sld )
1068 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1070 if( sender == o_audio_vol_fld )
1071 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1073 if( sender == o_audio_last_ckb )
1075 if( [o_audio_last_ckb state] == NSOnState )
1077 [o_audio_lastpwd_sfld setEnabled: YES];
1078 [o_audio_lastuser_fld setEnabled: YES];
1082 [o_audio_lastpwd_sfld setEnabled: NO];
1083 [o_audio_lastuser_fld setEnabled: NO];
1087 if( sender == o_audio_autosavevol_matrix )
1089 BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1090 [o_audio_vol_fld setEnabled: enableVolumeSlider];
1091 [o_audio_vol_sld setEnabled: enableVolumeSlider];
1094 b_audioSettingChanged = YES;
1097 - (void)showAudioSettings
1099 [self showSettingsForCategory: o_audio_view];
1102 - (IBAction)videoSettingChanged:(id)sender
1104 if( sender == o_video_snap_folder_btn )
1106 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1107 [o_selectFolderPanel setCanChooseDirectories: YES];
1108 [o_selectFolderPanel setCanChooseFiles: NO];
1109 [o_selectFolderPanel setResolvesAliases: YES];
1110 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1111 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1112 [o_selectFolderPanel setCanCreateDirectories: YES];
1113 [o_selectFolderPanel setPrompt: _NS("Choose")];
1114 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1116 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1117 contextInfo: o_video_snap_folder_btn];
1120 b_videoSettingChanged = YES;
1123 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1125 if( returnCode == NSOKButton )
1127 if( contextInfo == o_video_snap_folder_btn )
1129 [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1130 b_videoSettingChanged = YES;
1132 else if( contextInfo == o_input_record_btn )
1134 [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1135 b_inputSettingChanged = YES;
1139 [o_selectFolderPanel release];
1142 - (void)showVideoSettings
1144 [self showSettingsForCategory: o_video_view];
1147 - (IBAction)osdSettingChanged:(id)sender
1149 if( sender == o_osd_opacity_fld )
1150 [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1152 if( sender == o_osd_opacity_sld )
1153 [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1155 b_osdSettingChanged = YES;
1158 - (void)showOSDSettings
1160 [self showSettingsForCategory: o_osd_view];
1163 - (void)controlTextDidChange:(NSNotification *)o_notification
1165 id notificationObject = [o_notification object];
1166 if( notificationObject == o_audio_lang_fld ||
1167 notificationObject == o_audio_lastpwd_sfld ||
1168 notificationObject == o_audio_lastuser_fld ||
1169 notificationObject == o_audio_vol_fld )
1170 b_audioSettingChanged = YES;
1171 else if( notificationObject == o_input_record_fld ||
1172 notificationObject == o_input_httpproxy_fld ||
1173 notificationObject == o_input_httpproxypwd_sfld ||
1174 notificationObject == o_input_postproc_fld )
1175 b_inputSettingChanged = YES;
1176 else if( notificationObject == o_osd_font_fld ||
1177 notificationObject == o_osd_lang_fld ||
1178 notificationObject == o_osd_opacity_fld)
1179 b_osdSettingChanged = YES;
1180 else if( notificationObject == o_video_snap_folder_fld ||
1181 notificationObject == o_video_snap_prefix_fld )
1182 b_videoSettingChanged = YES;
1185 - (IBAction)showFontPicker:(id)sender
1187 char * font = config_GetPsz( p_intf, "freetype-font" );
1188 NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1190 if( fontFamilyName )
1192 NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1193 NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1194 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1196 [[NSFontManager sharedFontManager] setTarget: self];
1197 [[NSFontPanel sharedFontPanel] orderFront:self];
1200 - (void)changeFont:(id)sender
1202 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1203 [o_osd_font_fld setStringValue:[font familyName]];
1204 [self osdSettingChanged:self];
1207 - (IBAction)inputSettingChanged:(id)sender
1209 if( sender == o_input_cachelevel_pop )
1211 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1212 [o_input_cachelevel_custom_txt setHidden: NO];
1214 [o_input_cachelevel_custom_txt setHidden: YES];
1216 else if( sender == o_input_record_btn )
1218 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1219 [o_selectFolderPanel setCanChooseDirectories: YES];
1220 [o_selectFolderPanel setCanChooseFiles: YES];
1221 [o_selectFolderPanel setResolvesAliases: YES];
1222 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1223 [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1224 [o_selectFolderPanel setCanCreateDirectories: YES];
1225 [o_selectFolderPanel setPrompt: _NS("Choose")];
1226 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1228 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1229 contextInfo: o_input_record_btn];
1233 b_inputSettingChanged = YES;
1236 - (void)showInputSettings
1238 [self showSettingsForCategory: o_input_view];
1242 #pragma mark Hotkey actions
1244 - (void)hotkeyTableDoubleClick:(id)object
1247 if( [o_hotkeys_listbox clickedRow] >= 0 )
1248 [self hotkeySettingChanged:o_hotkeys_listbox];
1251 - (IBAction)hotkeySettingChanged:(id)sender
1253 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1255 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1256 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1257 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1258 [o_hotkeys_change_taken_lbl setStringValue: @""];
1259 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1260 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1261 [NSApp runModalForWindow: o_hotkeys_change_win];
1263 else if( sender == o_hotkeys_change_cancel_btn )
1266 [o_hotkeys_change_win close];
1268 else if( sender == o_hotkeys_change_ok_btn )
1270 NSInteger i_returnValue;
1271 if(! o_keyInTransition )
1274 [o_hotkeys_change_win close];
1275 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1279 b_hotkeyChanged = YES;
1281 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1282 if( i_returnValue != NSNotFound )
1283 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1284 NSString *tempString;
1285 tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1286 i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1287 if( i_returnValue != NSNotFound )
1288 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1290 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1293 [o_hotkeys_change_win close];
1295 [o_hotkeys_listbox reloadData];
1297 else if( sender == o_hotkeys_clear_btn )
1299 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1300 [o_hotkeys_listbox reloadData];
1301 b_hotkeyChanged = YES;
1304 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1309 - (void)showHotkeySettings
1311 [self showSettingsForCategory: o_hotkeys_view];
1314 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1316 return [o_hotkeySettings count];
1319 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1321 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1322 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1323 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1324 return [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1327 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1332 - (BOOL)changeHotkeyTo: (NSString *)theKey
1334 NSInteger i_returnValue, i_returnValue2;
1335 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1337 if( i_returnValue != NSNotFound || [theKey isEqualToString:@""] )
1339 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1340 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1341 [o_hotkeys_change_ok_btn setEnabled: NO];
1346 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:theKey]];
1348 i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1349 i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1350 if( i_returnValue != NSNotFound )
1351 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1352 _NS("This combination is already taken by \"%@\"."),
1353 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1354 else if( i_returnValue2 != NSNotFound )
1355 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1356 _NS("This combination is already taken by \"%@\"."),
1357 [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1359 [o_hotkeys_change_taken_lbl setStringValue: @""];
1361 [o_hotkeys_change_ok_btn setEnabled: YES];
1362 [o_keyInTransition release];
1363 o_keyInTransition = theKey;
1364 [o_keyInTransition retain];
1371 /********************
1372 * hotkeys settings *
1373 ********************/
1375 @implementation VLCHotkeyChangeWindow
1377 - (BOOL)acceptsFirstResponder
1382 - (BOOL)becomeFirstResponder
1387 - (BOOL)resignFirstResponder
1389 /* We need to stay the first responder or we'll miss the user's input */
1393 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1395 NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1396 NSString *keyString = [o_theEvent characters];
1398 unichar key = [keyString characterAtIndex:0];
1401 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1402 [tempString appendString:@"Ctrl-"];
1403 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1404 [tempString appendString:@"Alt-"];
1405 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1406 [tempString appendString:@"Shift-"];
1407 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1408 [tempString appendString:@"Command-"];
1410 /* non character keys */
1411 if( key == NSUpArrowFunctionKey )
1412 [tempString appendString:@"Up"];
1413 else if( key == NSDownArrowFunctionKey )
1414 [tempString appendString:@"Down"];
1415 else if( key == NSLeftArrowFunctionKey )
1416 [tempString appendString:@"Left"];
1417 else if( key == NSRightArrowFunctionKey )
1418 [tempString appendString:@"Right"];
1419 else if( key == NSF1FunctionKey )
1420 [tempString appendString:@"F1"];
1421 else if( key == NSF2FunctionKey )
1422 [tempString appendString:@"F2"];
1423 else if( key == NSF3FunctionKey )
1424 [tempString appendString:@"F3"];
1425 else if( key == NSF4FunctionKey )
1426 [tempString appendString:@"F4"];
1427 else if( key == NSF5FunctionKey )
1428 [tempString appendString:@"F5"];
1429 else if( key == NSF6FunctionKey )
1430 [tempString appendString:@"F6"];
1431 else if( key == NSF7FunctionKey )
1432 [tempString appendString:@"F7"];
1433 else if( key == NSF8FunctionKey )
1434 [tempString appendString:@"F8"];
1435 else if( key == NSF9FunctionKey )
1436 [tempString appendString:@"F9"];
1437 else if( key == NSF10FunctionKey )
1438 [tempString appendString:@"F10"];
1439 else if( key == NSF11FunctionKey )
1440 [tempString appendString:@"F11"];
1441 else if( key == NSF12FunctionKey )
1442 [tempString appendString:@"F12"];
1443 else if( key == NSInsertFunctionKey )
1444 [tempString appendString:@"Insert"];
1445 else if( key == NSHomeFunctionKey )
1446 [tempString appendString:@"Home"];
1447 else if( key == NSEndFunctionKey )
1448 [tempString appendString:@"End"];
1449 else if( key == NSPageUpFunctionKey )
1450 [tempString appendString:@"Pageup"];
1451 else if( key == NSPageDownFunctionKey )
1452 [tempString appendString:@"Pagedown"];
1453 else if( key == NSMenuFunctionKey )
1454 [tempString appendString:@"Menu"];
1455 else if( key == NSTabCharacter )
1456 [tempString appendString:@"Tab"];
1457 else if( key == NSCarriageReturnCharacter )
1458 [tempString appendString:@"Enter"];
1459 else if( key == NSEnterCharacter )
1460 [tempString appendString:@"Enter"];
1461 else if( key == NSDeleteCharacter )
1462 [tempString appendString:@"Delete"];
1463 else if( key == NSBackspaceCharacter )
1464 [tempString appendString:@"Backspace"];
1465 else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1466 [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1470 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1475 @implementation VLCSimplePrefsWindow
1477 - (BOOL)acceptsFirstResponder
1482 - (void)changeFont:(id)sender
1484 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];