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 + (VLCSimplePrefs *)sharedInstance
56 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
61 if (_o_sharedInstance) {
64 _o_sharedInstance = [super init];
68 return _o_sharedInstance;
73 [o_currentlyShownCategoryView release];
75 [o_hotkeySettings release];
76 [o_hotkeyDescriptions release];
77 [o_hotkeyNames release];
78 [o_hotkeysNonUseableKeys release];
80 [o_keyInTransition release];
85 - (NSString *)OSXStringKeyToString:(NSString *)theString
87 if (![theString isEqualToString:@""]) {
89 if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
90 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
93 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
94 theString = [NSString stringWithFormat:@"%@+", theString];
96 if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
97 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
100 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
101 theString = [NSString stringWithFormat:@"%@-", theString];
104 theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
105 theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
106 theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
107 theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
108 /* show non-character keys correctly */
109 theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
110 theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
111 theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
112 theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
113 theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
114 theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
115 theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]]; /* capitalize plain characters to suit the menubar's look */
116 theString = [theString capitalizedString];
119 theString = [NSString stringWithString:_NS("Not Set")];
127 /* setup the toolbar */
128 NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
129 [o_sprefs_toolbar setAllowsUserCustomization: NO];
130 [o_sprefs_toolbar setAutosavesConfiguration: NO];
131 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
132 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
133 [o_sprefs_toolbar setDelegate: self];
134 [o_sprefs_win setToolbar: o_sprefs_toolbar];
137 [o_sprefs_win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
139 [o_intf_nativefullscreen_ckb setEnabled:NO];
140 #ifndef MAC_OS_X_VERSION_10_7
141 [o_intf_nativefullscreen_ckb setEnabled:NO];
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 );
349 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
351 module_config_t *p_item;
353 [object removeAllItems];
354 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
356 /* serious problem, if no item found */
359 for( int i = 0; i < p_item->i_list; i++ )
362 if( p_item->ppsz_list_text != NULL )
363 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
364 else if( p_item->ppsz_list[i] && strcmp(p_item->ppsz_list[i],"") == 0 )
366 [[object menu] addItem: [NSMenuItem separatorItem]];
369 else if( p_item->ppsz_list[i] )
370 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
372 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name );
373 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
374 [[object menu] addItem: [mi autorelease]];
375 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
376 [object selectItem:[object lastItem]];
378 [object setToolTip: _NS( p_item->psz_longtext )];
381 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
383 module_config_t *p_item;
385 [object removeAllItems];
386 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
388 /* serious problem, if no item found */
391 for( int i = 0; i < p_item->i_list; i++ )
394 if( p_item->ppsz_list_text != NULL)
395 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
396 else if( p_item->pi_list[i] )
397 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
399 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name);
400 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
401 [[object menu] addItem: [mi autorelease]];
402 if( p_item->value.i == p_item->pi_list[i] )
403 [object selectItem:[object lastItem]];
405 [object setToolTip: _NS( p_item->psz_longtext )];
408 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
410 module_config_t *p_item;
411 module_t *p_parser, **p_list;
414 [object removeAllItems];
416 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
417 p_list = module_list_get( NULL );
418 if( !p_item ||!p_list )
420 if( p_list ) module_list_free(p_list);
421 msg_Err( p_intf, "serious problem, item or list not found" );
425 [object addItemWithTitle: _NS("Default")];
426 for( size_t i_index = 0; p_list[i_index]; i_index++ )
428 p_parser = p_list[i_index];
429 if( module_provides( p_parser, p_item->psz_type ) )
431 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
432 if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
433 [object selectItem: [object lastItem]];
436 module_list_free( p_list );
437 [object setToolTip: _NS(p_item->psz_longtext)];
440 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
442 [object setState: config_GetInt( p_intf, name )];
443 [object setToolTip: _NS(config_GetLabel( p_intf, name ) ?: "")];
446 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
448 char *psz_tmp = config_GetPsz( p_intf, psz_option );
449 [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
450 [o_object setToolTip: _NS(config_GetLabel( p_intf, psz_option ))];
454 - (void)resetControls
456 module_config_t *p_item;
460 /**********************
461 * interface settings *
462 **********************/
463 [self setupButton: o_intf_lang_pop forStringList: "language"];
464 [self setupButton: o_intf_art_pop forIntList: "album-art"];
466 [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
467 [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
468 [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
470 [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
472 [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
473 if( [[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL )
474 [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
476 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
477 psz_tmp = config_GetPsz( p_intf, "control" );
479 [o_intf_enableGrowl_ckb setState: (NSInteger)strstr( psz_tmp, "growl")];
483 [o_intf_enableGrowl_ckb setState: NSOffState];
484 if (config_GetInt( p_intf, "macosx-interfacestyle" ))
486 [o_intf_style_dark_bcell setState: YES];
487 [o_intf_style_bright_bcell setState: NO];
491 [o_intf_style_dark_bcell setState: NO];
492 [o_intf_style_bright_bcell setState: YES];
494 [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
495 [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
500 [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
502 if ( config_GetInt( p_intf, "macosx-autosave-volume" ))
504 [o_audio_autosavevol_yes_bcell setState: NSOnState];
505 [o_audio_autosavevol_no_bcell setState: NSOffState];
506 [o_audio_vol_fld setEnabled: NO];
507 [o_audio_vol_sld setEnabled: NO];
509 [o_audio_vol_sld setIntValue: 100];
510 [o_audio_vol_fld setIntValue: 100];
514 [o_audio_autosavevol_yes_bcell setState: NSOffState];
515 [o_audio_autosavevol_no_bcell setState: NSOnState];
516 [o_audio_vol_fld setEnabled: YES];
517 [o_audio_vol_sld setEnabled: YES];
519 i = config_GetInt( p_intf, "volume" );
520 i = i * 200 / AOUT_VOLUME_MAX;
521 [o_audio_vol_sld setIntValue: i];
522 [o_audio_vol_fld setIntValue: i];
525 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
527 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
528 [self setupField: o_audio_lang_fld forOption: "audio-language"];
530 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
532 /* Last.FM is optional */
533 if( module_exists( "audioscrobbler" ) )
535 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
536 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
538 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
540 [o_audio_last_ckb setState: NSOnState];
541 [o_audio_lastuser_fld setEnabled: YES];
542 [o_audio_lastpwd_sfld setEnabled: YES];
546 [o_audio_last_ckb setState: NSOffState];
547 [o_audio_lastuser_fld setEnabled: NO];
548 [o_audio_lastpwd_sfld setEnabled: NO];
552 [o_audio_last_ckb setEnabled: NO];
557 [self setupButton: o_video_enable_ckb forBoolValue: "video"];
558 [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
559 [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
560 [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
561 [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
563 [self setupButton: o_video_output_pop forModuleList: "vout"];
565 [o_video_device_pop removeAllItems];
567 y = [[NSScreen screens] count];
568 [o_video_device_pop addItemWithTitle: _NS("Default")];
569 [[o_video_device_pop lastItem] setTag: 0];
572 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
573 [o_video_device_pop addItemWithTitle:
574 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
575 (int)s_rect.size.width, (int)s_rect.size.height]];
576 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
579 [o_video_device_pop selectItemAtIndex: 0];
580 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
582 [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
583 [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
584 [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
585 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
587 /***************************
588 * input & codecs settings *
589 ***************************/
590 [self setupField: o_input_record_fld forOption:"input-record-path"];
591 [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
592 [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
593 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "postproc-q")];
594 [o_input_postproc_fld setToolTip: _NS(config_GetLabel( p_intf, "postproc-q"))];
596 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
598 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
599 [self setupButton: o_input_skipLoop_pop forIntList: "ffmpeg-skiploopfilter"];
601 [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
603 [o_input_cachelevel_pop removeAllItems];
604 [o_input_cachelevel_pop addItemsWithTitles:
605 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
606 _NS("High latency"), _NS("Higher latency"), nil]];
607 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
608 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
609 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
610 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
611 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
612 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
614 #define TestCaC( name, factor ) \
615 b_cache_equal = b_cache_equal && \
616 ( i_cache * factor == config_GetInt( p_intf, name ) );
618 /* Select the accurate value of the PopupButton */
619 bool b_cache_equal = true;
620 int i_cache = config_GetInt( p_intf, "file-caching");
622 TestCaC( "network-caching", 10/3 );
623 TestCaC( "disc-caching", 1 );
624 TestCaC( "live-caching", 1 );
627 [o_input_cachelevel_pop selectItemWithTag: i_cache];
628 [o_input_cachelevel_custom_txt setHidden: YES];
632 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
633 [o_input_cachelevel_custom_txt setHidden: NO];
637 /*********************
638 * subtitle settings *
639 *********************/
640 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
642 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
643 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
645 [self setupField: o_osd_font_fld forOption: "freetype-font"];
646 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
647 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
648 i = config_GetInt( p_intf, "freetype-opacity" );
649 [o_osd_opacity_fld setIntValue: i];
650 [o_osd_opacity_sld setIntValue: i];
651 [o_osd_opacity_sld setToolTip: _NS(config_GetLabel( p_intf, "freetype-opacity"))];
652 [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
653 [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
655 /********************
657 ********************/
658 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
659 [o_hotkeySettings release];
660 o_hotkeySettings = [[NSMutableArray alloc] init];
661 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
662 NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
664 /* Get the main Module */
665 module_t *p_main = module_get_main();
668 module_config_t *p_config;
670 p_config = module_config_get (p_main, &confsize);
672 for (size_t i = 0; i < confsize; i++)
674 module_config_t *p_item = p_config + i;
676 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
677 && !strncmp( p_item->psz_name , "key-", 4 )
678 && !EMPTY_STR( p_item->psz_text ) )
680 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
681 [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
682 if (p_item->value.psz)
683 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
685 [o_hotkeySettings addObject: [NSString string]];
688 module_config_free (p_config);
690 [o_hotkeyDescriptions release];
691 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
692 [o_tempArray_desc release];
693 [o_hotkeyNames release];
694 o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
695 [o_tempArray_names release];
696 [o_hotkeys_listbox reloadData];
699 - (void)showSimplePrefs
701 /* we want to show the interface settings, if no category was chosen */
702 if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
704 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
705 [self showInterfaceSettings];
708 [self resetControls];
710 [o_sprefs_win center];
711 [o_sprefs_win makeKeyAndOrderFront: self];
714 - (IBAction)buttonAction:(id)sender
716 if( sender == o_sprefs_cancel_btn )
717 [o_sprefs_win orderOut: sender];
718 else if( sender == o_sprefs_save_btn )
720 [self saveChangedSettings];
721 [o_sprefs_win orderOut: sender];
723 else if( sender == o_sprefs_reset_btn )
724 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
725 _NS("Continue"), nil, o_sprefs_win, self,
726 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
727 _NS("Beware this will reset the VLC media player preferences.\n"
728 "Are you sure you want to continue?") );
729 else if( sender == o_sprefs_showAll_btn )
731 [o_sprefs_win orderOut: self];
732 [[[VLCMain sharedInstance] preferences] showPrefs];
735 msg_Warn( p_intf, "unknown buttonAction sender" );
738 - (void)sheetDidEnd:(NSWindow *)o_sheet
739 returnCode:(int)i_return
740 contextInfo:(void *)o_context
742 if( i_return == NSAlertAlternateReturn )
744 config_ResetAll( p_intf );
745 [self resetControls];
746 config_SaveConfigFile( p_intf );
750 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
752 NSNumber *p_valueobject;
753 module_config_t *p_item;
754 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
755 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
756 assert([p_valueobject isKindOfClass:[NSNumber class]]);
757 if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
760 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
762 NSString *p_stringobject;
763 module_config_t *p_item;
764 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
765 p_stringobject = (NSString *)[[object selectedItem] representedObject];
766 assert([p_stringobject isKindOfClass:[NSString class]]);
769 config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
773 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
775 module_config_t *p_item;
776 module_t *p_parser, **p_list;
778 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
780 p_list = module_list_get( NULL );
781 for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
783 p_parser = p_list[i_module_index];
785 if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
787 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
789 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
794 module_list_free( p_list );
795 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
796 config_PutPsz( p_intf, name, "" );
799 - (void)saveChangedSettings
804 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
806 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
808 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
810 #define getString( name ) [NSString stringWithFormat:@"%s", config_GetPsz( p_intf, name )]
812 /**********************
813 * interface settings *
814 **********************/
815 if( b_intfSettingChanged )
817 SaveStringList( o_intf_lang_pop, "language" );
818 SaveIntList( o_intf_art_pop, "album-art" );
820 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
821 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
823 config_PutInt( p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state] );
824 config_PutInt( p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state] );
825 config_PutInt( p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state] );
826 config_PutInt( p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state] );
827 config_PutInt( p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state] );
828 config_PutInt( p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state] );
829 if( [o_intf_enableGrowl_ckb state] == NSOnState )
831 tmpString = getString( "control" );
832 tmpRange = [tmpString rangeOfString:@"growl"];
833 if( [tmpString length] > 0 && tmpRange.location == NSNotFound )
835 tmpString = [tmpString stringByAppendingString: @":growl"];
836 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
839 config_PutPsz( p_intf, "control", "growl" );
843 tmpString = getString( "control" );
844 if(! [tmpString isEqualToString:@""] )
846 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
847 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
848 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
849 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
853 /* activate stuff without restart */
854 if( [o_intf_appleremote_ckb state] == YES )
855 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
857 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
858 b_intfSettingChanged = NO;
864 if( b_audioSettingChanged )
866 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
867 if( [o_audio_vol_fld isEnabled] )
868 config_PutInt( p_intf, "volume", [o_audio_vol_fld intValue] * AOUT_VOLUME_MAX / 200 );
869 config_PutInt( p_intf, "macosx-autosave-volume", [o_audio_autosavevol_yes_bcell state] );
870 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
872 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
874 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
876 SaveModuleList( o_audio_visual_pop, "audio-visual" );
878 /* Last.FM is optional */
879 if( module_exists( "audioscrobbler" ) )
881 [o_audio_last_ckb setEnabled: YES];
882 if( [o_audio_last_ckb state] == NSOnState )
883 config_AddIntf( p_intf, "audioscrobbler" );
885 config_RemoveIntf( p_intf, "audioscrobbler" );
887 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
888 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
891 [o_audio_last_ckb setEnabled: NO];
892 b_audioSettingChanged = NO;
898 if( b_videoSettingChanged )
900 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
901 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
902 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
903 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
904 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
906 SaveModuleList( o_video_output_pop, "vout" );
907 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
909 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
910 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
911 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
912 SaveStringList( o_video_snap_format_pop, "snapshot-format" );
913 b_videoSettingChanged = NO;
916 /***************************
917 * input & codecs settings *
918 ***************************/
919 if( b_inputSettingChanged )
921 config_PutPsz( p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String] );
922 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
923 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
924 config_PutInt( p_intf, "postproc-q", [o_input_postproc_fld intValue] );
926 SaveIntList( o_input_avi_pop, "avi-index" );
928 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
929 SaveIntList( o_input_skipLoop_pop, "ffmpeg-skiploopfilter" );
931 config_PutInt( p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state] );
933 #define CaC( name, factor ) config_PutInt( p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor )
934 if ( [[o_input_cachelevel_pop selectedItem] tag] == 0 )
936 msg_Dbg( p_intf, "Custom chosen, not adjusting cache values" );
940 msg_Dbg( p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag] );
941 CaC( "file-caching", 1 );
942 CaC( "network-caching", 10/3 );
943 CaC( "disc-caching", 1 );
944 CaC( "live-caching", 1 );
947 b_inputSettingChanged = NO;
950 /**********************
951 * subtitles settings *
952 **********************/
953 if( b_osdSettingChanged )
955 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
957 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
958 SaveStringList( o_osd_encoding_pop, "subsdec-encoding" );
960 config_PutPsz( p_intf, "subsdec-encoding", "" );
962 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
964 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
965 SaveIntList( o_osd_font_color_pop, "freetype-color" );
966 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
967 config_PutInt( p_intf, "freetype-opacity", [o_osd_opacity_sld intValue] );
968 config_PutInt( p_intf, "freetype-bold", [o_osd_forcebold_ckb state] );
969 b_osdSettingChanged = NO;
972 /********************
974 ********************/
975 if( b_hotkeyChanged )
977 NSUInteger hotKeyCount = [o_hotkeySettings count];
978 for( NSUInteger i = 0; i < hotKeyCount; i++ )
979 config_PutPsz( p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String] );
980 b_hotkeyChanged = NO;
983 /* okay, let's save our changes to vlcrc */
984 config_SaveConfigFile( p_intf );
986 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
991 - (void)showSettingsForCategory: (id)o_new_category_view
993 NSRect o_win_rect, o_view_rect, o_old_view_rect;
994 o_win_rect = [o_sprefs_win frame];
995 o_view_rect = [o_new_category_view frame];
997 if( o_currentlyShownCategoryView != nil )
999 /* restore our window's height, if we've shown another category previously */
1000 o_old_view_rect = [o_currentlyShownCategoryView frame];
1001 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
1002 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
1005 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
1007 [o_new_category_view setFrame: NSMakeRect( 0,
1008 [o_sprefs_controls_box frame].size.height,
1009 o_view_rect.size.width,
1010 o_view_rect.size.height )];
1011 [o_new_category_view setAutoresizesSubviews: YES];
1012 if (o_currentlyShownCategoryView)
1014 [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
1015 [o_currentlyShownCategoryView release];
1016 [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
1020 [[o_sprefs_win contentView] addSubview: o_new_category_view];
1021 [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
1024 /* keep our current category for further reference */
1025 o_currentlyShownCategoryView = o_new_category_view;
1026 [o_currentlyShownCategoryView retain];
1029 - (IBAction)interfaceSettingChanged:(id)sender
1031 if( sender == o_intf_embedded_ckb && [o_intf_embedded_ckb state] == NSOffState )
1032 [o_intf_nativefullscreen_ckb setState: NSOffState];
1034 if( sender == o_intf_nativefullscreen_ckb && [o_intf_nativefullscreen_ckb state] == NSOnState )
1035 [o_intf_embedded_ckb setState: NSOnState];
1037 b_intfSettingChanged = YES;
1040 - (void)showInterfaceSettings
1042 [self showSettingsForCategory: o_intf_view];
1045 - (IBAction)audioSettingChanged:(id)sender
1047 if( sender == o_audio_vol_sld )
1048 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1050 if( sender == o_audio_vol_fld )
1051 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1053 if( sender == o_audio_last_ckb )
1055 if( [o_audio_last_ckb state] == NSOnState )
1057 [o_audio_lastpwd_sfld setEnabled: YES];
1058 [o_audio_lastuser_fld setEnabled: YES];
1062 [o_audio_lastpwd_sfld setEnabled: NO];
1063 [o_audio_lastuser_fld setEnabled: NO];
1067 if( sender == o_audio_autosavevol_matrix )
1069 BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1070 [o_audio_vol_fld setEnabled: enableVolumeSlider];
1071 [o_audio_vol_sld setEnabled: enableVolumeSlider];
1074 b_audioSettingChanged = YES;
1077 - (void)showAudioSettings
1079 [self showSettingsForCategory: o_audio_view];
1082 - (IBAction)videoSettingChanged:(id)sender
1084 if( sender == o_video_snap_folder_btn )
1086 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1087 [o_selectFolderPanel setCanChooseDirectories: YES];
1088 [o_selectFolderPanel setCanChooseFiles: NO];
1089 [o_selectFolderPanel setResolvesAliases: YES];
1090 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1091 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1092 [o_selectFolderPanel setCanCreateDirectories: YES];
1093 [o_selectFolderPanel setPrompt: _NS("Choose")];
1094 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1096 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1097 contextInfo: o_video_snap_folder_btn];
1100 b_videoSettingChanged = YES;
1103 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1105 if( returnCode == NSOKButton )
1107 if( contextInfo == o_video_snap_folder_btn )
1109 [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1110 b_videoSettingChanged = YES;
1112 else if( contextInfo == o_input_record_btn )
1114 [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1115 b_inputSettingChanged = YES;
1119 [o_selectFolderPanel release];
1122 - (void)showVideoSettings
1124 [self showSettingsForCategory: o_video_view];
1127 - (IBAction)osdSettingChanged:(id)sender
1129 if( sender == o_osd_opacity_fld )
1130 [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1132 if( sender == o_osd_opacity_sld )
1133 [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1135 b_osdSettingChanged = YES;
1138 - (void)showOSDSettings
1140 [self showSettingsForCategory: o_osd_view];
1143 - (void)controlTextDidChange:(NSNotification *)o_notification
1145 id notificationObject = [o_notification object];
1146 if( notificationObject == o_audio_lang_fld ||
1147 notificationObject == o_audio_lastpwd_sfld ||
1148 notificationObject == o_audio_lastuser_fld ||
1149 notificationObject == o_audio_vol_fld )
1150 b_audioSettingChanged = YES;
1151 else if( notificationObject == o_input_record_fld ||
1152 notificationObject == o_input_httpproxy_fld ||
1153 notificationObject == o_input_httpproxypwd_sfld ||
1154 notificationObject == o_input_postproc_fld )
1155 b_inputSettingChanged = YES;
1156 else if( notificationObject == o_osd_font_fld ||
1157 notificationObject == o_osd_lang_fld ||
1158 notificationObject == o_osd_opacity_fld)
1159 b_osdSettingChanged = YES;
1160 else if( notificationObject == o_video_snap_folder_fld ||
1161 notificationObject == o_video_snap_prefix_fld )
1162 b_videoSettingChanged = YES;
1165 - (IBAction)showFontPicker:(id)sender
1167 char * font = config_GetPsz( p_intf, "freetype-font" );
1168 NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1170 if( fontFamilyName )
1172 NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1173 NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1174 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1176 [[NSFontManager sharedFontManager] setTarget: self];
1177 [[NSFontPanel sharedFontPanel] orderFront:self];
1180 - (void)changeFont:(id)sender
1182 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1183 [o_osd_font_fld setStringValue:[font familyName]];
1184 [self osdSettingChanged:self];
1187 - (IBAction)inputSettingChanged:(id)sender
1189 if( sender == o_input_cachelevel_pop )
1191 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1192 [o_input_cachelevel_custom_txt setHidden: NO];
1194 [o_input_cachelevel_custom_txt setHidden: YES];
1196 else if( sender == o_input_record_btn )
1198 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1199 [o_selectFolderPanel setCanChooseDirectories: YES];
1200 [o_selectFolderPanel setCanChooseFiles: YES];
1201 [o_selectFolderPanel setResolvesAliases: YES];
1202 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1203 [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1204 [o_selectFolderPanel setCanCreateDirectories: YES];
1205 [o_selectFolderPanel setPrompt: _NS("Choose")];
1206 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1208 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1209 contextInfo: o_input_record_btn];
1213 b_inputSettingChanged = YES;
1216 - (void)showInputSettings
1218 [self showSettingsForCategory: o_input_view];
1221 - (IBAction)hotkeySettingChanged:(id)sender
1223 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1225 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1226 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1227 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1228 [o_hotkeys_change_taken_lbl setStringValue: @""];
1229 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1230 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1231 [NSApp runModalForWindow: o_hotkeys_change_win];
1233 else if( sender == o_hotkeys_change_cancel_btn )
1236 [o_hotkeys_change_win close];
1238 else if( sender == o_hotkeys_change_ok_btn )
1240 NSInteger i_returnValue;
1241 if(! o_keyInTransition )
1244 [o_hotkeys_change_win close];
1245 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1249 b_hotkeyChanged = YES;
1251 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1252 if( i_returnValue != NSNotFound )
1253 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1254 NSString *tempString;
1255 tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1256 i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1257 if( i_returnValue != NSNotFound )
1258 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1260 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1263 [o_hotkeys_change_win close];
1265 [o_hotkeys_listbox reloadData];
1267 else if( sender == o_hotkeys_clear_btn )
1269 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1270 [o_hotkeys_listbox reloadData];
1271 b_hotkeyChanged = YES;
1274 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1279 - (void)showHotkeySettings
1281 [self showSettingsForCategory: o_hotkeys_view];
1284 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1286 return [o_hotkeySettings count];
1289 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1291 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1292 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1293 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1294 return [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1297 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1302 - (BOOL)changeHotkeyTo: (NSString *)theKey
1304 NSInteger i_returnValue, i_returnValue2;
1305 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1307 if( i_returnValue != NSNotFound || [theKey isEqualToString:@""] )
1309 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1310 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1311 [o_hotkeys_change_ok_btn setEnabled: NO];
1316 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:theKey]];
1318 i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1319 i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1320 if( i_returnValue != NSNotFound )
1321 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1322 _NS("This combination is already taken by \"%@\"."),
1323 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1324 else if( i_returnValue2 != NSNotFound )
1325 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1326 _NS("This combination is already taken by \"%@\"."),
1327 [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1329 [o_hotkeys_change_taken_lbl setStringValue: @""];
1331 [o_hotkeys_change_ok_btn setEnabled: YES];
1332 [o_keyInTransition release];
1333 o_keyInTransition = theKey;
1334 [o_keyInTransition retain];
1341 /********************
1342 * hotkeys settings *
1343 ********************/
1345 @implementation VLCHotkeyChangeWindow
1347 - (BOOL)acceptsFirstResponder
1352 - (BOOL)becomeFirstResponder
1357 - (BOOL)resignFirstResponder
1359 /* We need to stay the first responder or we'll miss the user's input */
1363 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1365 NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1366 NSString *keyString = [o_theEvent characters];
1368 unichar key = [keyString characterAtIndex:0];
1371 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1372 [tempString appendString:@"Ctrl-"];
1373 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1374 [tempString appendString:@"Alt-"];
1375 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1376 [tempString appendString:@"Shift-"];
1377 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1378 [tempString appendString:@"Command-"];
1380 /* non character keys */
1381 if( key == NSUpArrowFunctionKey )
1382 [tempString appendString:@"Up"];
1383 else if( key == NSDownArrowFunctionKey )
1384 [tempString appendString:@"Down"];
1385 else if( key == NSLeftArrowFunctionKey )
1386 [tempString appendString:@"Left"];
1387 else if( key == NSRightArrowFunctionKey )
1388 [tempString appendString:@"Right"];
1389 else if( key == NSF1FunctionKey )
1390 [tempString appendString:@"F1"];
1391 else if( key == NSF2FunctionKey )
1392 [tempString appendString:@"F2"];
1393 else if( key == NSF3FunctionKey )
1394 [tempString appendString:@"F3"];
1395 else if( key == NSF4FunctionKey )
1396 [tempString appendString:@"F4"];
1397 else if( key == NSF5FunctionKey )
1398 [tempString appendString:@"F5"];
1399 else if( key == NSF6FunctionKey )
1400 [tempString appendString:@"F6"];
1401 else if( key == NSF7FunctionKey )
1402 [tempString appendString:@"F7"];
1403 else if( key == NSF8FunctionKey )
1404 [tempString appendString:@"F8"];
1405 else if( key == NSF9FunctionKey )
1406 [tempString appendString:@"F9"];
1407 else if( key == NSF10FunctionKey )
1408 [tempString appendString:@"F10"];
1409 else if( key == NSF11FunctionKey )
1410 [tempString appendString:@"F11"];
1411 else if( key == NSF12FunctionKey )
1412 [tempString appendString:@"F12"];
1413 else if( key == NSInsertFunctionKey )
1414 [tempString appendString:@"Insert"];
1415 else if( key == NSHomeFunctionKey )
1416 [tempString appendString:@"Home"];
1417 else if( key == NSEndFunctionKey )
1418 [tempString appendString:@"End"];
1419 else if( key == NSPageUpFunctionKey )
1420 [tempString appendString:@"Pageup"];
1421 else if( key == NSPageDownFunctionKey )
1422 [tempString appendString:@"Pagedown"];
1423 else if( key == NSMenuFunctionKey )
1424 [tempString appendString:@"Menu"];
1425 else if( key == NSTabCharacter )
1426 [tempString appendString:@"Tab"];
1427 else if( key == NSCarriageReturnCharacter )
1428 [tempString appendString:@"Enter"];
1429 else if( key == NSEnterCharacter )
1430 [tempString appendString:@"Enter"];
1431 else if( key == NSDeleteCharacter )
1432 [tempString appendString:@"Delete"];
1433 else if( key == NSBackspaceCharacter )
1434 [tempString appendString:@"Backspace"];
1435 else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1436 [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1440 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1445 @implementation VLCSimplePrefsWindow
1447 - (BOOL)acceptsFirstResponder
1452 - (void)changeFont:(id)sender
1454 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];