1 /*****************************************************************************
2 * MainMenu.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2011-2014 Felix Paul Kühne
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 <vlc_common.h>
28 #import <vlc_playlist.h>
34 #import "AudioEffects.h"
35 #import "TrackSynchronization.h"
36 #import "VideoEffects.h"
38 #import "simple_prefs.h"
39 #import "coredialogs.h"
42 #import "playlistinfo.h"
44 #import "CoreInteraction.h"
45 #import "MainWindow.h"
46 #import "ControlsBar.h"
47 #import "ExtensionsManager.h"
48 #import "ConvertAndSave.h"
49 #import "DebugMessageVisualizer.h"
50 #import "AddonManager.h"
52 @implementation VLCMainMenu
53 static VLCMainMenu *_o_sharedInstance = nil;
55 + (VLCMainMenu *)sharedInstance
57 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
60 #pragma mark - Initialization
64 if (_o_sharedInstance) {
66 return _o_sharedInstance;
68 _o_sharedInstance = [super init];
70 o_ptc_translation_dict = [[NSDictionary alloc] initWithObjectsAndKeys:
71 _NS("Track Number"), TRACKNUM_COLUMN,
72 _NS("Title"), TITLE_COLUMN,
73 _NS("Author"), ARTIST_COLUMN,
74 _NS("Duration"), DURATION_COLUMN,
75 _NS("Genre"), GENRE_COLUMN,
76 _NS("Album"), ALBUM_COLUMN,
77 _NS("Description"), DESCRIPTION_COLUMN,
78 _NS("Date"), DATE_COLUMN,
79 _NS("Language"), LANGUAGE_COLUMN,
80 _NS("URI"), URI_COLUMN,
81 _NS("File Size"), FILESIZE_COLUMN,
83 // this array also assigns tags (index) to type of menu item
84 o_ptc_menuorder = [[NSArray alloc] initWithObjects: TRACKNUM_COLUMN, TITLE_COLUMN,
85 ARTIST_COLUMN, DURATION_COLUMN, GENRE_COLUMN, ALBUM_COLUMN,
86 DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN,
90 return _o_sharedInstance;
95 [[NSNotificationCenter defaultCenter] removeObserver: self];
97 if (b_nib_about_loaded)
100 if (b_nib_videoeffects_loaded)
101 [o_videoeffects release];
103 if (b_nib_audioeffects_loaded)
104 [o_audioeffects release];
106 if (b_nib_tracksynchro_loaded)
107 [o_trackSynchronization release];
109 if (b_nib_convertandsave_loaded)
110 [o_convertandsave release];
114 if (o_mu_playlistTableColumnsContextMenu)
115 [o_mu_playlistTableColumnsContextMenu release];
117 [self releaseRepresentedObjects:[NSApp mainMenu]];
119 [o_ptc_translation_dict release];
120 [o_ptc_menuorder release];
127 [[NSNotificationCenter defaultCenter] addObserver: self
128 selector: @selector(applicationWillFinishLaunching:)
129 name: NSApplicationWillFinishLaunchingNotification
132 /* check whether the user runs OSX with a RTL language */
133 NSArray* languages = [NSLocale preferredLanguages];
134 NSString* preferredLanguage = [languages objectAtIndex:0];
136 if ([NSLocale characterDirectionForLanguage:preferredLanguage] == NSLocaleLanguageDirectionRightToLeft) {
137 msg_Dbg(VLCIntf, "adapting interface since '%s' is a RTL language", [preferredLanguage UTF8String]);
138 [o_mi_rate_fld setAlignment: NSLeftTextAlignment];
141 [self setRateControlsEnabled:NO];
146 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
149 playlist_t *p_playlist;
151 id o_vlcstringutility = [VLCStringUtility sharedInstance];
154 /* Check if we already did this once. Opening the other nibs calls it too,
155 because VLCMain is the owner */
156 if (b_mainMenu_setup)
159 /* Get ExtensionsManager */
160 o_extMgr = [ExtensionsManager getInstance:p_intf];
165 key = config_GetPsz(p_intf, "key-quit");
166 o_key = [NSString stringWithFormat:@"%s", key];
167 [o_mi_quit setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
168 [o_mi_quit setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
171 // do not assign play/pause key
173 key = config_GetPsz(p_intf, "key-stop");
174 o_key = [NSString stringWithFormat:@"%s", key];
175 [o_mi_stop setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
176 [o_mi_stop setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
179 key = config_GetPsz(p_intf, "key-prev");
180 o_key = [NSString stringWithFormat:@"%s", key];
181 [o_mi_previous setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
182 [o_mi_previous setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
185 key = config_GetPsz(p_intf, "key-next");
186 o_key = [NSString stringWithFormat:@"%s", key];
187 [o_mi_next setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
188 [o_mi_next setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
191 key = config_GetPsz(p_intf, "key-jump+short");
192 o_key = [NSString stringWithFormat:@"%s", key];
193 [o_mi_fwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
194 [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
197 key = config_GetPsz(p_intf, "key-jump-short");
198 o_key = [NSString stringWithFormat:@"%s", key];
199 [o_mi_bwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
200 [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
203 key = config_GetPsz(p_intf, "key-vol-up");
204 o_key = [NSString stringWithFormat:@"%s", key];
205 [o_mi_vol_up setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
206 [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
209 key = config_GetPsz(p_intf, "key-vol-down");
210 o_key = [NSString stringWithFormat:@"%s", key];
211 [o_mi_vol_down setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
212 [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
215 key = config_GetPsz(p_intf, "key-vol-mute");
216 o_key = [NSString stringWithFormat:@"%s", key];
217 [o_mi_mute setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
218 [o_mi_mute setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
221 key = config_GetPsz(p_intf, "key-toggle-fullscreen");
222 o_key = [NSString stringWithFormat:@"%s", key];
223 [o_mi_fullscreen setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
224 [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
227 key = config_GetPsz(p_intf, "key-snapshot");
228 o_key = [NSString stringWithFormat:@"%s", key];
229 [o_mi_snapshot setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
230 [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
233 key = config_GetPsz(p_intf, "key-random");
234 o_key = [NSString stringWithFormat:@"%s", key];
235 [o_mi_random setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
236 [o_mi_random setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
239 key = config_GetPsz(p_intf, "key-zoom-half");
240 o_key = [NSString stringWithFormat:@"%s", key];
241 [o_mi_half_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
242 [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
245 key = config_GetPsz(p_intf, "key-zoom-original");
246 o_key = [NSString stringWithFormat:@"%s", key];
247 [o_mi_normal_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
248 [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
251 key = config_GetPsz(p_intf, "key-zoom-double");
252 o_key = [NSString stringWithFormat:@"%s", key];
253 [o_mi_double_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
254 [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
257 [self setSubmenusEnabled: FALSE];
259 [[NSNotificationCenter defaultCenter] addObserver: self
260 selector: @selector(refreshVoutDeviceMenu:)
261 name: NSApplicationDidChangeScreenParametersNotification
265 b_mainMenu_setup = YES;
267 [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
268 var: "intf-add" selector: @selector(toggleVar:)];
270 /* setup extensions menu */
271 // FIXME: Implement preference for autoloading extensions on mac
272 if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad])
273 [o_extMgr loadExtensions];
275 /* Let the ExtensionsManager itself build the menu */
276 [o_extMgr buildMenu:o_mu_extensions];
277 [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
279 /* setup post-proc menu */
280 NSUInteger count = (NSUInteger) [o_mu_ffmpeg_pp numberOfItems];
282 [o_mu_ffmpeg_pp removeAllItems];
284 NSMenuItem * o_mitem;
285 [o_mu_ffmpeg_pp setAutoenablesItems: YES];
286 [o_mu_ffmpeg_pp addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
287 o_mitem = [o_mu_ffmpeg_pp itemAtIndex: 0];
288 [o_mitem setTag: -1];
289 [o_mitem setEnabled: YES];
290 [o_mitem setTarget: self];
291 for (NSUInteger x = 1; x < 7; x++) {
292 [o_mu_ffmpeg_pp addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
293 action:@selector(togglePostProcessing:)
295 o_mitem = [o_mu_ffmpeg_pp itemAtIndex:x];
296 [o_mitem setEnabled:YES];
298 [o_mitem setTarget:self];
300 char *psz_config = config_GetPsz(p_intf, "video-filter");
302 if (!strstr(psz_config, "postproc"))
303 [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
305 [[o_mu_ffmpeg_pp itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
308 [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
309 [o_mi_ffmpeg_pp setEnabled: NO];
311 [self refreshAudioDeviceList];
313 /* setup subtitles menu */
314 [self setupMenu: o_mu_subtitle_size withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
315 [self setupMenu: o_mu_subtitle_textcolor withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
316 [o_mi_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
317 [self setupMenu: o_mu_subtitle_bgcolor withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
318 [self setupMenu: o_mu_subtitle_outlinethickness withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
321 - (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
323 module_config_t *p_item;
325 [menu removeAllItems];
326 p_item = config_FindConfig(VLC_OBJECT(p_intf), psz_name);
328 /* serious problem, if no item found */
331 for (int i = 0; i < p_item->list_count; i++) {
333 if (p_item->list_text != NULL)
334 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
335 else if (p_item->list.i[i])
336 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
338 msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
343 [mi setAction:selector];
344 [mi setTag:p_item->list.i[i]];
345 [mi setRepresentedObject:[NSString stringWithUTF8String:psz_name]];
346 [menu addItem: [mi autorelease]];
347 if (p_item->value.i == p_item->list.i[i])
348 [mi setState:NSOnState];
355 [o_mi_about setTitle: [_NS("About VLC media player") \
356 stringByAppendingString: @"..."]];
357 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
358 [o_mi_prefs setTitle: _NS("Preferences...")];
359 [o_mi_extensions setTitle: _NS("Extensions")];
360 [o_mu_extensions setTitle: _NS("Extensions")];
361 [o_mi_addonManager setTitle: _NS("Addons Manager")];
362 [o_mi_add_intf setTitle: _NS("Add Interface")];
363 [o_mu_add_intf setTitle: _NS("Add Interface")];
364 [o_mi_services setTitle: _NS("Services")];
365 [o_mi_hide setTitle: _NS("Hide VLC")];
366 [o_mi_hide_others setTitle: _NS("Hide Others")];
367 [o_mi_show_all setTitle: _NS("Show All")];
368 [o_mi_quit setTitle: _NS("Quit VLC")];
370 [o_mu_file setTitle: _ANS("1:File")];
371 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
372 [o_mi_open_file setTitle: _NS("Open File...")];
373 [o_mi_open_disc setTitle: _NS("Open Disc...")];
374 [o_mi_open_net setTitle: _NS("Open Network...")];
375 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
376 [o_mi_open_recent setTitle: _NS("Open Recent")];
377 [o_mi_close_window setTitle: _NS("Close Window")];
378 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
379 [o_mi_convertandsave setTitle: _NS("Convert / Stream...")];
380 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
381 [o_mi_revealInFinder setTitle: _NS("Reveal in Finder")];
383 [o_mu_edit setTitle: _NS("Edit")];
384 [o_mi_cut setTitle: _NS("Cut")];
385 [o_mi_copy setTitle: _NS("Copy")];
386 [o_mi_paste setTitle: _NS("Paste")];
387 [o_mi_clear setTitle: _NS("Clear")];
388 [o_mi_select_all setTitle: _NS("Select All")];
390 [o_mu_view setTitle: _NS("View")];
391 [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
392 [o_mi_toggleJumpButtons setState: config_GetInt(VLCIntf, "macosx-show-playback-buttons")];
393 [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
394 [o_mi_togglePlaymodeButtons setState: config_GetInt(VLCIntf, "macosx-show-playmode-buttons")];
395 [o_mi_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
396 [o_mi_toggleEffectsButton setState: config_GetInt(VLCIntf, "macosx-show-effects-button")];
397 [o_mi_toggleSidebar setTitle: _NS("Show Sidebar")];
398 [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
399 [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
400 [o_mi_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
402 [o_mu_controls setTitle: _NS("Playback")];
403 [o_mi_play setTitle: _NS("Play")];
404 [o_mi_stop setTitle: _NS("Stop")];
405 [o_mi_record setTitle: _NS("Record")];
406 [o_mi_rate setView: o_mi_rate_view];
407 [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
408 [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
409 [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
410 [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
411 [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
412 [o_mi_previous setTitle: _NS("Previous")];
413 [o_mi_next setTitle: _NS("Next")];
414 [o_mi_random setTitle: _NS("Random")];
415 [o_mi_repeat setTitle: _NS("Repeat One")];
416 [o_mi_loop setTitle: _NS("Repeat All")];
417 [o_mi_AtoBloop setTitle: _NS("A→B Loop")];
418 [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
419 [o_mi_fwd setTitle: _NS("Step Forward")];
420 [o_mi_bwd setTitle: _NS("Step Backward")];
422 [o_mi_program setTitle: _NS("Program")];
423 [o_mu_program setTitle: _NS("Program")];
424 [o_mi_title setTitle: _NS("Title")];
425 [o_mu_title setTitle: _NS("Title")];
426 [o_mi_chapter setTitle: _NS("Chapter")];
427 [o_mu_chapter setTitle: _NS("Chapter")];
429 [o_mu_audio setTitle: _NS("Audio")];
430 [o_mi_vol_up setTitle: _NS("Increase Volume")];
431 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
432 [o_mi_mute setTitle: _NS("Mute")];
433 [o_mi_audiotrack setTitle: _NS("Audio Track")];
434 [o_mu_audiotrack setTitle: _NS("Audio Track")];
435 [o_mi_channels setTitle: _NS("Stereo audio mode")];
436 [o_mu_channels setTitle: _NS("Stereo audio mode")];
437 [o_mi_device setTitle: _NS("Audio Device")];
438 [o_mu_device setTitle: _NS("Audio Device")];
439 [o_mi_visual setTitle: _NS("Visualizations")];
440 [o_mu_visual setTitle: _NS("Visualizations")];
442 [o_mu_video setTitle: _NS("Video")];
443 [o_mi_half_window setTitle: _NS("Half Size")];
444 [o_mi_normal_window setTitle: _NS("Normal Size")];
445 [o_mi_double_window setTitle: _NS("Double Size")];
446 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
447 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
448 [o_mi_floatontop setTitle: _NS("Float on Top")];
449 [o_mi_snapshot setTitle: _NS("Snapshot")];
450 [o_mi_videotrack setTitle: _NS("Video Track")];
451 [o_mu_videotrack setTitle: _NS("Video Track")];
452 [o_mi_aspect_ratio setTitle: _NS("Aspect ratio")];
453 [o_mu_aspect_ratio setTitle: _NS("Aspect ratio")];
454 [o_mi_crop setTitle: _NS("Crop")];
455 [o_mu_crop setTitle: _NS("Crop")];
456 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
457 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
458 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
459 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
460 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
461 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
462 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
463 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
465 [o_mu_subtitles setTitle:_NS("Subtitles")];
466 [o_mi_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
467 [o_mi_subtitle_track setTitle: _NS("Subtitles Track")];
468 [o_mu_subtitle_tracks setTitle: _NS("Subtitles Track")];
469 [o_mi_subtitle_size setTitle: _NS("Text Size")];
470 [o_mi_subtitle_textcolor setTitle: _NS("Text Color")];
471 [o_mi_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
472 [o_mi_subtitle_bgopacity setView: o_mi_subtitle_bgopacity_view];
473 [o_mi_subtitle_bgopacity_lbl setStringValue: _NS("Background Opacity")];
474 [o_mi_subtitle_bgopacity_lbl_gray setStringValue: _NS("Background Opacity")];
475 [o_mi_subtitle_bgcolor setTitle: _NS("Background Color")];
476 [o_mi_teletext setTitle: _NS("Teletext")];
477 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
478 [o_mi_teletext_index setTitle: _NS("Index")];
479 [o_mi_teletext_red setTitle: _NS("Red")];
480 [o_mi_teletext_green setTitle: _NS("Green")];
481 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
482 [o_mi_teletext_blue setTitle: _NS("Blue")];
484 [o_mu_window setTitle: _NS("Window")];
485 [o_mi_minimize setTitle: _NS("Minimize")];
486 [o_mi_zoom_window setTitle: _NS("Zoom")];
487 [o_mi_player setTitle: _NS("Player...")];
488 [o_mi_controller setTitle: _NS("Main Window...")];
489 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
490 [o_mi_videoeffects setTitle: _NS("Video Effects...")];
491 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
492 [o_mi_playlist setTitle: _NS("Playlist...")];
493 [o_mi_info setTitle: _NS("Media Information...")];
494 [o_mi_messages setTitle: _NS("Messages...")];
495 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
497 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
499 [o_mu_help setTitle: _NS("Help")];
500 [o_mi_help setTitle: _NS("VLC media player Help...")];
501 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
502 [o_mi_license setTitle: _NS("License")];
503 [o_mi_documentation setTitle: _NS("Online Documentation...")];
504 [o_mi_website setTitle: _NS("VideoLAN Website...")];
505 [o_mi_donation setTitle: _NS("Make a donation...")];
506 [o_mi_forum setTitle: _NS("Online Forum...")];
509 [o_dmi_play setTitle: _NS("Play")];
510 [o_dmi_stop setTitle: _NS("Stop")];
511 [o_dmi_next setTitle: _NS("Next")];
512 [o_dmi_previous setTitle: _NS("Previous")];
513 [o_dmi_mute setTitle: _NS("Mute")];
516 [o_vmi_play setTitle: _NS("Play")];
517 [o_vmi_stop setTitle: _NS("Stop")];
518 [o_vmi_prev setTitle: _NS("Previous")];
519 [o_vmi_next setTitle: _NS("Next")];
520 [o_vmi_volup setTitle: _NS("Volume Up")];
521 [o_vmi_voldown setTitle: _NS("Volume Down")];
522 [o_vmi_mute setTitle: _NS("Mute")];
523 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
524 [o_vmi_snapshot setTitle: _NS("Snapshot")];
527 - (NSMenu *)setupPlaylistTableColumnsMenu
529 NSMenu *o_context_menu = [[NSMenu alloc] init];
531 NSMenuItem *o_mi_tmp;
532 NSUInteger count = [o_ptc_menuorder count];
533 for (NSUInteger i = 0; i < count; i++) {
534 NSString *o_title = [o_ptc_translation_dict objectForKey:[o_ptc_menuorder objectAtIndex:i]];
535 o_mi_tmp = [o_mu_playlistTableColumns addItemWithTitle:o_title
536 action:@selector(togglePlaylistColumnTable:)
538 /* don't set a valid target for the title column selector, since we want it to be disabled */
539 if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
540 [o_mi_tmp setTarget:self];
543 o_mi_tmp = [o_context_menu addItemWithTitle:o_title
544 action:@selector(togglePlaylistColumnTable:)
546 /* don't set a valid target for the title column selector, since we want it to be disabled */
547 if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
548 [o_mi_tmp setTarget:self];
551 if (!o_mu_playlistTableColumnsContextMenu)
552 o_mu_playlistTableColumnsContextMenu = [o_context_menu retain];
553 return [o_context_menu autorelease];
556 #pragma mark - Termination
558 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
562 NSArray *menuitems_array = [the_menu itemArray];
563 NSUInteger menuItemCount = [menuitems_array count];
564 for (NSUInteger i=0; i < menuItemCount; i++) {
565 NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
566 if ([one_item hasSubmenu])
567 [self releaseRepresentedObjects: [one_item submenu]];
569 [one_item setRepresentedObject:NULL];
573 #pragma mark - Interface update
577 playlist_t * p_playlist = pl_Get(p_intf);
578 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
579 if (p_input != NULL) {
580 [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
581 var: "program" selector: @selector(toggleVar:)];
583 [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
584 var: "title" selector: @selector(toggleVar:)];
586 [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
587 var: "chapter" selector: @selector(toggleVar:)];
589 [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
590 var: "audio-es" selector: @selector(toggleVar:)];
592 [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
593 var: "video-es" selector: @selector(toggleVar:)];
595 [self setupVarMenuItem: o_mi_subtitle_track target: (vlc_object_t *)p_input
596 var: "spu-es" selector: @selector(toggleVar:)];
598 audio_output_t * p_aout = playlist_GetAout(p_playlist);
599 if (p_aout != NULL) {
600 [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
601 var: "stereo-mode" selector: @selector(toggleVar:)];
603 [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
604 var: "visual" selector: @selector(toggleVar:)];
605 vlc_object_release(p_aout);
608 vout_thread_t * p_vout = getVoutForActiveWindow();
610 if (p_vout != NULL) {
611 [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
612 var: "aspect-ratio" selector: @selector(toggleVar:)];
614 [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
615 var: "crop" selector: @selector(toggleVar:)];
617 [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
618 var: "deinterlace" selector: @selector(toggleVar:)];
620 [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
621 var: "deinterlace-mode" selector: @selector(toggleVar:)];
623 vlc_object_release(p_vout);
625 [self refreshVoutDeviceMenu:nil];
627 [o_mi_ffmpeg_pp setEnabled:YES];
628 vlc_object_release(p_input);
630 [o_mi_ffmpeg_pp setEnabled:NO];
634 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
636 NSUInteger count = (NSUInteger) [o_mu_screen numberOfItems];
637 NSMenu * o_submenu = o_mu_screen;
639 [o_submenu removeAllItems];
641 NSArray * o_screens = [NSScreen screens];
642 NSMenuItem * o_mitem;
643 count = [o_screens count];
644 [o_mi_screen setEnabled: YES];
645 [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
646 o_mitem = [o_submenu itemAtIndex: 0];
648 [o_mitem setEnabled: YES];
649 [o_mitem setTarget: self];
651 for (NSUInteger i = 0; i < count; i++) {
652 s_rect = [[o_screens objectAtIndex:i] frame];
653 [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
654 (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
655 o_mitem = [o_submenu itemAtIndex:i+1];
656 [o_mitem setTag: (int)[[o_screens objectAtIndex:i] displayID]];
657 [o_mitem setEnabled: YES];
658 [o_mitem setTarget: self];
660 [[o_submenu itemWithTag: var_InheritInteger(VLCIntf, "macosx-vdev")] setState: NSOnState];
663 - (void)setSubmenusEnabled:(BOOL)b_enabled
665 [o_mi_program setEnabled: b_enabled];
666 [o_mi_title setEnabled: b_enabled];
667 [o_mi_chapter setEnabled: b_enabled];
668 [o_mi_audiotrack setEnabled: b_enabled];
669 [o_mi_visual setEnabled: b_enabled];
670 [o_mi_videotrack setEnabled: b_enabled];
671 [o_mi_subtitle_track setEnabled: b_enabled];
672 [o_mi_channels setEnabled: b_enabled];
673 [o_mi_deinterlace setEnabled: b_enabled];
674 [o_mi_deinterlace_mode setEnabled: b_enabled];
675 [o_mi_screen setEnabled: b_enabled];
676 [o_mi_aspect_ratio setEnabled: b_enabled];
677 [o_mi_crop setEnabled: b_enabled];
680 - (void)setSubtitleMenuEnabled:(BOOL)b_enabled
682 [o_mi_openSubtitleFile setEnabled: b_enabled];
684 [o_mi_subtitle_bgopacity_lbl_gray setHidden: YES];
685 [o_mi_subtitle_bgopacity_lbl setHidden: NO];
687 [o_mi_subtitle_bgopacity_lbl_gray setHidden: NO];
688 [o_mi_subtitle_bgopacity_lbl setHidden: YES];
690 [o_mi_subtitle_bgopacity_sld setEnabled: b_enabled];
691 [o_mi_teletext setEnabled: b_enabled];
694 - (void)setRateControlsEnabled:(BOOL)b_enabled
696 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
697 [o_mi_rate_sld setEnabled: b_enabled];
698 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
699 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
700 double speed = pow(2, (double)i / 17);
701 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
703 NSColor *o_color = b_enabled ? [NSColor controlTextColor] : [NSColor disabledControlTextColor];
705 [o_mi_rate_lbl setTextColor:o_color];
706 [o_mi_rate_slower_lbl setTextColor:o_color];
707 [o_mi_rate_normal_lbl setTextColor:o_color];
708 [o_mi_rate_faster_lbl setTextColor:o_color];
709 [o_mi_rate_fld setTextColor:o_color];
711 [self setSubtitleMenuEnabled: b_enabled];
717 - (IBAction)toggleEffectsButton:(id)sender
719 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-effects-button");
720 config_PutInt(VLCIntf, "macosx-show-effects-button", b_value);
721 [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
722 [o_mi_toggleEffectsButton setState: b_value];
725 - (IBAction)toggleJumpButtons:(id)sender
727 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playback-buttons");
728 config_PutInt(VLCIntf, "macosx-show-playback-buttons", b_value);
730 [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
731 [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
732 [[o_window controlsBar] toggleForwardBackwardMode: b_value];
735 [o_mi_toggleJumpButtons setState: b_value];
738 - (IBAction)togglePlaymodeButtons:(id)sender
740 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
741 config_PutInt(VLCIntf, "macosx-show-playmode-buttons", b_value);
742 [[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
743 [o_mi_togglePlaymodeButtons setState: b_value];
746 - (IBAction)toggleSidebar:(id)sender
748 [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
751 - (void)updateSidebarMenuItem
753 [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
756 - (IBAction)togglePlaylistColumnTable:(id)sender
758 NSInteger i_new_state = ![sender state];
759 NSInteger i_tag = [sender tag];
760 [[o_mu_playlistTableColumns itemWithTag: i_tag] setState: i_new_state];
761 [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];
763 NSString *o_column = [o_ptc_menuorder objectAtIndex:i_tag];
764 [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
767 - (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
769 NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
770 // prevent setting unknown columns
771 if(i_tag == NSNotFound)
774 [[o_mu_playlistTableColumns itemWithTag: i_tag] setState: i_state];
775 [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
776 [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
781 #pragma mark - Playback
783 - (IBAction)quitAfterPlayback:(id)sender
785 playlist_t *p_playlist = pl_Get(VLCIntf);
786 bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
787 var_SetBool(p_playlist, "play-and-exit", b_value);
788 config_PutInt(p_intf, "play-and-exit", b_value);
791 - (IBAction)toggleRecord:(id)sender
793 [[VLCCoreInteraction sharedInstance] toggleRecord];
796 - (void)updateRecordState:(BOOL)b_value
798 [o_mi_record setState:b_value];
801 - (IBAction)setPlaybackRate:(id)sender
803 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
804 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
805 double speed = pow(2, (double)i / 17);
806 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
809 - (void)updatePlaybackRate
811 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
812 double speed = pow(2, (double)i / 17);
813 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
814 [o_mi_rate_sld setIntValue: i];
817 - (IBAction)toggleAtoBloop:(id)sender
819 [[VLCCoreInteraction sharedInstance] setAtoB];
822 #pragma mark - audio menu
824 - (void)refreshAudioDeviceList
829 [o_mu_device removeAllItems];
831 audio_output_t * p_aout = getAout();
835 int n = aout_DevicesList(p_aout, &ids, &names);
837 vlc_object_release(p_aout);
841 currentDevice = aout_DeviceGet(p_aout);
842 NSMenuItem * o_mi_tmp;
844 for (NSUInteger x = 0; x < n; x++) {
845 o_mi_tmp = [o_mu_device addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
846 [o_mi_tmp setTarget:self];
847 [o_mi_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
849 vlc_object_release(p_aout);
851 [[o_mu_device itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];
855 for (NSUInteger x = 0; x < n; x++) {
862 [o_mu_device setAutoenablesItems:YES];
863 [o_mi_device setEnabled:YES];
866 - (IBAction)toggleAudioDevice:(id)sender
868 audio_output_t * p_aout = getAout();
874 if ([sender tag] > 0)
875 returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
877 returnValue = aout_DeviceSet(p_aout, NULL);
879 if (returnValue != 0)
880 msg_Warn(VLCIntf, "failed to set audio device %li", [sender tag]);
882 vlc_object_release(p_aout);
883 [self refreshAudioDeviceList];
886 #pragma mark - video menu
888 - (IBAction)toggleFullscreen:(id)sender
890 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
893 - (IBAction)resizeVideoWindow:(id)sender
895 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
897 vout_thread_t *p_vout = getVoutForActiveWindow();
899 if (sender == o_mi_half_window)
900 var_SetFloat(p_vout, "zoom", 0.5);
901 else if (sender == o_mi_normal_window)
902 var_SetFloat(p_vout, "zoom", 1.0);
903 else if (sender == o_mi_double_window)
904 var_SetFloat(p_vout, "zoom", 2.0);
907 [[NSApp keyWindow] performZoom:sender];
909 vlc_object_release(p_vout);
911 vlc_object_release(p_input);
915 - (IBAction)floatOnTop:(id)sender
917 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
919 vout_thread_t *p_vout = getVoutForActiveWindow();
921 BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
922 var_SetBool(pl_Get(p_intf), "video-on-top", b_fs);
924 vlc_object_release(p_vout);
926 vlc_object_release(p_input);
930 - (IBAction)createVideoSnapshot:(id)sender
932 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
934 vout_thread_t *p_vout = getVoutForActiveWindow();
936 var_TriggerCallback(p_vout, "video-snapshot");
937 vlc_object_release(p_vout);
939 vlc_object_release(p_input);
943 - (void)_disablePostProcessing
945 [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
948 - (void)_enablePostProcessing
950 [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
953 - (IBAction)togglePostProcessing:(id)sender
955 char *psz_name = "postproc";
956 NSInteger count = [o_mu_ffmpeg_pp numberOfItems];
957 for (NSUInteger x = 0; x < count; x++)
958 [[o_mu_ffmpeg_pp itemAtIndex:x] setState:NSOffState];
960 if ([sender tag] == -1) {
961 [self _disablePostProcessing];
962 [sender setState:NSOnState];
964 [self _enablePostProcessing];
965 [sender setState:NSOnState];
967 [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
971 - (IBAction)toggleFullscreenDevice:(id)sender
973 config_PutInt(VLCIntf, "macosx-vdev", [sender tag]);
974 [self refreshVoutDeviceMenu: nil];
982 #pragma mark - Subtitles Menu
984 - (IBAction)addSubtitleFile:(id)sender
986 NSInteger i_returnValue = 0;
987 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
991 input_item_t *p_item = input_GetItem(p_input);
993 vlc_object_release(p_input);
997 char *path = input_item_GetURI(p_item);
1002 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
1003 [openPanel setCanChooseFiles: YES];
1004 [openPanel setCanChooseDirectories: NO];
1005 [openPanel setAllowsMultipleSelection: YES];
1007 [openPanel setAllowedFileTypes: [NSArray arrayWithObjects:@"cdg",@"idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil",nil]];
1009 NSURL *o_url = [NSURL URLWithString:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]];
1010 o_url = [o_url URLByDeletingLastPathComponent];
1011 [openPanel setDirectoryURL: o_url];
1013 vlc_object_release(p_input);
1015 i_returnValue = [openPanel runModal];
1017 if (i_returnValue == NSOKButton)
1018 [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1021 - (IBAction)switchSubtitleOption:(id)sender
1023 int intValue = [sender tag];
1024 NSString *representedObject = [sender representedObject];
1026 config_PutInt(p_intf, [representedObject UTF8String], intValue);
1028 NSMenu *menu = [sender menu];
1029 NSUInteger count = (NSUInteger) [menu numberOfItems];
1030 for (NSUInteger x = 0; x < count; x++)
1031 [[menu itemAtIndex:x] setState:NSOffState];
1032 [[menu itemWithTag:intValue] setState:NSOnState];
1035 - (IBAction)switchSubtitleBackgroundOpacity:(id)sender
1037 config_PutInt(p_intf, "freetype-background-opacity", [sender intValue]);
1040 - (IBAction)telxTransparent:(id)sender
1042 vlc_object_t *p_vbi;
1043 p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1045 var_SetBool(p_vbi, "vbi-opaque", [sender state]);
1046 [sender setState: ![sender state]];
1047 vlc_object_release(p_vbi);
1051 - (IBAction)telxNavLink:(id)sender
1053 vlc_object_t *p_vbi;
1056 if ([[sender title] isEqualToString: _NS("Index")])
1058 else if ([[sender title] isEqualToString: _NS("Red")])
1060 else if ([[sender title] isEqualToString: _NS("Green")])
1062 else if ([[sender title] isEqualToString: _NS("Yellow")])
1064 else if ([[sender title] isEqualToString: _NS("Blue")])
1066 if (i_page == 0) return;
1068 p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1070 var_SetInteger(p_vbi, "vbi-page", i_page);
1071 vlc_object_release(p_vbi);
1075 #pragma mark - Panels
1077 - (IBAction)intfOpenFile:(id)sender
1079 [[[VLCMain sharedInstance] open] openFile];
1082 - (IBAction)intfOpenFileGeneric:(id)sender
1084 [[[VLCMain sharedInstance] open] openFileGeneric];
1087 - (IBAction)intfOpenDisc:(id)sender
1089 [[[VLCMain sharedInstance] open] openDisc];
1092 - (IBAction)intfOpenNet:(id)sender
1094 [[[VLCMain sharedInstance] open] openNet];
1097 - (IBAction)intfOpenCapture:(id)sender
1099 [[[VLCMain sharedInstance] open] openCapture];
1102 - (IBAction)showWizard:(id)sender
1104 [[[VLCMain sharedInstance] wizard] resetWizard];
1105 [[[VLCMain sharedInstance] wizard] showWizard];
1108 - (IBAction)savePlaylist:(id)sender
1110 [[[VLCMain sharedInstance] playlist] savePlaylist:sender];
1113 - (IBAction)revealItemInFinder:(id)sender
1115 [[[VLCMain sharedInstance] playlist] revealItemInFinder:sender];
1118 - (IBAction)showConvertAndSave:(id)sender
1120 if (o_convertandsave == nil)
1121 o_convertandsave = [[VLCConvertAndSave alloc] init];
1123 if (!b_nib_convertandsave_loaded)
1124 b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
1126 [o_convertandsave toggleWindow];
1129 - (IBAction)showVideoEffects:(id)sender
1131 if (o_videoeffects == nil)
1132 o_videoeffects = [[VLCVideoEffects alloc] init];
1134 if (!b_nib_videoeffects_loaded)
1135 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
1137 [o_videoeffects toggleWindow:sender];
1140 - (IBAction)showTrackSynchronization:(id)sender
1142 if (!o_trackSynchronization)
1143 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
1145 if (!b_nib_tracksynchro_loaded)
1146 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
1148 [o_trackSynchronization toggleWindow:sender];
1151 - (IBAction)showAudioEffects:(id)sender
1153 if (!o_audioeffects)
1154 o_audioeffects = [[VLCAudioEffects alloc] init];
1156 if (!b_nib_audioeffects_loaded)
1157 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
1159 [o_audioeffects toggleWindow:sender];
1162 - (IBAction)showBookmarks:(id)sender
1164 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
1167 - (IBAction)viewPreferences:(id)sender
1169 NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel];
1170 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
1173 - (IBAction)openAddonManager:(id)sender
1175 if (!o_addonManager)
1176 o_addonManager = [[VLCAddonManager alloc] init];
1178 if (!b_nib_addonmanager_loaded)
1179 b_nib_addonmanager_loaded = [NSBundle loadNibNamed:@"AddonManager" owner:NSApp];
1181 [o_addonManager showWindow];
1184 - (IBAction)showMessagesPanel:(id)showMessagesPanel
1186 [[VLCDebugMessageVisualizer sharedInstance] showPanel];
1189 - (IBAction)showMainWindow:(id)sender
1191 [[VLCMainWindow sharedInstance] makeKeyAndOrderFront:sender];
1194 - (IBAction)showPlaylist:(id)sender
1196 [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
1199 #pragma mark - Help and Docs
1204 o_about = [[VLAboutBox alloc] init];
1206 if (!b_nib_about_loaded)
1207 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
1210 - (IBAction)viewAbout:(id)sender
1213 [o_about showAbout];
1216 - (IBAction)showLicense:(id)sender
1222 - (IBAction)viewHelp:(id)sender
1228 - (IBAction)openReadMe:(id)sender
1230 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
1232 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
1235 - (IBAction)openDocumentation:(id)sender
1237 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
1239 [[NSWorkspace sharedWorkspace] openURL: o_url];
1242 - (IBAction)openWebsite:(id)sender
1244 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1246 [[NSWorkspace sharedWorkspace] openURL: o_url];
1249 - (IBAction)openForum:(id)sender
1251 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1253 [[NSWorkspace sharedWorkspace] openURL: o_url];
1256 - (IBAction)openDonate:(id)sender
1258 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1260 [[NSWorkspace sharedWorkspace] openURL: o_url];
1263 #pragma mark - Errors, warnings and messages
1265 - (IBAction)viewErrorsAndWarnings:(id)sender
1267 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
1270 - (IBAction)showInformationPanel:(id)sender
1272 [[[VLCMain sharedInstance] info] initPanel];
1275 #pragma mark - convinience stuff for other objects
1279 [o_mi_play setTitle: _NS("Play")];
1280 [o_dmi_play setTitle: _NS("Play")];
1281 [o_vmi_play setTitle: _NS("Play")];
1286 [o_mi_play setTitle: _NS("Pause")];
1287 [o_dmi_play setTitle: _NS("Pause")];
1288 [o_vmi_play setTitle: _NS("Pause")];
1291 - (void)setRepeatOne
1293 [o_mi_repeat setState: NSOnState];
1294 [o_mi_loop setState: NSOffState];
1297 - (void)setRepeatAll
1299 [o_mi_repeat setState: NSOffState];
1300 [o_mi_loop setState: NSOnState];
1303 - (void)setRepeatOff
1305 [o_mi_repeat setState: NSOffState];
1306 [o_mi_loop setState: NSOffState];
1312 playlist_t *p_playlist = pl_Get(VLCIntf);
1313 b_value = var_GetBool(p_playlist, "random");
1315 [o_mi_random setState: b_value];
1318 #pragma mark - Dynamic menu creation and validation
1320 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
1321 target:(vlc_object_t *)p_object
1322 var:(const char *)psz_variable
1323 selector:(SEL)pf_callback
1325 vlc_value_t val, text;
1326 int i_type = var_Type(p_object, psz_variable);
1328 switch(i_type & VLC_VAR_TYPE) {
1331 case VLC_VAR_VARIABLE:
1332 case VLC_VAR_STRING:
1333 case VLC_VAR_INTEGER:
1336 /* Variable doesn't exist or isn't handled */
1337 msg_Warn(p_object, "variable %s doesn't exist or isn't handled", psz_variable);
1341 /* Get the descriptive name of the variable */
1342 var_Change(p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL);
1343 [o_mi setTitle: _NS(text.psz_string ? text.psz_string : psz_variable)];
1345 if (i_type & VLC_VAR_HASCHOICE) {
1346 NSMenu *o_menu = [o_mi submenu];
1348 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
1349 var:psz_variable selector:pf_callback];
1351 free(text.psz_string);
1355 if (var_Get(p_object, psz_variable, &val) < 0)
1358 VLCAutoGeneratedMenuContent *o_data;
1359 switch(i_type & VLC_VAR_TYPE) {
1361 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1362 andValue: val ofType: i_type];
1363 [o_mi setRepresentedObject: [o_data autorelease]];
1367 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1368 andValue: val ofType: i_type];
1369 [o_mi setRepresentedObject: [o_data autorelease]];
1370 if (!(i_type & VLC_VAR_ISCOMMAND))
1371 [o_mi setState: val.b_bool ? TRUE : FALSE ];
1378 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1379 free(text.psz_string);
1383 - (void)setupVarMenu:(NSMenu *)o_menu
1384 forMenuItem: (NSMenuItem *)o_parent
1385 target:(vlc_object_t *)p_object
1386 var:(const char *)psz_variable
1387 selector:(SEL)pf_callback
1389 vlc_value_t val, val_list, text_list;
1392 /* remove previous items */
1393 [o_menu removeAllItems];
1395 /* we disable everything here, and enable it again when needed, below */
1396 [o_parent setEnabled:NO];
1399 if ([[o_parent title] isEqualToString: _NS("Aspect ratio")] == YES) {
1400 NSMenuItem *o_lmi_tmp2;
1401 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1402 [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1403 [o_lmi_tmp2 setEnabled: YES];
1404 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1405 [o_parent setEnabled: YES];
1406 [o_menu addItem: [NSMenuItem separatorItem]];
1409 /* Check the type of the object variable */
1410 i_type = var_Type(p_object, psz_variable);
1412 /* Make sure we want to display the variable */
1413 if (i_type & VLC_VAR_HASCHOICE) {
1414 var_Change(p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL);
1417 if ((i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1)
1423 switch(i_type & VLC_VAR_TYPE) {
1426 case VLC_VAR_VARIABLE:
1427 case VLC_VAR_STRING:
1428 case VLC_VAR_INTEGER:
1431 /* Variable doesn't exist or isn't handled */
1435 if (var_Get(p_object, psz_variable, &val) < 0) {
1439 if (var_Change(p_object, psz_variable, VLC_VAR_GETCHOICES,
1440 &val_list, &text_list) < 0) {
1441 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1445 /* make (un)sensitive */
1446 [o_parent setEnabled: (val_list.p_list->i_count > 1)];
1448 for (i = 0; i < val_list.p_list->i_count; i++) {
1450 NSString *o_title = @"";
1451 VLCAutoGeneratedMenuContent *o_data;
1453 switch(i_type & VLC_VAR_TYPE) {
1454 case VLC_VAR_STRING:
1456 o_title = _NS(text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string);
1458 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1459 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1460 andValue: val_list.p_list->p_values[i] ofType: i_type];
1461 [o_lmi setRepresentedObject: [o_data autorelease]];
1462 [o_lmi setTarget: self];
1464 if (!strcmp(val.psz_string, val_list.p_list->p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
1465 [o_lmi setState: TRUE ];
1469 case VLC_VAR_INTEGER:
1471 o_title = text_list.p_list->p_values[i].psz_string ?
1472 _NS(text_list.p_list->p_values[i].psz_string) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1474 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1475 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1476 andValue: val_list.p_list->p_values[i] ofType: i_type];
1477 [o_lmi setRepresentedObject: [o_data autorelease]];
1478 [o_lmi setTarget: self];
1480 if (val_list.p_list->p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
1481 [o_lmi setState: TRUE ];
1489 /* clean up everything */
1490 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1491 var_FreeList(&val_list, &text_list);
1494 - (IBAction)toggleVar:(id)sender
1496 NSMenuItem *o_mi = (NSMenuItem *)sender;
1497 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1498 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1499 toTarget: self withObject: o_data];
1504 - (int)toggleVarThread: (id)data
1506 vlc_object_t *p_object;
1507 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1509 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1510 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1512 p_object = [menuContent vlcObject];
1514 if (p_object != NULL) {
1515 var_Set(p_object, [menuContent name], [menuContent value]);
1516 vlc_object_release(p_object);
1521 return VLC_EGENERIC;
1526 @implementation VLCMainMenu (NSMenuValidation)
1528 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1530 NSString *o_title = [o_mi title];
1531 BOOL bEnabled = TRUE;
1533 playlist_t * p_playlist = pl_Get(p_intf);
1534 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
1536 if ([o_title isEqualToString: _NS("Stop")]) {
1539 [self setupMenus]; /* Make sure input menu is up to date */
1540 } else if ([o_title isEqualToString: _NS("Record")]) {
1543 bEnabled = var_GetBool(p_input, "can-record");
1544 } else if ([o_title isEqualToString: _NS("Previous")] ||
1545 [o_title isEqualToString: _NS("Next")]) {
1547 bEnabled = playlist_CurrentSize(p_playlist) > 1;
1549 } else if ([o_title isEqualToString: _NS("Random")]) {
1551 var_Get(p_playlist, "random", &val);
1552 i_state = val.b_bool ? NSOnState : NSOffState;
1553 [o_mi setState: i_state];
1554 } else if ([o_title isEqualToString: _NS("Repeat One")]) {
1556 var_Get(p_playlist, "repeat", &val);
1557 i_state = val.b_bool ? NSOnState : NSOffState;
1558 [o_mi setState: i_state];
1559 } else if ([o_title isEqualToString: _NS("Repeat All")]) {
1561 var_Get(p_playlist, "loop", &val);
1562 i_state = val.b_bool ? NSOnState : NSOffState;
1563 [o_mi setState: i_state];
1564 } else if ([o_title isEqualToString: _NS("Quit after Playback")]) {
1566 bool b_value = var_InheritBool(p_playlist, "play-and-exit");
1567 i_state = b_value ? NSOnState : NSOffState;
1568 [o_mi setState: i_state];
1569 } else if ([o_title isEqualToString: _NS("Step Forward")] ||
1570 [o_title isEqualToString: _NS("Step Backward")] ||
1571 [o_title isEqualToString: _NS("Jump to Time")]) {
1572 if (p_input != NULL) {
1573 var_Get(p_input, "can-seek", &val);
1574 bEnabled = val.b_bool;
1576 else bEnabled = FALSE;
1577 } else if ([o_title isEqualToString: _NS("Mute")]) {
1578 [o_mi setState: [[VLCCoreInteraction sharedInstance] mute] ? NSOnState : NSOffState];
1579 [self setupMenus]; /* Make sure audio menu is up to date */
1580 [self refreshAudioDeviceList];
1581 } else if ([o_title isEqualToString: _NS("Half Size")] ||
1582 [o_title isEqualToString: _NS("Normal Size")] ||
1583 [o_title isEqualToString: _NS("Double Size")] ||
1584 [o_title isEqualToString: _NS("Fit to Screen")] ||
1585 [o_title isEqualToString: _NS("Snapshot")] ||
1586 [o_title isEqualToString: _NS("Fullscreen")] ||
1587 [o_title isEqualToString: _NS("Float on Top")]) {
1590 if (p_input != NULL) {
1591 vout_thread_t *p_vout = getVoutForActiveWindow();
1592 if (p_vout != NULL) {
1593 if ([o_title isEqualToString: _NS("Float on Top")])
1594 [o_mi setState: var_GetBool(p_vout, "video-on-top")];
1596 if ([o_title isEqualToString: _NS("Fullscreen")])
1597 [o_mi setState: var_GetBool(p_vout, "fullscreen")];
1600 vlc_object_release(p_vout);
1604 [self setupMenus]; /* Make sure video menu is up to date */
1606 } else if ([o_title isEqualToString: _NS("Add Subtitle File...")]) {
1607 bEnabled = [o_mi isEnabled];
1608 [self setupMenus]; /* Make sure subtitles menu is up to date */
1610 NSMenuItem *o_mi_parent = [o_mi parentItem];
1611 if (o_mi_parent == o_mi_subtitle_size || o_mi == o_mi_subtitle_size ||
1612 o_mi_parent == o_mi_subtitle_textcolor || o_mi == o_mi_subtitle_textcolor ||
1613 o_mi_parent == o_mi_subtitle_bgcolor || o_mi == o_mi_subtitle_bgcolor ||
1614 o_mi_parent == o_mi_subtitle_bgopacity || o_mi == o_mi_subtitle_bgopacity ||
1615 o_mi_parent == o_mi_subtitle_outlinethickness || o_mi == o_mi_subtitle_outlinethickness ||
1616 o_mi_parent == o_mi_teletext || o_mi == o_mi_teletext)
1617 bEnabled = o_mi_openSubtitleFile.isEnabled;
1620 /* Special case for telx menu */
1621 if ([o_title isEqualToString: _NS("Normal Size")]) {
1622 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1623 bool b_telx = p_input && var_GetInteger(p_input, "teletext-es") >= 0;
1625 [[item submenu] setAutoenablesItems:NO];
1627 for (int k=0; k < [[item submenu] numberOfItems]; k++)
1628 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1632 vlc_object_release(p_input);
1640 /*****************************************************************************
1641 * VLCAutoGeneratedMenuContent implementation
1642 *****************************************************************************
1643 * Object connected to a playlistitem which remembers the data belonging to
1644 * the variable of the autogenerated menu
1645 *****************************************************************************/
1646 @implementation VLCAutoGeneratedMenuContent
1648 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1649 andValue:(vlc_value_t)val ofType:(int)type
1651 self = [super init];
1654 _vlc_object = vlc_object_hold(object);
1655 psz_name = strdup(name);
1658 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1659 value.psz_string = strdup(val.psz_string);
1668 vlc_object_release(_vlc_object);
1669 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1670 free(value.psz_string);
1675 - (const char *)name
1680 - (vlc_value_t)value
1685 - (vlc_object_t *)vlcObject
1687 return vlc_object_hold(_vlc_object);