1 /*****************************************************************************
2 * simple_prefs.m: Simple Preferences for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2008-2012 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("General Audio Settings"), @"spref_cone_Audio_64", showAudioSettings);
143 } else if ([o_itemIdent isEqual: VLCVideoSettingToolbarIdentifier]) {
144 CreateToolbarItem(_NS("Video"), _NS("General Video Settings"), @"spref_cone_Video_64", showVideoSettings);
145 } else if ([o_itemIdent isEqual: VLCOSDSettingToolbarIdentifier]) {
146 CreateToolbarItem(_NS(SUBPIC_TITLE), _NS("Subtitles & 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_ckb setTitle: _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")];
219 [o_intf_style_txt setStringValue: _NS("Interface style")];
220 [o_intf_style_dark_bcell setTitle: _NS("Dark")];
221 [o_intf_style_bright_bcell setTitle: _NS("Bright")];
222 [o_intf_art_txt setStringValue: _NS("Album art download policy")];
223 [o_intf_embedded_ckb setTitle: _NS("Show video within the main window")];
224 [o_intf_nativefullscreen_ckb setTitle: _NS("Use the native fullscreen mode on OS X Lion")];
225 [o_intf_fspanel_ckb setTitle: _NS("Show Fullscreen Controller")];
226 [o_intf_network_box setTitle: _NS("Privacy / Network Interaction")];
227 [o_intf_appleremote_ckb setTitle: _NS("Control playback with the Apple Remote")];
228 [o_intf_appleremote_sysvol_ckb setTitle: _NS("Control system volume with the Apple Remote")];
229 [o_intf_mediakeys_ckb setTitle: _NS("Control playback with media keys")];
230 [o_intf_update_ckb setTitle: _NS("Automatically check for updates")];
231 [o_intf_last_update_lbl setStringValue: @""];
232 [o_intf_enableGrowl_ckb setTitle: _NS("Enable Growl notifications (on playlist item change)")];
233 [o_intf_autoresize_ckb setTitle: _NS("Resize interface to the native video size")];
234 [o_intf_pauseminimized_ckb setTitle: _NS("Pause the video playback when minimized")];
236 /* Subtitles and OSD */
237 [o_osd_encoding_txt setStringValue: _NS("Default Encoding")];
238 [o_osd_font_box setTitle: _NS("Display Settings")];
239 [o_osd_font_btn setTitle: _NS("Choose...")];
240 [o_osd_font_color_txt setStringValue: _NS("Font Color")];
241 [o_osd_font_size_txt setStringValue: _NS("Font Size")];
242 [o_osd_font_txt setStringValue: _NS("Font")];
243 [o_osd_lang_box setTitle: _NS("Subtitle Languages")];
244 [o_osd_lang_txt setStringValue: _NS("Preferred Subtitle Language")];
245 [o_osd_osd_box setTitle: _NS("On Screen Display")];
246 [o_osd_osd_ckb setTitle: _NS("Enable OSD")];
247 [o_osd_opacity_txt setStringValue: _NS("Opacity")];
248 [o_osd_forcebold_ckb setTitle: _NS("Force Bold")];
249 [o_osd_outline_color_txt setStringValue: _NS("Outline Color")];
250 [o_osd_outline_thickness_txt setStringValue: _NS("Outline Thickness")];
253 [o_video_black_ckb setTitle: _NS("Black screens in Fullscreen mode")];
254 [o_video_device_txt setStringValue: _NS("Fullscreen Video Device")];
255 [o_video_display_box setTitle: _NS("Display")];
256 [o_video_enable_ckb setTitle: _NS("Enable Video")];
257 [o_video_fullscreen_ckb setTitle: _NS("Fullscreen")];
258 [o_video_videodeco_ckb setTitle: _NS("Window decorations")];
259 [o_video_onTop_ckb setTitle: _NS("Always on top")];
260 [o_video_output_txt setStringValue: _NS("Output module")];
261 [o_video_skipFrames_ckb setTitle: _NS("Skip frames")];
262 [o_video_snap_box setTitle: _NS("Video snapshots")];
263 [o_video_snap_folder_btn setTitle: _NS("Browse...")];
264 [o_video_snap_folder_txt setStringValue: _NS("Folder")];
265 [o_video_snap_format_txt setStringValue: _NS("Format")];
266 [o_video_snap_prefix_txt setStringValue: _NS("Prefix")];
267 [o_video_snap_seqnum_ckb setTitle: _NS("Sequential numbering")];
268 [o_video_deinterlace_txt setStringValue: _NS("Deinterlace")];
269 [o_video_deinterlace_mode_txt setStringValue: _NS("Deinterlace mode")];
270 [o_video_video_box setTitle: _NS("Video")];
273 [o_sprefs_showAll_btn setTitle: _NS("Show All")];
274 [o_sprefs_cancel_btn setTitle: _NS("Cancel")];
275 [o_sprefs_reset_btn setTitle: _NS("Reset All")];
276 [o_sprefs_save_btn setTitle: _NS("Save")];
277 [o_sprefs_win setTitle: _NS("Preferences")];
280 /* TODO: move this part to core */
281 #define config_GetLabel(a,b) __config_GetLabel(VLC_OBJECT(a),b)
282 static inline char * __config_GetLabel(vlc_object_t *p_this, const char *psz_name)
284 module_config_t *p_config;
286 p_config = config_FindConfig(p_this, psz_name);
290 msg_Err(p_this, "option %s does not exist", psz_name);
294 if (p_config->psz_longtext)
295 return p_config->psz_longtext;
296 else if (p_config->psz_text)
297 return p_config->psz_text;
299 msg_Warn(p_this, "option %s does not include any help", psz_name);
305 #pragma mark Setup controls
307 - (void)setupButton: (NSPopUpButton *)object forStringList: (const char *)name
309 module_config_t *p_item;
311 [object removeAllItems];
312 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
314 /* serious problem, if no item found */
317 for (int i = 0; i < p_item->list_count; i++) {
319 if (p_item->list_text != NULL)
320 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
321 else if (p_item->list.psz[i] && strcmp(p_item->list.psz[i],"") == 0) {
322 [[object menu] addItem: [NSMenuItem separatorItem]];
325 else if (p_item->list.psz[i])
326 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithUTF8String: p_item->list.psz[i]] action:NULL keyEquivalent: @""];
328 msg_Err(p_intf, "item %d of pref %s failed to be created", i, name);
329 [mi setRepresentedObject:[NSString stringWithUTF8String: p_item->list.psz[i]]];
330 [[object menu] addItem: [mi autorelease]];
331 if (p_item->value.psz && !strcmp(p_item->value.psz, p_item->list.psz[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->list_count; i++) {
349 if (p_item->list_text != NULL)
350 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
351 else if (p_item->list.i[i])
352 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
354 msg_Err(p_intf, "item %d of pref %s failed to be created", i, name);
355 [mi setRepresentedObject:[NSNumber numberWithInt: p_item->list.i[i]]];
356 [[object menu] addItem: [mi autorelease]];
357 if (p_item->value.i == p_item->list.i[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;
366 module_t *p_parser, **p_list;
369 [object removeAllItems];
371 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
373 p_list = module_list_get(&count);
374 if (!p_item ||!p_list) {
375 if (p_list) module_list_free(p_list);
376 msg_Err(p_intf, "serious problem, item or list not found");
380 [object addItemWithTitle: _NS("Default")];
381 for (size_t i_index = 0; i_index < count; i_index++) {
382 p_parser = p_list[i_index];
383 if (module_provides(p_parser, p_item->psz_type)) {
384 [object addItemWithTitle: [NSString stringWithUTF8String: _(module_GetLongName(p_parser)) ?: ""]];
385 if (p_item->value.psz && !strcmp(p_item->value.psz, module_get_object(p_parser)))
386 [object selectItem: [object lastItem]];
389 module_list_free(p_list);
390 [object setToolTip: _NS(p_item->psz_longtext)];
393 - (void)setupButton: (NSButton *)object forBoolValue: (const char *)name
395 [object setState: config_GetInt(p_intf, name)];
396 [object setToolTip: _NS(config_GetLabel(p_intf, name) ?: "")];
399 - (void)setupField:(NSTextField *)o_object forOption:(const char *)psz_option
401 char *psz_tmp = config_GetPsz(p_intf, psz_option);
402 [o_object setStringValue: [NSString stringWithUTF8String: psz_tmp ?: ""]];
403 [o_object setToolTip: _NS(config_GetLabel(p_intf, psz_option))];
407 - (void)resetControls
409 module_config_t *p_item;
413 /**********************
414 * interface settings *
415 **********************/
416 [self setupButton: o_intf_art_pop forIntList: "album-art"];
418 [self setupButton: o_intf_fspanel_ckb forBoolValue: "macosx-fspanel"];
420 [self setupButton: o_intf_nativefullscreen_ckb forBoolValue: "macosx-nativefullscreenmode"];
421 BOOL b_correct_sdk = NO;
422 #ifdef MAC_OS_X_VERSION_10_7
425 if (!(b_correct_sdk && !OSX_SNOW_LEOPARD)) {
426 [o_intf_nativefullscreen_ckb setState: NSOffState];
427 [o_intf_nativefullscreen_ckb setEnabled: NO];
430 [self setupButton: o_intf_embedded_ckb forBoolValue: "embedded-video"];
432 [self setupButton: o_intf_appleremote_ckb forBoolValue: "macosx-appleremote"];
433 [self setupButton: o_intf_appleremote_sysvol_ckb forBoolValue: "macosx-appleremote-sysvol"];
435 [self setupButton: o_intf_mediakeys_ckb forBoolValue: "macosx-mediakeys"];
436 if ([[SUUpdater sharedUpdater] lastUpdateCheckDate] != NULL)
437 [o_intf_last_update_lbl setStringValue: [NSString stringWithFormat: _NS("Last check on: %@"), [[[SUUpdater sharedUpdater] lastUpdateCheckDate] descriptionWithLocale: [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]]]];
439 [o_intf_last_update_lbl setStringValue: _NS("No check was performed yet.")];
440 psz_tmp = config_GetPsz(p_intf, "control");
442 [o_intf_enableGrowl_ckb setState: (NSInteger)strstr(psz_tmp, "growl")];
445 [o_intf_enableGrowl_ckb setState: NSOffState];
446 if (config_GetInt(p_intf, "macosx-interfacestyle")) {
447 [o_intf_style_dark_bcell setState: YES];
448 [o_intf_style_bright_bcell setState: NO];
450 [o_intf_style_dark_bcell setState: NO];
451 [o_intf_style_bright_bcell setState: YES];
453 [self setupButton: o_intf_autoresize_ckb forBoolValue: "macosx-video-autoresize"];
454 [self setupButton: o_intf_pauseminimized_ckb forBoolValue: "macosx-pause-minimized"];
459 [self setupButton: o_audio_enable_ckb forBoolValue: "audio"];
461 if (config_GetInt(p_intf, "volume-save")) {
462 [o_audio_autosavevol_yes_bcell setState: NSOnState];
463 [o_audio_autosavevol_no_bcell setState: NSOffState];
464 [o_audio_vol_fld setEnabled: NO];
465 [o_audio_vol_sld setEnabled: NO];
467 [o_audio_vol_sld setIntValue: 100];
468 [o_audio_vol_fld setIntValue: 100];
470 [o_audio_autosavevol_yes_bcell setState: NSOffState];
471 [o_audio_autosavevol_no_bcell setState: NSOnState];
472 [o_audio_vol_fld setEnabled: YES];
473 [o_audio_vol_sld setEnabled: YES];
475 i = config_GetInt(p_intf, "volume");
476 i = i * 200.0 / AOUT_VOLUME_MAX + 0.5;
477 [o_audio_vol_sld setIntValue: i];
478 [o_audio_vol_fld setIntValue: i];
481 [self setupButton: o_audio_spdif_ckb forBoolValue: "spdif"];
483 [self setupButton: o_audio_dolby_pop forIntList: "force-dolby-surround"];
484 [self setupField: o_audio_lang_fld forOption: "audio-language"];
486 [self setupButton: o_audio_visual_pop forModuleList: "audio-visual"];
488 /* Last.FM is optional */
489 if (module_exists("audioscrobbler")) {
490 [self setupField: o_audio_lastuser_fld forOption:"lastfm-username"];
491 [self setupField: o_audio_lastpwd_sfld forOption:"lastfm-password"];
493 if (config_ExistIntf(VLC_OBJECT(p_intf), "audioscrobbler")) {
494 [o_audio_last_ckb setState: NSOnState];
495 [o_audio_lastuser_fld setEnabled: YES];
496 [o_audio_lastpwd_sfld setEnabled: YES];
498 [o_audio_last_ckb setState: NSOffState];
499 [o_audio_lastuser_fld setEnabled: NO];
500 [o_audio_lastpwd_sfld setEnabled: NO];
503 [o_audio_last_ckb setEnabled: NO];
508 [self setupButton: o_video_enable_ckb forBoolValue: "video"];
509 [self setupButton: o_video_fullscreen_ckb forBoolValue: "fullscreen"];
510 [self setupButton: o_video_onTop_ckb forBoolValue: "video-on-top"];
511 [self setupButton: o_video_skipFrames_ckb forBoolValue: "skip-frames"];
512 [self setupButton: o_video_black_ckb forBoolValue: "macosx-black"];
513 [self setupButton: o_video_videodeco_ckb forBoolValue: "video-deco"];
515 [self setupButton: o_video_output_pop forModuleList: "vout"];
517 [o_video_device_pop removeAllItems];
519 y = [[NSScreen screens] count];
520 [o_video_device_pop addItemWithTitle: _NS("Default")];
521 [[o_video_device_pop lastItem] setTag: 0];
523 NSRect s_rect = [[[NSScreen screens] objectAtIndex: i] frame];
524 [o_video_device_pop addItemWithTitle:
525 [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
526 (int)s_rect.size.width, (int)s_rect.size.height]];
527 [[o_video_device_pop lastItem] setTag: (int)[[[NSScreen screens] objectAtIndex: i] displayID]];
530 [o_video_device_pop selectItemAtIndex: 0];
531 [o_video_device_pop selectItemWithTag: config_GetInt(p_intf, "macosx-vdev")];
533 [self setupField: o_video_snap_folder_fld forOption:"snapshot-path"];
534 [self setupField: o_video_snap_prefix_fld forOption:"snapshot-prefix"];
535 [self setupButton: o_video_snap_seqnum_ckb forBoolValue: "snapshot-sequential"];
536 [self setupButton: o_video_snap_format_pop forStringList: "snapshot-format"];
537 [self setupButton: o_video_deinterlace_pop forIntList: "deinterlace"];
538 [self setupButton: o_video_deinterlace_mode_pop forStringList: "deinterlace-mode"];
540 /***************************
541 * input & codecs settings *
542 ***************************/
543 [self setupField: o_input_record_fld forOption:"input-record-path"];
544 [self setupField: o_input_httpproxy_fld forOption:"http-proxy"];
545 [self setupField: o_input_httpproxypwd_sfld forOption:"http-proxy-pwd"];
546 [o_input_postproc_fld setIntValue: config_GetInt(p_intf, "postproc-q")];
547 [o_input_postproc_fld setToolTip: _NS(config_GetLabel(p_intf, "postproc-q"))];
548 [self setupButton: o_input_avcodec_hw_ckb forBoolValue:"avcodec-hw"];
550 [self setupButton: o_input_avi_pop forIntList: "avi-index"];
552 [self setupButton: o_input_rtsp_ckb forBoolValue: "rtsp-tcp"];
553 [self setupButton: o_input_skipLoop_pop forIntList: "avcodec-skiploopfilter"];
555 [self setupButton: o_input_mkv_preload_dir_ckb forBoolValue: "mkv-preload-local-dir"];
557 [o_input_cachelevel_pop removeAllItems];
558 [o_input_cachelevel_pop addItemsWithTitles:
559 [NSArray arrayWithObjects: _NS("Custom"), _NS("Lowest latency"), _NS("Low latency"), _NS("Normal"),
560 _NS("High latency"), _NS("Higher latency"), nil]];
561 [[o_input_cachelevel_pop itemAtIndex: 0] setTag: 0];
562 [[o_input_cachelevel_pop itemAtIndex: 1] setTag: 100];
563 [[o_input_cachelevel_pop itemAtIndex: 2] setTag: 200];
564 [[o_input_cachelevel_pop itemAtIndex: 3] setTag: 300];
565 [[o_input_cachelevel_pop itemAtIndex: 4] setTag: 500];
566 [[o_input_cachelevel_pop itemAtIndex: 5] setTag: 1000];
568 #define TestCaC(name, factor) \
569 b_cache_equal = b_cache_equal && \
570 (i_cache * factor == config_GetInt(p_intf, name));
572 /* Select the accurate value of the PopupButton */
573 bool b_cache_equal = true;
574 int i_cache = config_GetInt(p_intf, "file-caching");
576 TestCaC("network-caching", 10/3);
577 TestCaC("disc-caching", 1);
578 TestCaC("live-caching", 1);
580 [o_input_cachelevel_pop selectItemWithTag: i_cache];
581 [o_input_cachelevel_custom_txt setHidden: YES];
583 [o_input_cachelevel_pop selectItemWithTitle: _NS("Custom")];
584 [o_input_cachelevel_custom_txt setHidden: NO];
588 /*********************
589 * subtitle settings *
590 *********************/
591 [self setupButton: o_osd_osd_ckb forBoolValue: "osd"];
593 [self setupButton: o_osd_encoding_pop forStringList: "subsdec-encoding"];
594 [self setupField: o_osd_lang_fld forOption: "sub-language" ];
596 [self setupField: o_osd_font_fld forOption: "freetype-font"];
597 [self setupButton: o_osd_font_color_pop forIntList: "freetype-color"];
598 [self setupButton: o_osd_font_size_pop forIntList: "freetype-rel-fontsize"];
599 i = config_GetInt(p_intf, "freetype-opacity") * 100.0 / 255.0 + 0.5;
600 [o_osd_opacity_fld setIntValue: i];
601 [o_osd_opacity_sld setIntValue: i];
602 [o_osd_opacity_sld setToolTip: _NS(config_GetLabel(p_intf, "freetype-opacity"))];
603 [o_osd_opacity_fld setToolTip: [o_osd_opacity_sld toolTip]];
604 [self setupButton: o_osd_forcebold_ckb forBoolValue: "freetype-bold"];
605 [self setupButton: o_osd_outline_color_pop forIntList: "freetype-outline-color"];
606 [self setupButton: o_osd_outline_thickness_pop forIntList: "freetype-outline-thickness"];
608 /********************
610 ********************/
611 const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
612 [o_hotkeySettings release];
613 o_hotkeySettings = [[NSMutableArray alloc] init];
614 NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
615 NSMutableArray *o_tempArray_names = [[NSMutableArray alloc] init];
617 /* Get the main Module */
618 module_t *p_main = module_get_main();
621 module_config_t *p_config;
623 p_config = module_config_get (p_main, &confsize);
625 for (size_t i = 0; i < confsize; i++) {
626 module_config_t *p_item = p_config + i;
628 if (CONFIG_ITEM(p_item->i_type) && p_item->psz_name != NULL
629 && !strncmp(p_item->psz_name , "key-", 4)
630 && !EMPTY_STR(p_item->psz_text)) {
631 [o_tempArray_desc addObject: _NS(p_item->psz_text)];
632 [o_tempArray_names addObject: [NSString stringWithUTF8String:p_item->psz_name]];
633 if (p_item->value.psz)
634 [o_hotkeySettings addObject: [NSString stringWithUTF8String:p_item->value.psz]];
636 [o_hotkeySettings addObject: [NSString string]];
639 module_config_free (p_config);
641 [o_hotkeyDescriptions release];
642 o_hotkeyDescriptions = [[NSArray alloc] initWithArray: o_tempArray_desc copyItems: YES];
643 [o_tempArray_desc release];
644 [o_hotkeyNames release];
645 o_hotkeyNames = [[NSArray alloc] initWithArray: o_tempArray_names copyItems: YES];
646 [o_tempArray_names release];
647 [o_hotkeys_listbox reloadData];
651 #pragma mark General actions
653 - (void)showSimplePrefs
655 /* we want to show the interface settings, if no category was chosen */
656 if ([[o_sprefs_win toolbar] selectedItemIdentifier] == nil) {
657 [[o_sprefs_win toolbar] setSelectedItemIdentifier: VLCIntfSettingToolbarIdentifier];
658 [self showInterfaceSettings];
661 [self resetControls];
663 [o_sprefs_win center];
664 [o_sprefs_win makeKeyAndOrderFront: self];
667 - (void)showSimplePrefsWithLevel:(NSInteger)i_window_level
669 [o_sprefs_win setLevel: i_window_level];
670 [self showSimplePrefs];
673 - (IBAction)buttonAction:(id)sender
675 if (sender == o_sprefs_cancel_btn) {
676 [[NSFontPanel sharedFontPanel] close];
677 [o_sprefs_win orderOut: sender];
678 } else if (sender == o_sprefs_save_btn) {
679 [self saveChangedSettings];
680 [[NSFontPanel sharedFontPanel] close];
681 [o_sprefs_win orderOut: sender];
682 } else if (sender == o_sprefs_reset_btn)
683 NSBeginInformationalAlertSheet(_NS("Reset Preferences"), _NS("Cancel"),
684 _NS("Continue"), nil, o_sprefs_win, self,
685 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
686 _NS("Beware this will reset the VLC media player preferences.\n"
687 "Are you sure you want to continue?"));
688 else if (sender == o_sprefs_showAll_btn) {
689 [o_sprefs_win orderOut: self];
690 [[[VLCMain sharedInstance] preferences] showPrefsWithLevel:[o_sprefs_win level]];
692 msg_Warn(p_intf, "unknown buttonAction sender");
695 - (void)sheetDidEnd:(NSWindow *)o_sheet
696 returnCode:(int)i_return
697 contextInfo:(void *)o_context
699 if (i_return == NSAlertAlternateReturn) {
700 /* reset VLC's config */
701 config_ResetAll(p_intf);
702 [self resetControls];
703 config_SaveConfigFile(p_intf);
705 /* reset OS X defaults */
706 [NSUserDefaults resetStandardUserDefaults];
707 [[NSUserDefaults standardUserDefaults] synchronize];
711 static inline void save_int_list(intf_thread_t * p_intf, id object, const char * name)
713 NSNumber *p_valueobject;
714 module_config_t *p_item;
715 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
716 p_valueobject = (NSNumber *)[[object selectedItem] representedObject];
717 assert([p_valueobject isKindOfClass:[NSNumber class]]);
718 if (p_valueobject) config_PutInt(p_intf, name, [p_valueobject intValue]);
721 static inline void save_string_list(intf_thread_t * p_intf, id object, const char * name)
723 NSString *p_stringobject;
724 module_config_t *p_item;
725 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
726 p_stringobject = (NSString *)[[object selectedItem] representedObject];
727 assert([p_stringobject isKindOfClass:[NSString class]]);
728 if (p_stringobject) {
729 config_PutPsz(p_intf, name, [p_stringobject UTF8String]);
733 static inline void save_module_list(intf_thread_t * p_intf, id object, const char * name)
735 module_config_t *p_item;
736 module_t *p_parser, **p_list;
737 NSString * objectTitle = [[object selectedItem] title];
739 p_item = config_FindConfig(VLC_OBJECT(p_intf), name);
742 p_list = module_list_get(&count);
743 for (size_t i_module_index = 0; i_module_index < count; i_module_index++) {
744 p_parser = p_list[i_module_index];
746 if (p_item->i_type == CONFIG_ITEM_MODULE && module_provides(p_parser, p_item->psz_type)) {
747 if ([objectTitle isEqualToString: _NS(module_GetLongName(p_parser))])
749 config_PutPsz(p_intf, name, strdup(module_get_object(p_parser)));
754 module_list_free(p_list);
755 if ([objectTitle isEqualToString: _NS("Default")])
756 config_PutPsz(p_intf, name, "");
759 - (void)saveChangedSettings
764 #define SaveIntList(object, name) save_int_list(p_intf, object, name)
766 #define SaveStringList(object, name) save_string_list(p_intf, object, name)
768 #define SaveModuleList(object, name) save_module_list(p_intf, object, name)
770 #define getString(name) [NSString stringWithFormat:@"%s", config_GetPsz(p_intf, name)]
772 /**********************
773 * interface settings *
774 **********************/
775 if (b_intfSettingChanged) {
776 SaveIntList(o_intf_art_pop, "album-art");
778 config_PutInt(p_intf, "macosx-fspanel", [o_intf_fspanel_ckb state]);
779 config_PutInt(p_intf, "embedded-video", [o_intf_embedded_ckb state]);
781 config_PutInt(p_intf, "macosx-appleremote", [o_intf_appleremote_ckb state]);
782 config_PutInt(p_intf, "macosx-appleremote-sysvol", [o_intf_appleremote_sysvol_ckb state]);
783 config_PutInt(p_intf, "macosx-mediakeys", [o_intf_mediakeys_ckb state]);
784 config_PutInt(p_intf, "macosx-interfacestyle", [o_intf_style_dark_bcell state]);
785 config_PutInt(p_intf, "macosx-nativefullscreenmode", [o_intf_nativefullscreen_ckb state]);
786 config_PutInt(p_intf, "macosx-pause-minimized", [o_intf_pauseminimized_ckb state]);
787 config_PutInt(p_intf, "macosx-video-autoresize", [o_intf_autoresize_ckb state]);
788 if ([o_intf_enableGrowl_ckb state] == NSOnState) {
789 tmpString = getString("control");
790 tmpRange = [tmpString rangeOfString:@"growl"];
791 if ([tmpString length] > 0 && tmpRange.location == NSNotFound)
793 tmpString = [tmpString stringByAppendingString: @":growl"];
794 config_PutPsz(p_intf, "control", [tmpString UTF8String]);
797 config_PutPsz(p_intf, "control", "growl");
799 tmpString = getString("control");
800 if (! [tmpString isEqualToString:@""])
802 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@":growl"]];
803 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl:"]];
804 tmpString = [tmpString stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"growl"]];
805 config_PutPsz(p_intf, "control", [tmpString UTF8String]);
809 /* activate stuff without restart */
810 if ([o_intf_appleremote_ckb state] == YES)
811 [[[VLCMain sharedInstance] appleRemoteController] startListening: [VLCMain sharedInstance]];
813 [[[VLCMain sharedInstance] appleRemoteController] stopListening: [VLCMain sharedInstance]];
814 b_intfSettingChanged = NO;
820 if (b_audioSettingChanged) {
821 config_PutInt(p_intf, "audio", [o_audio_enable_ckb state]);
822 if ([o_audio_vol_fld isEnabled])
823 config_PutInt(p_intf, "volume", [o_audio_vol_fld intValue] * AOUT_VOLUME_MAX / 200.0 + 0.5);
824 config_PutInt(p_intf, "volume-save", [o_audio_autosavevol_yes_bcell state]);
825 config_PutInt(p_intf, "spdif", [o_audio_spdif_ckb state]);
827 SaveIntList(o_audio_dolby_pop, "force-dolby-surround");
829 config_PutPsz(p_intf, "audio-language", [[o_audio_lang_fld stringValue] UTF8String]);
831 SaveModuleList(o_audio_visual_pop, "audio-visual");
833 /* Last.FM is optional */
834 if (module_exists("audioscrobbler")) {
835 [o_audio_last_ckb setEnabled: YES];
836 if ([o_audio_last_ckb state] == NSOnState)
837 config_AddIntf(p_intf, "audioscrobbler");
839 config_RemoveIntf(p_intf, "audioscrobbler");
841 config_PutPsz(p_intf, "lastfm-username", [[o_audio_lastuser_fld stringValue] UTF8String]);
842 config_PutPsz(p_intf, "lastfm-password", [[o_audio_lastpwd_sfld stringValue] UTF8String]);
845 [o_audio_last_ckb setEnabled: NO];
846 b_audioSettingChanged = NO;
852 if (b_videoSettingChanged) {
853 config_PutInt(p_intf, "video", [o_video_enable_ckb state]);
854 config_PutInt(p_intf, "fullscreen", [o_video_fullscreen_ckb state]);
855 config_PutInt(p_intf, "video-deco", [o_video_videodeco_ckb state]);
856 config_PutInt(p_intf, "video-on-top", [o_video_onTop_ckb state]);
857 config_PutInt(p_intf, "skip-frames", [o_video_skipFrames_ckb state]);
858 config_PutInt(p_intf, "macosx-black", [o_video_black_ckb state]);
860 SaveModuleList(o_video_output_pop, "vout");
861 config_PutInt(p_intf, "macosx-vdev", [[o_video_device_pop selectedItem] tag]);
863 config_PutPsz(p_intf, "snapshot-path", [[o_video_snap_folder_fld stringValue] UTF8String]);
864 config_PutPsz(p_intf, "snapshot-prefix", [[o_video_snap_prefix_fld stringValue] UTF8String]);
865 config_PutInt(p_intf, "snapshot-sequential", [o_video_snap_seqnum_ckb state]);
866 SaveStringList(o_video_snap_format_pop, "snapshot-format");
867 SaveIntList(o_video_deinterlace_pop, "deinterlace");
868 SaveStringList(o_video_deinterlace_mode_pop, "deinterlace-mode");
869 b_videoSettingChanged = NO;
872 /***************************
873 * input & codecs settings *
874 ***************************/
875 if (b_inputSettingChanged) {
876 config_PutPsz(p_intf, "input-record-path", [[o_input_record_fld stringValue] UTF8String]);
877 config_PutPsz(p_intf, "http-proxy", [[o_input_httpproxy_fld stringValue] UTF8String]);
878 config_PutPsz(p_intf, "http-proxy-pwd", [[o_input_httpproxypwd_sfld stringValue] UTF8String]);
879 config_PutInt(p_intf, "postproc-q", [o_input_postproc_fld intValue]);
881 SaveIntList(o_input_avi_pop, "avi-index");
883 config_PutInt(p_intf, "rtsp-tcp", [o_input_rtsp_ckb state]);
884 config_PutInt(p_intf, "avcodec-hw", [o_input_avcodec_hw_ckb state]);
885 SaveIntList(o_input_skipLoop_pop, "avcodec-skiploopfilter");
887 config_PutInt(p_intf, "mkv-preload-local-dir", [o_input_mkv_preload_dir_ckb state]);
889 #define CaC(name, factor) config_PutInt(p_intf, name, [[o_input_cachelevel_pop selectedItem] tag] * factor)
890 if ([[o_input_cachelevel_pop selectedItem] tag] == 0) {
891 msg_Dbg(p_intf, "Custom chosen, not adjusting cache values");
893 msg_Dbg(p_intf, "Adjusting all cache values to: %i", (int)[[o_input_cachelevel_pop selectedItem] tag]);
894 CaC("file-caching", 1);
895 CaC("network-caching", 10/3);
896 CaC("disc-caching", 1);
897 CaC("live-caching", 1);
900 b_inputSettingChanged = NO;
903 /**********************
904 * subtitles settings *
905 **********************/
906 if (b_osdSettingChanged) {
907 config_PutInt(p_intf, "osd", [o_osd_osd_ckb state]);
909 if ([o_osd_encoding_pop indexOfSelectedItem] >= 0)
910 SaveStringList(o_osd_encoding_pop, "subsdec-encoding");
912 config_PutPsz(p_intf, "subsdec-encoding", "");
914 config_PutPsz(p_intf, "sub-language", [[o_osd_lang_fld stringValue] UTF8String]);
916 config_PutPsz(p_intf, "freetype-font", [[o_osd_font_fld stringValue] UTF8String]);
917 SaveIntList(o_osd_font_color_pop, "freetype-color");
918 SaveIntList(o_osd_font_size_pop, "freetype-rel-fontsize");
919 config_PutInt(p_intf, "freetype-opacity", [o_osd_opacity_fld intValue] * 255.0 / 100.0 + 0.5);
920 config_PutInt(p_intf, "freetype-bold", [o_osd_forcebold_ckb state]);
921 SaveIntList(o_osd_outline_color_pop, "freetype-outline-color");
922 SaveIntList(o_osd_outline_thickness_pop, "freetype-outline-thickness");
923 b_osdSettingChanged = NO;
926 /********************
928 ********************/
929 if (b_hotkeyChanged) {
930 NSUInteger hotKeyCount = [o_hotkeySettings count];
931 for (NSUInteger i = 0; i < hotKeyCount; i++)
932 config_PutPsz(p_intf, [[o_hotkeyNames objectAtIndex:i] UTF8String], [[o_hotkeySettings objectAtIndex:i]UTF8String]);
933 b_hotkeyChanged = NO;
936 [[VLCCoreInteraction sharedInstance] fixPreferences];
938 /* okay, let's save our changes to vlcrc */
939 config_SaveConfigFile(p_intf);
941 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
946 - (void)showSettingsForCategory: (id)o_new_category_view
948 NSRect o_win_rect, o_view_rect, o_old_view_rect;
949 o_win_rect = [o_sprefs_win frame];
950 o_view_rect = [o_new_category_view frame];
952 if (o_currentlyShownCategoryView != nil) {
953 /* restore our window's height, if we've shown another category previously */
954 o_old_view_rect = [o_currentlyShownCategoryView frame];
955 o_win_rect.size.height = o_win_rect.size.height - o_old_view_rect.size.height;
956 o_win_rect.origin.y = (o_win_rect.origin.y + o_old_view_rect.size.height) - o_view_rect.size.height;
959 o_win_rect.size.height = o_win_rect.size.height + o_view_rect.size.height;
961 [o_new_category_view setFrame: NSMakeRect(0,
962 [o_sprefs_controls_box frame].size.height,
963 o_view_rect.size.width,
964 o_view_rect.size.height)];
965 [o_new_category_view setAutoresizesSubviews: YES];
966 if (o_currentlyShownCategoryView) {
967 [[[o_sprefs_win contentView] animator] replaceSubview: o_currentlyShownCategoryView with: o_new_category_view];
968 [o_currentlyShownCategoryView release];
969 [[o_sprefs_win animator] setFrame: o_win_rect display:YES];
971 [[o_sprefs_win contentView] addSubview: o_new_category_view];
972 [o_sprefs_win setFrame: o_win_rect display:YES animate:NO];
975 /* keep our current category for further reference */
976 o_currentlyShownCategoryView = o_new_category_view;
977 [o_currentlyShownCategoryView retain];
981 #pragma mark Specific actions
983 - (IBAction)interfaceSettingChanged:(id)sender
985 if (sender == o_intf_embedded_ckb && [o_intf_embedded_ckb state] == NSOffState)
986 [o_intf_nativefullscreen_ckb setState: NSOffState];
988 if (sender == o_intf_nativefullscreen_ckb && [o_intf_nativefullscreen_ckb state] == NSOnState)
989 [o_intf_embedded_ckb setState: NSOnState];
991 b_intfSettingChanged = YES;
994 - (void)showInterfaceSettings
996 [self showSettingsForCategory: o_intf_view];
999 - (IBAction)audioSettingChanged:(id)sender
1001 if (sender == o_audio_vol_sld)
1002 [o_audio_vol_fld setIntValue: [o_audio_vol_sld intValue]];
1004 if (sender == o_audio_vol_fld)
1005 [o_audio_vol_sld setIntValue: [o_audio_vol_fld intValue]];
1007 if (sender == o_audio_last_ckb) {
1008 if ([o_audio_last_ckb state] == NSOnState) {
1009 [o_audio_lastpwd_sfld setEnabled: YES];
1010 [o_audio_lastuser_fld setEnabled: YES];
1012 [o_audio_lastpwd_sfld setEnabled: NO];
1013 [o_audio_lastuser_fld setEnabled: NO];
1017 if (sender == o_audio_autosavevol_matrix) {
1018 BOOL enableVolumeSlider = [o_audio_autosavevol_matrix selectedTag] == 1;
1019 [o_audio_vol_fld setEnabled: enableVolumeSlider];
1020 [o_audio_vol_sld setEnabled: enableVolumeSlider];
1023 b_audioSettingChanged = YES;
1026 - (void)showAudioSettings
1028 [self showSettingsForCategory: o_audio_view];
1031 - (IBAction)videoSettingChanged:(id)sender
1033 if (sender == o_video_snap_folder_btn) {
1034 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1035 [o_selectFolderPanel setCanChooseDirectories: YES];
1036 [o_selectFolderPanel setCanChooseFiles: NO];
1037 [o_selectFolderPanel setResolvesAliases: YES];
1038 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1039 [o_selectFolderPanel setMessage: _NS("Choose the folder to save your video snapshots to.")];
1040 [o_selectFolderPanel setCanCreateDirectories: YES];
1041 [o_selectFolderPanel setPrompt: _NS("Choose")];
1042 [o_selectFolderPanel beginSheetModalForWindow: o_sprefs_win completionHandler: ^(NSInteger returnCode) {
1043 if (returnCode == NSOKButton)
1045 [o_video_snap_folder_fld setStringValue: [[o_selectFolderPanel URL] path]];
1046 b_videoSettingChanged = YES;
1049 [o_selectFolderPanel release];
1051 b_videoSettingChanged = YES;
1054 - (void)showVideoSettings
1056 [self showSettingsForCategory: o_video_view];
1059 - (IBAction)osdSettingChanged:(id)sender
1061 if (sender == o_osd_opacity_fld)
1062 [o_osd_opacity_sld setIntValue: [o_osd_opacity_fld intValue]];
1064 if (sender == o_osd_opacity_sld)
1065 [o_osd_opacity_fld setIntValue: [o_osd_opacity_sld intValue]];
1067 b_osdSettingChanged = YES;
1070 - (void)showOSDSettings
1072 [self showSettingsForCategory: o_osd_view];
1075 - (void)controlTextDidChange:(NSNotification *)o_notification
1077 id notificationObject = [o_notification object];
1078 if (notificationObject == o_audio_lang_fld ||
1079 notificationObject == o_audio_lastpwd_sfld ||
1080 notificationObject == o_audio_lastuser_fld ||
1081 notificationObject == o_audio_vol_fld)
1082 b_audioSettingChanged = YES;
1083 else if (notificationObject == o_input_record_fld ||
1084 notificationObject == o_input_httpproxy_fld ||
1085 notificationObject == o_input_httpproxypwd_sfld ||
1086 notificationObject == o_input_postproc_fld)
1087 b_inputSettingChanged = YES;
1088 else if (notificationObject == o_osd_font_fld ||
1089 notificationObject == o_osd_lang_fld ||
1090 notificationObject == o_osd_opacity_fld)
1091 b_osdSettingChanged = YES;
1092 else if (notificationObject == o_video_snap_folder_fld ||
1093 notificationObject == o_video_snap_prefix_fld)
1094 b_videoSettingChanged = YES;
1097 - (IBAction)showFontPicker:(id)sender
1099 char * font = config_GetPsz(p_intf, "freetype-font");
1100 NSString * fontName = font ? [NSString stringWithUTF8String: font] : nil;
1103 NSFont * font = [NSFont fontWithName:fontName size:0.0];
1104 [[NSFontManager sharedFontManager] setSelectedFont:font isMultiple:NO];
1106 [[NSFontManager sharedFontManager] setTarget: self];
1107 [[NSFontPanel sharedFontPanel] orderFront:self];
1110 - (void)changeFont:(id)sender
1112 NSFont * font = [sender convertFont:[[NSFontManager sharedFontManager] selectedFont]];
1113 [o_osd_font_fld setStringValue:[font fontName]];
1114 [self osdSettingChanged:self];
1117 - (IBAction)inputSettingChanged:(id)sender
1119 if (sender == o_input_cachelevel_pop) {
1120 if ([[[o_input_cachelevel_pop selectedItem] title] isEqualToString: _NS("Custom")])
1121 [o_input_cachelevel_custom_txt setHidden: NO];
1123 [o_input_cachelevel_custom_txt setHidden: YES];
1124 } else if (sender == o_input_record_btn) {
1125 o_selectFolderPanel = [[NSOpenPanel alloc] init];
1126 [o_selectFolderPanel setCanChooseDirectories: YES];
1127 [o_selectFolderPanel setCanChooseFiles: YES];
1128 [o_selectFolderPanel setResolvesAliases: YES];
1129 [o_selectFolderPanel setAllowsMultipleSelection: NO];
1130 [o_selectFolderPanel setMessage: _NS("Choose the directory or filename where the records will be stored.")];
1131 [o_selectFolderPanel setCanCreateDirectories: YES];
1132 [o_selectFolderPanel setPrompt: _NS("Choose")];
1133 [o_selectFolderPanel beginSheetModalForWindow: o_sprefs_win completionHandler: ^(NSInteger returnCode) {
1134 if (returnCode == NSOKButton)
1136 [o_input_record_fld setStringValue: [[o_selectFolderPanel URL] path]];
1137 b_inputSettingChanged = YES;
1140 [o_selectFolderPanel release];
1145 b_inputSettingChanged = YES;
1148 - (void)showInputSettings
1150 [self showSettingsForCategory: o_input_view];
1154 #pragma mark Hotkey actions
1156 - (void)hotkeyTableDoubleClick:(id)object
1159 if ([o_hotkeys_listbox clickedRow] >= 0)
1160 [self hotkeySettingChanged:o_hotkeys_listbox];
1163 - (IBAction)hotkeySettingChanged:(id)sender
1165 if (sender == o_hotkeys_change_btn || sender == o_hotkeys_listbox) {
1166 [o_hotkeys_change_lbl setStringValue: [NSString stringWithFormat: _NS("Press new keys for\n\"%@\""),
1167 [o_hotkeyDescriptions objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1168 [o_hotkeys_change_keys_lbl setStringValue: [[VLCStringUtility sharedInstance] OSXStringKeyToString:[o_hotkeySettings objectAtIndex: [o_hotkeys_listbox selectedRow]]]];
1169 [o_hotkeys_change_taken_lbl setStringValue: @""];
1170 [o_hotkeys_change_win setInitialFirstResponder: [o_hotkeys_change_win contentView]];
1171 [o_hotkeys_change_win makeFirstResponder: [o_hotkeys_change_win contentView]];
1172 [NSApp runModalForWindow: o_hotkeys_change_win];
1173 } else if (sender == o_hotkeys_change_cancel_btn) {
1175 [o_hotkeys_change_win close];
1176 } else if (sender == o_hotkeys_change_ok_btn) {
1177 NSInteger i_returnValue;
1178 if (! o_keyInTransition) {
1180 [o_hotkeys_change_win close];
1181 msg_Err(p_intf, "internal error prevented the hotkey switch");
1185 b_hotkeyChanged = YES;
1187 i_returnValue = [o_hotkeySettings indexOfObject: o_keyInTransition];
1188 if (i_returnValue != NSNotFound)
1189 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1190 NSString *tempString;
1191 tempString = [o_keyInTransition stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
1192 i_returnValue = [o_hotkeySettings indexOfObject: tempString];
1193 if (i_returnValue != NSNotFound)
1194 [o_hotkeySettings replaceObjectAtIndex: i_returnValue withObject: [NSString string]];
1196 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [o_keyInTransition retain]];
1199 [o_hotkeys_change_win close];
1201 [o_hotkeys_listbox reloadData];
1202 } else if (sender == o_hotkeys_clear_btn) {
1203 [o_hotkeySettings replaceObjectAtIndex: [o_hotkeys_listbox selectedRow] withObject: [NSString string]];
1204 [o_hotkeys_listbox reloadData];
1205 b_hotkeyChanged = YES;
1208 [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCMediaKeySupportSettingChanged"
1213 - (void)showHotkeySettings
1215 [self showSettingsForCategory: o_hotkeys_view];
1218 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1220 return [o_hotkeySettings count];
1223 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
1225 NSString * identifier = [aTableColumn identifier];
1227 if ([identifier isEqualToString: @"action"])
1228 return [o_hotkeyDescriptions objectAtIndex: rowIndex];
1229 else if ([identifier isEqualToString: @"shortcut"])
1230 return [[VLCStringUtility sharedInstance] OSXStringKeyToString:[o_hotkeySettings objectAtIndex: rowIndex]];
1232 msg_Err(p_intf, "unknown TableColumn identifier (%s)!", [identifier UTF8String]);
1237 - (BOOL)changeHotkeyTo: (NSString *)theKey
1239 NSInteger i_returnValue, i_returnValue2;
1240 i_returnValue = [o_hotkeysNonUseableKeys indexOfObject: theKey];
1242 if (i_returnValue != NSNotFound || [theKey isEqualToString:@""]) {
1243 [o_hotkeys_change_keys_lbl setStringValue: _NS("Invalid combination")];
1244 [o_hotkeys_change_taken_lbl setStringValue: _NS("Regrettably, these keys cannot be assigned as hotkey shortcuts.")];
1245 [o_hotkeys_change_ok_btn setEnabled: NO];
1248 [o_hotkeys_change_keys_lbl setStringValue: [[VLCStringUtility sharedInstance] OSXStringKeyToString:theKey]];
1250 i_returnValue = [o_hotkeySettings indexOfObject: theKey];
1251 i_returnValue2 = [o_hotkeySettings indexOfObject: [theKey stringByReplacingOccurrencesOfString:@"-" withString:@"+"]];
1252 if (i_returnValue != NSNotFound)
1253 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1254 _NS("This combination is already taken by \"%@\"."),
1255 [o_hotkeyDescriptions objectAtIndex: i_returnValue]]];
1256 else if (i_returnValue2 != NSNotFound)
1257 [o_hotkeys_change_taken_lbl setStringValue: [NSString stringWithFormat:
1258 _NS("This combination is already taken by \"%@\"."),
1259 [o_hotkeyDescriptions objectAtIndex: i_returnValue2]]];
1261 [o_hotkeys_change_taken_lbl setStringValue: @""];
1263 [o_hotkeys_change_ok_btn setEnabled: YES];
1264 [o_keyInTransition release];
1265 o_keyInTransition = theKey;
1266 [o_keyInTransition retain];
1273 /********************
1274 * hotkeys settings *
1275 ********************/
1277 @implementation VLCHotkeyChangeWindow
1279 - (BOOL)acceptsFirstResponder
1284 - (BOOL)becomeFirstResponder
1289 - (BOOL)resignFirstResponder
1291 /* We need to stay the first responder or we'll miss the user's input */
1295 - (BOOL)performKeyEquivalent:(NSEvent *)o_theEvent
1297 NSMutableString *tempString = [[[NSMutableString alloc] init] autorelease];
1298 NSString *keyString = [o_theEvent characters];
1300 unichar key = [keyString characterAtIndex:0];
1301 NSUInteger i_modifiers = [o_theEvent modifierFlags];
1304 if (i_modifiers & NSControlKeyMask)
1305 [tempString appendString:@"Ctrl-"];
1306 if (i_modifiers & NSAlternateKeyMask )
1307 [tempString appendString:@"Alt-"];
1308 if (i_modifiers & NSShiftKeyMask)
1309 [tempString appendString:@"Shift-"];
1310 if (i_modifiers & NSCommandKeyMask)
1311 [tempString appendString:@"Command-"];
1313 /* non character keys */
1314 if (key == NSUpArrowFunctionKey)
1315 [tempString appendString:@"Up"];
1316 else if (key == NSDownArrowFunctionKey)
1317 [tempString appendString:@"Down"];
1318 else if (key == NSLeftArrowFunctionKey)
1319 [tempString appendString:@"Left"];
1320 else if (key == NSRightArrowFunctionKey)
1321 [tempString appendString:@"Right"];
1322 else if (key == NSF1FunctionKey)
1323 [tempString appendString:@"F1"];
1324 else if (key == NSF2FunctionKey)
1325 [tempString appendString:@"F2"];
1326 else if (key == NSF3FunctionKey)
1327 [tempString appendString:@"F3"];
1328 else if (key == NSF4FunctionKey)
1329 [tempString appendString:@"F4"];
1330 else if (key == NSF5FunctionKey)
1331 [tempString appendString:@"F5"];
1332 else if (key == NSF6FunctionKey)
1333 [tempString appendString:@"F6"];
1334 else if (key == NSF7FunctionKey)
1335 [tempString appendString:@"F7"];
1336 else if (key == NSF8FunctionKey)
1337 [tempString appendString:@"F8"];
1338 else if (key == NSF9FunctionKey)
1339 [tempString appendString:@"F9"];
1340 else if (key == NSF10FunctionKey)
1341 [tempString appendString:@"F10"];
1342 else if (key == NSF11FunctionKey)
1343 [tempString appendString:@"F11"];
1344 else if (key == NSF12FunctionKey)
1345 [tempString appendString:@"F12"];
1346 else if (key == NSInsertFunctionKey)
1347 [tempString appendString:@"Insert"];
1348 else if (key == NSHomeFunctionKey)
1349 [tempString appendString:@"Home"];
1350 else if (key == NSEndFunctionKey)
1351 [tempString appendString:@"End"];
1352 else if (key == NSPageUpFunctionKey)
1353 [tempString appendString:@"Pageup"];
1354 else if (key == NSPageDownFunctionKey)
1355 [tempString appendString:@"Pagedown"];
1356 else if (key == NSMenuFunctionKey)
1357 [tempString appendString:@"Menu"];
1358 else if (key == NSTabCharacter)
1359 [tempString appendString:@"Tab"];
1360 else if (key == NSCarriageReturnCharacter)
1361 [tempString appendString:@"Enter"];
1362 else if (key == NSEnterCharacter)
1363 [tempString appendString:@"Enter"];
1364 else if (key == NSDeleteCharacter)
1365 [tempString appendString:@"Delete"];
1366 else if (key == NSBackspaceCharacter)
1367 [tempString appendString:@"Backspace"];
1368 else if (![[[o_theEvent charactersIgnoringModifiers] lowercaseString] isEqualToString:@""]) //plain characters
1369 [tempString appendString:[[o_theEvent charactersIgnoringModifiers] lowercaseString]];
1373 return [[[VLCMain sharedInstance] simplePreferences] changeHotkeyTo: tempString];
1378 @implementation VLCSimplePrefsWindow
1380 - (BOOL)acceptsFirstResponder
1385 - (void)changeFont:(id)sender
1387 [[[VLCMain sharedInstance] simplePreferences] changeFont: sender];