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 const char *base = KeyToString( val & ~KEY_MODIFIER );
88 [o_temp_str appendString: [NSString stringWithUTF8String: base]];
90 o_temp_str = @"Unset";
98 /* setup the toolbar */
99 o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
100 [o_sprefs_toolbar setAllowsUserCustomization: NO];
101 [o_sprefs_toolbar setAutosavesConfiguration: NO];
102 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
103 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
104 [o_sprefs_toolbar setDelegate: self];
105 [o_sprefs_win setToolbar: o_sprefs_toolbar];
107 /* setup useful stuff */
108 /* TODO: hard-code this instead of one-the-run generation */
109 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
110 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
111 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
112 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
113 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
114 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
115 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
116 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
117 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
118 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
119 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
120 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
121 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
122 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
123 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
124 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
125 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
126 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
127 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
128 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
129 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
130 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'q'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
140 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
141 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
142 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
146 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
147 itemForItemIdentifier: (NSString *)o_itemIdent
148 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
150 NSToolbarItem *o_toolbarItem = nil;
152 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
153 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
155 [o_toolbarItem setLabel: o_name]; \
156 [o_toolbarItem setPaletteLabel: o_desc]; \
158 [o_toolbarItem setToolTip: o_desc]; \
159 [o_toolbarItem setImage: [NSImage imageNamed: o_img]]; \
161 [o_toolbarItem setTarget: self]; \
162 [o_toolbarItem setAction: @selector( sel )]; \
164 [o_toolbarItem setEnabled: YES]; \
165 [o_toolbarItem setAutovalidates: YES]
167 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
169 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
171 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
173 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
175 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
177 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
179 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
181 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & OSD Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
183 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
185 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
187 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
189 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
192 return o_toolbarItem;
195 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
197 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
198 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
201 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
203 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
204 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
207 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
209 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
210 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
216 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
217 [o_audio_effects_box setTitle: _NS("Effects")];
218 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
219 [o_audio_general_box setTitle: _NS("General Audio")];
220 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
221 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
222 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
223 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
224 [o_audio_lastuser_txt setStringValue: _NS("User name")];
225 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
226 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
227 [o_audio_visual_txt setStringValue: _NS("Visualization")];
228 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
231 [o_hotkeys_change_btn setTitle: _NS("Change")];
232 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
233 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
234 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
235 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
236 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
237 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
238 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
241 [o_input_access_box setTitle: _NS("Access Filter")];
242 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
243 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
244 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
245 [o_input_caching_box setTitle: _NS("Caching")];
246 [o_input_dump_ckb setTitle: _NS("Dump")];
247 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
248 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
249 [o_input_net_box setTitle: _NS("Network")];
250 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
251 [o_input_record_ckb setTitle: _NS("Record")];
252 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
253 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
254 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
257 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
258 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
259 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
260 [o_intf_lang_txt setStringValue: _NS("Language")];
261 [o_intf_meta_ckb setTitle: _NS("Fetch the metadata from the Internet")];
262 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
264 /* Subtitles and OSD */
265 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
266 [o_osd_font_box setTitle: _NS("Display Settings")];
267 [o_osd_font_btn setTitle: _NS("Browse...")];
268 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
269 [o_osd_font_effect_txt setStringValue: _NS("Effect")];
270 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
271 [o_osd_font_txt setStringValue: _NS("Font")];
272 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
273 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
274 [o_osd_osd_box setTitle: _NS("On Screen Display")];
275 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
278 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
279 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
280 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
281 [o_sprefs_reset_btn setTitle: _NS("Reset Preferences")];
282 [o_sprefs_save_btn setTitle: _NS("Save")];
283 [o_sprefs_win setTitle: _NS("Preferences")];
286 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
287 [o_video_device_txt setStringValue: _NS("Display device")];
288 [o_video_display_box setTitle: _NS("Display")];
289 [o_video_enable_ckb setTitle: _NS("Enable Video")];
290 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
291 [o_video_onTop_ckb setTitle: _NS("Always on top")];
292 [o_video_output_txt setStringValue: _NS("Output module")];
293 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
294 [o_video_snap_box setTitle: _NS("Video snapshots")];
295 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
296 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
297 [o_video_snap_format_txt setStringValue: _NS("Format")];
298 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
299 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
302 - (void)resetControls
304 module_config_t *p_item;
310 #define SetupIntList( object, name ) \
311 [object removeAllItems]; \
312 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
313 for( i = 0; i < p_item->i_list; i++ ) \
315 if( p_item->ppsz_list_text[i] != NULL) \
316 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
318 [object addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]]; \
320 if( p_item->value.i < [object numberOfItems] ) \
321 [object selectItemAtIndex: p_item->value.i]; \
323 [object selectItemAtIndex: 0]; \
324 [object setToolTip: _NS( p_item->psz_longtext )]
326 #define SetupStringList( object, name ) \
327 [object removeAllItems]; \
329 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
330 for( i = 0; p_item->ppsz_list[i] != nil; i++ ) \
332 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
333 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) ) \
336 [object selectItemAtIndex: y]; \
337 [object setToolTip: _NS( p_item->psz_longtext )]
339 #define SetupModuleList( object, name ) \
340 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
341 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
342 [object removeAllItems]; \
343 [object addItemWithTitle: _NS("Default")]; \
344 for( int i_index = 0; i_index < p_list->i_count; i_index++ ) \
346 p_parser = (module_t *)p_list->p_values[i_index].p_object ; \
348 if( module_IsCapable( p_parser, p_item->psz_type ) ) \
350 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser )]]; \
352 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) ) \
353 [object selectItem: [object lastItem]]; \
356 vlc_list_release( p_list ); \
357 [object setToolTip: _NS(p_item->psz_longtext)]
359 /**********************
360 * interface settings *
361 **********************/
362 SetupStringList( o_intf_lang_pop, "language" );
363 SetupIntList( o_intf_art_pop, "album-art" );
365 [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
366 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
367 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
372 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
373 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
374 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
376 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
378 SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
380 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
382 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
384 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
386 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
387 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
389 SetupModuleList( o_audio_visual_pop, "audio-visual" );
391 /* Last.FM is optional */
392 if( module_Exists( p_intf, "audioscrobbler" ) )
394 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
395 [o_audio_lastpwd_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
397 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
398 [o_audio_last_ckb setState: NSOnState];
400 [o_audio_last_ckb setState: NSOffState];
403 [o_audio_last_ckb setEnabled: NO];
408 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
409 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
410 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
411 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
412 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
414 SetupModuleList( o_video_output_pop, "vout" );
416 [o_video_device_pop removeAllItems];
418 y = [[NSScreen screens] count];
419 [o_video_device_pop addItemWithTitle: _NS("Default")];
420 [[o_video_device_pop lastItem] setTag: 0];
423 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
424 [o_video_device_pop addItemWithTitle:
425 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
426 (int)s_rect.size.width, (int)s_rect.size.height]];
427 [[o_video_device_pop lastItem] setTag: [[[NSScreen screens] objectAtIndex: i] displayID]];
430 [o_video_device_pop selectItemAtIndex: 0];
431 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
433 if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
434 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
435 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
436 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
438 p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
439 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
441 [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
442 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
445 [o_video_snap_format_pop selectItemAtIndex: y];
447 /***************************
448 * input & codecs settings *
449 ***************************/
450 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
451 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
452 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
453 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
455 SetupIntList( o_input_avi_pop, "avi-index" );
457 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
459 psz_tmp = config_GetPsz( p_intf, "access-filter" );
462 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
463 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
464 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
465 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
468 [o_input_cachelevel_pop removeAllItems];
469 [o_input_cachelevel_pop addItemsWithTitles:
470 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
471 _NS("High latency"), _NS("Higher latency"), nil]];
472 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
473 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
474 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
475 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
476 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
477 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
479 #define TestCaC( name ) \
480 b_cache_equal = b_cache_equal && \
481 ( i_cache == config_GetInt( p_intf, name ) )
483 #define TestCaCi( name, int ) \
484 b_cache_equal = b_cache_equal && \
485 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
487 /* Select the accurate value of the PopupButton */
488 bool b_cache_equal = true;
489 int i_cache = config_GetInt( p_intf, "file-caching");
491 TestCaC( "udp-caching" );
492 if( module_Exists (p_intf, "dvdread") )
493 TestCaC( "dvdread-caching" );
494 if( module_Exists (p_intf, "dvdnav") )
495 TestCaC( "dvdnav-caching" );
496 TestCaC( "tcp-caching" );
497 TestCaC( "fake-caching" );
498 TestCaC( "cdda-caching" );
499 TestCaC( "screen-caching" );
500 TestCaC( "vcd-caching" );
501 TestCaCi( "rtsp-caching", 4 );
502 TestCaCi( "ftp-caching", 2 );
503 TestCaCi( "http-caching", 4 );
504 if(module_Exists (p_intf, "access_realrtsp"))
505 TestCaCi( "realrtsp-caching", 10 );
506 TestCaCi( "mms-caching", 19 );
508 [o_input_cachelevel_pop selectItemWithTag: i_cache];
510 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
512 /*********************
513 * subtitle settings *
514 *********************/
515 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
517 [o_osd_encoding_pop removeAllItems];
519 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
520 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
522 if( p_item->ppsz_list[i] != "" )
523 [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
525 [o_osd_encoding_pop addItemWithTitle: @" "];
527 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
530 [o_osd_encoding_pop selectItemAtIndex: y];
532 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
533 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
534 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
536 SetupIntList( o_osd_font_color_pop, "freetype-color" );
537 SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
538 SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
540 /********************
542 ********************/
543 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
544 o_hotkeySettings = [[NSMutableArray alloc] init];
545 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
550 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
554 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
555 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
559 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
560 [o_tempArray_desc release];
561 [o_hotkeys_listbox reloadData];
564 - (void)showSimplePrefs
566 /* we want to show the interface settings, if no category was chosen */
567 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
569 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
570 [self showInterfaceSettings];
573 [self resetControls];
575 [o_sprefs_win center];
576 [o_sprefs_win makeKeyAndOrderFront: self];
579 - (IBAction)buttonAction:(id)sender
581 if( sender == o_sprefs_cancel_btn )
582 [o_sprefs_win orderOut: sender];
583 else if( sender == o_sprefs_save_btn )
585 [self saveChangedSettings];
586 [o_sprefs_win orderOut: sender];
588 else if( sender == o_sprefs_reset_btn )
589 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
590 _NS("Continue"), nil, o_sprefs_win, self,
591 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
592 _NS("Beware this will reset the VLC media player preferences.\n"
593 "Are you sure you want to continue?") );
594 else if( sender == o_sprefs_basicFull_matrix )
596 [o_sprefs_win orderOut: self];
597 [[[VLCMain sharedInstance] getPreferences] showPrefs];
598 [self resetControls];
601 msg_Err( p_intf, "unknown buttonAction sender" );
604 - (void)sheetDidEnd:(NSWindow *)o_sheet
605 returnCode:(int)i_return
606 contextInfo:(void *)o_context
608 if( i_return == NSAlertAlternateReturn )
610 config_ResetAll( p_intf );
611 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
612 [self resetControls];
616 - (void)saveChangedSettings
618 module_config_t *p_item;
624 #define SaveIntList( object, name ) \
625 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
626 if( [object indexOfSelectedItem] >= 0 ) \
627 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
629 config_PutInt( p_intf, name, [object intValue] ) \
631 #define SaveStringList( object, name ) \
632 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
633 if( [object indexOfSelectedItem] >= 0 ) \
634 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
636 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
638 #define SaveModuleList( object, name ) \
639 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
641 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
642 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
644 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
646 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
648 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
650 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
655 vlc_list_release( p_list ); \
656 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
657 config_PutPsz( p_intf, name, "" )
659 /**********************
660 * interface settings *
661 **********************/
662 if( b_intfSettingChanged )
664 SaveStringList( o_intf_lang_pop, "language" );
665 SaveIntList( o_intf_art_pop, "album-art" );
667 config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
668 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
669 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
671 /* okay, let's save our changes to vlcrc */
672 i = config_SaveConfigFile( p_intf, "main" );
673 i = config_SaveConfigFile( p_intf, "macosx" );
677 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
681 b_intfSettingChanged = NO;
687 if( b_audioSettingChanged )
689 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
690 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
691 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
693 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
695 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
696 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
698 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
700 config_PutPsz( p_intf, "audio-filter", "volnorm" );
701 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
703 /* work-around a GCC 4.0.1 bug */
704 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
705 config_PutPsz( p_intf, "audio-filter", psz_tmp );
709 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
710 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
711 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
712 config_PutPsz( p_intf, "audio-filter", psz_tmp );
714 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
716 SaveModuleList( o_audio_visual_pop, "audio-visual" );
718 /* Last.FM is optional */
719 if( module_Exists( p_intf, "audioscrobbler" ) )
721 if( [o_audio_last_ckb state] == NSOnState )
722 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
724 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
726 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
727 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastuser_fld stringValue] UTF8String] );
730 /* okay, let's save our changes to vlcrc */
731 i = config_SaveConfigFile( p_intf, "main" );
732 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
733 i = i + config_SaveConfigFile( p_intf, "volnorm" );
737 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
740 b_audioSettingChanged = NO;
746 if( b_videoSettingChanged )
748 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
749 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
750 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
751 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
752 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
754 SaveModuleList( o_video_output_pop, "vout" );
755 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
757 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
758 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
759 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
761 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
762 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
764 i = config_SaveConfigFile( p_intf, "main" );
765 i = i + config_SaveConfigFile( p_intf, "macosx" );
769 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
772 b_videoSettingChanged = NO;
775 /***************************
776 * input & codecs settings *
777 ***************************/
778 if( b_inputSettingChanged )
780 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
781 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
782 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
784 SaveIntList( o_input_avi_pop, "avi-index" );
786 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
788 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
789 #define CaC( name ) CaCi( name, 1 )
790 msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
791 CaC( "udp-caching" );
792 if( module_Exists (p_intf, "dvdread" ) )
794 CaC( "dvdread-caching" );
795 i = i + config_SaveConfigFile( p_intf, "dvdread" );
797 if( module_Exists (p_intf, "dvdnav" ) )
799 CaC( "dvdnav-caching" );
800 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
802 CaC( "tcp-caching" ); CaC( "vcd-caching" );
803 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
804 CaC( "screen-caching" );
805 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
806 CaCi( "http-caching", 4 );
807 if( module_Exists (p_intf, "access_realrtsp" ) )
809 CaCi( "realrtsp-caching", 10 );
810 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
812 CaCi( "mms-caching", 19 );
814 #define SaveAccessFilter( object, name ) \
815 if( [object state] == NSOnState ) \
819 [o_temp appendString: name]; \
823 [o_temp appendFormat: @":%@", name]; \
827 NSMutableString *o_temp = [[NSMutableString alloc] init];
828 SaveAccessFilter( o_input_record_ckb, @"record" );
829 SaveAccessFilter( o_input_dump_ckb, @"dump" );
830 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
831 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
832 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
835 i = config_SaveConfigFile( p_intf, "main" );
836 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
837 i = i + config_SaveConfigFile( p_intf, "access_http" );
838 i = i + config_SaveConfigFile( p_intf, "access_file" );
839 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
840 i = i + config_SaveConfigFile( p_intf, "access_fake" );
841 i = i + config_SaveConfigFile( p_intf, "cdda" );
842 i = i + config_SaveConfigFile( p_intf, "screen" );
843 i = i + config_SaveConfigFile( p_intf, "vcd" );
844 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
845 i = i + config_SaveConfigFile( p_intf, "access_mms" );
846 i = i + config_SaveConfigFile( p_intf, "live555" );
850 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
853 b_inputSettingChanged = NO;
856 /**********************
857 * subtitles settings *
858 **********************/
859 if( b_osdSettingChanged )
861 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
863 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
864 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
866 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
867 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
869 SaveIntList( o_osd_font_color_pop, "freetype-color" );
870 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
871 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
873 i = config_SaveConfigFile( p_intf, NULL );
877 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
880 b_osdSettingChanged = NO;
883 /********************
885 ********************/
886 if( b_hotkeyChanged )
888 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
890 while( i < [o_hotkeySettings count] )
892 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
896 i = config_SaveConfigFile( p_intf, "main" );
900 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
903 b_hotkeyChanged = NO;
907 - (void)showSettingsForCategory: (id)o_new_category_view
909 NSRect o_win_rect, o_view_rect, o_old_view_rect;
910 o_win_rect = [o_sprefs_win frame];
911 o_view_rect = [o_new_category_view frame];
913 if( o_currentlyShownCategoryView != nil )
915 /* restore our window's height, if we've shown another category previously */
916 o_old_view_rect = [o_currentlyShownCategoryView frame];
917 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
918 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
920 /* remove our previous category view */
921 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
924 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
926 [o_sprefs_win displayIfNeeded];
927 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
929 [o_new_category_view setFrame: NSMakeRect( 0,
930 [o_sprefs_controls_box frame].size.height,
931 o_view_rect.size.width,
932 o_view_rect.size.height )];
933 [o_new_category_view setNeedsDisplay: YES];
934 [o_new_category_view setAutoresizesSubviews: YES];
935 [[o_sprefs_win contentView] addSubview: o_new_category_view];
937 /* keep our current category for further reference */
938 [o_currentlyShownCategoryView release];
939 o_currentlyShownCategoryView = o_new_category_view;
940 [o_currentlyShownCategoryView retain];
943 - (IBAction)interfaceSettingChanged:(id)sender
945 b_intfSettingChanged = YES;
948 - (void)showInterfaceSettings
950 msg_Dbg( p_intf, "showing interface settings" );
951 [self showSettingsForCategory: o_intf_view];
954 - (IBAction)audioSettingChanged:(id)sender
956 if( sender == o_audio_vol_sld )
957 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
959 if( sender == o_audio_vol_fld )
960 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
962 b_audioSettingChanged = YES;
965 - (void)showAudioSettings
967 msg_Dbg( p_intf, "showing audio settings" );
968 [self showSettingsForCategory: o_audio_view];
971 - (IBAction)videoSettingChanged:(id)sender
973 if( sender == o_video_snap_folder_btn )
975 o_selectFolderPanel = [[NSOpenPanel alloc] init];
976 [o_selectFolderPanel setCanChooseDirectories: YES];
977 [o_selectFolderPanel setCanChooseFiles: NO];
978 [o_selectFolderPanel setResolvesAliases: YES];
979 [o_selectFolderPanel setAllowsMultipleSelection: NO];
980 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
981 [o_selectFolderPanel setCanCreateDirectories: YES];
982 [o_selectFolderPanel setPrompt: _NS("Choose")];
983 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
985 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
986 contextInfo: o_video_snap_folder_btn];
989 b_videoSettingChanged = YES;
992 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
994 if( returnCode == NSOKButton )
996 if( contextInfo == o_video_snap_folder_btn )
998 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
999 b_videoSettingChanged = YES;
1001 else if( contextInfo == o_osd_font_btn )
1003 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1004 b_osdSettingChanged = YES;
1008 [o_selectFolderPanel release];
1011 - (void)showVideoSettings
1013 msg_Dbg( p_intf, "showing video settings" );
1014 [self showSettingsForCategory: o_video_view];
1017 - (IBAction)osdSettingChanged:(id)sender
1019 if( sender == o_osd_font_btn )
1021 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1022 [o_selectFolderPanel setCanChooseDirectories: NO];
1023 [o_selectFolderPanel setCanChooseFiles: YES];
1024 [o_selectFolderPanel setResolvesAliases: YES];
1025 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1026 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1027 [o_selectFolderPanel setCanCreateDirectories: NO];
1028 [o_selectFolderPanel setPrompt: _NS("Choose")];
1029 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1030 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1032 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1033 contextInfo: o_osd_font_btn];
1036 b_osdSettingChanged = YES;
1039 - (void)showOSDSettings
1041 msg_Dbg( p_intf, "showing OSD settings" );
1042 [self showSettingsForCategory: o_osd_view];
1045 - (IBAction)inputSettingChanged:(id)sender
1047 b_inputSettingChanged = YES;
1050 - (void)showInputSettings
1052 msg_Dbg( p_intf, "showing Input Settings" );
1053 [self showSettingsForCategory: o_input_view];
1056 - (IBAction)hotkeySettingChanged:(id)sender
1058 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1060 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1061 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1062 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1063 [o_hotkeys_change_taken_lbl setStringValue: @""];
1064 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1065 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1066 [NSApp runModalForWindow: o_hotkeys_change_win];
1068 else if( sender == o_hotkeys_change_cancel_btn )
1071 [o_hotkeys_change_win close];
1073 else if( sender == o_hotkeys_change_ok_btn )
1076 if(! o_keyInTransition )
1079 [o_hotkeys_change_win close];
1080 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1084 b_hotkeyChanged = YES;
1086 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1087 if( i_returnValue != NSNotFound )
1088 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1090 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1093 [o_hotkeys_change_win close];
1095 [o_hotkeys_listbox reloadData];
1097 else if( sender == o_hotkeys_clear_btn )
1099 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1100 [o_hotkeys_listbox reloadData];
1101 b_hotkeyChanged = YES;
1105 - (void)showHotkeySettings
1107 msg_Dbg( p_intf, "showing HotKey Settings" );
1108 [self showSettingsForCategory: o_hotkeys_view];
1111 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1113 return [o_hotkeySettings count];
1116 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1118 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1119 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1120 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1121 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1124 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1129 - (void)changeHotkeyTo: (int)i_theNewKey
1132 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1133 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1135 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1136 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1137 [o_hotkeys_change_ok_btn setEnabled: NO];
1142 if( o_keyInTransition )
1143 [o_keyInTransition release];
1144 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1146 o_temp = [self OSXKeyToString: i_theNewKey];
1148 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1150 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1151 if( i_returnValue != NSNotFound )
1152 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1153 _NS("This combination is already taken by \"%@\"."),
1154 [self OSXKeyToString:[[o_hotkeyDescriptions objectAtIndex: i_returnValue] intValue]]]];
1156 [o_hotkeys_change_taken_lbl setStringValue: @""];
1158 [o_hotkeys_change_ok_btn setEnabled: YES];
1164 /********************
1165 * hotkeys settings *
1166 ********************/
1168 @implementation VLCHotkeyChangeWindow
1170 - (BOOL)resignFirstResponder
1172 /* We need to stay the first responder or we'll miss the user's input */
1176 - (void)keyDown:(NSEvent *)o_theEvent
1178 int i_nonReadableKey = 0;
1180 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1181 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1183 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1184 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1186 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1187 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1189 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1190 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1192 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1195 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1200 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1202 case NSF1FunctionKey:
1203 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1205 case NSF2FunctionKey:
1206 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1208 case NSF3FunctionKey:
1209 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1211 case NSF4FunctionKey:
1212 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1214 case NSF5FunctionKey:
1215 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1217 case NSF6FunctionKey:
1218 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1220 case NSF7FunctionKey:
1221 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1223 case NSF8FunctionKey:
1224 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1226 case NSF9FunctionKey:
1227 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1229 case NSF10FunctionKey:
1230 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1232 case NSF11FunctionKey:
1233 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1235 case NSF12FunctionKey:
1236 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1238 case NSInsertFunctionKey:
1239 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1241 case NSHomeFunctionKey:
1242 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1244 case NSEndFunctionKey:
1245 i_nonReadableKey = i_nonReadableKey | KEY_END;
1247 case NSPageUpFunctionKey:
1248 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1250 case NSPageDownFunctionKey:
1251 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1253 case NSMenuFunctionKey:
1254 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1256 case NSTabCharacter:
1257 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1259 case NSDeleteCharacter:
1260 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1262 case NSBackspaceCharacter:
1263 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1265 case NSUpArrowFunctionKey:
1266 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1268 case NSDownArrowFunctionKey:
1269 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1271 case NSRightArrowFunctionKey:
1272 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1274 case NSLeftArrowFunctionKey:
1275 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1277 case NSEnterCharacter:
1278 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1282 msg_Warn( VLCIntf, "user pressed unknown function key" );
1283 i_nonReadableKey = 0;
1290 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1291 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1293 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1296 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];