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"
27 #import <vlc_interface.h>
30 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
31 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
32 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
33 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
34 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
35 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
36 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
38 @implementation VLCSimplePrefs
40 static VLCSimplePrefs *_o_sharedInstance = nil;
42 + (VLCSimplePrefs *)sharedInstance
44 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
49 if (_o_sharedInstance) {
52 _o_sharedInstance = [super init];
56 return _o_sharedInstance;
61 [o_currentlyShownCategoryView release];
62 [o_sprefs_toolbar release];
64 [o_hotkeySettings release];
65 [o_hotkeyDescriptions release];
66 [o_hotkeysNonUseableKeys release];
68 if( o_keyInTransition )
69 [o_keyInTransition release];
75 - (NSString *)OSXKeyToString:(int)val
77 NSMutableString *o_temp_str = [[[NSMutableString alloc] init] autorelease];
78 if( val & KEY_MODIFIER_CTRL )
79 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
80 if( val & KEY_MODIFIER_ALT )
81 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
82 if( val & KEY_MODIFIER_SHIFT )
83 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
84 if( val & KEY_MODIFIER_COMMAND )
85 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
87 const char *base = KeyToString( val & ~KEY_MODIFIER );
89 [o_temp_str appendString: [NSString stringWithUTF8String: base]];
91 o_temp_str = @"Unset";
99 /* setup the toolbar */
100 o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
101 [o_sprefs_toolbar setAllowsUserCustomization: NO];
102 [o_sprefs_toolbar setAutosavesConfiguration: NO];
103 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
104 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
105 [o_sprefs_toolbar setDelegate: self];
106 [o_sprefs_win setToolbar: o_sprefs_toolbar];
108 /* setup useful stuff */
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|'w'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
140 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
141 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
145 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
146 itemForItemIdentifier: (NSString *)o_itemIdent
147 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
149 NSToolbarItem *o_toolbarItem = nil;
151 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
152 o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
154 [o_toolbarItem setLabel: o_name]; \
155 [o_toolbarItem setPaletteLabel: o_desc]; \
157 [o_toolbarItem setToolTip: o_desc]; \
158 [o_toolbarItem setImage: [NSImage imageNamed: o_img]]; \
160 [o_toolbarItem setTarget: self]; \
161 [o_toolbarItem setAction: @selector( sel )]; \
163 [o_toolbarItem setEnabled: YES]; \
164 [o_toolbarItem setAutovalidates: YES]
166 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
168 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
170 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
172 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
174 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
176 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
178 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
180 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & OSD Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
182 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
184 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
186 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
188 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
191 return o_toolbarItem;
194 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
196 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
197 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
200 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
202 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
203 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
206 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
208 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
209 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
215 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
216 [o_audio_effects_box setTitle: _NS("Effects")];
217 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
218 [o_audio_general_box setTitle: _NS("General Audio")];
219 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
220 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
221 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
222 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
223 [o_audio_lastuser_txt setStringValue: _NS("User name")];
224 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
225 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
226 [o_audio_visual_txt setStringValue: _NS("Visualization")];
227 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
230 [o_hotkeys_change_btn setTitle: _NS("Change")];
231 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
232 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
233 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
234 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
235 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
236 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
237 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
240 [o_input_access_box setTitle: _NS("Access Filter")];
241 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
242 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
243 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
244 [o_input_caching_box setTitle: _NS("Caching")];
245 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
246 [o_input_dump_ckb setTitle: _NS("Dump")];
247 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
248 [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
249 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
250 [o_input_net_box setTitle: _NS("Network")];
251 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
252 [o_input_record_ckb setTitle: _NS("Record")];
253 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
254 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
255 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
258 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
259 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
260 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
261 [o_intf_lang_txt setStringValue: _NS("Language")];
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_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
279 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
280 [o_video_display_box setTitle: _NS("Display")];
281 [o_video_enable_ckb setTitle: _NS("Enable Video")];
282 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
283 [o_video_onTop_ckb setTitle: _NS("Always on top")];
284 [o_video_output_txt setStringValue: _NS("Output module")];
285 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
286 [o_video_snap_box setTitle: _NS("Video snapshots")];
287 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
288 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
289 [o_video_snap_format_txt setStringValue: _NS("Format")];
290 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
291 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
294 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
295 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
296 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
297 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
298 [o_sprefs_save_btn setTitle: _NS("Save")];
299 [o_sprefs_win setTitle: _NS("Preferences")];
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 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
360 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
362 /**********************
363 * interface settings *
364 **********************/
365 SetupStringList( o_intf_lang_pop, "language" );
366 SetupIntList( o_intf_art_pop, "album-art" );
368 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
369 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
374 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
375 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
376 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
378 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
380 SetupIntList( o_audio_dolby_pop, "force-dolby-surround" );
382 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" )]];
384 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
386 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
388 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
389 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
391 SetupModuleList( o_audio_visual_pop, "audio-visual" );
393 /* Last.FM is optional */
394 if( module_Exists( p_intf, "audioscrobbler" ) )
396 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" )]];
397 [o_audio_lastpwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" )]];
399 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
401 [o_audio_last_ckb setState: NSOnState];
402 [o_audio_lastuser_fld setEnabled: YES];
403 [o_audio_lastpwd_sfld setEnabled: YES];
407 [o_audio_last_ckb setState: NSOffState];
408 [o_audio_lastuser_fld setEnabled: NO];
409 [o_audio_lastpwd_sfld setEnabled: NO];
413 [o_audio_last_ckb setEnabled: NO];
418 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
419 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
420 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
421 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
422 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
424 SetupModuleList( o_video_output_pop, "vout" );
426 [o_video_device_pop removeAllItems];
428 y = [[NSScreen screens] count];
429 [o_video_device_pop addItemWithTitle: _NS("Default")];
430 [[o_video_device_pop lastItem] setTag: 0];
433 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
434 [o_video_device_pop addItemWithTitle:
435 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
436 (int)s_rect.size.width, (int)s_rect.size.height]];
437 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
440 [o_video_device_pop selectItemAtIndex: 0];
441 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
443 if( config_GetPsz( p_intf, "snapshot-path" ) != NULL )
444 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" )]];
445 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" )]];
446 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
448 p_item = config_FindConfig( VLC_OBJECT(p_intf), "snapshot-format" );
449 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
451 [o_video_snap_format_pop addItemWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]]];
452 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
455 [o_video_snap_format_pop selectItemAtIndex: y];
457 /***************************
458 * input & codecs settings *
459 ***************************/
460 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
461 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
462 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" )]];
463 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
464 [o_input_httpproxypwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy-pwd" )]];
465 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
467 SetupIntList( o_input_avi_pop, "avi-index" );
469 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
471 psz_tmp = config_GetPsz( p_intf, "access-filter" );
474 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
475 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
476 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
477 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
480 [o_input_cachelevel_pop removeAllItems];
481 [o_input_cachelevel_pop addItemsWithTitles:
482 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
483 _NS("High latency"), _NS("Higher latency"), nil]];
484 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
485 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
486 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
487 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
488 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
489 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
491 #define TestCaC( name ) \
492 b_cache_equal = b_cache_equal && \
493 ( i_cache == config_GetInt( p_intf, name ) )
495 #define TestCaCi( name, int ) \
496 b_cache_equal = b_cache_equal && \
497 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
499 /* Select the accurate value of the PopupButton */
500 bool b_cache_equal = true;
501 int i_cache = config_GetInt( p_intf, "file-caching");
503 TestCaC( "udp-caching" );
504 if( module_Exists (p_intf, "dvdread") )
505 TestCaC( "dvdread-caching" );
506 if( module_Exists (p_intf, "dvdnav") )
507 TestCaC( "dvdnav-caching" );
508 TestCaC( "tcp-caching" );
509 TestCaC( "fake-caching" );
510 TestCaC( "cdda-caching" );
511 TestCaC( "screen-caching" );
512 TestCaC( "vcd-caching" );
513 TestCaCi( "rtsp-caching", 4 );
514 TestCaCi( "ftp-caching", 2 );
515 TestCaCi( "http-caching", 4 );
516 if(module_Exists (p_intf, "access_realrtsp"))
517 TestCaCi( "realrtsp-caching", 10 );
518 TestCaCi( "mms-caching", 19 );
521 [o_input_cachelevel_pop selectItemWithTag: i_cache];
522 [o_input_cachelevel_custom_txt setHidden: YES];
526 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
527 [o_input_cachelevel_custom_txt setHidden: NO];
530 /*********************
531 * subtitle settings *
532 *********************/
533 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
535 [o_osd_encoding_pop removeAllItems];
537 p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
538 for( i = 0; p_item->ppsz_list[i] != nil; i++ )
540 if( p_item->ppsz_list[i] != "" )
541 [o_osd_encoding_pop addItemWithTitle: _NS( p_item->ppsz_list[i] )];
543 [o_osd_encoding_pop addItemWithTitle: @" "];
545 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
548 [o_osd_encoding_pop selectItemAtIndex: y];
550 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" )]];
551 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
552 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" )]];
554 SetupIntList( o_osd_font_color_pop, "freetype-color" );
555 SetupIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
556 SetupIntList( o_osd_font_effect_pop, "freetype-effect" );
558 /********************
560 ********************/
561 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
562 o_hotkeySettings = [[NSMutableArray alloc] init];
563 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
568 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
572 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
573 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
577 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
578 [o_tempArray_desc release];
579 [o_hotkeys_listbox reloadData];
582 - (void)showSimplePrefs
584 /* we want to show the interface settings, if no category was chosen */
585 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
587 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
588 [self showInterfaceSettings];
591 [self resetControls];
593 [o_sprefs_win center];
594 [o_sprefs_win makeKeyAndOrderFront: self];
597 - (IBAction)buttonAction:(id)sender
599 if( sender == o_sprefs_cancel_btn )
600 [o_sprefs_win orderOut: sender];
601 else if( sender == o_sprefs_save_btn )
603 [self saveChangedSettings];
604 [o_sprefs_win orderOut: sender];
606 else if( sender == o_sprefs_reset_btn )
607 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
608 _NS("Continue"), nil, o_sprefs_win, self,
609 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
610 _NS("Beware this will reset the VLC media player preferences.\n"
611 "Are you sure you want to continue?") );
612 else if( sender == o_sprefs_basicFull_matrix )
614 [o_sprefs_win orderOut: self];
615 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
616 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
617 [[[VLCMain sharedInstance] getPreferences] showPrefs];
620 msg_Warn( p_intf, "unknown buttonAction sender" );
623 - (void)sheetDidEnd:(NSWindow *)o_sheet
624 returnCode:(int)i_return
625 contextInfo:(void *)o_context
627 if( i_return == NSAlertAlternateReturn )
629 config_ResetAll( p_intf );
630 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
631 [self resetControls];
635 - (void)saveChangedSettings
637 module_config_t *p_item;
643 #define SaveIntList( object, name ) \
644 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
645 if( [object indexOfSelectedItem] >= 0 ) \
646 config_PutInt( p_intf, name, p_item->pi_list[[object indexOfSelectedItem]] ); \
648 config_PutInt( p_intf, name, [object intValue] ) \
650 #define SaveStringList( object, name ) \
651 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
652 if( [object indexOfSelectedItem] >= 0 ) \
653 config_PutPsz( p_intf, name, strdup( p_item->ppsz_list[[object indexOfSelectedItem]] ) ); \
655 config_PutPsz( p_intf, name, strdup( [[VLCMain sharedInstance] delocalizeString: [object stringValue]] ) )
657 #define SaveModuleList( object, name ) \
658 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
660 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
661 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
663 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
665 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
667 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
669 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
674 vlc_list_release( p_list ); \
675 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
676 config_PutPsz( p_intf, name, "" )
678 /**********************
679 * interface settings *
680 **********************/
681 if( b_intfSettingChanged )
683 SaveStringList( o_intf_lang_pop, "language" );
684 SaveIntList( o_intf_art_pop, "album-art" );
686 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
687 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
689 /* okay, let's save our changes to vlcrc */
690 i = config_SaveConfigFile( p_intf, "main" );
691 i = i + config_SaveConfigFile( p_intf, "macosx" );
695 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
696 intf_UserFatal( p_intf, false, _("Interface Settings not saved"),
697 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
701 b_intfSettingChanged = NO;
707 if( b_audioSettingChanged )
709 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
710 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
711 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
713 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
715 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
716 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
718 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
720 config_PutPsz( p_intf, "audio-filter", "volnorm" );
721 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
723 /* work-around a GCC 4.0.1 bug */
724 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
725 config_PutPsz( p_intf, "audio-filter", psz_tmp );
729 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
730 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
731 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
732 config_PutPsz( p_intf, "audio-filter", psz_tmp );
734 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
736 SaveModuleList( o_audio_visual_pop, "audio-visual" );
738 /* Last.FM is optional */
739 if( module_Exists( p_intf, "audioscrobbler" ) )
741 [o_audio_last_ckb setEnabled: YES];
742 if( [o_audio_last_ckb state] == NSOnState )
743 config_AddIntf( p_intf, "audioscrobbler" );
745 config_RemoveIntf( p_intf, "audioscrobbler" );
747 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
748 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
751 [o_audio_last_ckb setEnabled: NO];
753 /* okay, let's save our changes to vlcrc */
754 i = config_SaveConfigFile( p_intf, "main" );
755 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
756 i = i + config_SaveConfigFile( p_intf, "volnorm" );
760 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
761 intf_UserFatal( p_intf, false, _("Audio Settings not saved"),
762 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
766 b_audioSettingChanged = NO;
772 if( b_videoSettingChanged )
774 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
775 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
776 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
777 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
778 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
780 SaveModuleList( o_video_output_pop, "vout" );
781 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
783 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
784 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
785 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
787 if( [o_video_snap_format_pop indexOfSelectedItem] >= 0 )
788 config_PutPsz( p_intf, "snapshot-format", [[[o_video_snap_format_pop selectedItem] title] UTF8String] );
790 i = config_SaveConfigFile( p_intf, "main" );
791 i = i + config_SaveConfigFile( p_intf, "macosx" );
795 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
796 intf_UserFatal( p_intf, false, _("Video Settings not saved"),
797 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
800 b_videoSettingChanged = NO;
803 /***************************
804 * input & codecs settings *
805 ***************************/
806 if( b_inputSettingChanged )
808 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
809 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
810 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
811 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
813 SaveIntList( o_input_avi_pop, "avi-index" );
815 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
817 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
818 #define CaC( name ) CaCi( name, 1 )
819 msg_Dbg( p_intf, "Adjusting all cache values to: %i", [[o_input_cachelevel_pop selectedItem] tag] );
820 CaC( "udp-caching" );
821 if( module_Exists (p_intf, "dvdread" ) )
823 CaC( "dvdread-caching" );
824 i = i + config_SaveConfigFile( p_intf, "dvdread" );
826 if( module_Exists (p_intf, "dvdnav" ) )
828 CaC( "dvdnav-caching" );
829 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
831 CaC( "tcp-caching" ); CaC( "vcd-caching" );
832 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
833 CaC( "screen-caching" );
834 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
835 CaCi( "http-caching", 4 );
836 if( module_Exists (p_intf, "access_realrtsp" ) )
838 CaCi( "realrtsp-caching", 10 );
839 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
841 CaCi( "mms-caching", 19 );
843 #define SaveAccessFilter( object, name ) \
844 if( [object state] == NSOnState ) \
848 [o_temp appendString: name]; \
852 [o_temp appendFormat: @":%@", name]; \
856 NSMutableString *o_temp = [[NSMutableString alloc] init];
857 SaveAccessFilter( o_input_record_ckb, @"record" );
858 SaveAccessFilter( o_input_dump_ckb, @"dump" );
859 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
860 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
861 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
864 i = config_SaveConfigFile( p_intf, "main" );
865 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
866 i = i + config_SaveConfigFile( p_intf, "access_http" );
867 i = i + config_SaveConfigFile( p_intf, "access_file" );
868 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
869 i = i + config_SaveConfigFile( p_intf, "access_fake" );
870 i = i + config_SaveConfigFile( p_intf, "cdda" );
871 i = i + config_SaveConfigFile( p_intf, "screen" );
872 i = i + config_SaveConfigFile( p_intf, "vcd" );
873 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
874 i = i + config_SaveConfigFile( p_intf, "access_mms" );
875 i = i + config_SaveConfigFile( p_intf, "live555" );
879 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
880 intf_UserFatal( p_intf, false, _("Input Settings not saved"),
881 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
884 b_inputSettingChanged = NO;
887 /**********************
888 * subtitles settings *
889 **********************/
890 if( b_osdSettingChanged )
892 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
894 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
895 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
897 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
898 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
900 SaveIntList( o_osd_font_color_pop, "freetype-color" );
901 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
902 SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
904 i = config_SaveConfigFile( p_intf, NULL );
908 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
909 intf_UserFatal( p_intf, false, _("OSD/Subtitle Settings not saved"),
910 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
913 b_osdSettingChanged = NO;
916 /********************
918 ********************/
919 if( b_hotkeyChanged )
921 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
923 while( i < [o_hotkeySettings count] )
925 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
929 i = config_SaveConfigFile( p_intf, "main" );
933 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
934 intf_UserFatal( p_intf, false, _("Hotkeys not saved"),
935 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
938 b_hotkeyChanged = NO;
942 - (void)showSettingsForCategory: (id)o_new_category_view
944 NSRect o_win_rect, o_view_rect, o_old_view_rect;
945 o_win_rect = [o_sprefs_win frame];
946 o_view_rect = [o_new_category_view frame];
948 if( o_currentlyShownCategoryView != nil )
950 /* restore our window's height, if we've shown another category previously */
951 o_old_view_rect = [o_currentlyShownCategoryView frame];
952 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
953 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
955 /* remove our previous category view */
956 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
959 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
961 [o_sprefs_win displayIfNeeded];
962 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
964 [o_new_category_view setFrame: NSMakeRect( 0,
965 [o_sprefs_controls_box frame].size.height,
966 o_view_rect.size.width,
967 o_view_rect.size.height )];
968 [o_new_category_view setNeedsDisplay: YES];
969 [o_new_category_view setAutoresizesSubviews: YES];
970 [[o_sprefs_win contentView] addSubview: o_new_category_view];
972 /* keep our current category for further reference */
973 [o_currentlyShownCategoryView release];
974 o_currentlyShownCategoryView = o_new_category_view;
975 [o_currentlyShownCategoryView retain];
978 - (IBAction)interfaceSettingChanged:(id)sender
980 b_intfSettingChanged = YES;
983 - (void)showInterfaceSettings
985 [self showSettingsForCategory: o_intf_view];
988 - (IBAction)audioSettingChanged:(id)sender
990 if( sender == o_audio_vol_sld )
991 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
993 if( sender == o_audio_vol_fld )
994 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
996 if( sender == o_audio_last_ckb )
998 if( [o_audio_last_ckb state] == NSOnState )
1000 [o_audio_lastpwd_sfld setEnabled: YES];
1001 [o_audio_lastuser_fld setEnabled: YES];
1005 [o_audio_lastpwd_sfld setEnabled: NO];
1006 [o_audio_lastuser_fld setEnabled: NO];
1010 b_audioSettingChanged = YES;
1013 - (void)showAudioSettings
1015 [self showSettingsForCategory: o_audio_view];
1018 - (IBAction)videoSettingChanged:(id)sender
1020 if( sender == o_video_snap_folder_btn )
1022 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1023 [o_selectFolderPanel setCanChooseDirectories: YES];
1024 [o_selectFolderPanel setCanChooseFiles: NO];
1025 [o_selectFolderPanel setResolvesAliases: YES];
1026 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1027 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1028 [o_selectFolderPanel setCanCreateDirectories: YES];
1029 [o_selectFolderPanel setPrompt: _NS("Choose")];
1030 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1032 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1033 contextInfo: o_video_snap_folder_btn];
1036 b_videoSettingChanged = YES;
1039 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1041 if( returnCode == NSOKButton )
1043 if( contextInfo == o_video_snap_folder_btn )
1045 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1046 b_videoSettingChanged = YES;
1048 else if( contextInfo == o_osd_font_btn )
1050 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1051 b_osdSettingChanged = YES;
1055 [o_selectFolderPanel release];
1058 - (void)showVideoSettings
1060 [self showSettingsForCategory: o_video_view];
1063 - (IBAction)osdSettingChanged:(id)sender
1065 if( sender == o_osd_font_btn )
1067 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1068 [o_selectFolderPanel setCanChooseDirectories: NO];
1069 [o_selectFolderPanel setCanChooseFiles: YES];
1070 [o_selectFolderPanel setResolvesAliases: YES];
1071 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1072 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1073 [o_selectFolderPanel setCanCreateDirectories: NO];
1074 [o_selectFolderPanel setPrompt: _NS("Choose")];
1075 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1076 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1078 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1079 contextInfo: o_osd_font_btn];
1082 b_osdSettingChanged = YES;
1085 - (void)showOSDSettings
1087 [self showSettingsForCategory: o_osd_view];
1090 - (IBAction)inputSettingChanged:(id)sender
1092 if( sender == o_input_cachelevel_pop )
1094 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1095 [o_input_cachelevel_custom_txt setHidden: NO];
1097 [o_input_cachelevel_custom_txt setHidden: YES];
1100 b_inputSettingChanged = YES;
1103 - (void)showInputSettings
1105 [self showSettingsForCategory: o_input_view];
1108 - (IBAction)hotkeySettingChanged:(id)sender
1110 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1112 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1113 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1114 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1115 [o_hotkeys_change_taken_lbl setStringValue: @""];
1116 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1117 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1118 [NSApp runModalForWindow: o_hotkeys_change_win];
1120 else if( sender == o_hotkeys_change_cancel_btn )
1123 [o_hotkeys_change_win close];
1125 else if( sender == o_hotkeys_change_ok_btn )
1128 if(! o_keyInTransition )
1131 [o_hotkeys_change_win close];
1132 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1136 b_hotkeyChanged = YES;
1138 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1139 if( i_returnValue != NSNotFound )
1140 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1142 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1145 [o_hotkeys_change_win close];
1147 [o_hotkeys_listbox reloadData];
1149 else if( sender == o_hotkeys_clear_btn )
1151 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1152 [o_hotkeys_listbox reloadData];
1153 b_hotkeyChanged = YES;
1157 - (void)showHotkeySettings
1159 [self showSettingsForCategory: o_hotkeys_view];
1162 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1164 return [o_hotkeySettings count];
1167 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1169 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1170 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1171 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1172 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1175 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1180 - (void)changeHotkeyTo: (int)i_theNewKey
1183 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1184 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1186 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1187 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1188 [o_hotkeys_change_ok_btn setEnabled: NO];
1193 if( o_keyInTransition )
1194 [o_keyInTransition release];
1195 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1197 o_temp = [self OSXKeyToString: i_theNewKey];
1199 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1201 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1202 if( i_returnValue != NSNotFound )
1203 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1204 _NS("This combination is already taken by \"%@\"."),
1205 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1207 [o_hotkeys_change_taken_lbl setStringValue: @""];
1209 [o_hotkeys_change_ok_btn setEnabled: YES];
1215 /********************
1216 * hotkeys settings *
1217 ********************/
1219 @implementation VLCHotkeyChangeWindow
1221 - (BOOL)resignFirstResponder
1223 /* We need to stay the first responder or we'll miss the user's input */
1227 - (void)keyDown:(NSEvent *)o_theEvent
1229 int i_nonReadableKey = 0;
1231 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1232 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1234 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1235 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1237 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1238 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1240 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1241 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1243 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1246 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1251 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1253 case NSF1FunctionKey:
1254 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1256 case NSF2FunctionKey:
1257 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1259 case NSF3FunctionKey:
1260 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1262 case NSF4FunctionKey:
1263 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1265 case NSF5FunctionKey:
1266 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1268 case NSF6FunctionKey:
1269 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1271 case NSF7FunctionKey:
1272 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1274 case NSF8FunctionKey:
1275 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1277 case NSF9FunctionKey:
1278 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1280 case NSF10FunctionKey:
1281 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1283 case NSF11FunctionKey:
1284 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1286 case NSF12FunctionKey:
1287 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1289 case NSInsertFunctionKey:
1290 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1292 case NSHomeFunctionKey:
1293 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1295 case NSEndFunctionKey:
1296 i_nonReadableKey = i_nonReadableKey | KEY_END;
1298 case NSPageUpFunctionKey:
1299 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1301 case NSPageDownFunctionKey:
1302 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1304 case NSMenuFunctionKey:
1305 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1307 case NSTabCharacter:
1308 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1310 case NSDeleteCharacter:
1311 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1313 case NSBackspaceCharacter:
1314 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1316 case NSUpArrowFunctionKey:
1317 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1319 case NSDownArrowFunctionKey:
1320 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1322 case NSRightArrowFunctionKey:
1323 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1325 case NSLeftArrowFunctionKey:
1326 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1328 case NSEnterCharacter:
1329 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1333 msg_Warn( VLCIntf, "user pressed unknown function key" );
1334 i_nonReadableKey = 0;
1341 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1342 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1344 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1347 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];