1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008-2013 VLC authors and VideoLAN
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 *****************************************************************************/
27 #import "CompatibilityFixes.h"
28 #import "simple_prefs.h"
31 #import <vlc_interface.h>
32 #import <vlc_dialog.h>
33 #import <vlc_modules.h>
34 #import <vlc_plugin.h>
35 #import <vlc_config_cat.h>
38 #import "AppleRemote.h"
39 #import "CoreInteraction.h"
41 #import <Sparkle/Sparkle.h> //for o_intf_last_update_lbl
43 static NSString* VLCSPrefsToolbarIdentifier = @"Our Simple Preferences Toolbar Identifier";
44 static NSString* VLCIntfSettingToolbarIdentifier = @"Intf Settings Item Identifier";
45 static NSString* VLCAudioSettingToolbarIdentifier = @"Audio Settings Item Identifier";
46 static NSString* VLCVideoSettingToolbarIdentifier = @"Video Settings Item Identifier";
47 static NSString* VLCOSDSettingToolbarIdentifier = @"Subtitles Settings Item Identifier";
48 static NSString* VLCInputSettingToolbarIdentifier = @"Input Settings Item Identifier";
49 static NSString* VLCHotkeysSettingToolbarIdentifier = @"Hotkeys Settings Item Identifier";
51 @implementation VLCSimplePrefs
53 static VLCSimplePrefs *_o_sharedInstance = nil;
55 #pragma mark Initialisation
57 + (VLCSimplePrefs *)sharedInstance
59 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
64 if (_o_sharedInstance)
67 _o_sharedInstance = [super init];
71 return _o_sharedInstance;
76 [o_currentlyShownCategoryView release];
78 [o_hotkeySettings release];
79 [o_hotkeyDescriptions release];
80 [o_hotkeyNames release];
81 [o_hotkeysNonUseableKeys release];
83 [o_keyInTransition release];
92 /* setup the toolbar */
93 NSToolbar * o_sprefs_toolbar = [[[NSToolbar alloc] initWithIdentifier: VLCSPrefsToolbarIdentifier] autorelease];
94 [o_sprefs_toolbar setAllowsUserCustomization: NO];
95 [o_sprefs_toolbar setAutosavesConfiguration: NO];
96 [o_sprefs_toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
97 [o_sprefs_toolbar setSizeMode: NSToolbarSizeModeRegular];
98 [o_sprefs_toolbar setDelegate: self];
99 [o_sprefs_win setToolbar: o_sprefs_toolbar];
101 if (!OSX_SNOW_LEOPARD)
102 [o_sprefs_win setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
104 [o_hotkeys_listbox setTarget:self];
105 [o_hotkeys_listbox setDoubleAction:@selector(hotkeyTableDoubleClick:)];
107 /* setup useful stuff */
108 o_hotkeysNonUseableKeys = [[NSArray arrayWithObjects: @"Command-c", @"Command-x", @"Command-v", @"Command-a", @"Command-," , @"Command-h", @"Command-Alt-h", @"Command-Shift-o", @"Command-o", @"Command-d", @"Command-n", @"Command-s", @"Command-z", @"Command-l", @"Command-r", @"Command-3", @"Command-m", @"Command-w", @"Command-Shift-w", @"Command-Shift-c", @"Command-Shift-p", @"Command-i", @"Command-e", @"Command-Shift-e", @"Command-b", @"Command-Shift-m", @"Command-Ctrl-m", @"Command-?", @"Command-Alt-?", nil] retain];
111 #define CreateToolbarItem(o_name, o_desc, o_img, sel) \
112 o_toolbarItem = create_toolbar_item(o_itemIdent, o_name, o_desc, o_img, self, @selector(sel));
113 static inline NSToolbarItem *
114 create_toolbar_item(NSString * o_itemIdent, NSString * o_name, NSString * o_desc, NSString * o_img, id target, SEL selector)
116 NSToolbarItem *o_toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: o_itemIdent] autorelease]; \
118 [o_toolbarItem setLabel: o_name];
119 [o_toolbarItem setPaletteLabel: o_desc];
121 [o_toolbarItem setToolTip: o_desc];
122 [o_toolbarItem setImage: [NSImage imageNamed: o_img]];
124 [o_toolbarItem setTarget: target];
125 [o_toolbarItem setAction: selector];
127 [o_toolbarItem setEnabled: YES];
128 [o_toolbarItem setAutovalidates: YES];
130 return o_toolbarItem;
133 - (NSToolbarItem *) toolbar: (NSToolbar *)o_sprefs_toolbar
134 itemForItemIdentifier: (NSString *)o_itemIdent
135 willBeInsertedIntoToolbar: (BOOL)b_willBeInserted
137 NSToolbarItem *o_toolbarItem = nil;
139 if ([o_itemIdent isEqual: VLCIntfSettingToolbarIdentifier]) {
140 CreateToolbarItem(_NS("Interface"), _NS("Interface Settings"), @"spref_cone_Interface_64", showInterfaceSettings);
141 } else if ([o_itemIdent isEqual: VLCAudioSettingToolbarIdentifier]) {
142 CreateToolbarItem(_NS("Audio"), _NS("Audio Settings"), @"spref_cone_Audio_64", showAudioSettings);
143 } else if ([o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier]) {
144 CreateToolbarItem(_NS("Video"), _NS("Video Settings"), @"spref_cone_Video_64", showVideoSettings);
145 } else if ([o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier]) {
146 CreateToolbarItem(_NS(SUBPIC_TITLE), _NS("Subtitle & On Screen Display Settings"), @"spref_cone_Subtitles_64", showOSDSettings);
147 } else if ([o_itemIdent isEqual: VLCInputSettingToolbarIdentifier]) {
148 CreateToolbarItem(_NS(INPUT_TITLE), _NS("Input & Codec Settings"), @"spref_cone_Input_64", showInputSettings);
149 } else if ([o_itemIdent isEqual: VLCHotkeysSettingToolbarIdentifier]) {
150 CreateToolbarItem(_NS("Hotkeys"), _NS("Hotkeys settings"), @"spref_cone_Hotkeys_64", showHotkeySettings);
153 return o_toolbarItem;
156 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
158 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
159 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
162 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
164 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
165 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, NSToolbarFlexibleSpaceItemIdentifier, nil];
168 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
170 return [NSArray arrayWithObjects: VLCIntfSettingToolbarIdentifier, VLCAudioSettingToolbarIdentifier, VLCVideoSettingToolbarIdentifier,
171 VLCOSDSettingToolbarIdentifier, VLCInputSettingToolbarIdentifier, VLCHotkeysSettingToolbarIdentifier, nil];
177 [o_audio_dolby_txt setStringValue: _NS("Force detection of Dolby Surround")];
178 [o_audio_effects_box setTitle: _NS("Effects")];
179 [o_audio_enable_ckb setTitle: _NS("Enable audio")];
180 [o_audio_general_box setTitle: _NS("General Audio")];
181 [o_audio_lang_txt setStringValue: _NS("Preferred Audio language")];
182 [o_audio_last_ckb setTitle: _NS("Enable Last.fm submissions")];
183 [o_audio_lastpwd_txt setStringValue: _NS("Password")];
184 [o_audio_lastuser_txt setStringValue: _NS("User name")];
185 [o_audio_spdif_ckb setTitle: _NS("Use S/PDIF when available")];
186 [o_audio_visual_txt setStringValue: _NS("Visualization")];
187 [o_audio_autosavevol_yes_bcell setTitle: _NS("Keep audio level between sessions")];
188 [o_audio_autosavevol_no_bcell setTitle: _NS("Always reset audio start level to:")];
191 [o_hotkeys_change_btn setTitle: _NS("Change")];
192 [o_hotkeys_change_win setTitle: _NS("Change Hotkey")];
193 [o_hotkeys_change_cancel_btn setTitle: _NS("Cancel")];
194 [o_hotkeys_change_ok_btn setTitle: _NS("OK")];
195 [o_hotkeys_clear_btn setTitle: _NS("Clear")];
196 [o_hotkeys_lbl setStringValue: _NS("Select an action to change the associated hotkey:")];
197 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"action"] headerCell] setStringValue: _NS("Action")];
198 [[[o_hotkeys_listbox tableColumnWithIdentifier: @"shortcut"] headerCell] setStringValue: _NS("Shortcut")];
201 [o_input_record_box setTitle: _NS("Record directory or filename")];
202 [o_input_record_btn setTitle: _NS("Browse...")];
203 [o_input_record_btn setToolTip: _NS("Directory or filename where the records will be stored")];
204 [o_input_avi_txt setStringValue: _NS("Repair AVI Files")];
205 [o_input_cachelevel_txt setStringValue: _NS("Default Caching Level")];
206 [o_input_caching_box setTitle: _NS("Caching")];
207 [o_input_cachelevel_custom_txt setStringValue: _NS("Use the complete preferences to configure custom caching values for each access module.")];
208 [o_input_httpproxy_txt setStringValue: _NS("HTTP Proxy")];
209 [o_input_httpproxypwd_txt setStringValue: _NS("Password for HTTP Proxy")];
210 [o_input_mux_box setTitle: _NS("Codecs / Muxers")];
211 [o_input_net_box setTitle: _NS("Network")];
212 [o_input_avcodec_hw_txt setStringValue: _NS("Hardware Acceleration")];
213 [o_input_postproc_txt setStringValue: _NS("Post-Processing Quality")];
214 [o_input_rtsp_ckb setTitle: _NS("Use RTP over RTSP (TCP)")];
215 [o_input_skipLoop_txt setStringValue: _NS("Skip the loop filter for H.264 decoding")];
216 [o_input_mkv_preload_dir_ckb setTitle: _NS("Preload MKV files in the same directory")];
217 [o_input_urlhandler_btn setTitle: _NS("Edit default application settings for network protocols")];
220 [o_urlhandler_title_txt setStringValue: _NS("Open network streams using the following protocols")];
221 [o_urlhandler_subtitle_txt setStringValue: _NS("Note that these are system-wide settings.")];
222 [o_urlhandler_save_btn setTitle: _NS("Save")];
223 [o_urlhandler_cancel_btn setTitle: _NS("Cancel")];
226 [o_intf_style_txt setStringValue: _NS("Interface style")];
227 [o_intf_style_dark_bcell setTitle: _NS("Dark")];
228 [o_intf_style_bright_bcell setTitle: _NS("Bright")];
229 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
230 [o_intf_embedded_ckb setTitle: _NS("Show video within the main window")];
231 [o_intf_nativefullscreen_ckb setTitle: _NS("Use the native fullscreen mode")];
232 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
233 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
234 [o_intf_appleremote_ckb setTitle: _NS("Control playback with the Apple Remote")];
235 [o_intf_appleremote_sysvol_ckb setTitle: _NS("Control system volume with the Apple Remote")];
236 [o_intf_mediakeys_ckb setTitle: _NS("Control playback with media keys")];
237 [o_intf_update_ckb setTitle: _NS("Automatically check for updates")];
238 [o_intf_last_update_lbl setStringValue: @""];
239 [o_intf_enableGrowl_ckb setTitle: _NS("Enable Growl notifications (on playlist item change)")];
240 [o_intf_autoresize_ckb setTitle: _NS("Resize interface to the native video size")];
241 [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
243 /* Subtitles and OSD */
244 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
245 [o_osd_font_box setTitle: _NS("Display Settings")];
246 [o_osd_font_btn setTitle: _NS("Choose...")];
247 [o_osd_font_color_txt setStringValue: _NS("Font color")];
248 [o_osd_font_size_txt setStringValue: _NS("Font size")];
249 [o_osd_font_txt setStringValue: _NS("Font")];
250 [o_osd_lang_box setTitle: _NS("Subtitle languages")];
251 [o_osd_lang_txt setStringValue: _NS("Preferred subtitle language")];
252 [o_osd_osd_box setTitle: _NS("On Screen Display")];
253 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
254 [o_osd_opacity_txt setStringValue: _NS("Opacity")];
255 [o_osd_forcebold_ckb setTitle: _NS("Force bold")];
256 [o_osd_outline_color_txt setStringValue: _NS("Outline color")];
257 [o_osd_outline_thickness_txt setStringValue: _NS("Outline thickness")];
260 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
261 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
262 [o_video_display_box setTitle: _NS("Display")];
263 [o_video_enable_ckb setTitle: _NS("Enable video")];
264 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
265 [o_video_videodeco_ckb setTitle: _NS("Window decorations")];
266 [o_video_onTop_ckb setTitle: _NS("Always on top")];
267 [o_video_output_txt setStringValue: _NS("Output module")];
268 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
269 [o_video_snap_box setTitle: _NS("Video snapshots")];
270 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
271 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
272 [o_video_snap_format_txt setStringValue: _NS("Format")];
273 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
274 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
275 [o_video_deinterlace_txt setStringValue: _NS("Deinterlace")];
276 [o_video_deinterlace_mode_txt setStringValue: _NS("Deinterlace mode")];
277 [o_video_video_box setTitle: _NS("Video")];
280 [o_sprefs_showAll_btn setTitle: _NS("Show All")];
281 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
282 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
283 [o_sprefs_save_btn setTitle: _NS("Save")];
284 [o_sprefs_win setTitle: _NS("Preferences")];
287 /* TODO: move this part to core */
288 #define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
289 static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_name)
291 module_config_t *p_config;
293 p_config = config_FindConfig(p_this, psz_name);
297 msg_Err(p_this, "option %s does not exist", psz_name);
301 if (p_config->psz_longtext)
302 return p_config->psz_longtext;
303 else if (p_config->psz_text)
304 return p_config->psz_text;
306 msg_Warn(p_this, "option %s does not include any help", psz_name);
312 #pragma mark Setup controls
314 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
316 module_config_t *p_item;
318 [object removeAllItems];
319 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
321 /* serious problem, if no item found */
324 for (int i = 0; i < p_item->list_count; i++) {
326 if (p_item->list_text != NULL)
327 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
328 else if (p_item->list.psz[i] && strcmp(p_item->list.psz[i],"") == 0) {
329 [[object menu] addItem: [NSMenuItem separatorItem]];
332 else if (p_item->list.psz[i])
333 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->list.psz[i]] action:NULL keyEquivalent: @""];
335 msg_Err(p_intf, "item %d of pref %s failed to be created", i, name);
336 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->list.psz[i]]];
337 [[object menu] addItem: [mi autorelease]];
338 if (p_item->value.psz && !strcmp(p_item->value.psz, p_item->list.psz[i]))
339 [object selectItem:[object lastItem]];
341 [object setToolTip: _NS(p_item->psz_longtext)];
344 - (void)setupButton: (NSPopUpButton *)object forIntList: (const char *)name
346 module_config_t *p_item;
348 [object removeAllItems];
349 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
351 /* serious problem, if no item found */
354 for (int i = 0; i < p_item->list_count; i++) {
356 if (p_item->list_text != NULL)
357 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
358 else if (p_item->list.i[i])
359 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
361 msg_Err(p_intf, "item %d of pref %s failed to be created", i, name);
362 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->list.i[i]]];
363 [[object menu] addItem: [mi autorelease]];
364 if (p_item->value.i == p_item->list.i[i])
365 [object selectItem:[object lastItem]];
367 [object setToolTip: _NS(p_item->psz_longtext)];
370 - (void)setupButton: (NSPopUpButton *)object forModuleList: (const char *)name
372 module_config_t *p_item;
373 module_t *p_parser, **p_list;
376 [object removeAllItems];
378 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
380 p_list = module_list_get(&count);
381 if (!p_item ||!p_list) {
382 if (p_list) module_list_free(p_list);
383 msg_Err(p_intf, "serious problem, item or list not found");
387 [object addItemWithTitle: _NS("Default")];
388 for (size_t i_index = 0; i_index < count; i_index++) {
389 p_parser = p_list[i_index];
390 if (module_provides(p_parser, p_item->psz_type)) {
391 [object addItemWithTitle: [NSString stringWithUTF8String: _(module_GetLongName(p_parser)) ?: ""]];
392 if (p_item->value.psz && !strcmp(p_item->value.psz, module_get_name(p_parser, false)))
393 [object selectItem: [object lastItem]];
396 module_list_free(p_list);
397 [object setToolTip: _NS(p_item->psz_longtext)];
400 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
402 [object setState: config_GetInt(p_intf, name)];
403 [object setToolTip: _NS(config_GetLabel(p_intf, name))];
406 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
408 char *psz_tmp = config_GetPsz(p_intf, psz_option);
409 [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
410 [o_object setToolTip: _NS(config_GetLabel(p_intf, psz_option))];
414 - (void)resetControls
416 module_config_t *p_item;
420 /**********************
421 * interface settings *
422 **********************/
423 [self setupButton: o_intf_art_pop forIntList: "album-art"];
425 [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
427 [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
428 BOOL b_correct_sdk = NO;
429 #ifdef MAC_OS_X_VERSION_10_7
432 if (!(b_correct_sdk && !OSX_SNOW_LEOPARD)) {
433 [o_intf_nativefullscreen_ckb setState: NSOffState];
434 [o_intf_nativefullscreen_ckb setEnabled: NO];
437 [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
439 [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
440 [self setupButton: o_intf_appleremote_sysvol_ckb forBoolValue: "macosx-appleremote-sysvol"];
442 [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
443 if ([[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL)
444 [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
446 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
447 psz_tmp = config_GetPsz(p_intf, "control");
449 [o_intf_enableGrowl_ckb setState: (NSInteger)strstr(psz_tmp, "growl")];
452 [o_intf_enableGrowl_ckb setState: NSOffState];
453 if (config_GetInt(p_intf, "macosx-interfacestyle")) {
454 [o_intf_style_dark_bcell setState: YES];
455 [o_intf_style_bright_bcell setState: NO];
457 [o_intf_style_dark_bcell setState: NO];
458 [o_intf_style_bright_bcell setState: YES];
460 [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
461 [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
466 [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
468 if (config_GetInt(p_intf, "volume-save")) {
469 [o_audio_autosavevol_yes_bcell setState: NSOnState];
470 [o_audio_autosavevol_no_bcell setState: NSOffState];
471 [o_audio_vol_fld setEnabled: NO];
472 [o_audio_vol_sld setEnabled: NO];
474 [o_audio_vol_sld setIntValue: 100];
475 [o_audio_vol_fld setIntValue: 100];
477 [o_audio_autosavevol_yes_bcell setState: NSOffState];
478 [o_audio_autosavevol_no_bcell setState: NSOnState];
479 [o_audio_vol_fld setEnabled: YES];
480 [o_audio_vol_sld setEnabled: YES];
482 i = var_InheritInteger(p_intf, "auhal-volume");
483 i = i * 200. / AOUT_VOLUME_MAX;
484 [o_audio_vol_sld setIntValue: i];
485 [o_audio_vol_fld setIntValue: i];
488 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
490 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
491 [self setupField: o_audio_lang_fld forOption: "audio-language"];
493 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
495 /* Last.FM is optional */
496 if (module_exists("audioscrobbler")) {
497 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
498 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
500 if (config_ExistIntf(VLC_OBJECT(p_intf), "audioscrobbler")) {
501 [o_audio_last_ckb setState: NSOnState];
502 [o_audio_lastuser_fld setEnabled: YES];
503 [o_audio_lastpwd_sfld setEnabled: YES];
505 [o_audio_last_ckb setState: NSOffState];
506 [o_audio_lastuser_fld setEnabled: NO];
507 [o_audio_lastpwd_sfld setEnabled: NO];
510 [o_audio_last_ckb setEnabled: NO];
515 [self setupButton: o_video_enable_ckb forBoolValue: "video"];
516 [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
517 [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
518 [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
519 [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
520 [self setupButton: o_video_videodeco_ckb forBoolValue: "video-deco"];
522 [self setupButton: o_video_output_pop forModuleList: "vout"];
524 [o_video_device_pop removeAllItems];
526 y = [[NSScreen screens] count];
527 [o_video_device_pop addItemWithTitle: _NS("Default")];
528 [[o_video_device_pop lastItem] setTag: 0];
530 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
531 [o_video_device_pop addItemWithTitle:
532 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
533 (int)s_rect.size.width, (int)s_rect.size.height]];
534 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
537 [o_video_device_pop selectItemAtIndex: 0];
538 [o_video_device_pop selectItemWithTag: config_GetInt(p_intf, "macosx-vdev")];
540 [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
541 [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
542 [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
543 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
544 [self setupButton: o_video_deinterlace_pop forIntList: "deinterlace"];
545 [self setupButton: o_video_deinterlace_mode_pop forStringList: "deinterlace-mode"];
547 /***************************
548 * input & codecs settings *
549 ***************************/
550 [self setupField: o_input_record_fld forOption:"input-record-path"];
551 [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
552 [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
553 [o_input_postproc_fld setIntValue: config_GetInt(p_intf, "postproc-q")];
554 [o_input_postproc_fld setToolTip: _NS(config_GetLabel(p_intf, "postproc-q"))];
555 [self setupButton: o_input_avcodec_hw_pop forModuleList: "avcodec-hw"];
557 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
559 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
560 [self setupButton: o_input_skipLoop_pop forIntList: "avcodec-skiploopfilter"];
562 [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
564 [o_input_cachelevel_pop removeAllItems];
565 [o_input_cachelevel_pop addItemsWithTitles:
566 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
567 _NS("High latency"), _NS("Higher latency"), nil]];
568 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
569 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
570 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
571 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
572 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
573 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
575 #define TestCaC(name, factor) \
576 b_cache_equal = b_cache_equal && \
577 (i_cache * factor == config_GetInt(p_intf, name));
579 /* Select the accurate value of the PopupButton */
580 bool b_cache_equal = true;
581 int i_cache = config_GetInt(p_intf, "file-caching");
583 TestCaC("network-caching", 10/3);
584 TestCaC("disc-caching", 1);
585 TestCaC("live-caching", 1);
587 [o_input_cachelevel_pop selectItemWithTag: i_cache];
588 [o_input_cachelevel_custom_txt setHidden: YES];
590 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
591 [o_input_cachelevel_custom_txt setHidden: NO];
595 /*********************
596 * subtitle settings *
597 *********************/
598 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
600 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
601 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
603 [self setupField: o_osd_font_fld forOption: "freetype-font"];
604 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
605 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
606 i = config_GetInt(p_intf, "freetype-opacity") * 100.0 / 255.0 + 0.5;
607 [o_osd_opacity_fld setIntValue: i];
608 [o_osd_opacity_sld setIntValue: i];
609 [o_osd_opacity_sld setToolTip: _NS(config_GetLabel(p_intf, "freetype-opacity"))];
610 [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
611 [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
612 [self setupButton: o_osd_outline_color_pop forIntList: "freetype-outline-color"];
613 [self setupButton: o_osd_outline_thickness_pop forIntList: "freetype-outline-thickness"];
615 /********************
617 ********************/
618 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
619 [o_hotkeySettings release];
620 o_hotkeySettings = [[NSMutableArray alloc] init];
621 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
622 NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
624 /* Get the main Module */
625 module_t *p_main = module_get_main();
628 module_config_t *p_config;
630 p_config = module_config_get (p_main, &confsize);
632 for (size_t i = 0; i < confsize; i++) {
633 module_config_t *p_item = p_config + i;
635 if (CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
636 && !strncmp(p_item->psz_name , "key-", 4)
637 && !EMPTY_STR(p_item->psz_text)) {
638 [o_tempArray_desc addObject: _NS(p_item->psz_text)];
639 [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
640 if (p_item->value.psz)
641 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
643 [o_hotkeySettings addObject: [NSString string]];
646 module_config_free (p_config);
648 [o_hotkeyDescriptions release];
649 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
650 [o_tempArray_desc release];
651 [o_hotkeyNames release];
652 o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
653 [o_tempArray_names release];
654 [o_hotkeys_listbox reloadData];
658 #pragma mark General actions
660 - (void)showSimplePrefs
662 /* we want to show the interface settings, if no category was chosen */
663 if ([[o_sprefs_win toolbar] selectedItemIdentifier] == nil) {
664 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
665 [self showInterfaceSettings];
668 [self resetControls];
670 [o_sprefs_win center];
671 [o_sprefs_win makeKeyAndOrderFront: self];
674 - (void)showSimplePrefsWithLevel:(NSInteger)i_window_level
676 [o_sprefs_win setLevel: i_window_level];
677 [self showSimplePrefs];
680 - (IBAction)buttonAction:(id)sender
682 if (sender == o_sprefs_cancel_btn) {
683 [[NSFontPanel sharedFontPanel] close];
684 [o_sprefs_win orderOut: sender];
685 } else if (sender == o_sprefs_save_btn) {
686 [self saveChangedSettings];
687 [[NSFontPanel sharedFontPanel] close];
688 [o_sprefs_win orderOut: sender];
689 } else if (sender == o_sprefs_reset_btn)
690 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"),
691 _NS("Continue"), nil, o_sprefs_win, self,
692 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, @"%@",
693 _NS("Beware this will reset the VLC media player preferences.\n"
694 "Are you sure you want to continue?"));
695 else if (sender == o_sprefs_showAll_btn) {
696 [o_sprefs_win orderOut: self];
697 [[[VLCMain sharedInstance] preferences] showPrefsWithLevel:[o_sprefs_win level]];
699 msg_Warn(p_intf, "unknown buttonAction sender");
702 - (void)sheetDidEnd:(NSWindow *)o_sheet
703 returnCode:(int)i_return
704 contextInfo:(void *)o_context
706 if (i_return == NSAlertAlternateReturn) {
707 /* reset VLC's config */
708 config_ResetAll(p_intf);
709 [self resetControls];
710 config_SaveConfigFile(p_intf);
712 /* reset OS X defaults */
713 [NSUserDefaults resetStandardUserDefaults];
714 [[NSUserDefaults standardUserDefaults] synchronize];
718 static inline void save_int_list(intf_thread_t * p_intf, id object, const char * name)
720 NSNumber *p_valueobject;
721 module_config_t *p_item;
722 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
723 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
724 assert([p_valueobject isKindOfClass:[NSNumber class]]);
725 if (p_valueobject) config_PutInt(p_intf, name, [p_valueobject intValue]);
728 static inline void save_string_list(intf_thread_t * p_intf, id object, const char * name)
730 NSString *p_stringobject;
731 module_config_t *p_item;
732 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
733 p_stringobject = (NSString *)[[object selectedItem] representedObject];
734 assert([p_stringobject isKindOfClass:[NSString class]]);
735 if (p_stringobject) {
736 config_PutPsz(p_intf, name, [p_stringobject UTF8String]);
740 static inline void save_module_list(intf_thread_t * p_intf, id object, const char * name)
742 module_config_t *p_item;
743 module_t *p_parser, **p_list;
744 NSString * objectTitle = [[object selectedItem] title];
746 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
749 p_list = module_list_get(&count);
750 for (size_t i_module_index = 0; i_module_index < count; i_module_index++) {
751 p_parser = p_list[i_module_index];
753 if (p_item->i_type == CONFIG_ITEM_MODULE && module_provides(p_parser, p_item->psz_type)) {
754 if ([objectTitle isEqualToString: _NS(module_GetLongName(p_parser))]) {
755 config_PutPsz(p_intf, name, strdup(module_get_name(p_parser, false)));
760 module_list_free(p_list);
761 if ([objectTitle isEqualToString: _NS("Default")]) {
762 if (!strcmp(name, "vout"))
763 config_PutPsz(p_intf, name, "");
765 config_PutPsz(p_intf, name, "none");
769 - (void)saveChangedSettings
774 #define SaveIntList(object, name) save_int_list(p_intf, object, name)
776 #define SaveStringList(object, name) save_string_list(p_intf, object, name)
778 #define SaveModuleList(object, name) save_module_list(p_intf, object, name)
780 #define getString(name) [NSString stringWithFormat:@"%s", config_GetPsz(p_intf, name)]
782 /**********************
783 * interface settings *
784 **********************/
785 if (b_intfSettingChanged) {
786 SaveIntList(o_intf_art_pop, "album-art");
788 config_PutInt(p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state]);
789 config_PutInt(p_intf, "embedded-video", [o_intf_embedded_ckb state]);
791 config_PutInt(p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state]);
792 config_PutInt(p_intf, "macosx-appleremote-sysvol", [o_intf_appleremote_sysvol_ckb state]);
793 config_PutInt(p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state]);
794 config_PutInt(p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state]);
795 config_PutInt(p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state]);
796 config_PutInt(p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state]);
797 config_PutInt(p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state]);
798 if ([o_intf_enableGrowl_ckb state] == NSOnState) {
799 tmpString = getString("control");
800 tmpRange = [tmpString rangeOfString:@"growl"];
801 if ([tmpString length] > 0 && tmpRange.location == NSNotFound)
803 tmpString = [tmpString stringByAppendingString: @":growl"];
804 config_PutPsz(p_intf, "control", [tmpString UTF8String]);
807 config_PutPsz(p_intf, "control", "growl");
809 tmpString = getString("control");
810 if (! [tmpString isEqualToString:@""])
812 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
813 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
814 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
815 config_PutPsz(p_intf, "control", [tmpString UTF8String]);
819 /* activate stuff without restart */
820 if ([o_intf_appleremote_ckb state] == YES)
821 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
823 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
824 b_intfSettingChanged = NO;
830 if (b_audioSettingChanged) {
831 config_PutInt(p_intf, "audio", [o_audio_enable_ckb state]);
832 config_PutInt(p_intf, "volume-save", [o_audio_autosavevol_yes_bcell state]);
833 var_SetBool(p_intf, "volume-save", [o_audio_autosavevol_yes_bcell state]);
834 config_PutInt(p_intf, "spdif", [o_audio_spdif_ckb state]);
835 if ([o_audio_vol_fld isEnabled])
836 config_PutInt(p_intf, "auhal-volume", ([o_audio_vol_fld intValue] * AOUT_VOLUME_MAX) / 200);
838 SaveIntList(o_audio_dolby_pop, "force-dolby-surround");
840 config_PutPsz(p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String]);
842 SaveModuleList(o_audio_visual_pop, "audio-visual");
844 /* Last.FM is optional */
845 if (module_exists("audioscrobbler")) {
846 [o_audio_last_ckb setEnabled: YES];
847 if ([o_audio_last_ckb state] == NSOnState)
848 config_AddIntf(p_intf, "audioscrobbler");
850 config_RemoveIntf(p_intf, "audioscrobbler");
852 config_PutPsz(p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String]);
853 config_PutPsz(p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String]);
856 [o_audio_last_ckb setEnabled: NO];
857 b_audioSettingChanged = NO;
863 if (b_videoSettingChanged) {
864 config_PutInt(p_intf, "video", [o_video_enable_ckb state]);
865 config_PutInt(p_intf, "fullscreen", [o_video_fullscreen_ckb state]);
866 config_PutInt(p_intf, "video-deco", [o_video_videodeco_ckb state]);
867 config_PutInt(p_intf, "video-on-top", [o_video_onTop_ckb state]);
868 config_PutInt(p_intf, "skip-frames", [o_video_skipFrames_ckb state]);
869 config_PutInt(p_intf, "macosx-black", [o_video_black_ckb state]);
871 SaveModuleList(o_video_output_pop, "vout");
872 config_PutInt(p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag]);
874 config_PutPsz(p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String]);
875 config_PutPsz(p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String]);
876 config_PutInt(p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state]);
877 SaveStringList(o_video_snap_format_pop, "snapshot-format");
878 SaveIntList(o_video_deinterlace_pop, "deinterlace");
879 SaveStringList(o_video_deinterlace_mode_pop, "deinterlace-mode");
880 b_videoSettingChanged = NO;
883 /***************************
884 * input & codecs settings *
885 ***************************/
886 if (b_inputSettingChanged) {
887 config_PutPsz(p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String]);
888 config_PutPsz(p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String]);
889 config_PutPsz(p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String]);
890 config_PutInt(p_intf, "postproc-q", [o_input_postproc_fld intValue]);
892 SaveIntList(o_input_avi_pop, "avi-index");
894 config_PutInt(p_intf, "rtsp-tcp", [o_input_rtsp_ckb state]);
895 SaveModuleList(o_input_avcodec_hw_pop, "avcodec-hw");
896 SaveIntList(o_input_skipLoop_pop, "avcodec-skiploopfilter");
898 config_PutInt(p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state]);
900 #define CaC(name, factor) config_PutInt(p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor)
901 if ([[o_input_cachelevel_pop selectedItem] tag] == 0) {
902 msg_Dbg(p_intf, "Custom chosen, not adjusting cache values");
904 msg_Dbg(p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag]);
905 CaC("file-caching", 1);
906 CaC("network-caching", 10/3);
907 CaC("disc-caching", 1);
908 CaC("live-caching", 1);
911 b_inputSettingChanged = NO;
914 /**********************
915 * subtitles settings *
916 **********************/
917 if (b_osdSettingChanged) {
918 config_PutInt(p_intf, "osd", [o_osd_osd_ckb state]);
920 if ([o_osd_encoding_pop indexOfSelectedItem] >= 0)
921 SaveStringList(o_osd_encoding_pop, "subsdec-encoding");
923 config_PutPsz(p_intf, "subsdec-encoding", "");
925 config_PutPsz(p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String]);
927 config_PutPsz(p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String]);
928 SaveIntList(o_osd_font_color_pop, "freetype-color");
929 SaveIntList(o_osd_font_size_pop, "freetype-rel-fontsize");
930 config_PutInt(p_intf, "freetype-opacity", [o_osd_opacity_fld intValue] * 255.0 / 100.0 + 0.5);
931 config_PutInt(p_intf, "freetype-bold", [o_osd_forcebold_ckb state]);
932 SaveIntList(o_osd_outline_color_pop, "freetype-outline-color");
933 SaveIntList(o_osd_outline_thickness_pop, "freetype-outline-thickness");
934 b_osdSettingChanged = NO;
937 /********************
939 ********************/
940 if (b_hotkeyChanged) {
941 NSUInteger hotKeyCount = [o_hotkeySettings count];
942 for (NSUInteger i = 0; i < hotKeyCount; i++)
943 config_PutPsz(p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String]);
944 b_hotkeyChanged = NO;
947 [[VLCCoreInteraction sharedInstance] fixPreferences];
949 /* okay, let's save our changes to vlcrc */
950 config_SaveConfigFile(p_intf);
952 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
957 - (void)showSettingsForCategory: (id)o_new_category_view
959 NSRect o_win_rect, o_view_rect, o_old_view_rect;
960 o_win_rect = [o_sprefs_win frame];
961 o_view_rect = [o_new_category_view frame];
963 if (o_currentlyShownCategoryView != nil) {
964 /* restore our window's height, if we've shown another category previously */
965 o_old_view_rect = [o_currentlyShownCategoryView frame];
966 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
967 o_win_rect.origin.y = (o_win_rect.origin.y + o_old_view_rect.size.height) - o_view_rect.size.height;
970 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
972 [o_new_category_view setFrame: NSMakeRect(0,
973 [o_sprefs_controls_box frame].size.height,
974 o_view_rect.size.width,
975 o_view_rect.size.height)];
976 [o_new_category_view setAutoresizesSubviews: YES];
977 if (o_currentlyShownCategoryView) {
978 [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
979 [o_currentlyShownCategoryView release];
980 [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
982 [[o_sprefs_win contentView] addSubview: o_new_category_view];
983 [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
986 /* keep our current category for further reference */
987 o_currentlyShownCategoryView = o_new_category_view;
988 [o_currentlyShownCategoryView retain];
992 #pragma mark Specific actions
994 - (IBAction)interfaceSettingChanged:(id)sender
996 b_intfSettingChanged = YES;
999 - (void)showInterfaceSettings
1001 [self showSettingsForCategory: o_intf_view];
1004 - (IBAction)audioSettingChanged:(id)sender
1006 if (sender == o_audio_vol_sld)
1007 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1009 if (sender == o_audio_vol_fld)
1010 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1012 if (sender == o_audio_last_ckb) {
1013 if ([o_audio_last_ckb state] == NSOnState) {
1014 [o_audio_lastpwd_sfld setEnabled: YES];
1015 [o_audio_lastuser_fld setEnabled: YES];
1017 [o_audio_lastpwd_sfld setEnabled: NO];
1018 [o_audio_lastuser_fld setEnabled: NO];
1022 if (sender == o_audio_autosavevol_matrix) {
1023 BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1024 [o_audio_vol_fld setEnabled: enableVolumeSlider];
1025 [o_audio_vol_sld setEnabled: enableVolumeSlider];
1028 b_audioSettingChanged = YES;
1031 - (void)showAudioSettings
1033 [self showSettingsForCategory: o_audio_view];
1036 - (IBAction)videoSettingChanged:(id)sender
1038 if (sender == o_video_snap_folder_btn) {
1039 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1040 [o_selectFolderPanel setCanChooseDirectories: YES];
1041 [o_selectFolderPanel setCanChooseFiles: NO];
1042 [o_selectFolderPanel setResolvesAliases: YES];
1043 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1044 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1045 [o_selectFolderPanel setCanCreateDirectories: YES];
1046 [o_selectFolderPanel setPrompt: _NS("Choose")];
1047 [o_selectFolderPanel beginSheetModalForWindow: o_sprefs_win completionHandler: ^(NSInteger returnCode) {
1048 if (returnCode == NSOKButton)
1050 [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1051 b_videoSettingChanged = YES;
1054 [o_selectFolderPanel release];
1056 b_videoSettingChanged = YES;
1059 - (void)showVideoSettings
1061 [self showSettingsForCategory: o_video_view];
1064 - (IBAction)osdSettingChanged:(id)sender
1066 if (sender == o_osd_opacity_fld)
1067 [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1069 if (sender == o_osd_opacity_sld)
1070 [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1072 b_osdSettingChanged = YES;
1075 - (void)showOSDSettings
1077 [self showSettingsForCategory: o_osd_view];
1080 - (void)controlTextDidChange:(NSNotification *)o_notification
1082 id notificationObject = [o_notification object];
1083 if (notificationObject == o_audio_lang_fld ||
1084 notificationObject == o_audio_lastpwd_sfld ||
1085 notificationObject == o_audio_lastuser_fld ||
1086 notificationObject == o_audio_vol_fld)
1087 b_audioSettingChanged = YES;
1088 else if (notificationObject == o_input_record_fld ||
1089 notificationObject == o_input_httpproxy_fld ||
1090 notificationObject == o_input_httpproxypwd_sfld ||
1091 notificationObject == o_input_postproc_fld)
1092 b_inputSettingChanged = YES;
1093 else if (notificationObject == o_osd_font_fld ||
1094 notificationObject == o_osd_lang_fld ||
1095 notificationObject == o_osd_opacity_fld)
1096 b_osdSettingChanged = YES;
1097 else if (notificationObject == o_video_snap_folder_fld ||
1098 notificationObject == o_video_snap_prefix_fld)
1099 b_videoSettingChanged = YES;
1102 - (IBAction)showFontPicker:(id)sender
1104 char * font = config_GetPsz(p_intf, "freetype-font");
1105 NSString * fontName = font ? [NSString stringWithUTF8String: font] : nil;
1108 NSFont * font = [NSFont fontWithName:fontName size:0.0];
1109 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1111 [[NSFontManager sharedFontManager] setTarget: self];
1112 [[NSFontPanel sharedFontPanel] orderFront:self];
1115 - (void)changeFont:(id)sender
1117 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1118 [o_osd_font_fld setStringValue:[font fontName]];
1119 [self osdSettingChanged:self];
1122 - (IBAction)inputSettingChanged:(id)sender
1124 if (sender == o_input_cachelevel_pop) {
1125 if ([[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")])
1126 [o_input_cachelevel_custom_txt setHidden: NO];
1128 [o_input_cachelevel_custom_txt setHidden: YES];
1129 } else if (sender == o_input_record_btn) {
1130 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1131 [o_selectFolderPanel setCanChooseDirectories: YES];
1132 [o_selectFolderPanel setCanChooseFiles: YES];
1133 [o_selectFolderPanel setResolvesAliases: YES];
1134 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1135 [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1136 [o_selectFolderPanel setCanCreateDirectories: YES];
1137 [o_selectFolderPanel setPrompt: _NS("Choose")];
1138 [o_selectFolderPanel beginSheetModalForWindow: o_sprefs_win completionHandler: ^(NSInteger returnCode) {
1139 if (returnCode == NSOKButton)
1141 [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1142 b_inputSettingChanged = YES;
1145 [o_selectFolderPanel release];
1150 b_inputSettingChanged = YES;
1153 - (void)showInputSettings
1155 [self showSettingsForCategory: o_input_view];
1158 - (NSString *)bundleIdentifierForApplicationName:(NSString *)appName
1160 NSWorkspace * workspace = [NSWorkspace sharedWorkspace];
1161 NSString * appPath = [workspace fullPathForApplication:appName];
1163 NSBundle * appBundle = [NSBundle bundleWithPath:appPath];
1164 return [appBundle bundleIdentifier];
1169 - (NSString *)applicationNameForBundleIdentifier:(NSString *)bundleIdentifier
1171 return [[[NSFileManager defaultManager] displayNameAtPath:[[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:bundleIdentifier]] stringByDeletingPathExtension];
1174 - (NSImage *)iconForBundleIdentifier:(NSString *)bundleIdentifier
1176 NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
1177 NSSize iconSize = NSMakeSize(16., 16.);
1178 NSImage *icon = [workspace iconForFile:[workspace absolutePathForAppBundleWithIdentifier:bundleIdentifier]];
1179 [icon setSize:iconSize];
1183 - (IBAction)urlHandlerAction:(id)sender
1185 NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
1187 if (sender == o_input_urlhandler_btn) {
1190 NSString *rawhandler;
1191 NSMutableArray *rawHandlers;
1194 #define fillUrlHandlerPopup( protocol, object ) \
1195 handlers = (NSArray *)LSCopyAllHandlersForURLScheme(CFSTR( protocol )); \
1196 rawHandlers = [[NSMutableArray alloc] init]; \
1197 [object removeAllItems]; \
1198 count = [handlers count]; \
1199 for (NSUInteger x = 0; x < count; x++) { \
1200 rawhandler = [handlers objectAtIndex:x]; \
1201 handler = [self applicationNameForBundleIdentifier:rawhandler]; \
1202 if (handler && ![handler isEqualToString:@""]) { \
1203 [object addItemWithTitle:handler]; \
1204 [[object lastItem] setImage: [self iconForBundleIdentifier:[handlers objectAtIndex:x]]]; \
1205 [rawHandlers addObject: rawhandler]; \
1208 [object selectItemAtIndex: [rawHandlers indexOfObject:(id)LSCopyDefaultHandlerForURLScheme(CFSTR( protocol ))]]; \
1209 [rawHandlers release]
1211 fillUrlHandlerPopup( "ftp", o_urlhandler_ftp_pop);
1212 fillUrlHandlerPopup( "mms", o_urlhandler_mms_pop);
1213 fillUrlHandlerPopup( "rtmp", o_urlhandler_rtmp_pop);
1214 fillUrlHandlerPopup( "rtp", o_urlhandler_rtp_pop);
1215 fillUrlHandlerPopup( "rtsp", o_urlhandler_rtsp_pop);
1216 fillUrlHandlerPopup( "sftp", o_urlhandler_sftp_pop);
1217 fillUrlHandlerPopup( "smb", o_urlhandler_smb_pop);
1218 fillUrlHandlerPopup( "udp", o_urlhandler_udp_pop);
1220 #undef fillUrlHandlerPopup
1222 [NSApp beginSheet:o_urlhandler_win modalForWindow:o_sprefs_win modalDelegate:self didEndSelector:NULL contextInfo:nil];
1224 [o_urlhandler_win orderOut:sender];
1225 [NSApp endSheet: o_urlhandler_win];
1227 if (sender == o_urlhandler_save_btn) {
1228 LSSetDefaultHandlerForURLScheme(CFSTR("ftp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_ftp_pop selectedItem] title]]);
1229 LSSetDefaultHandlerForURLScheme(CFSTR("mms"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_mms_pop selectedItem] title]]);
1230 LSSetDefaultHandlerForURLScheme(CFSTR("mmsh"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_mms_pop selectedItem] title]]);
1231 LSSetDefaultHandlerForURLScheme(CFSTR("rtmp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtmp_pop selectedItem] title]]);
1232 LSSetDefaultHandlerForURLScheme(CFSTR("rtp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtp_pop selectedItem] title]]);
1233 LSSetDefaultHandlerForURLScheme(CFSTR("rtsp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_rtsp_pop selectedItem] title]]);
1234 LSSetDefaultHandlerForURLScheme(CFSTR("sftp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_sftp_pop selectedItem] title]]);
1235 LSSetDefaultHandlerForURLScheme(CFSTR("smb"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_smb_pop selectedItem] title]]);
1236 LSSetDefaultHandlerForURLScheme(CFSTR("udp"), (CFStringRef)[self bundleIdentifierForApplicationName:[[o_urlhandler_udp_pop selectedItem] title]]);
1242 #pragma mark Hotkey actions
1244 - (void)hotkeyTableDoubleClick:(id)object
1247 if ([o_hotkeys_listbox clickedRow] >= 0)
1248 [self hotkeySettingChanged:o_hotkeys_listbox];
1251 - (IBAction)hotkeySettingChanged:(id)sender
1253 if (sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox) {
1254 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1255 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1256 [o_hotkeys_change_keys_lbl setStringValue: [[VLCStringUtility sharedInstance] OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1257 [o_hotkeys_change_taken_lbl setStringValue: @""];
1258 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1259 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1260 [NSApp runModalForWindow: o_hotkeys_change_win];
1261 } else if (sender == o_hotkeys_change_cancel_btn) {
1263 [o_hotkeys_change_win close];
1264 } else if (sender == o_hotkeys_change_ok_btn) {
1265 NSInteger i_returnValue;
1266 if (! o_keyInTransition) {
1268 [o_hotkeys_change_win close];
1269 msg_Err(p_intf, "internal error prevented the hotkey switch");
1273 b_hotkeyChanged = YES;
1275 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1276 if (i_returnValue != NSNotFound)
1277 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1278 NSString *tempString;
1279 tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1280 i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1281 if (i_returnValue != NSNotFound)
1282 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1284 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1287 [o_hotkeys_change_win close];
1289 [o_hotkeys_listbox reloadData];
1290 } else if (sender == o_hotkeys_clear_btn) {
1291 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1292 [o_hotkeys_listbox reloadData];
1293 b_hotkeyChanged = YES;
1296 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1301 - (void)showHotkeySettings
1303 [self showSettingsForCategory: o_hotkeys_view];
1306 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1308 return [o_hotkeySettings count];
1311 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1313 NSString * identifier = [aTableColumn identifier];
1315 if ([identifier isEqualToString: @"action"])
1316 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1317 else if ([identifier isEqualToString: @"shortcut"])
1318 return [[VLCStringUtility sharedInstance] OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1320 msg_Err(p_intf, "unknown TableColumn identifier (%s)!", [identifier UTF8String]);
1325 - (BOOL)changeHotkeyTo: (NSString *)theKey
1327 NSInteger i_returnValue, i_returnValue2;
1328 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1330 if (i_returnValue != NSNotFound || [theKey isEqualToString:@""]) {
1331 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1332 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1333 [o_hotkeys_change_ok_btn setEnabled: NO];
1336 [o_hotkeys_change_keys_lbl setStringValue: [[VLCStringUtility sharedInstance] OSXStringKeyToString:theKey]];
1338 i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1339 i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1340 if (i_returnValue != NSNotFound)
1341 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1342 _NS("This combination is already taken by \"%@\"."),
1343 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1344 else if (i_returnValue2 != NSNotFound)
1345 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1346 _NS("This combination is already taken by \"%@\"."),
1347 [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1349 [o_hotkeys_change_taken_lbl setStringValue: @""];
1351 [o_hotkeys_change_ok_btn setEnabled: YES];
1352 [o_keyInTransition release];
1353 o_keyInTransition = theKey;
1354 [o_keyInTransition retain];
1361 /********************
1362 * hotkeys settings *
1363 ********************/
1365 @implementation VLCHotkeyChangeWindow
1367 - (BOOL)acceptsFirstResponder
1372 - (BOOL)becomeFirstResponder
1377 - (BOOL)resignFirstResponder
1379 /* We need to stay the first responder or we'll miss the user's input */
1383 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1385 NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1386 NSString *keyString = [o_theEvent characters];
1388 unichar key = [keyString characterAtIndex:0];
1389 NSUInteger i_modifiers = [o_theEvent modifierFlags];
1392 if (i_modifiers & NSControlKeyMask)
1393 [tempString appendString:@"Ctrl-"];
1394 if (i_modifiers & NSAlternateKeyMask )
1395 [tempString appendString:@"Alt-"];
1396 if (i_modifiers & NSShiftKeyMask)
1397 [tempString appendString:@"Shift-"];
1398 if (i_modifiers & NSCommandKeyMask)
1399 [tempString appendString:@"Command-"];
1401 /* non character keys */
1402 if (key == NSUpArrowFunctionKey)
1403 [tempString appendString:@"Up"];
1404 else if (key == NSDownArrowFunctionKey)
1405 [tempString appendString:@"Down"];
1406 else if (key == NSLeftArrowFunctionKey)
1407 [tempString appendString:@"Left"];
1408 else if (key == NSRightArrowFunctionKey)
1409 [tempString appendString:@"Right"];
1410 else if (key == NSF1FunctionKey)
1411 [tempString appendString:@"F1"];
1412 else if (key == NSF2FunctionKey)
1413 [tempString appendString:@"F2"];
1414 else if (key == NSF3FunctionKey)
1415 [tempString appendString:@"F3"];
1416 else if (key == NSF4FunctionKey)
1417 [tempString appendString:@"F4"];
1418 else if (key == NSF5FunctionKey)
1419 [tempString appendString:@"F5"];
1420 else if (key == NSF6FunctionKey)
1421 [tempString appendString:@"F6"];
1422 else if (key == NSF7FunctionKey)
1423 [tempString appendString:@"F7"];
1424 else if (key == NSF8FunctionKey)
1425 [tempString appendString:@"F8"];
1426 else if (key == NSF9FunctionKey)
1427 [tempString appendString:@"F9"];
1428 else if (key == NSF10FunctionKey)
1429 [tempString appendString:@"F10"];
1430 else if (key == NSF11FunctionKey)
1431 [tempString appendString:@"F11"];
1432 else if (key == NSF12FunctionKey)
1433 [tempString appendString:@"F12"];
1434 else if (key == NSInsertFunctionKey)
1435 [tempString appendString:@"Insert"];
1436 else if (key == NSHomeFunctionKey)
1437 [tempString appendString:@"Home"];
1438 else if (key == NSEndFunctionKey)
1439 [tempString appendString:@"End"];
1440 else if (key == NSPageUpFunctionKey)
1441 [tempString appendString:@"Pageup"];
1442 else if (key == NSPageDownFunctionKey)
1443 [tempString appendString:@"Pagedown"];
1444 else if (key == NSMenuFunctionKey)
1445 [tempString appendString:@"Menu"];
1446 else if (key == NSTabCharacter)
1447 [tempString appendString:@"Tab"];
1448 else if (key == NSCarriageReturnCharacter)
1449 [tempString appendString:@"Enter"];
1450 else if (key == NSEnterCharacter)
1451 [tempString appendString:@"Enter"];
1452 else if (key == NSDeleteCharacter)
1453 [tempString appendString:@"Delete"];
1454 else if (key == NSBackspaceCharacter)
1455 [tempString appendString:@"Backspace"];
1456 else if (key == 0x001B)
1457 [tempString appendString:@"Esc"];
1458 else if (key == ' ')
1459 [tempString appendString:@"Space"];
1460 else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1461 [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1465 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1470 @implementation VLCSimplePrefsWindow
1472 - (BOOL)acceptsFirstResponder
1477 - (void)changeFont:(id)sender
1479 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];