1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #import "simple_prefs.h"
28 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
29 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
30 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
31 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
32 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
33 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
34 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
36 @implementation VLCSimplePrefs
38 static VLCSimplePrefs *_o_sharedInstance = nil;
40 + (VLCSimplePrefs *)sharedInstance
42 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
47 if (_o_sharedInstance) {
51 _o_sharedInstance = [super init];
54 return _o_sharedInstance;
59 [o_currentlyShownCategoryView release];
60 [o_sprefs_toolbar release];
62 [o_hotkeySettings release];
63 [o_hotkeyDescriptions release];
64 [o_hotkeysNonUseableKeys release];
66 if( o_keyInTransition )
67 [o_keyInTransition release];
73 - (NSString *)OSXKeyToString:(int)val
75 NSMutableString *o_temp_str = [[[NSMutableString alloc] init] autorelease];
76 if( val & KEY_MODIFIER_CTRL )
77 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
78 if( val & KEY_MODIFIER_ALT )
79 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
80 if( val & KEY_MODIFIER_SHIFT )
81 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
82 if( val & KEY_MODIFIER_COMMAND )
83 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
85 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
86 for( unsigned int i = 0; i< i_keys; i++ )
88 if( vlc_keys[i].i_key_code == (val& ~KEY_MODIFIER) )
90 if( vlc_keys[i].psz_key_string )
91 [o_temp_str appendString: [NSString stringWithUTF8String: vlc_keys[i].psz_key_string]];
93 o_temp_str = @"Unset";
103 /* setup the toolbar */
104 o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
105 [o_sprefs_toolbar setAllowsUserCustomization: NO];
106 [o_sprefs_toolbar setAutosavesConfiguration: NO];
107 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
108 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
109 [o_sprefs_toolbar setDelegate: self];
110 [o_sprefs_win setToolbar: o_sprefs_toolbar];
112 /* setup useful stuff */
113 /* TODO: hard-code this instead of one-the-run generation */
114 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
115 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
116 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
117 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
118 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
119 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
120 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
121 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
122 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
123 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
124 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
125 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
126 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
127 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
128 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
129 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
130 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'q'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
140 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
141 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
142 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
143 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
144 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
145 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
146 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
147 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
151 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
152 itemForItemIdentifier: (NSString *)o_itemIdent
153 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
155 NSToolbarItem *o_toolbarItem = nil;
157 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
158 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
160 [o_toolbarItem setLabel: o_name]; \
161 [o_toolbarItem setPaletteLabel: o_desc]; \
163 [o_toolbarItem setToolTip: o_desc]; \
164 [o_toolbarItem setImage: [NSImage imageNamed: o_img]]; \
166 [o_toolbarItem setTarget: self]; \
167 [o_toolbarItem setAction: @selector( sel )]; \
169 [o_toolbarItem setEnabled: YES]; \
170 [o_toolbarItem setAutovalidates: YES]
172 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
174 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
176 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
178 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
180 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
182 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
184 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
186 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & OSD Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
188 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
190 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
192 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
194 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
197 return o_toolbarItem;
200 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
202 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
203 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
206 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
208 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
209 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
212 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
214 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
215 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
221 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
222 [o_audio_effects_box setTitle: _NS("Effects")];
223 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
224 [o_audio_general_box setTitle: _NS("General Audio")];
225 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
226 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
227 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
228 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
229 [o_audio_lastuser_txt setStringValue: _NS("User name")];
230 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
231 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
232 [o_audio_visual_txt setStringValue: _NS("Visualization")];
233 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
236 [o_hotkeys_change_btn setTitle: _NS("Change")];
237 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
238 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
239 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
240 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
241 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
242 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
243 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
246 [o_input_access_box setTitle: _NS("Access Filter")];
247 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
248 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
249 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
250 [o_input_caching_box setTitle: _NS("Caching")];
251 [o_input_dump_ckb setTitle: _NS("Dump")];
252 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
253 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
254 [o_input_net_box setTitle: _NS("Network")];
255 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
256 [o_input_record_ckb setTitle: _NS("Record")];
257 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
258 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
259 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
262 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
263 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
264 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
265 [o_intf_lang_txt setStringValue: _NS("Language")];
266 [o_intf_meta_ckb setTitle: _NS("Fetch the metadata from the Internet")];
267 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
269 /* Subtitles and OSD */
270 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
271 [o_osd_font_box setTitle: _NS("Display Settings")];
272 [o_osd_font_btn setTitle: _NS("Browse...")];
273 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
274 [o_osd_font_effect_txt setStringValue: _NS("Effect")];
275 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
276 [o_osd_font_txt setStringValue: _NS("Font")];
277 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
278 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
279 [o_osd_osd_box setTitle: _NS("On Screen Display")];
280 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
283 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
284 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
285 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
286 [o_sprefs_reset_btn setTitle: _NS("Reset Preferences")];
287 [o_sprefs_save_btn setTitle: _NS("Save")];
288 [o_sprefs_win setTitle: _NS("Preferences")];
291 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
292 [o_video_device_txt setStringValue: _NS("Display device")];
293 [o_video_display_box setTitle: _NS("Display")];
294 [o_video_enable_ckb setTitle: _NS("Enable Video")];
295 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
296 [o_video_onTop_ckb setTitle: _NS("Always on top")];
297 [o_video_output_txt setStringValue: _NS("Output module")];
298 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
299 [o_video_snap_box setTitle: _NS("Video snapshots")];
300 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
301 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
302 [o_video_snap_format_txt setStringValue: _NS("Format")];
303 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
304 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
307 - (void)resetControls
309 module_config_t *p_item;
315 #define SetupIntList( object, name ) \
316 [object removeAllItems]; \
317 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
318 for( i = 0; i < p_item->i_list; i++ ) \
320 if( p_item->ppsz_list_text[i] != NULL) \
321 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
323 [object addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]]; \
325 if( p_item->value.i < [object numberOfItems] ) \
326 [object selectItemAtIndex: p_item->value.i]; \
328 [object selectItemAtIndex: 0]; \
329 [object setToolTip: _NS( p_item->psz_longtext )]
331 #define SetupStringList( object, name ) \
332 [object removeAllItems]; \
334 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
335 for( i = 0; p_item->ppsz_list[i] != nil; i++ ) \
337 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
338 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) ) \
341 [object selectItemAtIndex: y]; \
342 [object setToolTip: _NS( p_item->psz_longtext )]
344 #define SetupModuleList( object, name ) \
345 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
346 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
347 [object removeAllItems]; \
348 [object addItemWithTitle: _NS("Default")]; \
349 for( int i_index = 0; i_index < p_list->i_count; i_index++ ) \
351 p_parser = (module_t *)p_list->p_values[i_index].p_object ; \
353 if( module_IsCapable( p_parser, p_item->psz_type ) ) \
355 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser )]]; \
357 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) ) \
358 [object selectItem: [object lastItem]]; \
361 vlc_list_release( p_list ); \
362 [object setToolTip: _NS(p_item->psz_longtext)]
364 /**********************
365 * interface settings *
366 **********************/
367 SetupStringList( o_intf_lang_pop, "language" );
368 SetupIntList( o_intf_art_pop, "album-art" );
370 [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
371 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
372 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
377 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
378 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
379 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
381 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
383 SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
385 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
387 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
389 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
391 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
392 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
394 SetupModuleList( o_audio_visual_pop, "audio-visual" );
396 /* Last.FM is optional */
397 if( module_Exists( p_intf, "audioscrobbler" ) )
399 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
400 [o_audio_lastpwd_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
402 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
403 [o_audio_last_ckb setState: NSOnState];
405 [o_audio_last_ckb setState: NSOffState];
411 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
412 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
413 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
414 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
415 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
417 SetupModuleList( o_video_output_pop, "vout" );
419 msg_Warn( p_intf, "display device selector not implemented!" );
420 [o_video_device_pop removeAllItems];
422 if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
423 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
424 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
425 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
427 p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
428 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
430 [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
431 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
434 [o_video_snap_format_pop selectItemAtIndex: y];
436 /***************************
437 * input & codecs settings *
438 ***************************/
439 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
440 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
441 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
442 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
444 SetupIntList( o_input_avi_pop, "avi-index" );
446 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
448 psz_tmp = config_GetPsz( p_intf, "access-filter" );
451 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
452 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
453 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
454 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
457 [o_input_cachelevel_pop removeAllItems];
458 [o_input_cachelevel_pop addItemsWithTitles:
459 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
460 _NS("High latency"), _NS("Higher latency"), nil]];
461 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
462 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
463 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
464 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
465 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
466 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
468 #define TestCaC( name ) \
469 b_cache_equal = b_cache_equal && \
470 ( i_cache == config_GetInt( p_intf, name ) )
472 #define TestCaCi( name, int ) \
473 b_cache_equal = b_cache_equal && \
474 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
476 /* Select the accurate value of the PopupButton */
477 bool b_cache_equal = true;
478 int i_cache = config_GetInt( p_intf, "file-caching");
480 TestCaC( "udp-caching" );
481 if( module_Exists (p_intf, "dvdread") )
482 TestCaC( "dvdread-caching" );
483 if( module_Exists (p_intf, "dvdnav") )
484 TestCaC( "dvdnav-caching" );
485 TestCaC( "tcp-caching" );
486 TestCaC( "fake-caching" );
487 TestCaC( "cdda-caching" );
488 TestCaC( "screen-caching" );
489 TestCaC( "vcd-caching" );
490 TestCaCi( "rtsp-caching", 4 );
491 TestCaCi( "ftp-caching", 2 );
492 TestCaCi( "http-caching", 4 );
493 if(module_Exists (p_intf, "access_realrtsp"))
494 TestCaCi( "realrtsp-caching", 10 );
495 TestCaCi( "mms-caching", 19 );
497 [o_input_cachelevel_pop selectItemWithTag: i_cache];
499 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
501 /*********************
502 * subtitle settings *
503 *********************/
504 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
506 [o_osd_encoding_pop removeAllItems];
508 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
509 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
511 if( p_item->ppsz_list[i] != "" )
512 [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
514 [o_osd_encoding_pop addItemWithTitle: @" "];
516 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
519 [o_osd_encoding_pop selectItemAtIndex: y];
521 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
522 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
523 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
525 SetupIntList( o_osd_font_color_pop, "freetype-color" );
526 SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
527 SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
529 /********************
531 ********************/
532 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
533 o_hotkeySettings = [[NSMutableArray alloc] init];
534 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
539 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
543 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
544 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
548 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
549 [o_tempArray_desc release];
550 [o_hotkeys_listbox reloadData];
553 - (void)showSimplePrefs
555 /* we want to show the interface settings, if no category was chosen */
556 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
558 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
559 [self showInterfaceSettings];
562 [self resetControls];
564 [o_sprefs_win makeKeyAndOrderFront: self];
567 - (IBAction)buttonAction:(id)sender
569 if( sender == o_sprefs_cancel_btn )
570 [o_sprefs_win orderOut: sender];
571 else if( sender == o_sprefs_save_btn )
573 [self saveChangedSettings];
574 [o_sprefs_win orderOut: sender];
576 else if( sender == o_sprefs_reset_btn )
577 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
578 _NS("Continue"), nil, o_sprefs_win, self,
579 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
580 _NS("Beware this will reset the VLC media player preferences.\n"
581 "Are you sure you want to continue?") );
582 else if( sender == o_sprefs_basicFull_matrix )
584 [o_sprefs_win orderOut: self];
585 [[[VLCMain sharedInstance] getPreferences] showPrefs];
586 [self resetControls];
589 msg_Err( p_intf, "unknown buttonAction sender" );
592 - (void)sheetDidEnd:(NSWindow *)o_sheet
593 returnCode:(int)i_return
594 contextInfo:(void *)o_context
596 if( i_return == NSAlertAlternateReturn )
598 config_ResetAll( p_intf );
599 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
600 [self resetControls];
604 - (void)saveChangedSettings
606 module_config_t *p_item;
612 #define SaveIntList( object, name ) \
613 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
614 if( [object indexOfSelectedItem] >= 0 ) \
615 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
617 config_PutInt( p_intf, name, [object intValue] ) \
619 #define SaveStringList( object, name ) \
620 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
621 if( [object indexOfSelectedItem] >= 0 ) \
622 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
624 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
626 #define SaveModuleList( object, name ) \
627 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
629 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
630 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
632 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
634 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
636 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
638 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
643 vlc_list_release( p_list ); \
644 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
645 config_PutPsz( p_intf, name, "Default" )
647 /**********************
648 * interface settings *
649 **********************/
650 if( b_intfSettingChanged )
652 SaveStringList( o_intf_lang_pop, "language" );
653 SaveIntList( o_intf_art_pop, "album-art" );
655 config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
656 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
657 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
659 /* okay, let's save our changes to vlcrc */
660 i = config_SaveConfigFile( p_intf, "main" );
661 i = config_SaveConfigFile( p_intf, "macosx" );
665 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
669 b_intfSettingChanged = NO;
675 if( b_audioSettingChanged )
677 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
678 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
679 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
681 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
683 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
684 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
686 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
688 config_PutPsz( p_intf, "audio-filter", "volnorm" );
689 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
691 /* work-around a GCC 4.0.1 bug */
692 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
693 config_PutPsz( p_intf, "audio-filter", psz_tmp );
697 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
698 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
699 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
700 config_PutPsz( p_intf, "audio-filter", psz_tmp );
702 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
704 SaveModuleList( o_audio_visual_pop, "audio-visual" );
706 /* Last.FM is optional */
707 if( module_Exists( p_intf, "audioscrobbler" ) )
709 if( [o_audio_last_ckb state] == NSOnState )
710 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
712 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
714 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
715 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
718 /* okay, let's save our changes to vlcrc */
719 i = config_SaveConfigFile( p_intf, "main" );
720 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
721 i = i + config_SaveConfigFile( p_intf, "volnorm" );
725 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
728 b_audioSettingChanged = NO;
734 if( b_videoSettingChanged )
736 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
737 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
738 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
739 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
740 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
742 SaveModuleList( o_video_output_pop, "vout" );
743 msg_Warn( p_intf, "display device selector not implemented!" );
745 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
746 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
747 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
749 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
750 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
752 i = config_SaveConfigFile( p_intf, "main" );
753 i = i + config_SaveConfigFile( p_intf, "macosx" );
757 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
760 b_videoSettingChanged = NO;
763 /***************************
764 * input & codecs settings *
765 ***************************/
766 if( b_inputSettingChanged )
768 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
769 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
770 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
772 SaveIntList( o_input_avi_pop, "avi-index" );
774 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
776 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
777 #define CaC( name ) CaCi( name, 1 )
778 msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
779 CaC( "udp-caching" );
780 if( module_Exists (p_intf, "dvdread" ) )
782 CaC( "dvdread-caching" );
783 i = i + config_SaveConfigFile( p_intf, "dvdread" );
785 if( module_Exists (p_intf, "dvdnav" ) )
787 CaC( "dvdnav-caching" );
788 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
790 CaC( "tcp-caching" ); CaC( "vcd-caching" );
791 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
792 CaC( "screen-caching" );
793 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
794 CaCi( "http-caching", 4 );
795 if( module_Exists (p_intf, "access_realrtsp" ) )
797 CaCi( "realrtsp-caching", 10 );
798 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
800 CaCi( "mms-caching", 19 );
802 #define SaveAccessFilter( object, name ) \
803 if( [object state] == NSOnState ) \
807 [o_temp appendString: name]; \
811 [o_temp appendFormat: @":%@", name]; \
815 NSMutableString *o_temp = [[NSMutableString alloc] init];
816 SaveAccessFilter( o_input_record_ckb, @"record" );
817 SaveAccessFilter( o_input_dump_ckb, @"dump" );
818 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
819 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
820 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
823 i = config_SaveConfigFile( p_intf, "main" );
824 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
825 i = i + config_SaveConfigFile( p_intf, "access_http" );
826 i = i + config_SaveConfigFile( p_intf, "access_file" );
827 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
828 i = i + config_SaveConfigFile( p_intf, "access_fake" );
829 i = i + config_SaveConfigFile( p_intf, "cdda" );
830 i = i + config_SaveConfigFile( p_intf, "screen" );
831 i = i + config_SaveConfigFile( p_intf, "vcd" );
832 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
833 i = i + config_SaveConfigFile( p_intf, "access_mms" );
834 i = i + config_SaveConfigFile( p_intf, "live555" );
838 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
841 b_inputSettingChanged = NO;
844 /**********************
845 * subtitles settings *
846 **********************/
847 if( b_osdSettingChanged )
849 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
851 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
852 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
854 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
855 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
857 SaveIntList( o_osd_font_color_pop, "freetype-color" );
858 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
859 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
861 i = config_SaveConfigFile( p_intf, NULL );
865 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
868 b_osdSettingChanged = NO;
871 /********************
873 ********************/
874 if( b_hotkeyChanged )
876 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
878 while( i < [o_hotkeySettings count] )
880 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
884 i = config_SaveConfigFile( p_intf, "main" );
888 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
891 b_hotkeyChanged = NO;
895 - (void)showSettingsForCategory: (id)o_new_category_view
897 NSRect o_win_rect, o_view_rect, o_old_view_rect;
898 o_win_rect = [o_sprefs_win frame];
899 o_view_rect = [o_new_category_view frame];
901 if( o_currentlyShownCategoryView != nil )
903 /* restore our window's height, if we've shown another category previously */
904 o_old_view_rect = [o_currentlyShownCategoryView frame];
905 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
907 /* remove our previous category view */
908 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
911 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
913 [o_sprefs_win displayIfNeeded];
914 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
916 [o_new_category_view setFrame: NSMakeRect( 0,
917 [o_sprefs_controls_box frame].size.height,
918 o_view_rect.size.width,
919 o_view_rect.size.height )];
920 [o_new_category_view setNeedsDisplay: YES];
921 [o_new_category_view setAutoresizesSubviews: YES];
922 [[o_sprefs_win contentView] addSubview: o_new_category_view];
924 /* keep our current category for further reference */
925 [o_currentlyShownCategoryView release];
926 o_currentlyShownCategoryView = o_new_category_view;
927 [o_currentlyShownCategoryView retain];
930 - (IBAction)interfaceSettingChanged:(id)sender
932 b_intfSettingChanged = YES;
935 - (void)showInterfaceSettings
937 msg_Dbg( p_intf, "showing interface settings" );
938 [self showSettingsForCategory: o_intf_view];
941 - (IBAction)audioSettingChanged:(id)sender
943 if( sender == o_audio_vol_sld )
944 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
946 if( sender == o_audio_vol_fld )
947 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
949 b_audioSettingChanged = YES;
952 - (void)showAudioSettings
954 msg_Dbg( p_intf, "showing audio settings" );
955 [self showSettingsForCategory: o_audio_view];
958 - (IBAction)videoSettingChanged:(id)sender
960 if( sender == o_video_snap_folder_btn )
962 o_selectFolderPanel = [[NSOpenPanel alloc] init];
963 [o_selectFolderPanel setCanChooseDirectories: YES];
964 [o_selectFolderPanel setCanChooseFiles: NO];
965 [o_selectFolderPanel setResolvesAliases: YES];
966 [o_selectFolderPanel setAllowsMultipleSelection: NO];
967 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
968 [o_selectFolderPanel setCanCreateDirectories: YES];
969 [o_selectFolderPanel setPrompt: _NS("Choose")];
970 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
972 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
973 contextInfo: o_video_snap_folder_btn];
976 b_videoSettingChanged = YES;
979 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
981 if( returnCode == NSOKButton )
983 if( contextInfo == o_video_snap_folder_btn )
985 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
986 b_videoSettingChanged = YES;
988 else if( contextInfo == o_osd_font_btn )
990 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
991 b_osdSettingChanged = YES;
995 [o_selectFolderPanel release];
998 - (void)showVideoSettings
1000 msg_Dbg( p_intf, "showing video settings" );
1001 [self showSettingsForCategory: o_video_view];
1004 - (IBAction)osdSettingChanged:(id)sender
1006 if( sender == o_osd_font_btn )
1008 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1009 [o_selectFolderPanel setCanChooseDirectories: NO];
1010 [o_selectFolderPanel setCanChooseFiles: YES];
1011 [o_selectFolderPanel setResolvesAliases: YES];
1012 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1013 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1014 [o_selectFolderPanel setCanCreateDirectories: NO];
1015 [o_selectFolderPanel setPrompt: _NS("Choose")];
1016 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1017 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1019 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1020 contextInfo: o_osd_font_btn];
1023 b_osdSettingChanged = YES;
1026 - (void)showOSDSettings
1028 msg_Dbg( p_intf, "showing OSD settings" );
1029 [self showSettingsForCategory: o_osd_view];
1032 - (IBAction)inputSettingChanged:(id)sender
1034 b_inputSettingChanged = YES;
1037 - (void)showInputSettings
1039 msg_Dbg( p_intf, "showing Input Settings" );
1040 [self showSettingsForCategory: o_input_view];
1043 - (IBAction)hotkeySettingChanged:(id)sender
1045 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1047 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1048 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1049 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1050 [o_hotkeys_change_taken_lbl setStringValue: @""];
1051 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1052 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1053 [NSApp runModalForWindow: o_hotkeys_change_win];
1055 else if( sender == o_hotkeys_change_cancel_btn )
1058 [o_hotkeys_change_win close];
1060 else if( sender == o_hotkeys_change_ok_btn )
1063 if(! o_keyInTransition )
1066 [o_hotkeys_change_win close];
1067 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1071 b_hotkeyChanged = YES;
1073 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1074 if( i_returnValue != NSNotFound )
1075 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1077 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1080 [o_hotkeys_change_win close];
1082 [o_hotkeys_listbox reloadData];
1084 else if( sender == o_hotkeys_clear_btn )
1086 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1087 [o_hotkeys_listbox reloadData];
1088 b_hotkeyChanged = YES;
1092 - (void)showHotkeySettings
1094 msg_Dbg( p_intf, "showing HotKey Settings" );
1095 [self showSettingsForCategory: o_hotkeys_view];
1098 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1100 return [o_hotkeySettings count];
1103 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1105 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1106 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1107 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1108 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1111 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1116 - (void)changeHotkeyTo: (int)i_theNewKey
1119 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1120 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1122 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1123 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1124 [o_hotkeys_change_ok_btn setEnabled: NO];
1129 if( o_keyInTransition )
1130 [o_keyInTransition release];
1131 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1133 o_temp = [self OSXKeyToString: i_theNewKey];
1135 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1137 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1138 if( i_returnValue != NSNotFound )
1139 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1140 _NS("This combination is already taken by \"%@\"."),
1141 [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1143 [o_hotkeys_change_taken_lbl setStringValue: @""];
1145 [o_hotkeys_change_ok_btn setEnabled: YES];
1151 /********************
1152 * hotkeys settings *
1153 ********************/
1155 @implementation VLCHotkeyChangeWindow
1157 - (BOOL)resignFirstResponder
1159 /* We need to stay the first responder or we'll miss the user's input */
1163 - (void)keyDown:(NSEvent *)o_theEvent
1165 int i_nonReadableKey = 0;
1167 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1168 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1170 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1171 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1173 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1174 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1176 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1177 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1179 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1182 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1187 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1189 case NSF1FunctionKey:
1190 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1192 case NSF2FunctionKey:
1193 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1195 case NSF3FunctionKey:
1196 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1198 case NSF4FunctionKey:
1199 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1201 case NSF5FunctionKey:
1202 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1204 case NSF6FunctionKey:
1205 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1207 case NSF7FunctionKey:
1208 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1210 case NSF8FunctionKey:
1211 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1213 case NSF9FunctionKey:
1214 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1216 case NSF10FunctionKey:
1217 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1219 case NSF11FunctionKey:
1220 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1222 case NSF12FunctionKey:
1223 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1225 case NSInsertFunctionKey:
1226 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1228 case NSHomeFunctionKey:
1229 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1231 case NSEndFunctionKey:
1232 i_nonReadableKey = i_nonReadableKey | KEY_END;
1234 case NSPageUpFunctionKey:
1235 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1237 case NSPageDownFunctionKey:
1238 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1240 case NSMenuFunctionKey:
1241 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1243 case NSTabCharacter:
1244 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1246 case NSDeleteCharacter:
1247 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1249 case NSBackspaceCharacter:
1250 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1252 case NSUpArrowFunctionKey:
1253 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1255 case NSDownArrowFunctionKey:
1256 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1258 case NSRightArrowFunctionKey:
1259 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1261 case NSLeftArrowFunctionKey:
1262 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1264 case NSEnterCharacter:
1265 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1269 msg_Warn( VLCIntf, "user pressed unknown function key" );
1270 i_nonReadableKey = 0;
1277 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1278 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1280 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1283 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];