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 makeKeyAndOrderFront: self];
584 - (IBAction)buttonAction:(id)sender
586 if( sender == o_sprefs_cancel_btn )
587 [o_sprefs_win orderOut: sender];
588 else if( sender == o_sprefs_save_btn )
590 [self saveChangedSettings];
591 [o_sprefs_win orderOut: sender];
593 else if( sender == o_sprefs_reset_btn )
594 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
595 _NS("Continue"), nil, o_sprefs_win, self,
596 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
597 _NS("Beware this will reset the VLC media player preferences.\n"
598 "Are you sure you want to continue?") );
599 else if( sender == o_sprefs_basicFull_matrix )
601 [o_sprefs_win orderOut: self];
602 [[[VLCMain sharedInstance] getPreferences] showPrefs];
603 [self resetControls];
606 msg_Err( p_intf, "unknown buttonAction sender" );
609 - (void)sheetDidEnd:(NSWindow *)o_sheet
610 returnCode:(int)i_return
611 contextInfo:(void *)o_context
613 if( i_return == NSAlertAlternateReturn )
615 config_ResetAll( p_intf );
616 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
617 [self resetControls];
621 - (void)saveChangedSettings
623 module_config_t *p_item;
629 #define SaveIntList( object, name ) \
630 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
631 if( [object indexOfSelectedItem] >= 0 ) \
632 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
634 config_PutInt( p_intf, name, [object intValue] ) \
636 #define SaveStringList( object, name ) \
637 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
638 if( [object indexOfSelectedItem] >= 0 ) \
639 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
641 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
643 #define SaveModuleList( object, name ) \
644 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
646 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
647 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
649 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
651 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
653 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
655 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
660 vlc_list_release( p_list ); \
661 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
662 config_PutPsz( p_intf, name, "" )
664 /**********************
665 * interface settings *
666 **********************/
667 if( b_intfSettingChanged )
669 SaveStringList( o_intf_lang_pop, "language" );
670 SaveIntList( o_intf_art_pop, "album-art" );
672 config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
673 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
674 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
676 /* okay, let's save our changes to vlcrc */
677 i = config_SaveConfigFile( p_intf, "main" );
678 i = config_SaveConfigFile( p_intf, "macosx" );
682 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
686 b_intfSettingChanged = NO;
692 if( b_audioSettingChanged )
694 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
695 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
696 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
698 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
700 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
701 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
703 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
705 config_PutPsz( p_intf, "audio-filter", "volnorm" );
706 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
708 /* work-around a GCC 4.0.1 bug */
709 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
710 config_PutPsz( p_intf, "audio-filter", psz_tmp );
714 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
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 config_PutPsz( p_intf, "audio-filter", psz_tmp );
719 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
721 SaveModuleList( o_audio_visual_pop, "audio-visual" );
723 /* Last.FM is optional */
724 if( module_Exists( p_intf, "audioscrobbler" ) )
726 if( [o_audio_last_ckb state] == NSOnState )
727 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
729 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
731 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
732 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
735 /* okay, let's save our changes to vlcrc */
736 i = config_SaveConfigFile( p_intf, "main" );
737 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
738 i = i + config_SaveConfigFile( p_intf, "volnorm" );
742 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
745 b_audioSettingChanged = NO;
751 if( b_videoSettingChanged )
753 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
754 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
755 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
756 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
757 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
759 SaveModuleList( o_video_output_pop, "vout" );
760 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
762 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
763 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
764 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
766 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
767 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
769 i = config_SaveConfigFile( p_intf, "main" );
770 i = i + config_SaveConfigFile( p_intf, "macosx" );
774 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
777 b_videoSettingChanged = NO;
780 /***************************
781 * input & codecs settings *
782 ***************************/
783 if( b_inputSettingChanged )
785 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
786 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
787 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
789 SaveIntList( o_input_avi_pop, "avi-index" );
791 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
793 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
794 #define CaC( name ) CaCi( name, 1 )
795 msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
796 CaC( "udp-caching" );
797 if( module_Exists (p_intf, "dvdread" ) )
799 CaC( "dvdread-caching" );
800 i = i + config_SaveConfigFile( p_intf, "dvdread" );
802 if( module_Exists (p_intf, "dvdnav" ) )
804 CaC( "dvdnav-caching" );
805 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
807 CaC( "tcp-caching" ); CaC( "vcd-caching" );
808 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
809 CaC( "screen-caching" );
810 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
811 CaCi( "http-caching", 4 );
812 if( module_Exists (p_intf, "access_realrtsp" ) )
814 CaCi( "realrtsp-caching", 10 );
815 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
817 CaCi( "mms-caching", 19 );
819 #define SaveAccessFilter( object, name ) \
820 if( [object state] == NSOnState ) \
824 [o_temp appendString: name]; \
828 [o_temp appendFormat: @":%@", name]; \
832 NSMutableString *o_temp = [[NSMutableString alloc] init];
833 SaveAccessFilter( o_input_record_ckb, @"record" );
834 SaveAccessFilter( o_input_dump_ckb, @"dump" );
835 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
836 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
837 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
840 i = config_SaveConfigFile( p_intf, "main" );
841 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
842 i = i + config_SaveConfigFile( p_intf, "access_http" );
843 i = i + config_SaveConfigFile( p_intf, "access_file" );
844 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
845 i = i + config_SaveConfigFile( p_intf, "access_fake" );
846 i = i + config_SaveConfigFile( p_intf, "cdda" );
847 i = i + config_SaveConfigFile( p_intf, "screen" );
848 i = i + config_SaveConfigFile( p_intf, "vcd" );
849 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
850 i = i + config_SaveConfigFile( p_intf, "access_mms" );
851 i = i + config_SaveConfigFile( p_intf, "live555" );
855 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
858 b_inputSettingChanged = NO;
861 /**********************
862 * subtitles settings *
863 **********************/
864 if( b_osdSettingChanged )
866 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
868 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
869 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
871 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
872 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
874 SaveIntList( o_osd_font_color_pop, "freetype-color" );
875 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
876 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
878 i = config_SaveConfigFile( p_intf, NULL );
882 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
885 b_osdSettingChanged = NO;
888 /********************
890 ********************/
891 if( b_hotkeyChanged )
893 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
895 while( i < [o_hotkeySettings count] )
897 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
901 i = config_SaveConfigFile( p_intf, "main" );
905 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
908 b_hotkeyChanged = NO;
912 - (void)showSettingsForCategory: (id)o_new_category_view
914 NSRect o_win_rect, o_view_rect, o_old_view_rect;
915 o_win_rect = [o_sprefs_win frame];
916 o_view_rect = [o_new_category_view frame];
918 if( o_currentlyShownCategoryView != nil )
920 /* restore our window's height, if we've shown another category previously */
921 o_old_view_rect = [o_currentlyShownCategoryView frame];
922 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
924 /* remove our previous category view */
925 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
928 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
930 [o_sprefs_win displayIfNeeded];
931 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
933 [o_new_category_view setFrame: NSMakeRect( 0,
934 [o_sprefs_controls_box frame].size.height,
935 o_view_rect.size.width,
936 o_view_rect.size.height )];
937 [o_new_category_view setNeedsDisplay: YES];
938 [o_new_category_view setAutoresizesSubviews: YES];
939 [[o_sprefs_win contentView] addSubview: o_new_category_view];
941 /* keep our current category for further reference */
942 [o_currentlyShownCategoryView release];
943 o_currentlyShownCategoryView = o_new_category_view;
944 [o_currentlyShownCategoryView retain];
947 - (IBAction)interfaceSettingChanged:(id)sender
949 b_intfSettingChanged = YES;
952 - (void)showInterfaceSettings
954 msg_Dbg( p_intf, "showing interface settings" );
955 [self showSettingsForCategory: o_intf_view];
958 - (IBAction)audioSettingChanged:(id)sender
960 if( sender == o_audio_vol_sld )
961 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
963 if( sender == o_audio_vol_fld )
964 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
966 b_audioSettingChanged = YES;
969 - (void)showAudioSettings
971 msg_Dbg( p_intf, "showing audio settings" );
972 [self showSettingsForCategory: o_audio_view];
975 - (IBAction)videoSettingChanged:(id)sender
977 if( sender == o_video_snap_folder_btn )
979 o_selectFolderPanel = [[NSOpenPanel alloc] init];
980 [o_selectFolderPanel setCanChooseDirectories: YES];
981 [o_selectFolderPanel setCanChooseFiles: NO];
982 [o_selectFolderPanel setResolvesAliases: YES];
983 [o_selectFolderPanel setAllowsMultipleSelection: NO];
984 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
985 [o_selectFolderPanel setCanCreateDirectories: YES];
986 [o_selectFolderPanel setPrompt: _NS("Choose")];
987 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
989 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
990 contextInfo: o_video_snap_folder_btn];
993 b_videoSettingChanged = YES;
996 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
998 if( returnCode == NSOKButton )
1000 if( contextInfo == o_video_snap_folder_btn )
1002 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1003 b_videoSettingChanged = YES;
1005 else if( contextInfo == o_osd_font_btn )
1007 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1008 b_osdSettingChanged = YES;
1012 [o_selectFolderPanel release];
1015 - (void)showVideoSettings
1017 msg_Dbg( p_intf, "showing video settings" );
1018 [self showSettingsForCategory: o_video_view];
1021 - (IBAction)osdSettingChanged:(id)sender
1023 if( sender == o_osd_font_btn )
1025 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1026 [o_selectFolderPanel setCanChooseDirectories: NO];
1027 [o_selectFolderPanel setCanChooseFiles: YES];
1028 [o_selectFolderPanel setResolvesAliases: YES];
1029 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1030 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1031 [o_selectFolderPanel setCanCreateDirectories: NO];
1032 [o_selectFolderPanel setPrompt: _NS("Choose")];
1033 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1034 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1036 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1037 contextInfo: o_osd_font_btn];
1040 b_osdSettingChanged = YES;
1043 - (void)showOSDSettings
1045 msg_Dbg( p_intf, "showing OSD settings" );
1046 [self showSettingsForCategory: o_osd_view];
1049 - (IBAction)inputSettingChanged:(id)sender
1051 b_inputSettingChanged = YES;
1054 - (void)showInputSettings
1056 msg_Dbg( p_intf, "showing Input Settings" );
1057 [self showSettingsForCategory: o_input_view];
1060 - (IBAction)hotkeySettingChanged:(id)sender
1062 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1064 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1065 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1066 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1067 [o_hotkeys_change_taken_lbl setStringValue: @""];
1068 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1069 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1070 [NSApp runModalForWindow: o_hotkeys_change_win];
1072 else if( sender == o_hotkeys_change_cancel_btn )
1075 [o_hotkeys_change_win close];
1077 else if( sender == o_hotkeys_change_ok_btn )
1080 if(! o_keyInTransition )
1083 [o_hotkeys_change_win close];
1084 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1088 b_hotkeyChanged = YES;
1090 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1091 if( i_returnValue != NSNotFound )
1092 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1094 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1097 [o_hotkeys_change_win close];
1099 [o_hotkeys_listbox reloadData];
1101 else if( sender == o_hotkeys_clear_btn )
1103 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1104 [o_hotkeys_listbox reloadData];
1105 b_hotkeyChanged = YES;
1109 - (void)showHotkeySettings
1111 msg_Dbg( p_intf, "showing HotKey Settings" );
1112 [self showSettingsForCategory: o_hotkeys_view];
1115 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1117 return [o_hotkeySettings count];
1120 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1122 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1123 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1124 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1125 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1128 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1133 - (void)changeHotkeyTo: (int)i_theNewKey
1136 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1137 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1139 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1140 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1141 [o_hotkeys_change_ok_btn setEnabled: NO];
1146 if( o_keyInTransition )
1147 [o_keyInTransition release];
1148 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1150 o_temp = [self OSXKeyToString: i_theNewKey];
1152 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1154 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1155 if( i_returnValue != NSNotFound )
1156 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1157 _NS("This combination is already taken by \"%@\"."),
1158 [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1160 [o_hotkeys_change_taken_lbl setStringValue: @""];
1162 [o_hotkeys_change_ok_btn setEnabled: YES];
1168 /********************
1169 * hotkeys settings *
1170 ********************/
1172 @implementation VLCHotkeyChangeWindow
1174 - (BOOL)resignFirstResponder
1176 /* We need to stay the first responder or we'll miss the user's input */
1180 - (void)keyDown:(NSEvent *)o_theEvent
1182 int i_nonReadableKey = 0;
1184 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1185 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1187 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1188 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1190 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1191 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1193 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1194 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1196 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1199 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1204 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1206 case NSF1FunctionKey:
1207 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1209 case NSF2FunctionKey:
1210 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1212 case NSF3FunctionKey:
1213 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1215 case NSF4FunctionKey:
1216 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1218 case NSF5FunctionKey:
1219 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1221 case NSF6FunctionKey:
1222 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1224 case NSF7FunctionKey:
1225 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1227 case NSF8FunctionKey:
1228 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1230 case NSF9FunctionKey:
1231 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1233 case NSF10FunctionKey:
1234 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1236 case NSF11FunctionKey:
1237 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1239 case NSF12FunctionKey:
1240 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1242 case NSInsertFunctionKey:
1243 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1245 case NSHomeFunctionKey:
1246 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1248 case NSEndFunctionKey:
1249 i_nonReadableKey = i_nonReadableKey | KEY_END;
1251 case NSPageUpFunctionKey:
1252 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1254 case NSPageDownFunctionKey:
1255 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1257 case NSMenuFunctionKey:
1258 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1260 case NSTabCharacter:
1261 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1263 case NSDeleteCharacter:
1264 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1266 case NSBackspaceCharacter:
1267 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1269 case NSUpArrowFunctionKey:
1270 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1272 case NSDownArrowFunctionKey:
1273 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1275 case NSRightArrowFunctionKey:
1276 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1278 case NSLeftArrowFunctionKey:
1279 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1281 case NSEnterCharacter:
1282 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1286 msg_Warn( VLCIntf, "user pressed unknown function key" );
1287 i_nonReadableKey = 0;
1294 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1295 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1297 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1300 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];