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];
63 [o_hotkeySettings release];
64 [o_hotkeyDescriptions release];
65 [o_hotkeysNonUseableKeys release];
67 [o_keyInTransition release];
73 - (NSString *)OSXKeyToString:(int)val
75 NSMutableString *o_temp_str = [[[NSMutableString alloc] init] autorelease];
76 if( val & KEY_MODIFIER_CTRL )
77 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x83"]];
78 if( val & KEY_MODIFIER_ALT )
79 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\xA5"]];
80 if( val & KEY_MODIFIER_SHIFT )
81 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x87\xA7"]];
82 if( val & KEY_MODIFIER_COMMAND )
83 [o_temp_str appendString: [NSString stringWithUTF8String: "\xE2\x8C\x98"]];
85 const char *base = KeyToString( val & ~KEY_MODIFIER );
87 [o_temp_str appendString: [NSString stringWithUTF8String: base]];
89 o_temp_str = [NSMutableString stringWithString:_NS("Not Set")];
97 /* setup the toolbar */
98 NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
99 [o_sprefs_toolbar setAllowsUserCustomization: NO];
100 [o_sprefs_toolbar setAutosavesConfiguration: NO];
101 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
102 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
103 [o_sprefs_toolbar setDelegate: self];
104 [o_sprefs_win setToolbar: o_sprefs_toolbar];
106 /* setup useful stuff */
107 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects:
108 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'c'],
109 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'x'],
110 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'v'],
111 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'a'],
112 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|','],
113 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'h'],
114 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'h'],
115 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'o'],
116 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'o'],
117 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'d'],
118 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'n'],
119 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'s'],
120 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'z'],
121 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'l'],
122 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'r'],
123 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'0'],
124 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'1'],
125 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'2'],
126 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'3'],
127 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'m'],
128 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'w'],
129 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'w'],
130 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'c'],
131 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'p'],
132 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'i'],
133 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'e'],
134 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'e'],
135 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'b'],
136 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_SHIFT|'m'],
137 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_CTRL|'m'],
138 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|'?'],
139 [NSNumber numberWithInt: KEY_MODIFIER_COMMAND|KEY_MODIFIER_ALT|'?'],
143 #define CreateToolbarItem( o_name, o_desc, o_img, sel ) \
144 o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
145 static inline NSToolbarItem *
146 create_toolbar_item( NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector )
148 NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
150 [o_toolbarItem setLabel: o_name];
151 [o_toolbarItem setPaletteLabel: o_desc];
153 [o_toolbarItem setToolTip: o_desc];
154 [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
156 [o_toolbarItem setTarget: target];
157 [o_toolbarItem setAction: selector];
159 [o_toolbarItem setEnabled: YES];
160 [o_toolbarItem setAutovalidates: YES];
162 return o_toolbarItem;
165 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
166 itemForItemIdentifier: (NSString *)o_itemIdent
167 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
169 NSToolbarItem *o_toolbarItem = nil;
171 if( [o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier] )
173 CreateToolbarItem( _NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings );
175 else if( [o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier] )
177 CreateToolbarItem( _NS("Audio"), _NS("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings );
179 else if( [o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier] )
181 CreateToolbarItem( _NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings );
183 else if( [o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier] )
185 CreateToolbarItem( _NS("Subtitles & OSD"), _NS("Subtitles & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings );
187 else if( [o_itemIdent isEqual: VLCInputSettingToolbarIdentifier] )
189 CreateToolbarItem( _NS("Input & Codecs"), _NS("Input & Codec settings"), @"spref_cone_Input_64", showInputSettings );
191 else if( [o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier] )
193 CreateToolbarItem( _NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings );
196 return o_toolbarItem;
199 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
201 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
202 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
205 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
207 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
208 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
211 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
213 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
214 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
220 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
221 [o_audio_effects_box setTitle: _NS("Effects")];
222 [o_audio_enable_ckb setTitle: _NS("Enable Audio")];
223 [o_audio_general_box setTitle: _NS("General Audio")];
224 [o_audio_headphone_ckb setTitle: _NS("Headphone surround effect")];
225 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
226 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
227 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
228 [o_audio_lastuser_txt setStringValue: _NS("User name")];
229 [o_audio_norm_ckb setTitle: _NS("Volume normalizer")];
230 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
231 [o_audio_visual_txt setStringValue: _NS("Visualization")];
232 [o_audio_vol_txt setStringValue: _NS("Default Volume")];
235 [o_hotkeys_change_btn setTitle: _NS("Change")];
236 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
237 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
238 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
239 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
240 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
241 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
242 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
245 [o_input_access_box setTitle: _NS("Access Filter")];
246 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
247 [o_input_bandwidth_ckb setTitle: _NS("Bandwidth limiter")];
248 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
249 [o_input_caching_box setTitle: _NS("Caching")];
250 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
251 [o_input_dump_ckb setTitle: _NS("Dump")];
252 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
253 [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
254 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
255 [o_input_net_box setTitle: _NS("Network")];
256 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
257 [o_input_record_ckb setTitle: _NS("Record")];
258 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
259 [o_input_serverport_txt setStringValue: _NS("Default Server Port")];
260 [o_input_timeshift_ckb setTitle: _NS("Timeshift")];
263 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
264 [o_intf_embedded_ckb setTitle: _NS("Add controls to the video window")];
265 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
266 [o_intf_lang_txt setStringValue: _NS("Language")];
267 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
269 /* Subtitles and OSD */
270 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
271 [o_osd_font_box setTitle: _NS("Display Settings")];
272 [o_osd_font_btn setTitle: _NS("Browse...")];
273 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
274 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
275 [o_osd_font_txt setStringValue: _NS("Font")];
276 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
277 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
278 [o_osd_osd_box setTitle: _NS("On Screen Display")];
279 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
282 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
283 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
284 [o_video_display_box setTitle: _NS("Display")];
285 [o_video_enable_ckb setTitle: _NS("Enable Video")];
286 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
287 [o_video_onTop_ckb setTitle: _NS("Always on top")];
288 [o_video_output_txt setStringValue: _NS("Output module")];
289 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
290 [o_video_snap_box setTitle: _NS("Video snapshots")];
291 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
292 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
293 [o_video_snap_format_txt setStringValue: _NS("Format")];
294 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
295 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
298 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 0] setStringValue: _NS("Basic")];
299 [[o_sprefs_basicFull_matrix cellAtRow: 0 column: 1] setStringValue: _NS("All")];
300 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
301 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
302 [o_sprefs_save_btn setTitle: _NS("Save")];
303 [o_sprefs_win setTitle: _NS("Preferences")];
306 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
308 module_config_t *p_item;
310 [object removeAllItems];
311 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
313 /* serious problem, if no item found */
316 for( int i = 0; i < p_item->i_list; i++ )
319 if( p_item->ppsz_list_text != NULL )
320 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
321 else if( p_item->ppsz_list[i] && p_item->ppsz_list[i] == "" )
323 [[object menu] addItem: [NSMenuItem separatorItem]];
326 else if( p_item->ppsz_list[i] )
327 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->ppsz_list[i]] action:NULL keyEquivalent: @""];
328 else NSLog( @"item %d of pref %s failed to be created", i, name);
329 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->ppsz_list[i]]];
330 [[object menu] addItem: [mi autorelease]];
331 if( p_item->value.psz && !strcmp( p_item->value.psz, p_item->ppsz_list[i] ) )
332 [object selectItem:[object lastItem]];
334 [object setToolTip: _NS( p_item->psz_longtext )];
337 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
339 module_config_t *p_item;
341 [object removeAllItems];
342 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
344 /* serious problem, if no item found */
347 for( int i = 0; i < p_item->i_list; i++ )
350 if( p_item->ppsz_list_text != NULL)
351 mi = [[NSMenuItem alloc] initWithTitle: _NS( p_item->ppsz_list_text[i] ) action:NULL keyEquivalent: @""];
352 else if( p_item->pi_list[i] )
353 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->pi_list[i]] action:NULL keyEquivalent: @""];
354 else NSLog( @"item %d of pref %s failed to be created", i, name);
355 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->pi_list[i]]];
356 [[object menu] addItem: [mi autorelease]];
357 if( p_item->value.i == p_item->pi_list[i] )
358 [object selectItem:[object lastItem]];
360 [object setToolTip: _NS( p_item->psz_longtext )];
363 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
365 module_config_t *p_item;
370 [object removeAllItems];
372 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
373 p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
374 if( !p_item ||!p_list )
376 if( p_list ) vlc_list_release(p_list);
377 NSLog( @"serious problem, item or list not found" );
381 [object addItemWithTitle: _NS("Default")];
382 for( int i_index = 0; i_index < p_list->i_count; i_index++ )
384 p_parser = (module_t *)p_list->p_values[i_index].p_object;
385 if( p_parser && module_IsCapable( p_parser, p_item->psz_type ) )
387 [object addItemWithTitle: [NSString stringWithUTF8String: module_GetLongName( p_parser ) ?: ""]];
388 if( p_item->value.psz && !strcmp( p_item->value.psz, module_GetObjName( p_parser ) ) )
389 [object selectItem: [object lastItem]];
392 vlc_list_release( p_list );
393 [object setToolTip: _NS(p_item->psz_longtext)];
396 - (void)resetControls
398 module_config_t *p_item;
402 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOnState];
403 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOffState];
405 /**********************
406 * interface settings *
407 **********************/
408 [self setupButton: o_intf_lang_pop forStringList: "language"];
409 [self setupButton: o_intf_art_pop forIntList: "album-art"];
411 [o_intf_fspanel_ckb setState: config_GetInt( p_intf, "macosx-fspanel" )];
412 [o_intf_embedded_ckb setState: config_GetInt( p_intf, "embedded-video" )];
417 [o_audio_enable_ckb setState: config_GetInt( p_intf, "audio" )];
418 [o_audio_vol_fld setIntValue: config_GetInt( p_intf, "volume" )];
419 [o_audio_vol_sld setIntValue: config_GetInt( p_intf, "volume" )];
421 [o_audio_spdif_ckb setState: config_GetInt( p_intf, "spdif" )];
423 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
425 [o_audio_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "audio-language" ) ?: ""]];
427 [o_audio_headphone_ckb setState: config_GetInt( p_intf, "headphone-dolby" )];
429 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
431 [o_audio_norm_ckb setState: (int)strstr( psz_tmp, "normvol" )];
432 [o_audio_norm_fld setFloatValue: config_GetFloat( p_intf, "norm-max-level" )];
434 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
436 /* Last.FM is optional */
437 if( module_Exists( p_intf, "audioscrobbler" ) )
439 [o_audio_lastuser_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-username" ) ?: ""]];
440 [o_audio_lastpwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "lastfm-password" ) ?: ""]];
442 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
444 [o_audio_last_ckb setState: NSOnState];
445 [o_audio_lastuser_fld setEnabled: YES];
446 [o_audio_lastpwd_sfld setEnabled: YES];
450 [o_audio_last_ckb setState: NSOffState];
451 [o_audio_lastuser_fld setEnabled: NO];
452 [o_audio_lastpwd_sfld setEnabled: NO];
456 [o_audio_last_ckb setEnabled: NO];
461 [o_video_enable_ckb setState: config_GetInt( p_intf, "video" )];
462 [o_video_fullscreen_ckb setState: config_GetInt( p_intf, "fullscreen" )];
463 [o_video_onTop_ckb setState: config_GetInt( p_intf, "video-on-top" )];
464 [o_video_skipFrames_ckb setState: config_GetInt( p_intf, "skip-frames" )];
465 [o_video_black_ckb setState: config_GetInt( p_intf, "macosx-black" )];
467 [self setupButton: o_video_output_pop forModuleList: "vout"];
469 [o_video_device_pop removeAllItems];
471 y = [[NSScreen screens] count];
472 [o_video_device_pop addItemWithTitle: _NS("Default")];
473 [[o_video_device_pop lastItem] setTag: 0];
476 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
477 [o_video_device_pop addItemWithTitle:
478 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
479 (int)s_rect.size.width, (int)s_rect.size.height]];
480 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
483 [o_video_device_pop selectItemAtIndex: 0];
484 [o_video_device_pop selectItemWithTag: config_GetInt( p_intf, "macosx-vdev" )];
486 [o_video_snap_folder_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-path" ) ?: ""]];
487 [o_video_snap_prefix_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "snapshot-prefix" ) ?: ""]];
488 [o_video_snap_seqnum_ckb setState: config_GetInt( p_intf, "snapshot-sequential" )];
489 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
491 /***************************
492 * input & codecs settings *
493 ***************************/
494 [o_input_serverport_fld setIntValue: config_GetInt( p_intf, "server-port" )];
495 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
496 [o_input_httpproxy_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy" ) ?: ""]];
497 if( config_GetPsz( p_intf, "http-proxy" ) != NULL )
498 [o_input_httpproxypwd_sfld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "http-proxy-pwd" ) ?: ""]];
499 [o_input_postproc_fld setIntValue: config_GetInt( p_intf, "ffmpeg-pp-q" )];
501 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
503 [o_input_rtsp_ckb setState: config_GetInt( p_intf, "rtsp-tcp" )];
505 psz_tmp = config_GetPsz( p_intf, "access-filter" );
508 [o_input_record_ckb setState: (int)strstr( psz_tmp, "record" )];
509 [o_input_dump_ckb setState: (int)strstr( psz_tmp, "dump" )];
510 [o_input_bandwidth_ckb setState: (int)strstr( psz_tmp, "bandwidth" )];
511 [o_input_timeshift_ckb setState: (int)strstr( psz_tmp, "timeshift" )];
514 [o_input_cachelevel_pop removeAllItems];
515 [o_input_cachelevel_pop addItemsWithTitles:
516 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
517 _NS("High latency"), _NS("Higher latency"), nil]];
518 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
519 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
520 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
521 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
522 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 400];
523 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 500];
525 #define TestCaC( name ) \
526 b_cache_equal = b_cache_equal && \
527 ( i_cache == config_GetInt( p_intf, name ) )
529 #define TestCaCi( name, int ) \
530 b_cache_equal = b_cache_equal && \
531 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
533 /* Select the accurate value of the PopupButton */
534 bool b_cache_equal = true;
535 int i_cache = config_GetInt( p_intf, "file-caching");
537 TestCaC( "udp-caching" );
538 if( module_Exists (p_intf, "dvdread") )
539 TestCaC( "dvdread-caching" );
540 if( module_Exists (p_intf, "dvdnav") )
541 TestCaC( "dvdnav-caching" );
542 TestCaC( "tcp-caching" );
543 TestCaC( "fake-caching" );
544 TestCaC( "cdda-caching" );
545 TestCaC( "screen-caching" );
546 TestCaC( "vcd-caching" );
547 TestCaCi( "rtsp-caching", 4 );
548 TestCaCi( "ftp-caching", 2 );
549 TestCaCi( "http-caching", 4 );
550 if(module_Exists (p_intf, "access_realrtsp"))
551 TestCaCi( "realrtsp-caching", 10 );
552 TestCaCi( "mms-caching", 19 );
555 [o_input_cachelevel_pop selectItemWithTag: i_cache];
556 [o_input_cachelevel_custom_txt setHidden: YES];
560 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
561 [o_input_cachelevel_custom_txt setHidden: NO];
564 /*********************
565 * subtitle settings *
566 *********************/
567 [o_osd_osd_ckb setState: config_GetInt( p_intf, "osd" )];
569 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
571 [o_osd_lang_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "sub-language" ) ?: ""]];
572 if( config_GetPsz( p_intf, "freetype-font" ) != NULL )
573 [o_osd_font_fld setStringValue: [NSString stringWithUTF8String: config_GetPsz( p_intf, "freetype-font" ) ?: ""]];
575 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
576 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
578 /********************
580 ********************/
581 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
582 o_hotkeySettings = [[NSMutableArray alloc] init];
583 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
588 p_item = config_FindConfig( VLC_OBJECT(p_intf), p_hotkeys[i].psz_action );
592 [o_tempArray_desc addObject: _NS( p_item->psz_text )];
593 [o_hotkeySettings addObject: [NSNumber numberWithInt: p_item->value.i]];
597 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
598 [o_tempArray_desc release];
599 [o_hotkeys_listbox reloadData];
602 - (void)showSimplePrefs
604 /* we want to show the interface settings, if no category was chosen */
605 if( [[o_sprefs_win toolbar] selectedItemIdentifier] == nil )
607 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
608 [self showInterfaceSettings];
611 [self resetControls];
613 [o_sprefs_win center];
614 [o_sprefs_win makeKeyAndOrderFront: self];
617 - (IBAction)buttonAction:(id)sender
619 if( sender == o_sprefs_cancel_btn )
620 [o_sprefs_win orderOut: sender];
621 else if( sender == o_sprefs_save_btn )
623 [self saveChangedSettings];
624 [o_sprefs_win orderOut: sender];
626 else if( sender == o_sprefs_reset_btn )
627 NSBeginInformationalAlertSheet( _NS("Reset Preferences"), _NS("Cancel"),
628 _NS("Continue"), nil, o_sprefs_win, self,
629 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
630 _NS("Beware this will reset the VLC media player preferences.\n"
631 "Are you sure you want to continue?") );
632 else if( sender == o_sprefs_basicFull_matrix )
634 [o_sprefs_win orderOut: self];
635 [[o_sprefs_basicFull_matrix cellAtRow:0 column:0] setState: NSOffState];
636 [[o_sprefs_basicFull_matrix cellAtRow:0 column:1] setState: NSOnState];
637 [[[VLCMain sharedInstance] getPreferences] showPrefs];
640 msg_Warn( p_intf, "unknown buttonAction sender" );
643 - (void)sheetDidEnd:(NSWindow *)o_sheet
644 returnCode:(int)i_return
645 contextInfo:(void *)o_context
647 if( i_return == NSAlertAlternateReturn )
649 config_ResetAll( p_intf );
650 b_intfSettingChanged = b_videoSettingChanged = b_audioSettingChanged = YES;
651 [self resetControls];
655 static inline void save_int_list( intf_thread_t * p_intf, id object, const char * name )
657 NSNumber *p_valueobject;
658 module_config_t *p_item;
659 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
660 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
661 assert([p_valueobject isKindOfClass:[NSNumber class]]);
662 if( p_valueobject) config_PutInt( p_intf, name, [p_valueobject intValue] );
665 static inline void save_string_list( intf_thread_t * p_intf, id object, const char * name )
667 NSString *p_stringobject;
668 module_config_t *p_item;
669 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
670 p_stringobject = (NSString *)[[object selectedItem] representedObject];
671 assert([p_stringobject isKindOfClass:[NSString class]]);
672 if( p_stringobject ) config_PutPsz( p_intf, name, [p_stringobject UTF8String] );
675 static inline void save_module_list( intf_thread_t * p_intf, id object, const char * name )
677 module_config_t *p_item;
681 p_item = config_FindConfig( VLC_OBJECT(p_intf), name );
683 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
684 for( int i_module_index = 0; i_module_index < p_list->i_count; i_module_index++ )
686 p_parser = (module_t *)p_list->p_values[i_module_index].p_object;
688 if( p_item->i_type == CONFIG_ITEM_MODULE && module_IsCapable( p_parser, p_item->psz_type ) )
690 if( [[[object selectedItem] title] isEqualToString: _NS( module_GetLongName( p_parser ) )] )
692 config_PutPsz( p_intf, name, strdup( module_GetObjName( p_parser )));
697 vlc_list_release( p_list );
698 if( [[[object selectedItem] title] isEqualToString: _NS( "Default" )] )
699 config_PutPsz( p_intf, name, "" );
702 - (void)saveChangedSettings
706 NSString *p_stringobject;
708 #define SaveIntList( object, name ) save_int_list( p_intf, object, name )
710 #define SaveStringList( object, name ) save_string_list( p_intf, object, name )
712 #define SaveModuleList( object, name ) save_module_list( p_intf, object, name )
714 /**********************
715 * interface settings *
716 **********************/
717 if( b_intfSettingChanged )
719 SaveStringList( o_intf_lang_pop, "language" );
720 SaveIntList( o_intf_art_pop, "album-art" );
722 config_PutInt( p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state] );
723 config_PutInt( p_intf, "embedded-video", [o_intf_embedded_ckb state] );
725 /* okay, let's save our changes to vlcrc */
726 i = config_SaveConfigFile( p_intf, "main" );
727 i = i + config_SaveConfigFile( p_intf, "macosx" );
731 msg_Err( p_intf, "An error occurred while saving the Interface settings using SimplePrefs (%i)", i );
732 intf_UserFatal( p_intf, false, _("Interface Settings not saved"),
733 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
737 b_intfSettingChanged = NO;
743 if( b_audioSettingChanged )
745 config_PutInt( p_intf, "audio", [o_audio_enable_ckb state] );
746 config_PutInt( p_intf, "volume", [o_audio_vol_sld intValue] );
747 config_PutInt( p_intf, "spdif", [o_audio_spdif_ckb state] );
749 SaveIntList( o_audio_dolby_pop, "force-dolby-surround" );
751 config_PutPsz( p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String] );
752 config_PutInt( p_intf, "headphone-dolby", [o_audio_headphone_ckb state] );
754 psz_tmp = config_GetPsz( p_intf, "audio-filter" );
756 config_PutPsz( p_intf, "audio-filter", "volnorm" );
757 else if( (int)strstr( psz_tmp, "normvol" ) == NO )
759 /* work-around a GCC 4.0.1 bug */
760 psz_tmp = (char *)[[NSString stringWithFormat: @"%s:volnorm", psz_tmp] UTF8String];
761 config_PutPsz( p_intf, "audio-filter", psz_tmp );
765 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":volnorm"]] UTF8String];
766 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm:"]] UTF8String];
767 psz_tmp = (char *)[[[NSString stringWithUTF8String: psz_tmp] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"volnorm"]] UTF8String];
768 config_PutPsz( p_intf, "audio-filter", psz_tmp );
770 config_PutFloat( p_intf, "norm-max-level", [o_audio_norm_fld floatValue] );
772 SaveModuleList( o_audio_visual_pop, "audio-visual" );
774 /* Last.FM is optional */
775 if( module_Exists( p_intf, "audioscrobbler" ) )
777 [o_audio_last_ckb setEnabled: YES];
778 if( [o_audio_last_ckb state] == NSOnState )
779 config_AddIntf( p_intf, "audioscrobbler" );
781 config_RemoveIntf( p_intf, "audioscrobbler" );
783 config_PutPsz( p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String] );
784 config_PutPsz( p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String] );
787 [o_audio_last_ckb setEnabled: NO];
789 /* okay, let's save our changes to vlcrc */
790 i = config_SaveConfigFile( p_intf, "main" );
791 i = i + config_SaveConfigFile( p_intf, "audioscrobbler" );
792 i = i + config_SaveConfigFile( p_intf, "volnorm" );
796 msg_Err( p_intf, "An error occurred while saving the Audio settings using SimplePrefs (%i)", i );
797 intf_UserFatal( p_intf, false, _("Audio Settings not saved"),
798 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
802 b_audioSettingChanged = NO;
808 if( b_videoSettingChanged )
810 config_PutInt( p_intf, "video", [o_video_enable_ckb state] );
811 config_PutInt( p_intf, "fullscreen", [o_video_fullscreen_ckb state] );
812 config_PutInt( p_intf, "video-on-top", [o_video_onTop_ckb state] );
813 config_PutInt( p_intf, "skip-frames", [o_video_skipFrames_ckb state] );
814 config_PutInt( p_intf, "macosx-black", [o_video_black_ckb state] );
816 SaveModuleList( o_video_output_pop, "vout" );
817 config_PutInt( p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag] );
819 config_PutPsz( p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String] );
820 config_PutPsz( p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String] );
821 config_PutInt( p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state] );
822 SaveStringList( o_video_snap_format_pop, "snapshot-format" );
824 i = config_SaveConfigFile( p_intf, "main" );
825 i = i + config_SaveConfigFile( p_intf, "macosx" );
829 msg_Err( p_intf, "An error occurred while saving the Video settings using SimplePrefs (%i)", i );
830 intf_UserFatal( p_intf, false, _("Video Settings not saved"),
831 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
834 b_videoSettingChanged = NO;
837 /***************************
838 * input & codecs settings *
839 ***************************/
840 if( b_inputSettingChanged )
842 config_PutInt( p_intf, "server-port", [o_input_serverport_fld intValue] );
843 config_PutPsz( p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String] );
844 config_PutPsz( p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String] );
845 config_PutInt( p_intf, "ffmpeg-pp-q", [o_input_postproc_fld intValue] );
847 SaveIntList( o_input_avi_pop, "avi-index" );
849 config_PutInt( p_intf, "rtsp-tcp", [o_input_rtsp_ckb state] );
851 #define CaCi( name, int ) config_PutInt( p_intf, name, int * [[o_input_cachelevel_pop selectedItem] tag] )
852 #define CaC( name ) CaCi( name, 1 )
853 msg_Dbg( p_intf, "Adjusting all cache values to: %i", [[o_input_cachelevel_pop selectedItem] tag] );
854 CaC( "udp-caching" );
855 if( module_Exists (p_intf, "dvdread" ) )
857 CaC( "dvdread-caching" );
858 i = i + config_SaveConfigFile( p_intf, "dvdread" );
860 if( module_Exists (p_intf, "dvdnav" ) )
862 CaC( "dvdnav-caching" );
863 i = i + config_SaveConfigFile( p_intf, "dvdnav" );
865 CaC( "tcp-caching" ); CaC( "vcd-caching" );
866 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
867 CaC( "screen-caching" );
868 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
869 CaCi( "http-caching", 4 );
870 if( module_Exists (p_intf, "access_realrtsp" ) )
872 CaCi( "realrtsp-caching", 10 );
873 i = i + config_SaveConfigFile( p_intf, "access_realrtsp" );
875 CaCi( "mms-caching", 19 );
877 #define SaveAccessFilter( object, name ) \
878 if( [object state] == NSOnState ) \
882 [o_temp appendString: name]; \
886 [o_temp appendFormat: @":%@", name]; \
890 NSMutableString *o_temp = [[NSMutableString alloc] init];
891 SaveAccessFilter( o_input_record_ckb, @"record" );
892 SaveAccessFilter( o_input_dump_ckb, @"dump" );
893 SaveAccessFilter( o_input_bandwidth_ckb, @"bandwidth" );
894 SaveAccessFilter( o_input_timeshift_ckb, @"timeshift" );
895 config_PutPsz( p_intf, "access-filter", [o_temp UTF8String] );
898 i = config_SaveConfigFile( p_intf, "main" );
899 i = i + config_SaveConfigFile( p_intf, "ffmpeg" );
900 i = i + config_SaveConfigFile( p_intf, "access_http" );
901 i = i + config_SaveConfigFile( p_intf, "access_file" );
902 i = i + config_SaveConfigFile( p_intf, "access_tcp" );
903 i = i + config_SaveConfigFile( p_intf, "access_fake" );
904 i = i + config_SaveConfigFile( p_intf, "cdda" );
905 i = i + config_SaveConfigFile( p_intf, "screen" );
906 i = i + config_SaveConfigFile( p_intf, "vcd" );
907 i = i + config_SaveConfigFile( p_intf, "access_ftp" );
908 i = i + config_SaveConfigFile( p_intf, "access_mms" );
909 i = i + config_SaveConfigFile( p_intf, "live555" );
910 i = i + config_SaveConfigFile( p_intf, "avi" );
914 msg_Err( p_intf, "An error occurred while saving the Input settings using SimplePrefs (%i)", i );
915 intf_UserFatal( p_intf, false, _("Input Settings not saved"),
916 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
919 b_inputSettingChanged = NO;
922 /**********************
923 * subtitles settings *
924 **********************/
925 if( b_osdSettingChanged )
927 config_PutInt( p_intf, "osd", [o_osd_osd_ckb state] );
929 if( [o_osd_encoding_pop indexOfSelectedItem] >= 0 )
930 config_PutPsz( p_intf, "subsdec-encoding", [[[o_osd_encoding_pop selectedItem] title] UTF8String] );
932 config_PutPsz( p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String] );
933 config_PutPsz( p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String] );
935 SaveIntList( o_osd_font_color_pop, "freetype-color" );
936 SaveIntList( o_osd_font_size_pop, "freetype-rel-fontsize" );
938 i = config_SaveConfigFile( p_intf, NULL );
942 msg_Err( p_intf, "An error occurred while saving the OSD/Subtitle settings using SimplePrefs (%i)", i );
943 intf_UserFatal( p_intf, false, _("On Screen Display/Subtitle Settings not saved"),
944 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
947 b_osdSettingChanged = NO;
950 /********************
952 ********************/
953 if( b_hotkeyChanged )
955 struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
957 while( i < [o_hotkeySettings count] )
959 config_PutInt( p_intf, p_hotkeys[i].psz_action, [[o_hotkeySettings objectAtIndex: i-1] intValue] );
963 i = config_SaveConfigFile( p_intf, "main" );
967 msg_Err( p_intf, "An error occurred while saving the Hotkey settings using SimplePrefs (%i)", i );
968 intf_UserFatal( p_intf, false, _("Hotkeys not saved"),
969 _("An error occured while saving your settings via SimplePrefs (%i)."), i );
972 b_hotkeyChanged = NO;
976 - (void)showSettingsForCategory: (id)o_new_category_view
978 NSRect o_win_rect, o_view_rect, o_old_view_rect;
979 o_win_rect = [o_sprefs_win frame];
980 o_view_rect = [o_new_category_view frame];
982 if( o_currentlyShownCategoryView != nil )
984 /* restore our window's height, if we've shown another category previously */
985 o_old_view_rect = [o_currentlyShownCategoryView frame];
986 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
987 o_win_rect.origin.y = ( o_win_rect.origin.y + o_old_view_rect.size.height ) - o_view_rect.size.height;
989 /* remove our previous category view */
990 [o_currentlyShownCategoryView removeFromSuperviewWithoutNeedingDisplay];
993 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
995 [o_sprefs_win displayIfNeeded];
996 [o_sprefs_win setFrame: o_win_rect display:YES animate: YES];
998 [o_new_category_view setFrame: NSMakeRect( 0,
999 [o_sprefs_controls_box frame].size.height,
1000 o_view_rect.size.width,
1001 o_view_rect.size.height )];
1002 [o_new_category_view setNeedsDisplay: YES];
1003 [o_new_category_view setAutoresizesSubviews: YES];
1004 [[o_sprefs_win contentView] addSubview: o_new_category_view];
1006 /* keep our current category for further reference */
1007 [o_currentlyShownCategoryView release];
1008 o_currentlyShownCategoryView = o_new_category_view;
1009 [o_currentlyShownCategoryView retain];
1012 - (IBAction)interfaceSettingChanged:(id)sender
1014 b_intfSettingChanged = YES;
1017 - (void)showInterfaceSettings
1019 [self showSettingsForCategory: o_intf_view];
1022 - (IBAction)audioSettingChanged:(id)sender
1024 if( sender == o_audio_vol_sld )
1025 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1027 if( sender == o_audio_vol_fld )
1028 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1030 if( sender == o_audio_last_ckb )
1032 if( [o_audio_last_ckb state] == NSOnState )
1034 [o_audio_lastpwd_sfld setEnabled: YES];
1035 [o_audio_lastuser_fld setEnabled: YES];
1039 [o_audio_lastpwd_sfld setEnabled: NO];
1040 [o_audio_lastuser_fld setEnabled: NO];
1044 b_audioSettingChanged = YES;
1047 - (void)showAudioSettings
1049 [self showSettingsForCategory: o_audio_view];
1052 - (IBAction)videoSettingChanged:(id)sender
1054 if( sender == o_video_snap_folder_btn )
1056 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1057 [o_selectFolderPanel setCanChooseDirectories: YES];
1058 [o_selectFolderPanel setCanChooseFiles: NO];
1059 [o_selectFolderPanel setResolvesAliases: YES];
1060 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1061 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1062 [o_selectFolderPanel setCanCreateDirectories: YES];
1063 [o_selectFolderPanel setPrompt: _NS("Choose")];
1064 [o_selectFolderPanel beginSheetForDirectory: nil file: nil modalForWindow: o_sprefs_win
1066 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1067 contextInfo: o_video_snap_folder_btn];
1070 b_videoSettingChanged = YES;
1073 - (void)savePanelDidEnd:(NSOpenPanel * )panel returnCode: (int)returnCode contextInfo: (void *)contextInfo
1075 if( returnCode == NSOKButton )
1077 if( contextInfo == o_video_snap_folder_btn )
1079 [o_video_snap_folder_fld setStringValue: [o_selectFolderPanel filename]];
1080 b_videoSettingChanged = YES;
1082 else if( contextInfo == o_osd_font_btn )
1084 [o_osd_font_fld setStringValue: [o_selectFolderPanel filename]];
1085 b_osdSettingChanged = YES;
1089 [o_selectFolderPanel release];
1092 - (void)showVideoSettings
1094 [self showSettingsForCategory: o_video_view];
1097 - (IBAction)osdSettingChanged:(id)sender
1099 if( sender == o_osd_font_btn )
1101 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1102 [o_selectFolderPanel setCanChooseDirectories: NO];
1103 [o_selectFolderPanel setCanChooseFiles: YES];
1104 [o_selectFolderPanel setResolvesAliases: YES];
1105 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1106 [o_selectFolderPanel setMessage: _NS("Choose the font to display your Subtitles with.")];
1107 [o_selectFolderPanel setCanCreateDirectories: NO];
1108 [o_selectFolderPanel setPrompt: _NS("Choose")];
1109 [o_selectFolderPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"dfont", @"ttf", @"otf", @"FFIL", nil]];
1110 [o_selectFolderPanel beginSheetForDirectory: @"/System/Library/Fonts/" file: nil modalForWindow: o_sprefs_win
1112 didEndSelector: @selector(savePanelDidEnd:returnCode:contextInfo:)
1113 contextInfo: o_osd_font_btn];
1116 b_osdSettingChanged = YES;
1119 - (void)showOSDSettings
1121 [self showSettingsForCategory: o_osd_view];
1124 - (IBAction)inputSettingChanged:(id)sender
1126 if( sender == o_input_cachelevel_pop )
1128 if( [[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")] )
1129 [o_input_cachelevel_custom_txt setHidden: NO];
1131 [o_input_cachelevel_custom_txt setHidden: YES];
1134 b_inputSettingChanged = YES;
1137 - (void)showInputSettings
1139 [self showSettingsForCategory: o_input_view];
1142 - (IBAction)hotkeySettingChanged:(id)sender
1144 if( sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox )
1146 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1147 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1148 [o_hotkeys_change_keys_lbl setStringValue: [self OSXKeyToString:[[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]] intValue]]];
1149 [o_hotkeys_change_taken_lbl setStringValue: @""];
1150 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1151 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1152 [NSApp runModalForWindow: o_hotkeys_change_win];
1154 else if( sender == o_hotkeys_change_cancel_btn )
1157 [o_hotkeys_change_win close];
1159 else if( sender == o_hotkeys_change_ok_btn )
1162 if(! o_keyInTransition )
1165 [o_hotkeys_change_win close];
1166 msg_Err( p_intf, "internal error prevented the hotkey switch" );
1170 b_hotkeyChanged = YES;
1172 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1173 if( i_returnValue != NSNotFound )
1174 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [[NSNumber numberWithInt: 0] retain]];
1176 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1179 [o_hotkeys_change_win close];
1181 [o_hotkeys_listbox reloadData];
1183 else if( sender == o_hotkeys_clear_btn )
1185 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSNumber numberWithInt: 0]];
1186 [o_hotkeys_listbox reloadData];
1187 b_hotkeyChanged = YES;
1191 - (void)showHotkeySettings
1193 [self showSettingsForCategory: o_hotkeys_view];
1196 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1198 return [o_hotkeySettings count];
1201 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1203 if( [[aTableColumn identifier] isEqualToString: @"action"] )
1204 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1205 else if( [[aTableColumn identifier] isEqualToString: @"shortcut"] )
1206 return [self OSXKeyToString: [[o_hotkeySettings objectAtIndex: rowIndex] intValue]];
1209 msg_Err( p_intf, "unknown TableColumn identifier (%s)!", [[aTableColumn identifier] UTF8String] );
1214 - (BOOL)changeHotkeyTo: (int)i_theNewKey
1217 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: [NSNumber numberWithInt: i_theNewKey]];
1218 if( i_returnValue != NSNotFound || i_theNewKey == 0 )
1220 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1221 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1222 [o_hotkeys_change_ok_btn setEnabled: NO];
1228 if( o_keyInTransition )
1229 [o_keyInTransition release];
1230 o_keyInTransition = [[NSNumber numberWithInt: i_theNewKey] retain];
1232 o_temp = [self OSXKeyToString: i_theNewKey];
1234 [o_hotkeys_change_keys_lbl setStringValue: o_temp];
1236 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1237 if( i_returnValue != NSNotFound )
1238 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1239 _NS("This combination is already taken by \"%@\"."),
1240 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1242 [o_hotkeys_change_taken_lbl setStringValue: @""];
1244 [o_hotkeys_change_ok_btn setEnabled: YES];
1251 /********************
1252 * hotkeys settings *
1253 ********************/
1255 @implementation VLCHotkeyChangeWindow
1257 - (BOOL)acceptsFirstResponder
1262 - (BOOL)becomeFirstResponder
1267 - (BOOL)resignFirstResponder
1269 /* We need to stay the first responder or we'll miss the user's input */
1273 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1278 if( [o_theEvent modifierFlags] & NSControlKeyMask )
1279 i_key |= KEY_MODIFIER_CTRL;
1281 if( [o_theEvent modifierFlags] & NSAlternateKeyMask )
1282 i_key |= KEY_MODIFIER_ALT;
1284 if( [o_theEvent modifierFlags] & NSShiftKeyMask )
1285 i_key |= KEY_MODIFIER_SHIFT;
1287 if( [o_theEvent modifierFlags] & NSCommandKeyMask )
1288 i_key |= KEY_MODIFIER_COMMAND;
1290 key = [[[o_theEvent charactersIgnoringModifiers] lowercaseString] characterAtIndex: 0];
1293 i_key |= CocoaKeyToVLC( key );
1294 return [[[VLCMain sharedInstance] getSimplePreferences] changeHotkeyTo: i_key];