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_plugin.h>
36 #import <vlc_config_cat.h>
39 #import "AppleRemote.h"
40 #import "CoreInteraction.h"
42 #import <Sparkle/Sparkle.h> //for o_intf_last_update_lbl
44 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
45 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
46 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
47 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
48 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
49 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
50 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
52 @implementation VLCSimplePrefs
54 static VLCSimplePrefs *_o_sharedInstance = nil;
56 #pragma mark Initialisation
58 + (VLCSimplePrefs *)sharedInstance
60 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
65 if (_o_sharedInstance) {
68 _o_sharedInstance = [super init];
72 return _o_sharedInstance;
77 [o_currentlyShownCategoryView release];
79 [o_hotkeySettings release];
80 [o_hotkeyDescriptions release];
81 [o_hotkeyNames release];
82 [o_hotkeysNonUseableKeys release];
84 [o_keyInTransition release];
89 - (NSString *)OSXStringKeyToString:(NSString *)theString
91 if (![theString isEqualToString:@""]) {
93 if ([theString characterAtIndex:([theString length] - 1)] != 0x2b)
94 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
97 theString = [theString stringByReplacingOccurrencesOfString:@"+" withString:@""];
98 theString = [NSString stringWithFormat:@"%@+", theString];
100 if ([theString characterAtIndex:([theString length] - 1)] != 0x2d)
101 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
104 theString = [theString stringByReplacingOccurrencesOfString:@"-" withString:@""];
105 theString = [NSString stringWithFormat:@"%@-", theString];
108 theString = [theString stringByReplacingOccurrencesOfString:@"Command" withString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
109 theString = [theString stringByReplacingOccurrencesOfString:@"Alt" withString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
110 theString = [theString stringByReplacingOccurrencesOfString:@"Shift" withString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
111 theString = [theString stringByReplacingOccurrencesOfString:@"Ctrl" withString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
112 /* show non-character keys correctly */
113 theString = [theString stringByReplacingOccurrencesOfString:@"Right" withString:[NSString stringWithUTF8String:"\xE2\x86\x92"]];
114 theString = [theString stringByReplacingOccurrencesOfString:@"Left" withString:[NSString stringWithUTF8String:"\xE2\x86\x90"]];
115 theString = [theString stringByReplacingOccurrencesOfString:@"Up" withString:[NSString stringWithUTF8String:"\xE2\x86\x91"]];
116 theString = [theString stringByReplacingOccurrencesOfString:@"Down" withString:[NSString stringWithUTF8String:"\xE2\x86\x93"]];
117 theString = [theString stringByReplacingOccurrencesOfString:@"Enter" withString:[NSString stringWithUTF8String:"\xe2\x86\xb5"]];
118 theString = [theString stringByReplacingOccurrencesOfString:@"Tab" withString:[NSString stringWithUTF8String:"\xe2\x87\xa5"]];
119 theString = [theString stringByReplacingOccurrencesOfString:@"Delete" withString:[NSString stringWithUTF8String:"\xe2\x8c\xab"]]; /* capitalize plain characters to suit the menubar's look */
120 theString = [theString capitalizedString];
123 theString = [NSString stringWithString:_NS("Not Set")];
131 /* setup the toolbar */
132 NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
133 [o_sprefs_toolbar setAllowsUserCustomization: NO];
134 [o_sprefs_toolbar setAutosavesConfiguration: NO];
135 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
136 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
137 [o_sprefs_toolbar setDelegate: self];
138 [o_sprefs_win setToolbar: o_sprefs_toolbar];
141 [o_sprefs_win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
143 [o_hotkeys_listbox setTarget:self];
144 [o_hotkeys_listbox setDoubleAction:@selector(hotkeyTableDoubleClick:)];
146 /* setup useful stuff */
147 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];
150 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
151 o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
152 static inline NSToolbarItem *
153 create_toolbar_item( NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector )
155 NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
157 [o_toolbarItem setLabel: o_name];
158 [o_toolbarItem setPaletteLabel: o_desc];
160 [o_toolbarItem setToolTip: o_desc];
161 [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
163 [o_toolbarItem setTarget: target];
164 [o_toolbarItem setAction: selector];
166 [o_toolbarItem setEnabled: YES];
167 [o_toolbarItem setAutovalidates: YES];
169 return o_toolbarItem;
172 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
173 itemForItemIdentifier: (NSString *)o_itemIdent
174 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
176 NSToolbarItem *o_toolbarItem = nil;
178 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
180 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
182 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
184 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
186 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
188 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
190 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
192 CreateToolbarItem( _NS(SUBPIC_TITLE), _NS("Subtitles & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
194 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
196 CreateToolbarItem( _NS(INPUT_TITLE), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
198 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
200 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
203 return o_toolbarItem;
206 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
208 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
209 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
212 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
214 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
215 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
218 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
220 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
221 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
227 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
228 [o_audio_effects_box setTitle: _NS("Effects")];
229 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
230 [o_audio_general_box setTitle: _NS("General Audio")];
231 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
232 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
233 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
234 [o_audio_lastuser_txt setStringValue: _NS("User name")];
235 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
236 [o_audio_visual_txt setStringValue: _NS("Visualization")];
237 [o_audio_autosavevol_yes_bcell setTitle: _NS("Keep audio level between sessions")];
238 [o_audio_autosavevol_no_bcell setTitle: _NS("Always reset audio start level to:")];
241 [o_hotkeys_change_btn setTitle: _NS("Change")];
242 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
243 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
244 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
245 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
246 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
247 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
248 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
251 [o_input_record_box setTitle: _NS("Record directory or filename")];
252 [o_input_record_btn setTitle: _NS("Browse...")];
253 [o_input_record_btn setToolTip: _NS("Directory or filename where the records will be stored")];
254 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
255 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
256 [o_input_caching_box setTitle: _NS("Caching")];
257 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
258 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
259 [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
260 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
261 [o_input_net_box setTitle: _NS("Network")];
262 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
263 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
264 [o_input_skipLoop_txt setStringValue: _NS("Skip the loop filter for H.264 decoding")];
265 [o_input_mkv_preload_dir_ckb setTitle: _NS("Preload MKV files in the same directory")];
268 [o_intf_style_txt setStringValue: _NS("Interface style")];
269 [o_intf_style_dark_bcell setTitle: _NS("Dark")];
270 [o_intf_style_bright_bcell setTitle: _NS("Bright")];
271 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
272 [o_intf_embedded_ckb setTitle: _NS("Show video within the main window")];
273 [o_intf_nativefullscreen_ckb setTitle: _NS("Use the native fullscreen mode on OS X Lion")];
274 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
275 [o_intf_lang_txt setStringValue: _NS("Language")];
276 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
278 [o_intf_appleremote_ckb setTitle: _NS("Control playback with the Apple Remote")];
280 [o_intf_mediakeys_ckb setTitle: _NS("Control playback with media keys")];
281 [o_intf_update_ckb setTitle: _NS("Automatically check for updates")];
282 [o_intf_last_update_lbl setStringValue: @""];
283 [o_intf_enableGrowl_ckb setTitle: _NS("Enable Growl notifications (on playlist item change)")];
284 [o_intf_autoresize_ckb setTitle: _NS("Resize interface to the native video size")];
285 [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
287 /* Subtitles and OSD */
288 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
289 [o_osd_font_box setTitle: _NS("Display Settings")];
290 [o_osd_font_btn setTitle: _NS("Choose...")];
291 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
292 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
293 [o_osd_font_txt setStringValue: _NS("Font")];
294 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
295 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
296 [o_osd_osd_box setTitle: _NS("On Screen Display")];
297 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
298 [o_osd_opacity_txt setStringValue: _NS("Opacity")];
299 [o_osd_forcebold_ckb setTitle: _NS("Force Bold")];
300 [o_osd_outline_color_txt setStringValue: _NS("Outline Color")];
301 [o_osd_outline_thickness_txt setStringValue: _NS("Outline Thickness")];
304 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
305 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
306 [o_video_display_box setTitle: _NS("Display")];
307 [o_video_enable_ckb setTitle: _NS("Enable Video")];
308 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
309 [o_video_onTop_ckb setTitle: _NS("Always on top")];
310 [o_video_output_txt setStringValue: _NS("Output module")];
311 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
312 [o_video_snap_box setTitle: _NS("Video snapshots")];
313 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
314 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
315 [o_video_snap_format_txt setStringValue: _NS("Format")];
316 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
317 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
318 [o_video_deinterlace_txt setStringValue: _NS("Deinterlace")];
319 [o_video_deinterlace_mode_txt setStringValue: _NS("Deinterlace mode")];
320 [o_video_video_box setTitle: _NS("Video")];
323 [o_sprefs_showAll_btn setTitle: _NS("Show All")];
324 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
325 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
326 [o_sprefs_save_btn setTitle: _NS("Save")];
327 [o_sprefs_win setTitle: _NS("Preferences")];
330 /* TODO: move this part to core */
331 #define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
332 static inline char * __config_GetLabel( vlc_object_t *p_this, const char *psz_name )
334 module_config_t *p_config;
336 p_config = config_FindConfig( p_this, psz_name );
341 msg_Err( p_this, "option %s does not exist", psz_name );
345 if ( p_config->psz_longtext )
346 return p_config->psz_longtext;
347 else if( p_config->psz_text )
348 return p_config->psz_text;
350 msg_Warn( p_this, "option %s does not include any help", psz_name );
356 #pragma mark Setup controls
358 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
360 module_config_t *p_item;
362 [object removeAllItems];
363 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
365 /* serious problem, if no item found */
368 for( int i = 0; i < p_item->i_list; i++ )
371 if( p_item->ppsz_list_text != NULL )
372 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
373 else if( p_item->ppsz_list[i] && strcmp(p_item->ppsz_list[i],"") == 0 )
375 [[object menu] addItem: [NSMenuItem separatorItem]];
378 else if( p_item->ppsz_list[i] )
379 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
381 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name );
382 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
383 [[object menu] addItem: [mi autorelease]];
384 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
385 [object selectItem:[object lastItem]];
387 [object setToolTip: _NS( p_item->psz_longtext )];
390 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
392 module_config_t *p_item;
394 [object removeAllItems];
395 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
397 /* serious problem, if no item found */
400 for( int i = 0; i < p_item->i_list; i++ )
403 if( p_item->ppsz_list_text != NULL)
404 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
405 else if( p_item->pi_list[i] )
406 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
408 msg_Err( p_intf, "item %d of pref %s failed to be created", i, name);
409 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
410 [[object menu] addItem: [mi autorelease]];
411 if( p_item->value.i == p_item->pi_list[i] )
412 [object selectItem:[object lastItem]];
414 [object setToolTip: _NS( p_item->psz_longtext )];
417 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
419 module_config_t *p_item;
420 module_t *p_parser, **p_list;
423 [object removeAllItems];
425 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
426 p_list = module_list_get( NULL );
427 if( !p_item ||!p_list )
429 if( p_list ) module_list_free(p_list);
430 msg_Err( p_intf, "serious problem, item or list not found" );
434 [object addItemWithTitle: _NS("Default")];
435 for( size_t i_index = 0; p_list[i_index]; i_index++ )
437 p_parser = p_list[i_index];
438 if( module_provides( p_parser, p_item->psz_type ) )
440 [object addItemWithTitle: [NSString stringWithUTF8String: _(module_GetLongName( p_parser )) ?: ""]];
441 if( p_item->value.psz && !strcmp( p_item->value.psz, module_get_object( p_parser ) ) )
442 [object selectItem: [object lastItem]];
445 module_list_free( p_list );
446 [object setToolTip: _NS(p_item->psz_longtext)];
449 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
451 [object setState: config_GetInt( p_intf, name )];
452 [object setToolTip: _NS(config_GetLabel( p_intf, name ) ?: "")];
455 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
457 char *psz_tmp = config_GetPsz( p_intf, psz_option );
458 [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
459 [o_object setToolTip: _NS(config_GetLabel( p_intf, psz_option ))];
463 - (void)resetControls
465 module_config_t *p_item;
469 /**********************
470 * interface settings *
471 **********************/
472 [self setupButton: o_intf_lang_pop forStringList: "language"];
473 [self setupButton: o_intf_art_pop forIntList: "album-art"];
475 [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
477 [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
478 BOOL b_correct_sdk = NO;
479 #ifdef MAC_OS_X_VERSION_10_7
482 if( !( b_correct_sdk && OSX_LION ))
484 [o_intf_nativefullscreen_ckb setState: NSOffState];
485 [o_intf_nativefullscreen_ckb setEnabled: NO];
488 [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
490 [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
492 [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
493 if( [[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL )
494 [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
496 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
497 psz_tmp = config_GetPsz( p_intf, "control" );
499 [o_intf_enableGrowl_ckb setState: (NSInteger)strstr( psz_tmp, "growl")];
503 [o_intf_enableGrowl_ckb setState: NSOffState];
504 if (config_GetInt( p_intf, "macosx-interfacestyle" ))
506 [o_intf_style_dark_bcell setState: YES];
507 [o_intf_style_bright_bcell setState: NO];
511 [o_intf_style_dark_bcell setState: NO];
512 [o_intf_style_bright_bcell setState: YES];
514 [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
515 [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
520 [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
522 if ( config_GetInt( p_intf, "macosx-autosave-volume" ))
524 [o_audio_autosavevol_yes_bcell setState: NSOnState];
525 [o_audio_autosavevol_no_bcell setState: NSOffState];
526 [o_audio_vol_fld setEnabled: NO];
527 [o_audio_vol_sld setEnabled: NO];
529 [o_audio_vol_sld setIntValue: 100];
530 [o_audio_vol_fld setIntValue: 100];
534 [o_audio_autosavevol_yes_bcell setState: NSOffState];
535 [o_audio_autosavevol_no_bcell setState: NSOnState];
536 [o_audio_vol_fld setEnabled: YES];
537 [o_audio_vol_sld setEnabled: YES];
539 i = config_GetInt( p_intf, "volume" );
540 i = i * 200 / AOUT_VOLUME_MAX;
541 [o_audio_vol_sld setIntValue: i];
542 [o_audio_vol_fld setIntValue: i];
545 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
547 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
548 [self setupField: o_audio_lang_fld forOption: "audio-language"];
550 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
552 /* Last.FM is optional */
553 if( module_exists( "audioscrobbler" ) )
555 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
556 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
558 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
560 [o_audio_last_ckb setState: NSOnState];
561 [o_audio_lastuser_fld setEnabled: YES];
562 [o_audio_lastpwd_sfld setEnabled: YES];
566 [o_audio_last_ckb setState: NSOffState];
567 [o_audio_lastuser_fld setEnabled: NO];
568 [o_audio_lastpwd_sfld setEnabled: NO];
572 [o_audio_last_ckb setEnabled: NO];
577 [self setupButton: o_video_enable_ckb forBoolValue: "video"];
578 [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
579 [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
580 [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
581 [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
583 [self setupButton: o_video_output_pop forModuleList: "vout"];
585 [o_video_device_pop removeAllItems];
587 y = [[NSScreen screens] count];
588 [o_video_device_pop addItemWithTitle: _NS("Default")];
589 [[o_video_device_pop lastItem] setTag: 0];
592 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
593 [o_video_device_pop addItemWithTitle:
594 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
595 (int)s_rect.size.width, (int)s_rect.size.height]];
596 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
599 [o_video_device_pop selectItemAtIndex: 0];
600 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
602 [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
603 [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
604 [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
605 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
606 [self setupButton: o_video_deinterlace_pop forIntList: "deinterlace"];
607 [self setupButton: o_video_deinterlace_mode_pop forStringList: "deinterlace-mode"];
609 /***************************
610 * input & codecs settings *
611 ***************************/
612 [self setupField: o_input_record_fld forOption:"input-record-path"];
613 [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
614 [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
615 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "postproc-q")];
616 [o_input_postproc_fld setToolTip: _NS(config_GetLabel( p_intf, "postproc-q"))];
618 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
620 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
621 [self setupButton: o_input_skipLoop_pop forIntList: "ffmpeg-skiploopfilter"];
623 [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
625 [o_input_cachelevel_pop removeAllItems];
626 [o_input_cachelevel_pop addItemsWithTitles:
627 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
628 _NS("High latency"), _NS("Higher latency"), nil]];
629 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
630 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
631 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
632 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
633 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
634 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
636 #define TestCaC( name, factor ) \
637 b_cache_equal = b_cache_equal && \
638 ( i_cache * factor == config_GetInt( p_intf, name ) );
640 /* Select the accurate value of the PopupButton */
641 bool b_cache_equal = true;
642 int i_cache = config_GetInt( p_intf, "file-caching");
644 TestCaC( "network-caching", 10/3 );
645 TestCaC( "disc-caching", 1 );
646 TestCaC( "live-caching", 1 );
649 [o_input_cachelevel_pop selectItemWithTag: i_cache];
650 [o_input_cachelevel_custom_txt setHidden: YES];
654 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
655 [o_input_cachelevel_custom_txt setHidden: NO];
659 /*********************
660 * subtitle settings *
661 *********************/
662 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
664 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
665 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
667 [self setupField: o_osd_font_fld forOption: "freetype-font"];
668 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
669 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
670 i = config_GetInt( p_intf, "freetype-opacity" );
671 [o_osd_opacity_fld setIntValue: i];
672 [o_osd_opacity_sld setIntValue: i];
673 [o_osd_opacity_sld setToolTip: _NS(config_GetLabel( p_intf, "freetype-opacity"))];
674 [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
675 [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
676 [self setupButton: o_osd_outline_color_pop forIntList: "freetype-outline-color"];
677 [self setupButton: o_osd_outline_thickness_pop forIntList: "freetype-outline-thickness"];
679 /********************
681 ********************/
682 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
683 [o_hotkeySettings release];
684 o_hotkeySettings = [[NSMutableArray alloc] init];
685 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
686 NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
688 /* Get the main Module */
689 module_t *p_main = module_get_main();
692 module_config_t *p_config;
694 p_config = module_config_get (p_main, &confsize);
696 for (size_t i = 0; i < confsize; i++)
698 module_config_t *p_item = p_config + i;
700 if( CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
701 && !strncmp( p_item->psz_name , "key-", 4 )
702 && !EMPTY_STR( p_item->psz_text ) )
704 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
705 [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
706 if (p_item->value.psz)
707 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
709 [o_hotkeySettings addObject: [NSString string]];
712 module_config_free (p_config);
714 [o_hotkeyDescriptions release];
715 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
716 [o_tempArray_desc release];
717 [o_hotkeyNames release];
718 o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
719 [o_tempArray_names release];
720 [o_hotkeys_listbox reloadData];
724 #pragma mark General actions
726 - (void)showSimplePrefs
728 /* we want to show the interface settings, if no category was chosen */
729 if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
731 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
732 [self showInterfaceSettings];
735 [self resetControls];
737 [o_sprefs_win center];
738 [o_sprefs_win makeKeyAndOrderFront: self];
741 - (IBAction)buttonAction:(id)sender
743 if( sender == o_sprefs_cancel_btn )
744 [o_sprefs_win orderOut: sender];
745 else if( sender == o_sprefs_save_btn )
747 [self saveChangedSettings];
748 [o_sprefs_win orderOut: sender];
750 else if( sender == o_sprefs_reset_btn )
751 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
752 _NS("Continue"), nil, o_sprefs_win, self,
753 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
754 _NS("Beware this will reset the VLC media player preferences.\n"
755 "Are you sure you want to continue?") );
756 else if( sender == o_sprefs_showAll_btn )
758 [o_sprefs_win orderOut: self];
759 [[[VLCMain sharedInstance] preferences] showPrefs];
762 msg_Warn( p_intf, "unknown buttonAction sender" );
765 - (void)sheetDidEnd:(NSWindow *)o_sheet
766 returnCode:(int)i_return
767 contextInfo:(void *)o_context
769 if( i_return == NSAlertAlternateReturn )
771 config_ResetAll( p_intf );
772 [self resetControls];
773 config_SaveConfigFile( p_intf );
777 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
779 NSNumber *p_valueobject;
780 module_config_t *p_item;
781 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
782 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
783 assert([p_valueobject isKindOfClass:[NSNumber class]]);
784 if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
787 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
789 NSString *p_stringobject;
790 module_config_t *p_item;
791 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
792 p_stringobject = (NSString *)[[object selectedItem] representedObject];
793 assert([p_stringobject isKindOfClass:[NSString class]]);
796 config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
800 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
802 module_config_t *p_item;
803 module_t *p_parser, **p_list;
805 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
807 p_list = module_list_get( NULL );
808 for( size_t i_module_index = 0; p_list[i_module_index]; i_module_index++ )
810 p_parser = p_list[i_module_index];
812 if( p_item->i_type == CONFIG_ITEM_MODULE && module_provides( p_parser, p_item->psz_type ) )
814 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
816 config_PutPsz( p_intf, name, strdup( module_get_object( p_parser )));
821 module_list_free( p_list );
822 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
823 config_PutPsz( p_intf, name, "" );
826 - (void)saveChangedSettings
831 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
833 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
835 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
837 #define getString( name ) [NSString stringWithFormat:@"%s", config_GetPsz( p_intf, name )]
839 /**********************
840 * interface settings *
841 **********************/
842 if( b_intfSettingChanged )
844 SaveStringList( o_intf_lang_pop, "language" );
845 SaveIntList( o_intf_art_pop, "album-art" );
847 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
848 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
850 config_PutInt( p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state] );
851 config_PutInt( p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state] );
852 config_PutInt( p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state] );
853 config_PutInt( p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state] );
854 config_PutInt( p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state] );
855 config_PutInt( p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state] );
856 if( [o_intf_enableGrowl_ckb state] == NSOnState )
858 tmpString = getString( "control" );
859 tmpRange = [tmpString rangeOfString:@"growl"];
860 if( [tmpString length] > 0 && tmpRange.location == NSNotFound )
862 tmpString = [tmpString stringByAppendingString: @":growl"];
863 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
866 config_PutPsz( p_intf, "control", "growl" );
870 tmpString = getString( "control" );
871 if(! [tmpString isEqualToString:@""] )
873 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
874 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
875 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
876 config_PutPsz( p_intf, "control", [tmpString UTF8String] );
880 /* activate stuff without restart */
881 if( [o_intf_appleremote_ckb state] == YES )
882 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
884 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
885 b_intfSettingChanged = NO;
891 if( b_audioSettingChanged )
893 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
894 if( [o_audio_vol_fld isEnabled] )
895 config_PutInt( p_intf, "volume", [o_audio_vol_fld intValue] * AOUT_VOLUME_MAX / 200 );
896 config_PutInt( p_intf, "macosx-autosave-volume", [o_audio_autosavevol_yes_bcell state] );
897 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
899 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
901 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
903 SaveModuleList( o_audio_visual_pop, "audio-visual" );
905 /* Last.FM is optional */
906 if( module_exists( "audioscrobbler" ) )
908 [o_audio_last_ckb setEnabled: YES];
909 if( [o_audio_last_ckb state] == NSOnState )
910 config_AddIntf( p_intf, "audioscrobbler" );
912 config_RemoveIntf( p_intf, "audioscrobbler" );
914 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
915 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
918 [o_audio_last_ckb setEnabled: NO];
919 b_audioSettingChanged = NO;
925 if( b_videoSettingChanged )
927 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
928 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
929 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
930 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
931 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
933 SaveModuleList( o_video_output_pop, "vout" );
934 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
936 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
937 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
938 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
939 SaveStringList( o_video_snap_format_pop, "snapshot-format" );
940 SaveIntList( o_video_deinterlace_pop, "deinterlace" );
941 SaveStringList( o_video_deinterlace_mode_pop, "deinterlace-mode" );
942 b_videoSettingChanged = NO;
945 /***************************
946 * input & codecs settings *
947 ***************************/
948 if( b_inputSettingChanged )
950 config_PutPsz( p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String] );
951 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
952 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
953 config_PutInt( p_intf, "postproc-q", [o_input_postproc_fld intValue] );
955 SaveIntList( o_input_avi_pop, "avi-index" );
957 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
958 SaveIntList( o_input_skipLoop_pop, "ffmpeg-skiploopfilter" );
960 config_PutInt( p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state] );
962 #define CaC( name, factor ) config_PutInt( p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor )
963 if ( [[o_input_cachelevel_pop selectedItem] tag] == 0 )
965 msg_Dbg( p_intf, "Custom chosen, not adjusting cache values" );
969 msg_Dbg( p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag] );
970 CaC( "file-caching", 1 );
971 CaC( "network-caching", 10/3 );
972 CaC( "disc-caching", 1 );
973 CaC( "live-caching", 1 );
976 b_inputSettingChanged = NO;
979 /**********************
980 * subtitles settings *
981 **********************/
982 if( b_osdSettingChanged )
984 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
986 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
987 SaveStringList( o_osd_encoding_pop, "subsdec-encoding" );
989 config_PutPsz( p_intf, "subsdec-encoding", "" );
991 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
993 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
994 SaveIntList( o_osd_font_color_pop, "freetype-color" );
995 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
996 config_PutInt( p_intf, "freetype-opacity", [o_osd_opacity_sld intValue] );
997 config_PutInt( p_intf, "freetype-bold", [o_osd_forcebold_ckb state] );
998 SaveIntList( o_osd_outline_color_pop, "freetype-outline-color" );
999 SaveIntList( o_osd_outline_thickness_pop, "freetype-outline-thickness" );
1000 b_osdSettingChanged = NO;
1003 /********************
1004 * hotkeys settings *
1005 ********************/
1006 if( b_hotkeyChanged )
1008 NSUInteger hotKeyCount = [o_hotkeySettings count];
1009 for( NSUInteger i = 0; i < hotKeyCount; i++ )
1010 config_PutPsz( p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String] );
1011 b_hotkeyChanged = NO;
1014 /* okay, let's save our changes to vlcrc */
1015 config_SaveConfigFile( p_intf );
1017 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1022 - (void)showSettingsForCategory: (id)o_new_category_view
1024 NSRect o_win_rect, o_view_rect, o_old_view_rect;
1025 o_win_rect = [o_sprefs_win frame];
1026 o_view_rect = [o_new_category_view frame];
1028 if( o_currentlyShownCategoryView != nil )
1030 /* restore our window's height, if we've shown another category previously */
1031 o_old_view_rect = [o_currentlyShownCategoryView frame];
1032 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
1033 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
1036 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
1038 [o_new_category_view setFrame: NSMakeRect( 0,
1039 [o_sprefs_controls_box frame].size.height,
1040 o_view_rect.size.width,
1041 o_view_rect.size.height )];
1042 [o_new_category_view setAutoresizesSubviews: YES];
1043 if (o_currentlyShownCategoryView)
1045 [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
1046 [o_currentlyShownCategoryView release];
1047 [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
1051 [[o_sprefs_win contentView] addSubview: o_new_category_view];
1052 [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
1055 /* keep our current category for further reference */
1056 o_currentlyShownCategoryView = o_new_category_view;
1057 [o_currentlyShownCategoryView retain];
1061 #pragma mark Specific actions
1063 - (IBAction)interfaceSettingChanged:(id)sender
1065 if( sender == o_intf_embedded_ckb && [o_intf_embedded_ckb state] == NSOffState )
1066 [o_intf_nativefullscreen_ckb setState: NSOffState];
1068 if( sender == o_intf_nativefullscreen_ckb && [o_intf_nativefullscreen_ckb state] == NSOnState )
1069 [o_intf_embedded_ckb setState: NSOnState];
1071 if( sender == o_intf_embedded_ckb )
1072 [[VLCCoreInteraction sharedInstance] stop];
1074 b_intfSettingChanged = YES;
1077 - (void)showInterfaceSettings
1079 [self showSettingsForCategory: o_intf_view];
1082 - (IBAction)audioSettingChanged:(id)sender
1084 if( sender == o_audio_vol_sld )
1085 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1087 if( sender == o_audio_vol_fld )
1088 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1090 if( sender == o_audio_last_ckb )
1092 if( [o_audio_last_ckb state] == NSOnState )
1094 [o_audio_lastpwd_sfld setEnabled: YES];
1095 [o_audio_lastuser_fld setEnabled: YES];
1099 [o_audio_lastpwd_sfld setEnabled: NO];
1100 [o_audio_lastuser_fld setEnabled: NO];
1104 if( sender == o_audio_autosavevol_matrix )
1106 BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1107 [o_audio_vol_fld setEnabled: enableVolumeSlider];
1108 [o_audio_vol_sld setEnabled: enableVolumeSlider];
1111 b_audioSettingChanged = YES;
1114 - (void)showAudioSettings
1116 [self showSettingsForCategory: o_audio_view];
1119 - (IBAction)videoSettingChanged:(id)sender
1121 if( sender == o_video_snap_folder_btn )
1123 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1124 [o_selectFolderPanel setCanChooseDirectories: YES];
1125 [o_selectFolderPanel setCanChooseFiles: NO];
1126 [o_selectFolderPanel setResolvesAliases: YES];
1127 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1128 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1129 [o_selectFolderPanel setCanCreateDirectories: YES];
1130 [o_selectFolderPanel setPrompt: _NS("Choose")];
1131 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1133 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1134 contextInfo: o_video_snap_folder_btn];
1137 b_videoSettingChanged = YES;
1140 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1142 if( returnCode == NSOKButton )
1144 if( contextInfo == o_video_snap_folder_btn )
1146 [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1147 b_videoSettingChanged = YES;
1149 else if( contextInfo == o_input_record_btn )
1151 [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1152 b_inputSettingChanged = YES;
1156 [o_selectFolderPanel release];
1159 - (void)showVideoSettings
1161 [self showSettingsForCategory: o_video_view];
1164 - (IBAction)osdSettingChanged:(id)sender
1166 if( sender == o_osd_opacity_fld )
1167 [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1169 if( sender == o_osd_opacity_sld )
1170 [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1172 b_osdSettingChanged = YES;
1175 - (void)showOSDSettings
1177 [self showSettingsForCategory: o_osd_view];
1180 - (void)controlTextDidChange:(NSNotification *)o_notification
1182 id notificationObject = [o_notification object];
1183 if( notificationObject == o_audio_lang_fld ||
1184 notificationObject == o_audio_lastpwd_sfld ||
1185 notificationObject == o_audio_lastuser_fld ||
1186 notificationObject == o_audio_vol_fld )
1187 b_audioSettingChanged = YES;
1188 else if( notificationObject == o_input_record_fld ||
1189 notificationObject == o_input_httpproxy_fld ||
1190 notificationObject == o_input_httpproxypwd_sfld ||
1191 notificationObject == o_input_postproc_fld )
1192 b_inputSettingChanged = YES;
1193 else if( notificationObject == o_osd_font_fld ||
1194 notificationObject == o_osd_lang_fld ||
1195 notificationObject == o_osd_opacity_fld)
1196 b_osdSettingChanged = YES;
1197 else if( notificationObject == o_video_snap_folder_fld ||
1198 notificationObject == o_video_snap_prefix_fld )
1199 b_videoSettingChanged = YES;
1202 - (IBAction)showFontPicker:(id)sender
1204 char * font = config_GetPsz( p_intf, "freetype-font" );
1205 NSString * fontFamilyName = font ? [NSString stringWithUTF8String: font] : nil;
1207 if( fontFamilyName )
1209 NSFontDescriptor * fd = [NSFontDescriptor fontDescriptorWithFontAttributes:nil];
1210 NSFont * font = [NSFont fontWithDescriptor:[fd fontDescriptorWithFamily:fontFamilyName] textTransform:nil];
1211 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1213 [[NSFontManager sharedFontManager] setTarget: self];
1214 [[NSFontPanel sharedFontPanel] orderFront:self];
1217 - (void)changeFont:(id)sender
1219 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1220 [o_osd_font_fld setStringValue:[font familyName]];
1221 [self osdSettingChanged:self];
1224 - (IBAction)inputSettingChanged:(id)sender
1226 if( sender == o_input_cachelevel_pop )
1228 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1229 [o_input_cachelevel_custom_txt setHidden: NO];
1231 [o_input_cachelevel_custom_txt setHidden: YES];
1233 else if( sender == o_input_record_btn )
1235 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1236 [o_selectFolderPanel setCanChooseDirectories: YES];
1237 [o_selectFolderPanel setCanChooseFiles: YES];
1238 [o_selectFolderPanel setResolvesAliases: YES];
1239 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1240 [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1241 [o_selectFolderPanel setCanCreateDirectories: YES];
1242 [o_selectFolderPanel setPrompt: _NS("Choose")];
1243 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1245 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1246 contextInfo: o_input_record_btn];
1250 b_inputSettingChanged = YES;
1253 - (void)showInputSettings
1255 [self showSettingsForCategory: o_input_view];
1259 #pragma mark Hotkey actions
1261 - (void)hotkeyTableDoubleClick:(id)object
1264 if( [o_hotkeys_listbox clickedRow] >= 0 )
1265 [self hotkeySettingChanged:o_hotkeys_listbox];
1268 - (IBAction)hotkeySettingChanged:(id)sender
1270 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1272 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1273 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1274 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1275 [o_hotkeys_change_taken_lbl setStringValue: @""];
1276 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1277 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1278 [NSApp runModalForWindow: o_hotkeys_change_win];
1280 else if( sender == o_hotkeys_change_cancel_btn )
1283 [o_hotkeys_change_win close];
1285 else if( sender == o_hotkeys_change_ok_btn )
1287 NSInteger i_returnValue;
1288 if(! o_keyInTransition )
1291 [o_hotkeys_change_win close];
1292 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1296 b_hotkeyChanged = YES;
1298 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1299 if( i_returnValue != NSNotFound )
1300 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1301 NSString *tempString;
1302 tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1303 i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1304 if( i_returnValue != NSNotFound )
1305 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1307 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1310 [o_hotkeys_change_win close];
1312 [o_hotkeys_listbox reloadData];
1314 else if( sender == o_hotkeys_clear_btn )
1316 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1317 [o_hotkeys_listbox reloadData];
1318 b_hotkeyChanged = YES;
1321 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1326 - (void)showHotkeySettings
1328 [self showSettingsForCategory: o_hotkeys_view];
1331 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1333 return [o_hotkeySettings count];
1336 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1338 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1339 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1340 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1341 return [self OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1344 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1349 - (BOOL)changeHotkeyTo: (NSString *)theKey
1351 NSInteger i_returnValue, i_returnValue2;
1352 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1354 if( i_returnValue != NSNotFound || [theKey isEqualToString:@""] )
1356 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1357 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1358 [o_hotkeys_change_ok_btn setEnabled: NO];
1363 [o_hotkeys_change_keys_lbl setStringValue: [self OSXStringKeyToString:theKey]];
1365 i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1366 i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1367 if( i_returnValue != NSNotFound )
1368 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1369 _NS("This combination is already taken by \"%@\"."),
1370 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1371 else if( i_returnValue2 != NSNotFound )
1372 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1373 _NS("This combination is already taken by \"%@\"."),
1374 [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1376 [o_hotkeys_change_taken_lbl setStringValue: @""];
1378 [o_hotkeys_change_ok_btn setEnabled: YES];
1379 [o_keyInTransition release];
1380 o_keyInTransition = theKey;
1381 [o_keyInTransition retain];
1388 /********************
1389 * hotkeys settings *
1390 ********************/
1392 @implementation VLCHotkeyChangeWindow
1394 - (BOOL)acceptsFirstResponder
1399 - (BOOL)becomeFirstResponder
1404 - (BOOL)resignFirstResponder
1406 /* We need to stay the first responder or we'll miss the user's input */
1410 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1412 NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1413 NSString *keyString = [o_theEvent characters];
1415 unichar key = [keyString characterAtIndex:0];
1418 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1419 [tempString appendString:@"Ctrl-"];
1420 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1421 [tempString appendString:@"Alt-"];
1422 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1423 [tempString appendString:@"Shift-"];
1424 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1425 [tempString appendString:@"Command-"];
1427 /* non character keys */
1428 if( key == NSUpArrowFunctionKey )
1429 [tempString appendString:@"Up"];
1430 else if( key == NSDownArrowFunctionKey )
1431 [tempString appendString:@"Down"];
1432 else if( key == NSLeftArrowFunctionKey )
1433 [tempString appendString:@"Left"];
1434 else if( key == NSRightArrowFunctionKey )
1435 [tempString appendString:@"Right"];
1436 else if( key == NSF1FunctionKey )
1437 [tempString appendString:@"F1"];
1438 else if( key == NSF2FunctionKey )
1439 [tempString appendString:@"F2"];
1440 else if( key == NSF3FunctionKey )
1441 [tempString appendString:@"F3"];
1442 else if( key == NSF4FunctionKey )
1443 [tempString appendString:@"F4"];
1444 else if( key == NSF5FunctionKey )
1445 [tempString appendString:@"F5"];
1446 else if( key == NSF6FunctionKey )
1447 [tempString appendString:@"F6"];
1448 else if( key == NSF7FunctionKey )
1449 [tempString appendString:@"F7"];
1450 else if( key == NSF8FunctionKey )
1451 [tempString appendString:@"F8"];
1452 else if( key == NSF9FunctionKey )
1453 [tempString appendString:@"F9"];
1454 else if( key == NSF10FunctionKey )
1455 [tempString appendString:@"F10"];
1456 else if( key == NSF11FunctionKey )
1457 [tempString appendString:@"F11"];
1458 else if( key == NSF12FunctionKey )
1459 [tempString appendString:@"F12"];
1460 else if( key == NSInsertFunctionKey )
1461 [tempString appendString:@"Insert"];
1462 else if( key == NSHomeFunctionKey )
1463 [tempString appendString:@"Home"];
1464 else if( key == NSEndFunctionKey )
1465 [tempString appendString:@"End"];
1466 else if( key == NSPageUpFunctionKey )
1467 [tempString appendString:@"Pageup"];
1468 else if( key == NSPageDownFunctionKey )
1469 [tempString appendString:@"Pagedown"];
1470 else if( key == NSMenuFunctionKey )
1471 [tempString appendString:@"Menu"];
1472 else if( key == NSTabCharacter )
1473 [tempString appendString:@"Tab"];
1474 else if( key == NSCarriageReturnCharacter )
1475 [tempString appendString:@"Enter"];
1476 else if( key == NSEnterCharacter )
1477 [tempString appendString:@"Enter"];
1478 else if( key == NSDeleteCharacter )
1479 [tempString appendString:@"Delete"];
1480 else if( key == NSBackspaceCharacter )
1481 [tempString appendString:@"Backspace"];
1482 else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1483 [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1487 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1492 @implementation VLCSimplePrefsWindow
1494 - (BOOL)acceptsFirstResponder
1499 - (void)changeFont:(id)sender
1501 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];