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 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
109 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
110 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
111 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
112 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
113 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
114 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
115 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
116 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
117 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
118 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
119 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
120 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
121 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
122 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
123 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
124 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
125 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
126 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
127 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
128 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
129 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
130 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
140 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
144 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
145 itemForItemIdentifier: (NSString *)o_itemIdent
146 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
148 NSToolbarItem *o_toolbarItem = nil;
150 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
151 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
153 [o_toolbarItem setLabel: o_name]; \
154 [o_toolbarItem setPaletteLabel: o_desc]; \
156 [o_toolbarItem setToolTip: o_desc]; \
157 [o_toolbarItem setImage: [NSImage imageNamed: o_img]]; \
159 [o_toolbarItem setTarget: self]; \
160 [o_toolbarItem setAction: @selector( sel )]; \
162 [o_toolbarItem setEnabled: YES]; \
163 [o_toolbarItem setAutovalidates: YES]
165 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
167 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
169 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
171 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
173 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
175 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
177 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
179 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & OSD Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
181 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
183 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
185 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
187 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
190 return o_toolbarItem;
193 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
195 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
196 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
199 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
201 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
202 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
205 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
207 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
208 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
214 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
215 [o_audio_effects_box setTitle: _NS("Effects")];
216 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
217 [o_audio_general_box setTitle: _NS("General Audio")];
218 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
219 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
220 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
221 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
222 [o_audio_lastuser_txt setStringValue: _NS("User name")];
223 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
224 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
225 [o_audio_visual_txt setStringValue: _NS("Visualization")];
226 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
229 [o_hotkeys_change_btn setTitle: _NS("Change")];
230 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
231 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
232 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
233 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
234 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
235 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
236 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
239 [o_input_access_box setTitle: _NS("Access Filter")];
240 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
241 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
242 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
243 [o_input_caching_box setTitle: _NS("Caching")];
244 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
245 [o_input_dump_ckb setTitle: _NS("Dump")];
246 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
247 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
248 [o_input_net_box setTitle: _NS("Network")];
249 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
250 [o_input_record_ckb setTitle: _NS("Record")];
251 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
252 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
253 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
256 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
257 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
258 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
259 [o_intf_lang_txt setStringValue: _NS("Language")];
260 [o_intf_meta_ckb setTitle: _NS("Fetch the metadata from the Internet")];
261 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
263 /* Subtitles and OSD */
264 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
265 [o_osd_font_box setTitle: _NS("Display Settings")];
266 [o_osd_font_btn setTitle: _NS("Browse...")];
267 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
268 [o_osd_font_effect_txt setStringValue: _NS("Effect")];
269 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
270 [o_osd_font_txt setStringValue: _NS("Font")];
271 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
272 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
273 [o_osd_osd_box setTitle: _NS("On Screen Display")];
274 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
277 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
278 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
279 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
280 [o_sprefs_reset_btn setTitle: _NS("Reset Preferences")];
281 [o_sprefs_save_btn setTitle: _NS("Save")];
282 [o_sprefs_win setTitle: _NS("Preferences")];
285 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
286 [o_video_device_txt setStringValue: _NS("Display device")];
287 [o_video_display_box setTitle: _NS("Display")];
288 [o_video_enable_ckb setTitle: _NS("Enable Video")];
289 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
290 [o_video_onTop_ckb setTitle: _NS("Always on top")];
291 [o_video_output_txt setStringValue: _NS("Output module")];
292 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
293 [o_video_snap_box setTitle: _NS("Video snapshots")];
294 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
295 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
296 [o_video_snap_format_txt setStringValue: _NS("Format")];
297 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
298 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
301 - (void)resetControls
303 module_config_t *p_item;
309 #define SetupIntList( object, name ) \
310 [object removeAllItems]; \
311 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
312 for( i = 0; i < p_item->i_list; i++ ) \
314 if( p_item->ppsz_list_text[i] != NULL) \
315 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
317 [object addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]]; \
319 if( p_item->value.i < [object numberOfItems] ) \
320 [object selectItemAtIndex: p_item->value.i]; \
322 [object selectItemAtIndex: 0]; \
323 [object setToolTip: _NS( p_item->psz_longtext )]
325 #define SetupStringList( object, name ) \
326 [object removeAllItems]; \
328 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
329 for( i = 0; p_item->ppsz_list[i] != nil; i++ ) \
331 [object addItemWithTitle: _NS( p_item->ppsz_list_text[i] )]; \
332 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) ) \
335 [object selectItemAtIndex: y]; \
336 [object setToolTip: _NS( p_item->psz_longtext )]
338 #define SetupModuleList( object, name ) \
339 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
340 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
341 [object removeAllItems]; \
342 [object addItemWithTitle: _NS("Default")]; \
343 for( int i_index = 0; i_index < p_list->i_count; i_index++ ) \
345 p_parser = (module_t *)p_list->p_values[i_index].p_object ; \
347 if( module_IsCapable( p_parser, p_item->psz_type ) ) \
349 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser )]]; \
351 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) ) \
352 [object selectItem: [object lastItem]]; \
355 vlc_list_release( p_list ); \
356 [object setToolTip: _NS(p_item->psz_longtext)]
358 /**********************
359 * interface settings *
360 **********************/
361 SetupStringList( o_intf_lang_pop, "language" );
362 SetupIntList( o_intf_art_pop, "album-art" );
364 [o_intf_meta_ckb setState: config_GetInt( p_intf, "fetch-meta" )];
365 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
366 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
371 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
372 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
373 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
375 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
377 SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
379 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
381 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
383 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
385 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
386 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
388 SetupModuleList( o_audio_visual_pop, "audio-visual" );
390 /* Last.FM is optional */
391 if( module_Exists( p_intf, "audioscrobbler" ) )
393 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
394 [o_audio_lastpwd_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
396 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
398 [o_audio_last_ckb setState: NSOnState];
399 [o_audio_lastuser_fld setEnabled: YES];
400 [o_audio_lastpwd_fld setEnabled: YES];
404 [o_audio_last_ckb setState: NSOffState];
405 [o_audio_lastuser_fld setEnabled: NO];
406 [o_audio_lastpwd_fld setEnabled: NO];
410 [o_audio_last_ckb setEnabled: NO];
415 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
416 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
417 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
418 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
419 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
421 SetupModuleList( o_video_output_pop, "vout" );
423 [o_video_device_pop removeAllItems];
425 y = [[NSScreen screens] count];
426 [o_video_device_pop addItemWithTitle: _NS("Default")];
427 [[o_video_device_pop lastItem] setTag: 0];
430 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
431 [o_video_device_pop addItemWithTitle:
432 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
433 (int)s_rect.size.width, (int)s_rect.size.height]];
434 [[o_video_device_pop lastItem] setTag: [[[NSScreen screens] objectAtIndex: i] displayID]];
437 [o_video_device_pop selectItemAtIndex: 0];
438 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
440 if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
441 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
442 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
443 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
445 p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
446 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
448 [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
449 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
452 [o_video_snap_format_pop selectItemAtIndex: y];
454 /***************************
455 * input & codecs settings *
456 ***************************/
457 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
458 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
459 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
460 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
462 SetupIntList( o_input_avi_pop, "avi-index" );
464 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
466 psz_tmp = config_GetPsz( p_intf, "access-filter" );
469 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
470 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
471 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
472 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
475 [o_input_cachelevel_pop removeAllItems];
476 [o_input_cachelevel_pop addItemsWithTitles:
477 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
478 _NS("High latency"), _NS("Higher latency"), nil]];
479 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
480 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
481 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
482 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
483 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
484 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
486 #define TestCaC( name ) \
487 b_cache_equal = b_cache_equal && \
488 ( i_cache == config_GetInt( p_intf, name ) )
490 #define TestCaCi( name, int ) \
491 b_cache_equal = b_cache_equal && \
492 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
494 /* Select the accurate value of the PopupButton */
495 bool b_cache_equal = true;
496 int i_cache = config_GetInt( p_intf, "file-caching");
498 TestCaC( "udp-caching" );
499 if( module_Exists (p_intf, "dvdread") )
500 TestCaC( "dvdread-caching" );
501 if( module_Exists (p_intf, "dvdnav") )
502 TestCaC( "dvdnav-caching" );
503 TestCaC( "tcp-caching" );
504 TestCaC( "fake-caching" );
505 TestCaC( "cdda-caching" );
506 TestCaC( "screen-caching" );
507 TestCaC( "vcd-caching" );
508 TestCaCi( "rtsp-caching", 4 );
509 TestCaCi( "ftp-caching", 2 );
510 TestCaCi( "http-caching", 4 );
511 if(module_Exists (p_intf, "access_realrtsp"))
512 TestCaCi( "realrtsp-caching", 10 );
513 TestCaCi( "mms-caching", 19 );
516 [o_input_cachelevel_pop selectItemWithTag: i_cache];
517 [o_input_cachelevel_custom_txt setHidden: YES];
521 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
522 [o_input_cachelevel_custom_txt setHidden: NO];
525 /*********************
526 * subtitle settings *
527 *********************/
528 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
530 [o_osd_encoding_pop removeAllItems];
532 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
533 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
535 if( p_item->ppsz_list[i] != "" )
536 [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
538 [o_osd_encoding_pop addItemWithTitle: @" "];
540 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
543 [o_osd_encoding_pop selectItemAtIndex: y];
545 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
546 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
547 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
549 SetupIntList( o_osd_font_color_pop, "freetype-color" );
550 SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
551 SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
553 /********************
555 ********************/
556 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
557 o_hotkeySettings = [[NSMutableArray alloc] init];
558 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
563 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
567 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
568 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
572 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
573 [o_tempArray_desc release];
574 [o_hotkeys_listbox reloadData];
577 - (void)showSimplePrefs
579 /* we want to show the interface settings, if no category was chosen */
580 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
582 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
583 [self showInterfaceSettings];
586 [self resetControls];
588 [o_sprefs_win center];
589 [o_sprefs_win makeKeyAndOrderFront: self];
592 - (IBAction)buttonAction:(id)sender
594 if( sender == o_sprefs_cancel_btn )
595 [o_sprefs_win orderOut: sender];
596 else if( sender == o_sprefs_save_btn )
598 [self saveChangedSettings];
599 [o_sprefs_win orderOut: sender];
601 else if( sender == o_sprefs_reset_btn )
602 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
603 _NS("Continue"), nil, o_sprefs_win, self,
604 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
605 _NS("Beware this will reset the VLC media player preferences.\n"
606 "Are you sure you want to continue?") );
607 else if( sender == o_sprefs_basicFull_matrix )
609 [o_sprefs_win orderOut: self];
610 [[[VLCMain sharedInstance] getPreferences] showPrefs];
611 [self resetControls];
614 msg_Err( p_intf, "unknown buttonAction sender" );
617 - (void)sheetDidEnd:(NSWindow *)o_sheet
618 returnCode:(int)i_return
619 contextInfo:(void *)o_context
621 if( i_return == NSAlertAlternateReturn )
623 config_ResetAll( p_intf );
624 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
625 [self resetControls];
629 - (void)saveChangedSettings
631 module_config_t *p_item;
637 #define SaveIntList( object, name ) \
638 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
639 if( [object indexOfSelectedItem] >= 0 ) \
640 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
642 config_PutInt( p_intf, name, [object intValue] ) \
644 #define SaveStringList( object, name ) \
645 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
646 if( [object indexOfSelectedItem] >= 0 ) \
647 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
649 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
651 #define SaveModuleList( object, name ) \
652 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
654 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
655 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
657 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
659 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
661 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
663 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
668 vlc_list_release( p_list ); \
669 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
670 config_PutPsz( p_intf, name, "" )
672 /**********************
673 * interface settings *
674 **********************/
675 if( b_intfSettingChanged )
677 SaveStringList( o_intf_lang_pop, "language" );
678 SaveIntList( o_intf_art_pop, "album-art" );
680 config_PutInt( p_intf, "fetch-meta", [o_intf_meta_ckb state] );
681 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
682 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
684 /* okay, let's save our changes to vlcrc */
685 i = config_SaveConfigFile( p_intf, "main" );
686 i = config_SaveConfigFile( p_intf, "macosx" );
690 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
694 b_intfSettingChanged = NO;
700 if( b_audioSettingChanged )
702 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
703 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
704 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
706 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
708 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
709 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
711 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
713 config_PutPsz( p_intf, "audio-filter", "volnorm" );
714 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
716 /* work-around a GCC 4.0.1 bug */
717 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
718 config_PutPsz( p_intf, "audio-filter", psz_tmp );
722 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
723 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
724 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
725 config_PutPsz( p_intf, "audio-filter", psz_tmp );
727 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
729 SaveModuleList( o_audio_visual_pop, "audio-visual" );
731 /* Last.FM is optional */
732 if( module_Exists( p_intf, "audioscrobbler" ) )
734 [o_audio_last_ckb setEnabled: YES];
735 if( [o_audio_last_ckb state] == NSOnState )
736 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
738 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
740 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
741 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_fld stringValue] UTF8String] );
744 [o_audio_last_ckb setEnabled: NO];
746 /* okay, let's save our changes to vlcrc */
747 i = config_SaveConfigFile( p_intf, "main" );
748 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
749 i = i + config_SaveConfigFile( p_intf, "volnorm" );
753 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
756 b_audioSettingChanged = NO;
762 if( b_videoSettingChanged )
764 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
765 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
766 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
767 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
768 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
770 SaveModuleList( o_video_output_pop, "vout" );
771 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
773 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
774 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
775 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
777 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
778 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
780 i = config_SaveConfigFile( p_intf, "main" );
781 i = i + config_SaveConfigFile( p_intf, "macosx" );
785 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
788 b_videoSettingChanged = NO;
791 /***************************
792 * input & codecs settings *
793 ***************************/
794 if( b_inputSettingChanged )
796 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
797 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
798 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
800 SaveIntList( o_input_avi_pop, "avi-index" );
802 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
804 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
805 #define CaC( name ) CaCi( name, 1 )
806 msg_Dbg( p_intf, "Adjusting all cache values at: %i", [[o_input_cachelevel_pop selectedItem] tag] );
807 CaC( "udp-caching" );
808 if( module_Exists (p_intf, "dvdread" ) )
810 CaC( "dvdread-caching" );
811 i = i + config_SaveConfigFile( p_intf, "dvdread" );
813 if( module_Exists (p_intf, "dvdnav" ) )
815 CaC( "dvdnav-caching" );
816 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
818 CaC( "tcp-caching" ); CaC( "vcd-caching" );
819 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
820 CaC( "screen-caching" );
821 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
822 CaCi( "http-caching", 4 );
823 if( module_Exists (p_intf, "access_realrtsp" ) )
825 CaCi( "realrtsp-caching", 10 );
826 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
828 CaCi( "mms-caching", 19 );
830 #define SaveAccessFilter( object, name ) \
831 if( [object state] == NSOnState ) \
835 [o_temp appendString: name]; \
839 [o_temp appendFormat: @":%@", name]; \
843 NSMutableString *o_temp = [[NSMutableString alloc] init];
844 SaveAccessFilter( o_input_record_ckb, @"record" );
845 SaveAccessFilter( o_input_dump_ckb, @"dump" );
846 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
847 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
848 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
851 i = config_SaveConfigFile( p_intf, "main" );
852 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
853 i = i + config_SaveConfigFile( p_intf, "access_http" );
854 i = i + config_SaveConfigFile( p_intf, "access_file" );
855 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
856 i = i + config_SaveConfigFile( p_intf, "access_fake" );
857 i = i + config_SaveConfigFile( p_intf, "cdda" );
858 i = i + config_SaveConfigFile( p_intf, "screen" );
859 i = i + config_SaveConfigFile( p_intf, "vcd" );
860 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
861 i = i + config_SaveConfigFile( p_intf, "access_mms" );
862 i = i + config_SaveConfigFile( p_intf, "live555" );
866 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
869 b_inputSettingChanged = NO;
872 /**********************
873 * subtitles settings *
874 **********************/
875 if( b_osdSettingChanged )
877 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
879 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
880 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
882 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
883 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
885 SaveIntList( o_osd_font_color_pop, "freetype-color" );
886 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
887 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
889 i = config_SaveConfigFile( p_intf, NULL );
893 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
896 b_osdSettingChanged = NO;
899 /********************
901 ********************/
902 if( b_hotkeyChanged )
904 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
906 while( i < [o_hotkeySettings count] )
908 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
912 i = config_SaveConfigFile( p_intf, "main" );
916 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
919 b_hotkeyChanged = NO;
923 - (void)showSettingsForCategory: (id)o_new_category_view
925 NSRect o_win_rect, o_view_rect, o_old_view_rect;
926 o_win_rect = [o_sprefs_win frame];
927 o_view_rect = [o_new_category_view frame];
929 if( o_currentlyShownCategoryView != nil )
931 /* restore our window's height, if we've shown another category previously */
932 o_old_view_rect = [o_currentlyShownCategoryView frame];
933 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
934 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
936 /* remove our previous category view */
937 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
940 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
942 [o_sprefs_win displayIfNeeded];
943 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
945 [o_new_category_view setFrame: NSMakeRect( 0,
946 [o_sprefs_controls_box frame].size.height,
947 o_view_rect.size.width,
948 o_view_rect.size.height )];
949 [o_new_category_view setNeedsDisplay: YES];
950 [o_new_category_view setAutoresizesSubviews: YES];
951 [[o_sprefs_win contentView] addSubview: o_new_category_view];
953 /* keep our current category for further reference */
954 [o_currentlyShownCategoryView release];
955 o_currentlyShownCategoryView = o_new_category_view;
956 [o_currentlyShownCategoryView retain];
959 - (IBAction)interfaceSettingChanged:(id)sender
961 b_intfSettingChanged = YES;
964 - (void)showInterfaceSettings
966 msg_Dbg( p_intf, "showing interface settings" );
967 [self showSettingsForCategory: o_intf_view];
970 - (IBAction)audioSettingChanged:(id)sender
972 if( sender == o_audio_vol_sld )
973 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
975 if( sender == o_audio_vol_fld )
976 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
978 if( sender == o_audio_last_ckb )
980 if( [o_audio_last_ckb state] == NSOnState )
982 [o_audio_lastpwd_fld setEnabled: YES];
983 [o_audio_lastuser_fld setEnabled: YES];
987 [o_audio_lastpwd_fld setEnabled: NO];
988 [o_audio_lastuser_fld setEnabled: NO];
992 b_audioSettingChanged = YES;
995 - (void)showAudioSettings
997 msg_Dbg( p_intf, "showing audio settings" );
998 [self showSettingsForCategory: o_audio_view];
1001 - (IBAction)videoSettingChanged:(id)sender
1003 if( sender == o_video_snap_folder_btn )
1005 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1006 [o_selectFolderPanel setCanChooseDirectories: YES];
1007 [o_selectFolderPanel setCanChooseFiles: NO];
1008 [o_selectFolderPanel setResolvesAliases: YES];
1009 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1010 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1011 [o_selectFolderPanel setCanCreateDirectories: YES];
1012 [o_selectFolderPanel setPrompt: _NS("Choose")];
1013 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1015 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1016 contextInfo: o_video_snap_folder_btn];
1019 b_videoSettingChanged = YES;
1022 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1024 if( returnCode == NSOKButton )
1026 if( contextInfo == o_video_snap_folder_btn )
1028 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1029 b_videoSettingChanged = YES;
1031 else if( contextInfo == o_osd_font_btn )
1033 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1034 b_osdSettingChanged = YES;
1038 [o_selectFolderPanel release];
1041 - (void)showVideoSettings
1043 msg_Dbg( p_intf, "showing video settings" );
1044 [self showSettingsForCategory: o_video_view];
1047 - (IBAction)osdSettingChanged:(id)sender
1049 if( sender == o_osd_font_btn )
1051 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1052 [o_selectFolderPanel setCanChooseDirectories: NO];
1053 [o_selectFolderPanel setCanChooseFiles: YES];
1054 [o_selectFolderPanel setResolvesAliases: YES];
1055 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1056 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1057 [o_selectFolderPanel setCanCreateDirectories: NO];
1058 [o_selectFolderPanel setPrompt: _NS("Choose")];
1059 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1060 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1062 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1063 contextInfo: o_osd_font_btn];
1066 b_osdSettingChanged = YES;
1069 - (void)showOSDSettings
1071 msg_Dbg( p_intf, "showing OSD settings" );
1072 [self showSettingsForCategory: o_osd_view];
1075 - (IBAction)inputSettingChanged:(id)sender
1077 if( sender == o_input_cachelevel_pop )
1079 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1080 [o_input_cachelevel_custom_txt setHidden: NO];
1082 [o_input_cachelevel_custom_txt setHidden: YES];
1085 b_inputSettingChanged = YES;
1088 - (void)showInputSettings
1090 msg_Dbg( p_intf, "showing Input Settings" );
1091 [self showSettingsForCategory: o_input_view];
1094 - (IBAction)hotkeySettingChanged:(id)sender
1096 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1098 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1099 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1100 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1101 [o_hotkeys_change_taken_lbl setStringValue: @""];
1102 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1103 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1104 [NSApp runModalForWindow: o_hotkeys_change_win];
1106 else if( sender == o_hotkeys_change_cancel_btn )
1109 [o_hotkeys_change_win close];
1111 else if( sender == o_hotkeys_change_ok_btn )
1114 if(! o_keyInTransition )
1117 [o_hotkeys_change_win close];
1118 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1122 b_hotkeyChanged = YES;
1124 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1125 if( i_returnValue != NSNotFound )
1126 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1128 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1131 [o_hotkeys_change_win close];
1133 [o_hotkeys_listbox reloadData];
1135 else if( sender == o_hotkeys_clear_btn )
1137 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1138 [o_hotkeys_listbox reloadData];
1139 b_hotkeyChanged = YES;
1143 - (void)showHotkeySettings
1145 msg_Dbg( p_intf, "showing HotKey Settings" );
1146 [self showSettingsForCategory: o_hotkeys_view];
1149 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1151 return [o_hotkeySettings count];
1154 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1156 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1157 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1158 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1159 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1162 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1167 - (void)changeHotkeyTo: (int)i_theNewKey
1170 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1171 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1173 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1174 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1175 [o_hotkeys_change_ok_btn setEnabled: NO];
1180 if( o_keyInTransition )
1181 [o_keyInTransition release];
1182 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1184 o_temp = [self OSXKeyToString: i_theNewKey];
1186 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1188 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1189 if( i_returnValue != NSNotFound )
1190 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1191 _NS("This combination is already taken by \"%@\"."),
1192 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1194 [o_hotkeys_change_taken_lbl setStringValue: @""];
1196 [o_hotkeys_change_ok_btn setEnabled: YES];
1202 /********************
1203 * hotkeys settings *
1204 ********************/
1206 @implementation VLCHotkeyChangeWindow
1208 - (BOOL)resignFirstResponder
1210 /* We need to stay the first responder or we'll miss the user's input */
1214 - (void)keyDown:(NSEvent *)o_theEvent
1216 int i_nonReadableKey = 0;
1218 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1219 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1221 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1222 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1224 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1225 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1227 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1228 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1230 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1233 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1238 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1240 case NSF1FunctionKey:
1241 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1243 case NSF2FunctionKey:
1244 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1246 case NSF3FunctionKey:
1247 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1249 case NSF4FunctionKey:
1250 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1252 case NSF5FunctionKey:
1253 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1255 case NSF6FunctionKey:
1256 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1258 case NSF7FunctionKey:
1259 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1261 case NSF8FunctionKey:
1262 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1264 case NSF9FunctionKey:
1265 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1267 case NSF10FunctionKey:
1268 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1270 case NSF11FunctionKey:
1271 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1273 case NSF12FunctionKey:
1274 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1276 case NSInsertFunctionKey:
1277 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1279 case NSHomeFunctionKey:
1280 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1282 case NSEndFunctionKey:
1283 i_nonReadableKey = i_nonReadableKey | KEY_END;
1285 case NSPageUpFunctionKey:
1286 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1288 case NSPageDownFunctionKey:
1289 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1291 case NSMenuFunctionKey:
1292 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1294 case NSTabCharacter:
1295 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1297 case NSDeleteCharacter:
1298 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1300 case NSBackspaceCharacter:
1301 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1303 case NSUpArrowFunctionKey:
1304 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1306 case NSDownArrowFunctionKey:
1307 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1309 case NSRightArrowFunctionKey:
1310 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1312 case NSLeftArrowFunctionKey:
1313 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1315 case NSEnterCharacter:
1316 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1320 msg_Warn( VLCIntf, "user pressed unknown function key" );
1321 i_nonReadableKey = 0;
1328 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1329 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1331 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1334 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];