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 & On Screen Display 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)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
304 module_config_t *p_item;
306 [object removeAllItems];
307 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
309 /* serious problem, if no item found */
312 for( int i = 0; i < p_item->i_list; i++ )
315 if( p_item->ppsz_list_text != NULL )
316 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
317 else if( p_item->ppsz_list[i] && p_item->ppsz_list[i] == "" )
319 [[object menu] addItem: [NSMenuItem separatorItem]];
322 else if( p_item->ppsz_list[i] )
323 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
324 else NSLog( @"item %d of pref %s failed to be created", i, name);
325 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
326 [[object menu] addItem: [mi autorelease]];
327 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
328 [object selectItem:[object lastItem]];
330 [object setToolTip: _NS( p_item->psz_longtext )];
333 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
335 module_config_t *p_item;
337 [object removeAllItems];
338 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
340 /* serious problem, if no item found */
343 for( int i = 0; i < p_item->i_list; i++ )
346 if( p_item->ppsz_list_text != NULL)
347 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
348 else if( p_item->pi_list[i] )
349 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
350 else NSLog( @"item %d of pref %s failed to be created", i, name);
351 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
352 [[object menu] addItem: [mi autorelease]];
353 if( p_item->value.i == p_item->pi_list[i] )
354 [object selectItem:[object lastItem]];
356 [object setToolTip: _NS( p_item->psz_longtext )];
359 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
361 module_config_t *p_item;
366 [object removeAllItems];
368 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
369 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
370 if( !p_item ||!p_list )
372 if( p_list ) vlc_list_release(p_list);
373 NSLog( @"serious problem, item or list not found" );
377 [object addItemWithTitle: _NS("Default")];
378 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
380 p_parser = (module_t *)p_list->p_values[i_index].p_object;
381 if( p_parser && module_IsCapable( p_parser, p_item->psz_type ) )
383 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
384 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) )
385 [object selectItem: [object lastItem]];
388 vlc_list_release( p_list );
389 [object setToolTip: _NS(p_item->psz_longtext)];
392 - (void)resetControls
394 module_config_t *p_item;
398 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
399 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
401 /**********************
402 * interface settings *
403 **********************/
404 [self setupButton: o_intf_lang_pop forStringList: "language"];
405 [self setupButton: o_intf_art_pop forIntList: "album-art"];
407 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
408 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
413 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
414 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
415 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
417 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
419 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
421 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" ) ?: ""]];
423 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
425 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
427 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
428 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
430 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
432 /* Last.FM is optional */
433 if( module_Exists( p_intf, "audioscrobbler" ) )
435 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" ) ?: ""]];
436 [o_audio_lastpwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" ) ?: ""]];
438 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
440 [o_audio_last_ckb setState: NSOnState];
441 [o_audio_lastuser_fld setEnabled: YES];
442 [o_audio_lastpwd_sfld setEnabled: YES];
446 [o_audio_last_ckb setState: NSOffState];
447 [o_audio_lastuser_fld setEnabled: NO];
448 [o_audio_lastpwd_sfld setEnabled: NO];
452 [o_audio_last_ckb setEnabled: NO];
457 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
458 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
459 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
460 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
461 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
463 [self setupButton: o_video_output_pop forModuleList: "vout"];
465 [o_video_device_pop removeAllItems];
467 y = [[NSScreen screens] count];
468 [o_video_device_pop addItemWithTitle: _NS("Default")];
469 [[o_video_device_pop lastItem] setTag: 0];
472 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
473 [o_video_device_pop addItemWithTitle:
474 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
475 (int)s_rect.size.width, (int)s_rect.size.height]];
476 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
479 [o_video_device_pop selectItemAtIndex: 0];
480 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
482 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" ) ?: ""]];
483 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" ) ?: ""]];
484 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
485 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
487 /***************************
488 * input & codecs settings *
489 ***************************/
490 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
491 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
492 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" ) ?: ""]];
493 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
494 [o_input_httpproxypwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy-pwd" ) ?: ""]];
495 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
497 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
499 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
501 psz_tmp = config_GetPsz( p_intf, "access-filter" );
504 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
505 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
506 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
507 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
510 [o_input_cachelevel_pop removeAllItems];
511 [o_input_cachelevel_pop addItemsWithTitles:
512 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
513 _NS("High latency"), _NS("Higher latency"), nil]];
514 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
515 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
516 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
517 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
518 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
519 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
521 #define TestCaC( name ) \
522 b_cache_equal = b_cache_equal && \
523 ( i_cache == config_GetInt( p_intf, name ) )
525 #define TestCaCi( name, int ) \
526 b_cache_equal = b_cache_equal && \
527 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
529 /* Select the accurate value of the PopupButton */
530 bool b_cache_equal = true;
531 int i_cache = config_GetInt( p_intf, "file-caching");
533 TestCaC( "udp-caching" );
534 if( module_Exists (p_intf, "dvdread") )
535 TestCaC( "dvdread-caching" );
536 if( module_Exists (p_intf, "dvdnav") )
537 TestCaC( "dvdnav-caching" );
538 TestCaC( "tcp-caching" );
539 TestCaC( "fake-caching" );
540 TestCaC( "cdda-caching" );
541 TestCaC( "screen-caching" );
542 TestCaC( "vcd-caching" );
543 TestCaCi( "rtsp-caching", 4 );
544 TestCaCi( "ftp-caching", 2 );
545 TestCaCi( "http-caching", 4 );
546 if(module_Exists (p_intf, "access_realrtsp"))
547 TestCaCi( "realrtsp-caching", 10 );
548 TestCaCi( "mms-caching", 19 );
551 [o_input_cachelevel_pop selectItemWithTag: i_cache];
552 [o_input_cachelevel_custom_txt setHidden: YES];
556 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
557 [o_input_cachelevel_custom_txt setHidden: NO];
560 /*********************
561 * subtitle settings *
562 *********************/
563 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
565 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
567 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" ) ?: ""]];
568 if( config_GetPsz( p_intf, "quartztext-font" ) != NULL )
569 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "quartztext-font" ) ?: ""]];
571 [self setupButton: o_osd_font_color_pop forIntList: "quartztext-color"];
572 [self setupButton: o_osd_font_size_pop forIntList: "quartztext-rel-fontsize"];
573 //[self setupButton: o_osd_font_effect_pop forIntList: "quartztext-effect"];
575 /********************
577 ********************/
578 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
579 o_hotkeySettings = [[NSMutableArray alloc] init];
580 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
585 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
589 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
590 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
594 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
595 [o_tempArray_desc release];
596 [o_hotkeys_listbox reloadData];
599 - (void)showSimplePrefs
601 /* we want to show the interface settings, if no category was chosen */
602 if( [o_sprefs_toolbar selectedItemIdentifier] == nil )
604 [o_sprefs_toolbar setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
605 [self showInterfaceSettings];
608 [self resetControls];
610 [o_sprefs_win center];
611 [o_sprefs_win makeKeyAndOrderFront: self];
614 - (IBAction)buttonAction:(id)sender
616 if( sender == o_sprefs_cancel_btn )
617 [o_sprefs_win orderOut: sender];
618 else if( sender == o_sprefs_save_btn )
620 [self saveChangedSettings];
621 [o_sprefs_win orderOut: sender];
623 else if( sender == o_sprefs_reset_btn )
624 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
625 _NS("Continue"), nil, o_sprefs_win, self,
626 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
627 _NS("Beware this will reset the VLC media player preferences.\n"
628 "Are you sure you want to continue?") );
629 else if( sender == o_sprefs_basicFull_matrix )
631 [o_sprefs_win orderOut: self];
632 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
633 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
634 [[[VLCMain sharedInstance] getPreferences] showPrefs];
637 msg_Warn( p_intf, "unknown buttonAction sender" );
640 - (void)sheetDidEnd:(NSWindow *)o_sheet
641 returnCode:(int)i_return
642 contextInfo:(void *)o_context
644 if( i_return == NSAlertAlternateReturn )
646 config_ResetAll( p_intf );
647 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
648 [self resetControls];
652 - (void)saveChangedSettings
654 module_config_t *p_item;
659 NSNumber *p_valueobject;
660 NSString *p_stringobject;
662 #define SaveIntList( object, name ) \
663 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
664 p_valueobject = (NSNumber *)[[object selectedItem] representedObject]; \
665 if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
667 #define SaveStringList( object, name ) \
668 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
669 p_stringobject = (NSString *)[[object selectedItem] representedObject]; \
670 if( p_stringobject ) config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
672 #define SaveModuleList( object, name ) \
673 p_item = config_FindConfig( VLC_OBJECT(p_intf), name ); \
675 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE ); \
676 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ ) \
678 p_parser = (module_t *)p_list->p_values[i_module_index].p_object; \
680 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) ) \
682 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] ) \
684 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser ))); \
689 vlc_list_release( p_list ); \
690 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] ) \
691 config_PutPsz( p_intf, name, "" )
693 /**********************
694 * interface settings *
695 **********************/
696 if( b_intfSettingChanged )
698 SaveStringList( o_intf_lang_pop, "language" );
699 SaveIntList( o_intf_art_pop, "album-art" );
701 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
702 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
704 /* okay, let's save our changes to vlcrc */
705 i = config_SaveConfigFile( p_intf, "main" );
706 i = i + config_SaveConfigFile( p_intf, "macosx" );
710 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
711 intf_UserFatal( p_intf, false, _("Interface Settings not saved"),
712 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
716 b_intfSettingChanged = NO;
722 if( b_audioSettingChanged )
724 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
725 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
726 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
728 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
730 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
731 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
733 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
735 config_PutPsz( p_intf, "audio-filter", "volnorm" );
736 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
738 /* work-around a GCC 4.0.1 bug */
739 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
740 config_PutPsz( p_intf, "audio-filter", psz_tmp );
744 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
745 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
746 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
747 config_PutPsz( p_intf, "audio-filter", psz_tmp );
749 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
751 SaveModuleList( o_audio_visual_pop, "audio-visual" );
753 /* Last.FM is optional */
754 if( module_Exists( p_intf, "audioscrobbler" ) )
756 [o_audio_last_ckb setEnabled: YES];
757 if( [o_audio_last_ckb state] == NSOnState )
758 config_AddIntf( p_intf, "audioscrobbler" );
760 config_RemoveIntf( p_intf, "audioscrobbler" );
762 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
763 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
766 [o_audio_last_ckb setEnabled: NO];
768 /* okay, let's save our changes to vlcrc */
769 i = config_SaveConfigFile( p_intf, "main" );
770 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
771 i = i + config_SaveConfigFile( p_intf, "volnorm" );
775 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
776 intf_UserFatal( p_intf, false, _("Audio Settings not saved"),
777 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
781 b_audioSettingChanged = NO;
787 if( b_videoSettingChanged )
789 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
790 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
791 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
792 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
793 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
795 SaveModuleList( o_video_output_pop, "vout" );
796 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
798 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
799 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
800 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
801 SaveStringList( o_video_snap_format_pop, "snapshot-format" );
803 i = config_SaveConfigFile( p_intf, "main" );
804 i = i + config_SaveConfigFile( p_intf, "macosx" );
808 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
809 intf_UserFatal( p_intf, false, _("Video Settings not saved"),
810 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
813 b_videoSettingChanged = NO;
816 /***************************
817 * input & codecs settings *
818 ***************************/
819 if( b_inputSettingChanged )
821 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
822 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
823 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
824 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
826 SaveIntList( o_input_avi_pop, "avi-index" );
828 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
830 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
831 #define CaC( name ) CaCi( name, 1 )
832 msg_Dbg( p_intf, "Adjusting all cache values to: %i", [[o_input_cachelevel_pop selectedItem] tag] );
833 CaC( "udp-caching" );
834 if( module_Exists (p_intf, "dvdread" ) )
836 CaC( "dvdread-caching" );
837 i = i + config_SaveConfigFile( p_intf, "dvdread" );
839 if( module_Exists (p_intf, "dvdnav" ) )
841 CaC( "dvdnav-caching" );
842 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
844 CaC( "tcp-caching" ); CaC( "vcd-caching" );
845 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
846 CaC( "screen-caching" );
847 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
848 CaCi( "http-caching", 4 );
849 if( module_Exists (p_intf, "access_realrtsp" ) )
851 CaCi( "realrtsp-caching", 10 );
852 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
854 CaCi( "mms-caching", 19 );
856 #define SaveAccessFilter( object, name ) \
857 if( [object state] == NSOnState ) \
861 [o_temp appendString: name]; \
865 [o_temp appendFormat: @":%@", name]; \
869 NSMutableString *o_temp = [[NSMutableString alloc] init];
870 SaveAccessFilter( o_input_record_ckb, @"record" );
871 SaveAccessFilter( o_input_dump_ckb, @"dump" );
872 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
873 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
874 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
877 i = config_SaveConfigFile( p_intf, "main" );
878 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
879 i = i + config_SaveConfigFile( p_intf, "access_http" );
880 i = i + config_SaveConfigFile( p_intf, "access_file" );
881 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
882 i = i + config_SaveConfigFile( p_intf, "access_fake" );
883 i = i + config_SaveConfigFile( p_intf, "cdda" );
884 i = i + config_SaveConfigFile( p_intf, "screen" );
885 i = i + config_SaveConfigFile( p_intf, "vcd" );
886 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
887 i = i + config_SaveConfigFile( p_intf, "access_mms" );
888 i = i + config_SaveConfigFile( p_intf, "live555" );
892 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
893 intf_UserFatal( p_intf, false, _("Input Settings not saved"),
894 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
897 b_inputSettingChanged = NO;
900 /**********************
901 * subtitles settings *
902 **********************/
903 if( b_osdSettingChanged )
905 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
907 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
908 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
910 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
911 config_PutPsz( p_intf, "quartztext-font", [[o_osd_font_fld stringValue] UTF8String] );
913 SaveIntList( o_osd_font_color_pop, "quartztext-color" );
914 SaveIntList( o_osd_font_size_pop, "quartztext-rel-fontsize" );
915 //SaveIntList( o_osd_font_effect_pop, "freetype-effect" );
917 i = config_SaveConfigFile( p_intf, NULL );
921 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
922 intf_UserFatal( p_intf, false, _("On Screen Display/Subtitle Settings not saved"),
923 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
926 b_osdSettingChanged = NO;
929 /********************
931 ********************/
932 if( b_hotkeyChanged )
934 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
936 while( i < [o_hotkeySettings count] )
938 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
942 i = config_SaveConfigFile( p_intf, "main" );
946 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
947 intf_UserFatal( p_intf, false, _("Hotkeys not saved"),
948 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
951 b_hotkeyChanged = NO;
955 - (void)showSettingsForCategory: (id)o_new_category_view
957 NSRect o_win_rect, o_view_rect, o_old_view_rect;
958 o_win_rect = [o_sprefs_win frame];
959 o_view_rect = [o_new_category_view frame];
961 if( o_currentlyShownCategoryView != nil )
963 /* restore our window's height, if we've shown another category previously */
964 o_old_view_rect = [o_currentlyShownCategoryView frame];
965 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
966 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
968 /* remove our previous category view */
969 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
972 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
974 [o_sprefs_win displayIfNeeded];
975 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
977 [o_new_category_view setFrame: NSMakeRect( 0,
978 [o_sprefs_controls_box frame].size.height,
979 o_view_rect.size.width,
980 o_view_rect.size.height )];
981 [o_new_category_view setNeedsDisplay: YES];
982 [o_new_category_view setAutoresizesSubviews: YES];
983 [[o_sprefs_win contentView] addSubview: o_new_category_view];
985 /* keep our current category for further reference */
986 [o_currentlyShownCategoryView release];
987 o_currentlyShownCategoryView = o_new_category_view;
988 [o_currentlyShownCategoryView retain];
991 - (IBAction)interfaceSettingChanged:(id)sender
993 b_intfSettingChanged = YES;
996 - (void)showInterfaceSettings
998 [self showSettingsForCategory: o_intf_view];
1001 - (IBAction)audioSettingChanged:(id)sender
1003 if( sender == o_audio_vol_sld )
1004 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1006 if( sender == o_audio_vol_fld )
1007 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1009 if( sender == o_audio_last_ckb )
1011 if( [o_audio_last_ckb state] == NSOnState )
1013 [o_audio_lastpwd_sfld setEnabled: YES];
1014 [o_audio_lastuser_fld setEnabled: YES];
1018 [o_audio_lastpwd_sfld setEnabled: NO];
1019 [o_audio_lastuser_fld setEnabled: NO];
1023 b_audioSettingChanged = YES;
1026 - (void)showAudioSettings
1028 [self showSettingsForCategory: o_audio_view];
1031 - (IBAction)videoSettingChanged:(id)sender
1033 if( sender == o_video_snap_folder_btn )
1035 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1036 [o_selectFolderPanel setCanChooseDirectories: YES];
1037 [o_selectFolderPanel setCanChooseFiles: NO];
1038 [o_selectFolderPanel setResolvesAliases: YES];
1039 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1040 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1041 [o_selectFolderPanel setCanCreateDirectories: YES];
1042 [o_selectFolderPanel setPrompt: _NS("Choose")];
1043 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1045 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1046 contextInfo: o_video_snap_folder_btn];
1049 b_videoSettingChanged = YES;
1052 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1054 if( returnCode == NSOKButton )
1056 if( contextInfo == o_video_snap_folder_btn )
1058 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1059 b_videoSettingChanged = YES;
1061 else if( contextInfo == o_osd_font_btn )
1063 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1064 b_osdSettingChanged = YES;
1068 [o_selectFolderPanel release];
1071 - (void)showVideoSettings
1073 [self showSettingsForCategory: o_video_view];
1076 - (IBAction)osdSettingChanged:(id)sender
1078 if( sender == o_osd_font_btn )
1080 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1081 [o_selectFolderPanel setCanChooseDirectories: NO];
1082 [o_selectFolderPanel setCanChooseFiles: YES];
1083 [o_selectFolderPanel setResolvesAliases: YES];
1084 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1085 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1086 [o_selectFolderPanel setCanCreateDirectories: NO];
1087 [o_selectFolderPanel setPrompt: _NS("Choose")];
1088 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1089 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1091 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1092 contextInfo: o_osd_font_btn];
1095 b_osdSettingChanged = YES;
1098 - (void)showOSDSettings
1100 [self showSettingsForCategory: o_osd_view];
1103 - (IBAction)inputSettingChanged:(id)sender
1105 if( sender == o_input_cachelevel_pop )
1107 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1108 [o_input_cachelevel_custom_txt setHidden: NO];
1110 [o_input_cachelevel_custom_txt setHidden: YES];
1113 b_inputSettingChanged = YES;
1116 - (void)showInputSettings
1118 [self showSettingsForCategory: o_input_view];
1121 - (IBAction)hotkeySettingChanged:(id)sender
1123 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1125 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1126 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1127 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1128 [o_hotkeys_change_taken_lbl setStringValue: @""];
1129 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1130 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1131 [NSApp runModalForWindow: o_hotkeys_change_win];
1133 else if( sender == o_hotkeys_change_cancel_btn )
1136 [o_hotkeys_change_win close];
1138 else if( sender == o_hotkeys_change_ok_btn )
1141 if(! o_keyInTransition )
1144 [o_hotkeys_change_win close];
1145 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1149 b_hotkeyChanged = YES;
1151 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1152 if( i_returnValue != NSNotFound )
1153 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1155 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1158 [o_hotkeys_change_win close];
1160 [o_hotkeys_listbox reloadData];
1162 else if( sender == o_hotkeys_clear_btn )
1164 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1165 [o_hotkeys_listbox reloadData];
1166 b_hotkeyChanged = YES;
1170 - (void)showHotkeySettings
1172 [self showSettingsForCategory: o_hotkeys_view];
1175 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
1177 return [o_hotkeySettings count];
1180 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
1182 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1183 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1184 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1185 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1188 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1193 - (void)changeHotkeyTo: (int)i_theNewKey
1196 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1197 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1199 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1200 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1201 [o_hotkeys_change_ok_btn setEnabled: NO];
1206 if( o_keyInTransition )
1207 [o_keyInTransition release];
1208 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1210 o_temp = [self OSXKeyToString: i_theNewKey];
1212 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1214 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1215 if( i_returnValue != NSNotFound )
1216 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1217 _NS("This combination is already taken by \"%@\"."),
1218 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1220 [o_hotkeys_change_taken_lbl setStringValue: @""];
1222 [o_hotkeys_change_ok_btn setEnabled: YES];
1228 /********************
1229 * hotkeys settings *
1230 ********************/
1232 @implementation VLCHotkeyChangeWindow
1234 - (BOOL)resignFirstResponder
1236 /* We need to stay the first responder or we'll miss the user's input */
1240 - (void)keyDown:(NSEvent *)o_theEvent
1242 int i_nonReadableKey = 0;
1244 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1245 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_CTRL;
1247 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1248 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_ALT;
1250 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1251 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_SHIFT;
1253 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1254 i_nonReadableKey = i_nonReadableKey | KEY_MODIFIER_COMMAND;
1256 if( [o_theEvent modifierFlags] & NSFunctionKeyMask )
1259 key = [[o_theEvent charactersIgnoringModifiers] characterAtIndex: 0];
1264 i_nonReadableKey = i_nonReadableKey | KEY_ESC;
1266 case NSF1FunctionKey:
1267 i_nonReadableKey = i_nonReadableKey | KEY_F1;
1269 case NSF2FunctionKey:
1270 i_nonReadableKey = i_nonReadableKey | KEY_F2;
1272 case NSF3FunctionKey:
1273 i_nonReadableKey = i_nonReadableKey | KEY_F3;
1275 case NSF4FunctionKey:
1276 i_nonReadableKey = i_nonReadableKey | KEY_F4;
1278 case NSF5FunctionKey:
1279 i_nonReadableKey = i_nonReadableKey | KEY_F5;
1281 case NSF6FunctionKey:
1282 i_nonReadableKey = i_nonReadableKey | KEY_F6;
1284 case NSF7FunctionKey:
1285 i_nonReadableKey = i_nonReadableKey | KEY_F7;
1287 case NSF8FunctionKey:
1288 i_nonReadableKey = i_nonReadableKey | KEY_F8;
1290 case NSF9FunctionKey:
1291 i_nonReadableKey = i_nonReadableKey | KEY_F9;
1293 case NSF10FunctionKey:
1294 i_nonReadableKey = i_nonReadableKey | KEY_F10;
1296 case NSF11FunctionKey:
1297 i_nonReadableKey = i_nonReadableKey | KEY_F11;
1299 case NSF12FunctionKey:
1300 i_nonReadableKey = i_nonReadableKey | KEY_F12;
1302 case NSInsertFunctionKey:
1303 i_nonReadableKey = i_nonReadableKey | KEY_INSERT;
1305 case NSHomeFunctionKey:
1306 i_nonReadableKey = i_nonReadableKey | KEY_HOME;
1308 case NSEndFunctionKey:
1309 i_nonReadableKey = i_nonReadableKey | KEY_END;
1311 case NSPageUpFunctionKey:
1312 i_nonReadableKey = i_nonReadableKey | KEY_PAGEUP;
1314 case NSPageDownFunctionKey:
1315 i_nonReadableKey = i_nonReadableKey | KEY_PAGEDOWN;
1317 case NSMenuFunctionKey:
1318 i_nonReadableKey = i_nonReadableKey | KEY_MENU;
1320 case NSTabCharacter:
1321 i_nonReadableKey = i_nonReadableKey | KEY_TAB;
1323 case NSDeleteCharacter:
1324 i_nonReadableKey = i_nonReadableKey | KEY_DELETE;
1326 case NSBackspaceCharacter:
1327 i_nonReadableKey = i_nonReadableKey | KEY_BACKSPACE;
1329 case NSUpArrowFunctionKey:
1330 i_nonReadableKey = i_nonReadableKey | KEY_UP;
1332 case NSDownArrowFunctionKey:
1333 i_nonReadableKey = i_nonReadableKey | KEY_DOWN;
1335 case NSRightArrowFunctionKey:
1336 i_nonReadableKey = i_nonReadableKey | KEY_RIGHT;
1338 case NSLeftArrowFunctionKey:
1339 i_nonReadableKey = i_nonReadableKey | KEY_LEFT;
1341 case NSEnterCharacter:
1342 i_nonReadableKey = i_nonReadableKey | KEY_ENTER;
1346 msg_Warn( VLCIntf, "user pressed unknown function key" );
1347 i_nonReadableKey = 0;
1354 if( [[o_theEvent charactersIgnoringModifiers] isEqualToString: @" "] )
1355 i_nonReadableKey = i_nonReadableKey | KEY_SPACE;
1357 i_nonReadableKey = i_nonReadableKey | StringToKey( (char *)[[[o_theEvent charactersIgnoringModifiers] lowercaseString] UTF8String] );
1360 [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_nonReadableKey];