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"
29 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
30 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
31 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
32 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
33 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
34 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
35 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
37 @implementation VLCSimplePrefs
39 static VLCSimplePrefs *_o_sharedInstance = nil;
41 + (VLCSimplePrefs *)sharedInstance
43 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
48 if (_o_sharedInstance) {
52 _o_sharedInstance = [super init];
55 return _o_sharedInstance;
60 [o_currentlyShownCategoryView release];
61 [o_sprefs_toolbar release];
63 [o_hotkeySettings release];
64 [o_hotkeyDescriptions release];
65 [o_hotkeysNonUseableKeys release];
67 if( o_keyInTransition )
68 [o_keyInTransition release];
74 - (NSString *)OSXKeyToString:(int)val
76 NSMutableString *o_temp_str = [[[NSMutableString alloc] init] autorelease];
77 if( val & KEY_MODIFIER_CTRL )
78 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
79 if( val & KEY_MODIFIER_ALT )
80 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
81 if( val & KEY_MODIFIER_SHIFT )
82 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
83 if( val & KEY_MODIFIER_COMMAND )
84 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
86 unsigned int i_keys = sizeof(vlc_keys)/sizeof(key_descriptor_t);
87 for( unsigned int i = 0; i< i_keys; i++ )
89 if( vlc_keys[i].i_key_code == (val& ~KEY_MODIFIER) )
91 if( vlc_keys[i].psz_key_string )
92 [o_temp_str appendString: [NSString stringWithUTF8String: vlc_keys[i].psz_key_string]];
94 o_temp_str = @"Unset";
104 /* setup the toolbar */
105 o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
106 [o_sprefs_toolbar setAllowsUserCustomization: NO];
107 [o_sprefs_toolbar setAutosavesConfiguration: NO];
108 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
109 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
110 [o_sprefs_toolbar setDelegate: self];
111 [o_sprefs_win setToolbar: o_sprefs_toolbar];
113 /* setup useful stuff */
114 /* TODO: hard-code this instead of one-the-run generation */
115 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
116 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
117 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
118 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
119 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
120 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
121 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
122 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
123 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
124 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
125 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
126 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
127 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
128 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
129 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
130 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'q'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
140 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
141 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
142 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
143 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
144 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
145 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
146 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
147 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
148 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
152 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
153 itemForItemIdentifier: (NSString *)o_itemIdent
154 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
156 NSToolbarItem *o_toolbarItem = nil;
158 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
159 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
161 [o_toolbarItem setLabel: o_name]; \
162 [o_toolbarItem setPaletteLabel: o_desc]; \
164 [o_toolbarItem setToolTip: o_desc]; \
165 [o_toolbarItem setImage: [NSImage imageNamed: o_img]]; \
167 [o_toolbarItem setTarget: self]; \
168 [o_toolbarItem setAction: @selector( sel )]; \
170 [o_toolbarItem setEnabled: YES]; \
171 [o_toolbarItem setAutovalidates: YES]
173 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
175 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
177 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
179 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
181 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
183 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
185 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
187 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & OSD Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
189 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
191 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
193 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
195 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
198 return o_toolbarItem;
201 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
203 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
204 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
207 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
209 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
210 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
213 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
215 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
216 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
222 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
223 [o_audio_effects_box setTitle: _NS("Effects")];
224 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
225 [o_audio_general_box setTitle: _NS("General Audio")];
226 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
227 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
228 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
229 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
230 [o_audio_lastuser_txt setStringValue: _NS("User name")];
231 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
232 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
233 [o_audio_visual_txt setStringValue: _NS("Visualization")];
234 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
237 [o_hotkeys_change_btn setTitle: _NS("Change")];
238 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
239 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
240 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
241 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
242 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
243 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
244 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
247 [o_input_access_box setTitle: _NS("Access Filter")];
248 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
249 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
250 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
251 [o_input_caching_box setTitle: _NS("Caching")];
252 [o_input_dump_ckb setTitle: _NS("Dump")];
253 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
254 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
255 [o_input_net_box setTitle: _NS("Network")];
256 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
257 [o_input_record_ckb setTitle: _NS("Record")];
258 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
259 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
260 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
263 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
264 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
265 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
266 [o_intf_lang_txt setStringValue: _NS("Language")];
267 [o_intf_meta_ckb setTitle: _NS("Fetch the metadata from the Internet")];
268 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
270 /* Subtitles and OSD */
271 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
272 [o_osd_font_box setTitle: _NS("Display Settings")];
273 [o_osd_font_btn setTitle: _NS("Browse...")];
274 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
275 [o_osd_font_effect_txt setStringValue: _NS("Effect")];
276 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
277 [o_osd_font_txt setStringValue: _NS("Font")];
278 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
279 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
280 [o_osd_osd_box setTitle: _NS("On Screen Display")];
281 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
284 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
285 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
286 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
287 [o_sprefs_reset_btn setTitle: _NS("Reset Preferences")];
288 [o_sprefs_save_btn setTitle: _NS("Save")];
289 [o_sprefs_win setTitle: _NS("Preferences")];
292 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
293 [o_video_device_txt setStringValue: _NS("Display device")];
294 [o_video_display_box setTitle: _NS("Display")];
295 [o_video_enable_ckb setTitle: _NS("Enable Video")];
296 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
297 [o_video_onTop_ckb setTitle: _NS("Always on top")];
298 [o_video_output_txt setStringValue: _NS("Output module")];
299 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
300 [o_video_snap_box setTitle: _NS("Video snapshots")];
301 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
302 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
303 [o_video_snap_format_txt setStringValue: _NS("Format")];
304 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
305 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
308 - (void)resetControls
310 module_config_t *p_item;
316 #define SetupIntList( object, name ) \
317 [object removeAllItems]; \
318 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
319 for( i = 0; i < p_item->i_list; i++ ) \
321 if( p_item->ppsz_list_text[i] != NULL) \
322 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
324 [object addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]]; \
326 if( p_item->value.i < [object numberOfItems] ) \
327 [object selectItemAtIndex: p_item->value.i]; \
329 [object selectItemAtIndex: 0]; \
330 [object setToolTip: _NS( p_item->psz_longtext )]
332 #define SetupStringList( object, name ) \
333 [object removeAllItems]; \
335 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
336 for( i = 0; p_item->ppsz_list[i] != nil; i++ ) \
338 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
339 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) ) \
342 [object selectItemAtIndex: y]; \
343 [object setToolTip: _NS( p_item->psz_longtext )]
345 #define SetupModuleList( object, name ) \
346 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
347 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
348 [object removeAllItems]; \
349 [object addItemWithTitle: _NS("Default")]; \
350 for( int i_index = 0; i_index < p_list->i_count; i_index++ ) \
352 p_parser = (module_t *)p_list->p_values[i_index].p_object ; \
354 if( module_IsCapable( p_parser, p_item->psz_type ) ) \
356 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser )]]; \
358 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) ) \
359 [object selectItem: [object lastItem]]; \
362 vlc_list_release( p_list ); \
363 [object setToolTip: _NS(p_item->psz_longtext)]
365 /**********************
366 * interface settings *
367 **********************/
368 SetupStringList( o_intf_lang_pop, "language" );
369 SetupIntList( o_intf_art_pop, "album-art" );
371 [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
372 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
373 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
378 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
379 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
380 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
382 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
384 SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
386 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
388 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
390 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
392 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
393 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
395 SetupModuleList( o_audio_visual_pop, "audio-visual" );
397 /* Last.FM is optional */
398 if( module_Exists( p_intf, "audioscrobbler" ) )
400 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
401 [o_audio_lastpwd_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
403 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
404 [o_audio_last_ckb setState: NSOnState];
406 [o_audio_last_ckb setState: NSOffState];
409 [o_audio_last_ckb setEnabled: NO];
414 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
415 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
416 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
417 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
418 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
420 SetupModuleList( o_video_output_pop, "vout" );
422 [o_video_device_pop removeAllItems];
424 y = [[NSScreen screens] count];
425 [o_video_device_pop addItemWithTitle: _NS("Default")];
426 [[o_video_device_pop lastItem] setTag: 0];
429 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
430 [o_video_device_pop addItemWithTitle:
431 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
432 (int)s_rect.size.width, (int)s_rect.size.height]];
433 [[o_video_device_pop lastItem] setTag: [[[NSScreen screens] objectAtIndex: i] displayID]];
436 [o_video_device_pop selectItemAtIndex: 0];
437 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
439 if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
440 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
441 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
442 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
444 p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
445 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
447 [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
448 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
451 [o_video_snap_format_pop selectItemAtIndex: y];
453 /***************************
454 * input & codecs settings *
455 ***************************/
456 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
457 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
458 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
459 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
461 SetupIntList( o_input_avi_pop, "avi-index" );
463 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
465 psz_tmp = config_GetPsz( p_intf, "access-filter" );
468 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
469 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
470 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
471 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
474 [o_input_cachelevel_pop removeAllItems];
475 [o_input_cachelevel_pop addItemsWithTitles:
476 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
477 _NS("High latency"), _NS("Higher latency"), nil]];
478 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
479 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
480 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
481 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
482 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
483 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
485 #define TestCaC( name ) \
486 b_cache_equal = b_cache_equal && \
487 ( i_cache == config_GetInt( p_intf, name ) )
489 #define TestCaCi( name, int ) \
490 b_cache_equal = b_cache_equal && \
491 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
493 /* Select the accurate value of the PopupButton */
494 bool b_cache_equal = true;
495 int i_cache = config_GetInt( p_intf, "file-caching");
497 TestCaC( "udp-caching" );
498 if( module_Exists (p_intf, "dvdread") )
499 TestCaC( "dvdread-caching" );
500 if( module_Exists (p_intf, "dvdnav") )
501 TestCaC( "dvdnav-caching" );
502 TestCaC( "tcp-caching" );
503 TestCaC( "fake-caching" );
504 TestCaC( "cdda-caching" );
505 TestCaC( "screen-caching" );
506 TestCaC( "vcd-caching" );
507 TestCaCi( "rtsp-caching", 4 );
508 TestCaCi( "ftp-caching", 2 );
509 TestCaCi( "http-caching", 4 );
510 if(module_Exists (p_intf, "access_realrtsp"))
511 TestCaCi( "realrtsp-caching", 10 );
512 TestCaCi( "mms-caching", 19 );
514 [o_input_cachelevel_pop selectItemWithTag: i_cache];
516 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
518 /*********************
519 * subtitle settings *
520 *********************/
521 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
523 [o_osd_encoding_pop removeAllItems];
525 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
526 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
528 if( p_item->ppsz_list[i] != "" )
529 [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
531 [o_osd_encoding_pop addItemWithTitle: @" "];
533 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
536 [o_osd_encoding_pop selectItemAtIndex: y];
538 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
539 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
540 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
542 SetupIntList( o_osd_font_color_pop, "freetype-color" );
543 SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
544 SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
546 /********************
548 ********************/
549 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
550 o_hotkeySettings = [[NSMutableArray alloc] init];
551 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
556 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
560 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
561 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
565 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
566 [o_tempArray_desc release];
567 [o_hotkeys_listbox reloadData];
570 - (void)showSimplePrefs
572 /* we want to show the interface settings, if no category was chosen */
573 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
575 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
576 [self showInterfaceSettings];
579 [self resetControls];
581 [o_sprefs_win center];
582 [o_sprefs_win makeKeyAndOrderFront: self];
585 - (IBAction)buttonAction:(id)sender
587 if( sender == o_sprefs_cancel_btn )
588 [o_sprefs_win orderOut: sender];
589 else if( sender == o_sprefs_save_btn )
591 [self saveChangedSettings];
592 [o_sprefs_win orderOut: sender];
594 else if( sender == o_sprefs_reset_btn )
595 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
596 _NS("Continue"), nil, o_sprefs_win, self,
597 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
598 _NS("Beware this will reset the VLC media player preferences.\n"
599 "Are you sure you want to continue?") );
600 else if( sender == o_sprefs_basicFull_matrix )
602 [o_sprefs_win orderOut: self];
603 [[[VLCMain sharedInstance] getPreferences] showPrefs];
604 [self resetControls];
607 msg_Err( p_intf, "unknown buttonAction sender" );
610 - (void)sheetDidEnd:(NSWindow *)o_sheet
611 returnCode:(int)i_return
612 contextInfo:(void *)o_context
614 if( i_return == NSAlertAlternateReturn )
616 config_ResetAll( p_intf );
617 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
618 [self resetControls];
622 - (void)saveChangedSettings
624 module_config_t *p_item;
630 #define SaveIntList( object, name ) \
631 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
632 if( [object indexOfSelectedItem] >= 0 ) \
633 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
635 config_PutInt( p_intf, name, [object intValue] ) \
637 #define SaveStringList( object, name ) \
638 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
639 if( [object indexOfSelectedItem] >= 0 ) \
640 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
642 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
644 #define SaveModuleList( object, name ) \
645 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
647 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
648 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
650 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
652 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
654 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
656 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
661 vlc_list_release( p_list ); \
662 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
663 config_PutPsz( p_intf, name, "" )
665 /**********************
666 * interface settings *
667 **********************/
668 if( b_intfSettingChanged )
670 SaveStringList( o_intf_lang_pop, "language" );
671 SaveIntList( o_intf_art_pop, "album-art" );
673 config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
674 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
675 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
677 /* okay, let's save our changes to vlcrc */
678 i = config_SaveConfigFile( p_intf, "main" );
679 i = config_SaveConfigFile( p_intf, "macosx" );
683 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
687 b_intfSettingChanged = NO;
693 if( b_audioSettingChanged )
695 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
696 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
697 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
699 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
701 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
702 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
704 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
706 config_PutPsz( p_intf, "audio-filter", "volnorm" );
707 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
709 /* work-around a GCC 4.0.1 bug */
710 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
711 config_PutPsz( p_intf, "audio-filter", psz_tmp );
715 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
716 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
717 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
718 config_PutPsz( p_intf, "audio-filter", psz_tmp );
720 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
722 SaveModuleList( o_audio_visual_pop, "audio-visual" );
724 /* Last.FM is optional */
725 if( module_Exists( p_intf, "audioscrobbler" ) )
727 if( [o_audio_last_ckb state] == NSOnState )
728 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
730 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
732 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
733 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
736 /* okay, let's save our changes to vlcrc */
737 i = config_SaveConfigFile( p_intf, "main" );
738 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
739 i = i + config_SaveConfigFile( p_intf, "volnorm" );
743 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
746 b_audioSettingChanged = NO;
752 if( b_videoSettingChanged )
754 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
755 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
756 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
757 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
758 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
760 SaveModuleList( o_video_output_pop, "vout" );
761 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
763 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
764 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
765 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
767 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
768 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
770 i = config_SaveConfigFile( p_intf, "main" );
771 i = i + config_SaveConfigFile( p_intf, "macosx" );
775 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
778 b_videoSettingChanged = NO;
781 /***************************
782 * input & codecs settings *
783 ***************************/
784 if( b_inputSettingChanged )
786 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
787 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
788 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
790 SaveIntList( o_input_avi_pop, "avi-index" );
792 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
794 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
795 #define CaC( name ) CaCi( name, 1 )
796 msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
797 CaC( "udp-caching" );
798 if( module_Exists (p_intf, "dvdread" ) )
800 CaC( "dvdread-caching" );
801 i = i + config_SaveConfigFile( p_intf, "dvdread" );
803 if( module_Exists (p_intf, "dvdnav" ) )
805 CaC( "dvdnav-caching" );
806 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
808 CaC( "tcp-caching" ); CaC( "vcd-caching" );
809 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
810 CaC( "screen-caching" );
811 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
812 CaCi( "http-caching", 4 );
813 if( module_Exists (p_intf, "access_realrtsp" ) )
815 CaCi( "realrtsp-caching", 10 );
816 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
818 CaCi( "mms-caching", 19 );
820 #define SaveAccessFilter( object, name ) \
821 if( [object state] == NSOnState ) \
825 [o_temp appendString: name]; \
829 [o_temp appendFormat: @":%@", name]; \
833 NSMutableString *o_temp = [[NSMutableString alloc] init];
834 SaveAccessFilter( o_input_record_ckb, @"record" );
835 SaveAccessFilter( o_input_dump_ckb, @"dump" );
836 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
837 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
838 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
841 i = config_SaveConfigFile( p_intf, "main" );
842 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
843 i = i + config_SaveConfigFile( p_intf, "access_http" );
844 i = i + config_SaveConfigFile( p_intf, "access_file" );
845 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
846 i = i + config_SaveConfigFile( p_intf, "access_fake" );
847 i = i + config_SaveConfigFile( p_intf, "cdda" );
848 i = i + config_SaveConfigFile( p_intf, "screen" );
849 i = i + config_SaveConfigFile( p_intf, "vcd" );
850 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
851 i = i + config_SaveConfigFile( p_intf, "access_mms" );
852 i = i + config_SaveConfigFile( p_intf, "live555" );
856 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
859 b_inputSettingChanged = NO;
862 /**********************
863 * subtitles settings *
864 **********************/
865 if( b_osdSettingChanged )
867 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
869 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
870 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
872 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
873 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
875 SaveIntList( o_osd_font_color_pop, "freetype-color" );
876 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
877 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
879 i = config_SaveConfigFile( p_intf, NULL );
883 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
886 b_osdSettingChanged = NO;
889 /********************
891 ********************/
892 if( b_hotkeyChanged )
894 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
896 while( i < [o_hotkeySettings count] )
898 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
902 i = config_SaveConfigFile( p_intf, "main" );
906 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
909 b_hotkeyChanged = NO;
913 - (void)showSettingsForCategory: (id)o_new_category_view
915 NSRect o_win_rect, o_view_rect, o_old_view_rect;
916 o_win_rect = [o_sprefs_win frame];
917 o_view_rect = [o_new_category_view frame];
919 if( o_currentlyShownCategoryView != nil )
921 /* restore our window's height, if we've shown another category previously */
922 o_old_view_rect = [o_currentlyShownCategoryView frame];
923 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
924 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
926 /* remove our previous category view */
927 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
930 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
932 [o_sprefs_win displayIfNeeded];
933 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
935 [o_new_category_view setFrame: NSMakeRect( 0,
936 [o_sprefs_controls_box frame].size.height,
937 o_view_rect.size.width,
938 o_view_rect.size.height )];
939 [o_new_category_view setNeedsDisplay: YES];
940 [o_new_category_view setAutoresizesSubviews: YES];
941 [[o_sprefs_win contentView] addSubview: o_new_category_view];
943 /* keep our current category for further reference */
944 [o_currentlyShownCategoryView release];
945 o_currentlyShownCategoryView = o_new_category_view;
946 [o_currentlyShownCategoryView retain];
949 - (IBAction)interfaceSettingChanged:(id)sender
951 b_intfSettingChanged = YES;
954 - (void)showInterfaceSettings
956 msg_Dbg( p_intf, "showing interface settings" );
957 [self showSettingsForCategory: o_intf_view];
960 - (IBAction)audioSettingChanged:(id)sender
962 if( sender == o_audio_vol_sld )
963 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
965 if( sender == o_audio_vol_fld )
966 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
968 b_audioSettingChanged = YES;
971 - (void)showAudioSettings
973 msg_Dbg( p_intf, "showing audio settings" );
974 [self showSettingsForCategory: o_audio_view];
977 - (IBAction)videoSettingChanged:(id)sender
979 if( sender == o_video_snap_folder_btn )
981 o_selectFolderPanel = [[NSOpenPanel alloc] init];
982 [o_selectFolderPanel setCanChooseDirectories: YES];
983 [o_selectFolderPanel setCanChooseFiles: NO];
984 [o_selectFolderPanel setResolvesAliases: YES];
985 [o_selectFolderPanel setAllowsMultipleSelection: NO];
986 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
987 [o_selectFolderPanel setCanCreateDirectories: YES];
988 [o_selectFolderPanel setPrompt: _NS("Choose")];
989 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
991 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
992 contextInfo: o_video_snap_folder_btn];
995 b_videoSettingChanged = YES;
998 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1000 if( returnCode == NSOKButton )
1002 if( contextInfo == o_video_snap_folder_btn )
1004 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1005 b_videoSettingChanged = YES;
1007 else if( contextInfo == o_osd_font_btn )
1009 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1010 b_osdSettingChanged = YES;
1014 [o_selectFolderPanel release];
1017 - (void)showVideoSettings
1019 msg_Dbg( p_intf, "showing video settings" );
1020 [self showSettingsForCategory: o_video_view];
1023 - (IBAction)osdSettingChanged:(id)sender
1025 if( sender == o_osd_font_btn )
1027 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1028 [o_selectFolderPanel setCanChooseDirectories: NO];
1029 [o_selectFolderPanel setCanChooseFiles: YES];
1030 [o_selectFolderPanel setResolvesAliases: YES];
1031 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1032 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1033 [o_selectFolderPanel setCanCreateDirectories: NO];
1034 [o_selectFolderPanel setPrompt: _NS("Choose")];
1035 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1036 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1038 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1039 contextInfo: o_osd_font_btn];
1042 b_osdSettingChanged = YES;
1045 - (void)showOSDSettings
1047 msg_Dbg( p_intf, "showing OSD settings" );
1048 [self showSettingsForCategory: o_osd_view];
1051 - (IBAction)inputSettingChanged:(id)sender
1053 b_inputSettingChanged = YES;
1056 - (void)showInputSettings
1058 msg_Dbg( p_intf, "showing Input Settings" );
1059 [self showSettingsForCategory: o_input_view];
1062 - (IBAction)hotkeySettingChanged:(id)sender
1064 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1066 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1067 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1068 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1069 [o_hotkeys_change_taken_lbl setStringValue: @""];
1070 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1071 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1072 [NSApp runModalForWindow: o_hotkeys_change_win];
1074 else if( sender == o_hotkeys_change_cancel_btn )
1077 [o_hotkeys_change_win close];
1079 else if( sender == o_hotkeys_change_ok_btn )
1082 if(! o_keyInTransition )
1085 [o_hotkeys_change_win close];
1086 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1090 b_hotkeyChanged = YES;
1092 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1093 if( i_returnValue != NSNotFound )
1094 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1096 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1099 [o_hotkeys_change_win close];
1101 [o_hotkeys_listbox reloadData];
1103 else if( sender == o_hotkeys_clear_btn )
1105 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1106 [o_hotkeys_listbox reloadData];
1107 b_hotkeyChanged = YES;
1111 - (void)showHotkeySettings
1113 msg_Dbg( p_intf, "showing HotKey Settings" );
1114 [self showSettingsForCategory: o_hotkeys_view];
1117 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1119 return [o_hotkeySettings count];
1122 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1124 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1125 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1126 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1127 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1130 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1135 - (void)changeHotkeyTo: (int)i_theNewKey
1138 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1139 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1141 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1142 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1143 [o_hotkeys_change_ok_btn setEnabled: NO];
1148 if( o_keyInTransition )
1149 [o_keyInTransition release];
1150 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1152 o_temp = [self OSXKeyToString: i_theNewKey];
1154 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1156 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1157 if( i_returnValue != NSNotFound )
1158 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1159 _NS("This combination is already taken by \"%@\"."),
1160 [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1162 [o_hotkeys_change_taken_lbl setStringValue: @""];
1164 [o_hotkeys_change_ok_btn setEnabled: YES];
1170 /********************
1171 * hotkeys settings *
1172 ********************/
1174 @implementation VLCHotkeyChangeWindow
1176 - (BOOL)resignFirstResponder
1178 /* We need to stay the first responder or we'll miss the user's input */
1182 - (void)keyDown:(NSEvent *)o_theEvent
1184 int i_nonReadableKey = 0;
1186 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1187 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1189 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1190 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1192 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1193 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1195 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1196 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1198 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1201 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1206 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1208 case NSF1FunctionKey:
1209 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1211 case NSF2FunctionKey:
1212 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1214 case NSF3FunctionKey:
1215 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1217 case NSF4FunctionKey:
1218 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1220 case NSF5FunctionKey:
1221 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1223 case NSF6FunctionKey:
1224 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1226 case NSF7FunctionKey:
1227 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1229 case NSF8FunctionKey:
1230 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1232 case NSF9FunctionKey:
1233 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1235 case NSF10FunctionKey:
1236 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1238 case NSF11FunctionKey:
1239 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1241 case NSF12FunctionKey:
1242 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1244 case NSInsertFunctionKey:
1245 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1247 case NSHomeFunctionKey:
1248 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1250 case NSEndFunctionKey:
1251 i_nonReadableKey = i_nonReadableKey | KEY_END;
1253 case NSPageUpFunctionKey:
1254 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1256 case NSPageDownFunctionKey:
1257 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1259 case NSMenuFunctionKey:
1260 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1262 case NSTabCharacter:
1263 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1265 case NSDeleteCharacter:
1266 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1268 case NSBackspaceCharacter:
1269 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1271 case NSUpArrowFunctionKey:
1272 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1274 case NSDownArrowFunctionKey:
1275 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1277 case NSRightArrowFunctionKey:
1278 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1280 case NSLeftArrowFunctionKey:
1281 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1283 case NSEnterCharacter:
1284 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1288 msg_Warn( VLCIntf, "user pressed unknown function key" );
1289 i_nonReadableKey = 0;
1296 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1297 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1299 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1302 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];