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];
142 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
147 playlist_t *p_playlist;
149 id o_vlcstringutility = [VLCStringUtility sharedInstance];
152 /* Check if we already did this once. Opening the other nibs calls it too,
153 because VLCMain is the owner */
154 if (b_mainMenu_setup)
157 /* Get ExtensionsManager */
158 o_extMgr = [ExtensionsManager getInstance:p_intf];
163 key = config_GetPsz(p_intf, "key-quit");
164 o_key = [NSString stringWithFormat:@"%s", key];
165 [o_mi_quit setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
166 [o_mi_quit setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
169 // do not assign play/pause key
171 key = config_GetPsz(p_intf, "key-stop");
172 o_key = [NSString stringWithFormat:@"%s", key];
173 [o_mi_stop setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
174 [o_mi_stop setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
177 key = config_GetPsz(p_intf, "key-prev");
178 o_key = [NSString stringWithFormat:@"%s", key];
179 [o_mi_previous setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
180 [o_mi_previous setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
183 key = config_GetPsz(p_intf, "key-next");
184 o_key = [NSString stringWithFormat:@"%s", key];
185 [o_mi_next setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
186 [o_mi_next setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
189 key = config_GetPsz(p_intf, "key-jump+short");
190 o_key = [NSString stringWithFormat:@"%s", key];
191 [o_mi_fwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
192 [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
195 key = config_GetPsz(p_intf, "key-jump-short");
196 o_key = [NSString stringWithFormat:@"%s", key];
197 [o_mi_bwd setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
198 [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
201 key = config_GetPsz(p_intf, "key-vol-up");
202 o_key = [NSString stringWithFormat:@"%s", key];
203 [o_mi_vol_up setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
204 [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
207 key = config_GetPsz(p_intf, "key-vol-down");
208 o_key = [NSString stringWithFormat:@"%s", key];
209 [o_mi_vol_down setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
210 [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
213 key = config_GetPsz(p_intf, "key-vol-mute");
214 o_key = [NSString stringWithFormat:@"%s", key];
215 [o_mi_mute setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
216 [o_mi_mute setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
219 key = config_GetPsz(p_intf, "key-toggle-fullscreen");
220 o_key = [NSString stringWithFormat:@"%s", key];
221 [o_mi_fullscreen setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
222 [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
225 key = config_GetPsz(p_intf, "key-snapshot");
226 o_key = [NSString stringWithFormat:@"%s", key];
227 [o_mi_snapshot setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
228 [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
231 key = config_GetPsz(p_intf, "key-random");
232 o_key = [NSString stringWithFormat:@"%s", key];
233 [o_mi_random setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
234 [o_mi_random setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
237 key = config_GetPsz(p_intf, "key-zoom-half");
238 o_key = [NSString stringWithFormat:@"%s", key];
239 [o_mi_half_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
240 [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
243 key = config_GetPsz(p_intf, "key-zoom-original");
244 o_key = [NSString stringWithFormat:@"%s", key];
245 [o_mi_normal_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
246 [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
249 key = config_GetPsz(p_intf, "key-zoom-double");
250 o_key = [NSString stringWithFormat:@"%s", key];
251 [o_mi_double_window setKeyEquivalent: [o_vlcstringutility VLCKeyToString: o_key]];
252 [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcstringutility VLCModifiersToCocoa:o_key]];
255 [self setSubmenusEnabled: FALSE];
257 [[NSNotificationCenter defaultCenter] addObserver: self
258 selector: @selector(refreshVoutDeviceMenu:)
259 name: NSApplicationDidChangeScreenParametersNotification
263 b_mainMenu_setup = YES;
265 [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
266 var: "intf-add" selector: @selector(toggleVar:)];
268 /* setup extensions menu */
269 // FIXME: Implement preference for autoloading extensions on mac
270 if (![o_extMgr isLoaded] && ![o_extMgr cannotLoad])
271 [o_extMgr loadExtensions];
273 /* Let the ExtensionsManager itself build the menu */
274 [o_extMgr buildMenu:o_mu_extensions];
275 [o_mi_extensions setEnabled: ([o_mu_extensions numberOfItems] > 0)];
277 /* setup post-proc menu */
278 NSUInteger count = (NSUInteger) [o_mu_ffmpeg_pp numberOfItems];
280 [o_mu_ffmpeg_pp removeAllItems];
282 NSMenuItem * o_mitem;
283 [o_mu_ffmpeg_pp setAutoenablesItems: YES];
284 [o_mu_ffmpeg_pp addItemWithTitle: _NS("Disable") action:@selector(togglePostProcessing:) keyEquivalent:@""];
285 o_mitem = [o_mu_ffmpeg_pp itemAtIndex: 0];
286 [o_mitem setTag: -1];
287 [o_mitem setEnabled: YES];
288 [o_mitem setTarget: self];
289 for (NSUInteger x = 1; x < 7; x++) {
290 [o_mu_ffmpeg_pp addItemWithTitle:[NSString stringWithFormat:_NS("Level %i"), x]
291 action:@selector(togglePostProcessing:)
293 o_mitem = [o_mu_ffmpeg_pp itemAtIndex:x];
294 [o_mitem setEnabled:YES];
296 [o_mitem setTarget:self];
298 char *psz_config = config_GetPsz(p_intf, "video-filter");
300 if (!strstr(psz_config, "postproc"))
301 [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
303 [[o_mu_ffmpeg_pp itemWithTag:config_GetInt(p_intf, "postproc-q")] setState:NSOnState];
306 [[o_mu_ffmpeg_pp itemAtIndex:0] setState:NSOnState];
307 [o_mi_ffmpeg_pp setEnabled: NO];
309 [self refreshAudioDeviceList];
311 /* setup subtitles menu */
312 [self setupMenu: o_mu_subtitle_size withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
313 [self setupMenu: o_mu_subtitle_textcolor withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
314 [o_mi_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
315 [self setupMenu: o_mu_subtitle_bgcolor withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
316 [self setupMenu: o_mu_subtitle_outlinethickness withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
319 - (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
321 module_config_t *p_item;
323 [menu removeAllItems];
324 p_item = config_FindConfig(VLC_OBJECT(p_intf), psz_name);
326 /* serious problem, if no item found */
329 for (int i = 0; i < p_item->list_count; i++) {
331 if (p_item->list_text != NULL)
332 mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
333 else if (p_item->list.i[i])
334 mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
336 msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
341 [mi setAction:selector];
342 [mi setTag:p_item->list.i[i]];
343 [mi setRepresentedObject:[NSString stringWithUTF8String:psz_name]];
344 [menu addItem: [mi autorelease]];
345 if (p_item->value.i == p_item->list.i[i])
346 [mi setState:NSOnState];
353 [o_mi_about setTitle: [_NS("About VLC media player") \
354 stringByAppendingString: @"..."]];
355 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
356 [o_mi_prefs setTitle: _NS("Preferences...")];
357 [o_mi_extensions setTitle: _NS("Extensions")];
358 [o_mu_extensions setTitle: _NS("Extensions")];
359 [o_mi_addonManager setTitle: _NS("Addons Manager")];
360 [o_mi_add_intf setTitle: _NS("Add Interface")];
361 [o_mu_add_intf setTitle: _NS("Add Interface")];
362 [o_mi_services setTitle: _NS("Services")];
363 [o_mi_hide setTitle: _NS("Hide VLC")];
364 [o_mi_hide_others setTitle: _NS("Hide Others")];
365 [o_mi_show_all setTitle: _NS("Show All")];
366 [o_mi_quit setTitle: _NS("Quit VLC")];
368 [o_mu_file setTitle: _ANS("1:File")];
369 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
370 [o_mi_open_file setTitle: _NS("Open File...")];
371 [o_mi_open_disc setTitle: _NS("Open Disc...")];
372 [o_mi_open_net setTitle: _NS("Open Network...")];
373 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
374 [o_mi_open_recent setTitle: _NS("Open Recent")];
375 [o_mi_close_window setTitle: _NS("Close Window")];
376 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
377 [o_mi_convertandsave setTitle: _NS("Convert / Stream...")];
378 [o_mi_save_playlist setTitle: _NS("Save Playlist...")];
380 [o_mu_edit setTitle: _NS("Edit")];
381 [o_mi_cut setTitle: _NS("Cut")];
382 [o_mi_copy setTitle: _NS("Copy")];
383 [o_mi_paste setTitle: _NS("Paste")];
384 [o_mi_clear setTitle: _NS("Clear")];
385 [o_mi_select_all setTitle: _NS("Select All")];
387 [o_mu_view setTitle: _NS("View")];
388 [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
389 [o_mi_toggleJumpButtons setState: config_GetInt(VLCIntf, "macosx-show-playback-buttons")];
390 [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
391 [o_mi_togglePlaymodeButtons setState: config_GetInt(VLCIntf, "macosx-show-playmode-buttons")];
392 [o_mi_toggleEffectsButton setTitle: _NS("Show Audio Effects Button")];
393 [o_mi_toggleEffectsButton setState: config_GetInt(VLCIntf, "macosx-show-effects-button")];
394 [o_mi_toggleSidebar setTitle: _NS("Show Sidebar")];
395 [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
396 [o_mu_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
397 [o_mi_playlistTableColumns setTitle: _NS("Playlist Table Columns")];
399 [o_mu_controls setTitle: _NS("Playback")];
400 [o_mi_play setTitle: _NS("Play")];
401 [o_mi_stop setTitle: _NS("Stop")];
402 [o_mi_record setTitle: _NS("Record")];
403 [o_mi_rate setView: o_mi_rate_view];
404 [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
405 [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
406 [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
407 [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
408 [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
409 [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
410 [o_mi_previous setTitle: _NS("Previous")];
411 [o_mi_next setTitle: _NS("Next")];
412 [o_mi_random setTitle: _NS("Random")];
413 [o_mi_repeat setTitle: _NS("Repeat One")];
414 [o_mi_loop setTitle: _NS("Repeat All")];
415 [o_mi_AtoBloop setTitle: _NS("A→B Loop")];
416 [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
417 [o_mi_fwd setTitle: _NS("Step Forward")];
418 [o_mi_bwd setTitle: _NS("Step Backward")];
420 [o_mi_program setTitle: _NS("Program")];
421 [o_mu_program setTitle: _NS("Program")];
422 [o_mi_title setTitle: _NS("Title")];
423 [o_mu_title setTitle: _NS("Title")];
424 [o_mi_chapter setTitle: _NS("Chapter")];
425 [o_mu_chapter setTitle: _NS("Chapter")];
427 [o_mu_audio setTitle: _NS("Audio")];
428 [o_mi_vol_up setTitle: _NS("Increase Volume")];
429 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
430 [o_mi_mute setTitle: _NS("Mute")];
431 [o_mi_audiotrack setTitle: _NS("Audio Track")];
432 [o_mu_audiotrack setTitle: _NS("Audio Track")];
433 [o_mi_channels setTitle: _NS("Stereo audio mode")];
434 [o_mu_channels setTitle: _NS("Stereo audio mode")];
435 [o_mi_device setTitle: _NS("Audio Device")];
436 [o_mu_device setTitle: _NS("Audio Device")];
437 [o_mi_visual setTitle: _NS("Visualizations")];
438 [o_mu_visual setTitle: _NS("Visualizations")];
440 [o_mu_video setTitle: _NS("Video")];
441 [o_mi_half_window setTitle: _NS("Half Size")];
442 [o_mi_normal_window setTitle: _NS("Normal Size")];
443 [o_mi_double_window setTitle: _NS("Double Size")];
444 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
445 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
446 [o_mi_floatontop setTitle: _NS("Float on Top")];
447 [o_mi_snapshot setTitle: _NS("Snapshot")];
448 [o_mi_videotrack setTitle: _NS("Video Track")];
449 [o_mu_videotrack setTitle: _NS("Video Track")];
450 [o_mi_aspect_ratio setTitle: _NS("Aspect ratio")];
451 [o_mu_aspect_ratio setTitle: _NS("Aspect ratio")];
452 [o_mi_crop setTitle: _NS("Crop")];
453 [o_mu_crop setTitle: _NS("Crop")];
454 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
455 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
456 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
457 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
458 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
459 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
460 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
461 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
463 [o_mu_subtitles setTitle:_NS("Subtitles")];
464 [o_mi_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
465 [o_mi_subtitle_track setTitle: _NS("Subtitles Track")];
466 [o_mu_subtitle_tracks setTitle: _NS("Subtitles Track")];
467 [o_mi_subtitle_size setTitle: _NS("Text Size")];
468 [o_mi_subtitle_textcolor setTitle: _NS("Text Color")];
469 [o_mi_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
470 [o_mi_subtitle_bgopacity setView: o_mi_subtitle_bgopacity_view];
471 [o_mi_subtitle_bgopacity_lbl setStringValue: _NS("Background Opacity")];
472 [o_mi_subtitle_bgopacity_lbl_gray setStringValue: _NS("Background Opacity")];
473 [o_mi_subtitle_bgcolor setTitle: _NS("Background Color")];
474 [o_mi_teletext setTitle: _NS("Teletext")];
475 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
476 [o_mi_teletext_index setTitle: _NS("Index")];
477 [o_mi_teletext_red setTitle: _NS("Red")];
478 [o_mi_teletext_green setTitle: _NS("Green")];
479 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
480 [o_mi_teletext_blue setTitle: _NS("Blue")];
482 [o_mu_window setTitle: _NS("Window")];
483 [o_mi_minimize setTitle: _NS("Minimize")];
484 [o_mi_zoom_window setTitle: _NS("Zoom")];
485 [o_mi_player setTitle: _NS("Player...")];
486 [o_mi_controller setTitle: _NS("Main Window...")];
487 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
488 [o_mi_videoeffects setTitle: _NS("Video Effects...")];
489 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
490 [o_mi_playlist setTitle: _NS("Playlist...")];
491 [o_mi_info setTitle: _NS("Media Information...")];
492 [o_mi_messages setTitle: _NS("Messages...")];
493 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
495 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
497 [o_mu_help setTitle: _NS("Help")];
498 [o_mi_help setTitle: _NS("VLC media player Help...")];
499 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
500 [o_mi_license setTitle: _NS("License")];
501 [o_mi_documentation setTitle: _NS("Online Documentation...")];
502 [o_mi_website setTitle: _NS("VideoLAN Website...")];
503 [o_mi_donation setTitle: _NS("Make a donation...")];
504 [o_mi_forum setTitle: _NS("Online Forum...")];
507 [o_dmi_play setTitle: _NS("Play")];
508 [o_dmi_stop setTitle: _NS("Stop")];
509 [o_dmi_next setTitle: _NS("Next")];
510 [o_dmi_previous setTitle: _NS("Previous")];
511 [o_dmi_mute setTitle: _NS("Mute")];
514 [o_vmi_play setTitle: _NS("Play")];
515 [o_vmi_stop setTitle: _NS("Stop")];
516 [o_vmi_prev setTitle: _NS("Previous")];
517 [o_vmi_next setTitle: _NS("Next")];
518 [o_vmi_volup setTitle: _NS("Volume Up")];
519 [o_vmi_voldown setTitle: _NS("Volume Down")];
520 [o_vmi_mute setTitle: _NS("Mute")];
521 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
522 [o_vmi_snapshot setTitle: _NS("Snapshot")];
525 - (NSMenu *)setupPlaylistTableColumnsMenu
527 NSMenu *o_context_menu = [[NSMenu alloc] init];
529 NSMenuItem *o_mi_tmp;
530 NSUInteger count = [o_ptc_menuorder count];
531 for (NSUInteger i = 0; i < count; i++) {
532 NSString *o_title = [o_ptc_translation_dict objectForKey:[o_ptc_menuorder objectAtIndex:i]];
533 o_mi_tmp = [o_mu_playlistTableColumns addItemWithTitle:o_title
534 action:@selector(togglePlaylistColumnTable:)
536 /* don't set a valid target for the title column selector, since we want it to be disabled */
537 if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
538 [o_mi_tmp setTarget:self];
541 o_mi_tmp = [o_context_menu addItemWithTitle:o_title
542 action:@selector(togglePlaylistColumnTable:)
544 /* don't set a valid target for the title column selector, since we want it to be disabled */
545 if (![[o_ptc_menuorder objectAtIndex:i] isEqualToString: TITLE_COLUMN])
546 [o_mi_tmp setTarget:self];
549 if (!o_mu_playlistTableColumnsContextMenu)
550 o_mu_playlistTableColumnsContextMenu = [o_context_menu retain];
551 return [o_context_menu autorelease];
554 #pragma mark - Termination
556 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
560 NSArray *menuitems_array = [the_menu itemArray];
561 NSUInteger menuItemCount = [menuitems_array count];
562 for (NSUInteger i=0; i < menuItemCount; i++) {
563 NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
564 if ([one_item hasSubmenu])
565 [self releaseRepresentedObjects: [one_item submenu]];
567 [one_item setRepresentedObject:NULL];
571 #pragma mark - Interface update
575 playlist_t * p_playlist = pl_Get(p_intf);
576 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
577 if (p_input != NULL) {
578 [o_mi_record setEnabled: var_GetBool(p_input, "can-record")];
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_record setEnabled: NO];
631 [o_mi_ffmpeg_pp setEnabled:NO];
635 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
637 NSUInteger count = (NSUInteger) [o_mu_screen numberOfItems];
638 NSMenu * o_submenu = o_mu_screen;
640 [o_submenu removeAllItems];
642 NSArray * o_screens = [NSScreen screens];
643 NSMenuItem * o_mitem;
644 count = [o_screens count];
645 [o_mi_screen setEnabled: YES];
646 [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
647 o_mitem = [o_submenu itemAtIndex: 0];
649 [o_mitem setEnabled: YES];
650 [o_mitem setTarget: self];
652 for (NSUInteger i = 0; i < count; i++) {
653 s_rect = [[o_screens objectAtIndex:i] frame];
654 [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
655 (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
656 o_mitem = [o_submenu itemAtIndex:i+1];
657 [o_mitem setTag: (int)[[o_screens objectAtIndex:i] displayID]];
658 [o_mitem setEnabled: YES];
659 [o_mitem setTarget: self];
661 [[o_submenu itemWithTag: var_InheritInteger(VLCIntf, "macosx-vdev")] setState: NSOnState];
664 - (void)setSubmenusEnabled:(BOOL)b_enabled
666 [o_mi_program setEnabled: b_enabled];
667 [o_mi_title setEnabled: b_enabled];
668 [o_mi_chapter setEnabled: b_enabled];
669 [o_mi_audiotrack setEnabled: b_enabled];
670 [o_mi_visual setEnabled: b_enabled];
671 [o_mi_videotrack setEnabled: b_enabled];
672 [o_mi_subtitle_track setEnabled: b_enabled];
673 [o_mi_channels setEnabled: b_enabled];
674 [o_mi_deinterlace setEnabled: b_enabled];
675 [o_mi_deinterlace_mode setEnabled: b_enabled];
676 [o_mi_screen setEnabled: b_enabled];
677 [o_mi_aspect_ratio setEnabled: b_enabled];
678 [o_mi_crop setEnabled: b_enabled];
681 - (void)setSubtitleMenuEnabled:(BOOL)b_enabled
683 [o_mi_openSubtitleFile setEnabled: b_enabled];
685 [o_mi_subtitle_bgopacity_lbl_gray setHidden: YES];
686 [o_mi_subtitle_bgopacity_lbl setHidden: NO];
688 [o_mi_subtitle_bgopacity_lbl_gray setHidden: NO];
689 [o_mi_subtitle_bgopacity_lbl setHidden: YES];
691 [o_mi_subtitle_bgopacity_sld setEnabled: b_enabled];
692 [o_mi_teletext setEnabled: b_enabled];
695 - (void)setRateControlsEnabled:(BOOL)b_enabled
697 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
698 [o_mi_rate_sld setEnabled: b_enabled];
699 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
700 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
701 double speed = pow(2, (double)i / 17);
702 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
704 [o_mi_rate_lbl setHidden: NO];
705 [o_mi_rate_lbl_gray setHidden: YES];
707 [o_mi_rate_lbl setHidden: YES];
708 [o_mi_rate_lbl_gray setHidden: NO];
710 [self setSubtitleMenuEnabled: b_enabled];
716 - (IBAction)toggleEffectsButton:(id)sender
718 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-effects-button");
719 config_PutInt(VLCIntf, "macosx-show-effects-button", b_value);
720 [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleEffectsButton];
721 [o_mi_toggleEffectsButton setState: b_value];
724 - (IBAction)toggleJumpButtons:(id)sender
726 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playback-buttons");
727 config_PutInt(VLCIntf, "macosx-show-playback-buttons", b_value);
729 [[[[VLCMain sharedInstance] mainWindow] controlsBar] toggleJumpButtons];
730 [[[VLCMain sharedInstance] voutController] updateWindowsUsingBlock:^(VLCVideoWindowCommon *o_window) {
731 [[o_window controlsBar] toggleForwardBackwardMode: b_value];
734 [o_mi_toggleJumpButtons setState: b_value];
737 - (IBAction)togglePlaymodeButtons:(id)sender
739 BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-playmode-buttons");
740 config_PutInt(VLCIntf, "macosx-show-playmode-buttons", b_value);
741 [[[[VLCMain sharedInstance] mainWindow] controlsBar] togglePlaymodeButtons];
742 [o_mi_togglePlaymodeButtons setState: b_value];
745 - (IBAction)toggleSidebar:(id)sender
747 [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
750 - (void)updateSidebarMenuItem
752 [o_mi_toggleSidebar setState: config_GetInt(VLCIntf, "macosx-show-sidebar")];
755 - (IBAction)togglePlaylistColumnTable:(id)sender
757 NSInteger i_new_state = ![sender state];
758 NSInteger i_tag = [sender tag];
759 [[o_mu_playlistTableColumns itemWithTag: i_tag] setState: i_new_state];
760 [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];
762 NSString *o_column = [o_ptc_menuorder objectAtIndex:i_tag];
763 [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
766 - (BOOL)setPlaylistColumnTableState:(NSInteger)i_state forColumn:(NSString *)o_column
768 NSUInteger i_tag = [o_ptc_menuorder indexOfObject: o_column];
769 // prevent setting unknown columns
770 if(i_tag == NSNotFound)
773 [[o_mu_playlistTableColumns itemWithTag: i_tag] setState: i_state];
774 [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_state];
775 [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_state translationDict: o_ptc_translation_dict];
780 #pragma mark - Playback
782 - (IBAction)quitAfterPlayback:(id)sender
784 playlist_t *p_playlist = pl_Get(VLCIntf);
785 bool b_value = !var_CreateGetBool(p_playlist, "play-and-exit");
786 var_SetBool(p_playlist, "play-and-exit", b_value);
787 config_PutInt(p_intf, "play-and-exit", b_value);
790 - (IBAction)toggleRecord:(id)sender
792 [[VLCCoreInteraction sharedInstance] toggleRecord];
795 - (void)updateRecordState:(BOOL)b_value
797 [o_mi_record setState:b_value];
800 - (IBAction)setPlaybackRate:(id)sender
802 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
803 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
804 double speed = pow(2, (double)i / 17);
805 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
808 - (void)updatePlaybackRate
810 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
811 double speed = pow(2, (double)i / 17);
812 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
813 [o_mi_rate_sld setIntValue: i];
816 - (IBAction)toggleAtoBloop:(id)sender
818 [[VLCCoreInteraction sharedInstance] setAtoB];
821 #pragma mark - audio menu
823 - (void)refreshAudioDeviceList
828 [o_mu_device removeAllItems];
830 audio_output_t * p_aout = getAout();
834 int n = aout_DevicesList(p_aout, &ids, &names);
836 vlc_object_release(p_aout);
840 currentDevice = aout_DeviceGet(p_aout);
841 NSMenuItem * o_mi_tmp;
843 for (NSUInteger x = 0; x < n; x++) {
844 o_mi_tmp = [o_mu_device addItemWithTitle:toNSStr(names[x]) action:@selector(toggleAudioDevice:) keyEquivalent:@""];
845 [o_mi_tmp setTarget:self];
846 [o_mi_tmp setTag:[[NSString stringWithFormat:@"%s", ids[x]] intValue]];
848 vlc_object_release(p_aout);
850 [[o_mu_device itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];
854 for (NSUInteger x = 0; x < n; x++) {
861 [o_mu_device setAutoenablesItems:YES];
862 [o_mi_device setEnabled:YES];
865 - (IBAction)toggleAudioDevice:(id)sender
867 audio_output_t * p_aout = getAout();
873 if ([sender tag] > 0)
874 returnValue = aout_DeviceSet(p_aout, [[NSString stringWithFormat:@"%li", [sender tag]] UTF8String]);
876 returnValue = aout_DeviceSet(p_aout, NULL);
878 if (returnValue != 0)
879 msg_Warn(VLCIntf, "failed to set audio device %li", [sender tag]);
881 vlc_object_release(p_aout);
882 [self refreshAudioDeviceList];
885 #pragma mark - video menu
887 - (IBAction)toggleFullscreen:(id)sender
889 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
892 - (IBAction)resizeVideoWindow:(id)sender
894 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
896 vout_thread_t *p_vout = getVoutForActiveWindow();
898 if (sender == o_mi_half_window)
899 var_SetFloat(p_vout, "zoom", 0.5);
900 else if (sender == o_mi_normal_window)
901 var_SetFloat(p_vout, "zoom", 1.0);
902 else if (sender == o_mi_double_window)
903 var_SetFloat(p_vout, "zoom", 2.0);
906 [[NSApp keyWindow] performZoom:sender];
908 vlc_object_release(p_vout);
910 vlc_object_release(p_input);
914 - (IBAction)floatOnTop:(id)sender
916 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
918 vout_thread_t *p_vout = getVoutForActiveWindow();
920 BOOL b_fs = var_ToggleBool(p_vout, "video-on-top");
921 var_SetBool(pl_Get(p_intf), "video-on-top", b_fs);
923 vlc_object_release(p_vout);
925 vlc_object_release(p_input);
929 - (IBAction)createVideoSnapshot:(id)sender
931 input_thread_t *p_input = pl_CurrentInput(VLCIntf);
933 vout_thread_t *p_vout = getVoutForActiveWindow();
935 var_TriggerCallback(p_vout, "video-snapshot");
936 vlc_object_release(p_vout);
938 vlc_object_release(p_input);
942 - (void)_disablePostProcessing
944 [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:false];
947 - (void)_enablePostProcessing
949 [[VLCCoreInteraction sharedInstance] setVideoFilter:"postproc" on:true];
952 - (IBAction)togglePostProcessing:(id)sender
954 char *psz_name = "postproc";
955 NSInteger count = [o_mu_ffmpeg_pp numberOfItems];
956 for (NSUInteger x = 0; x < count; x++)
957 [[o_mu_ffmpeg_pp itemAtIndex:x] setState:NSOffState];
959 if ([sender tag] == -1) {
960 [self _disablePostProcessing];
961 [sender setState:NSOnState];
963 [self _enablePostProcessing];
964 [sender setState:NSOnState];
966 [[VLCCoreInteraction sharedInstance] setVideoFilterProperty:"postproc-q" forFilter:"postproc" integer:[sender tag]];
970 - (IBAction)toggleFullscreenDevice:(id)sender
972 config_PutInt(VLCIntf, "macosx-vdev", [sender tag]);
973 [self refreshVoutDeviceMenu: nil];
981 #pragma mark - Subtitles Menu
983 - (IBAction)addSubtitleFile:(id)sender
985 NSInteger i_returnValue = 0;
986 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
990 input_item_t *p_item = input_GetItem(p_input);
992 vlc_object_release(p_input);
996 char *path = input_item_GetURI(p_item);
1001 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
1002 [openPanel setCanChooseFiles: YES];
1003 [openPanel setCanChooseDirectories: NO];
1004 [openPanel setAllowsMultipleSelection: YES];
1006 [openPanel setAllowedFileTypes: [NSArray arrayWithObjects:@"cdg",@"idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil",nil]];
1008 NSURL *o_url = [NSURL URLWithString:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]];
1009 o_url = [o_url URLByDeletingLastPathComponent];
1010 [openPanel setDirectoryURL: o_url];
1012 vlc_object_release(p_input);
1014 i_returnValue = [openPanel runModal];
1016 if (i_returnValue == NSOKButton)
1017 [[VLCCoreInteraction sharedInstance] addSubtitlesToCurrentInput:[openPanel URLs]];
1020 - (IBAction)switchSubtitleOption:(id)sender
1022 int intValue = [sender tag];
1023 NSString *representedObject = [sender representedObject];
1025 config_PutInt(p_intf, [representedObject UTF8String], intValue);
1027 NSMenu *menu = [sender menu];
1028 NSUInteger count = (NSUInteger) [menu numberOfItems];
1029 for (NSUInteger x = 0; x < count; x++)
1030 [[menu itemAtIndex:x] setState:NSOffState];
1031 [[menu itemWithTag:intValue] setState:NSOnState];
1034 - (IBAction)switchSubtitleBackgroundOpacity:(id)sender
1036 config_PutInt(p_intf, "freetype-background-opacity", [sender intValue]);
1039 - (IBAction)telxTransparent:(id)sender
1041 vlc_object_t *p_vbi;
1042 p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1044 var_SetBool(p_vbi, "vbi-opaque", [sender state]);
1045 [sender setState: ![sender state]];
1046 vlc_object_release(p_vbi);
1050 - (IBAction)telxNavLink:(id)sender
1052 vlc_object_t *p_vbi;
1055 if ([[sender title] isEqualToString: _NS("Index")])
1057 else if ([[sender title] isEqualToString: _NS("Red")])
1059 else if ([[sender title] isEqualToString: _NS("Green")])
1061 else if ([[sender title] isEqualToString: _NS("Yellow")])
1063 else if ([[sender title] isEqualToString: _NS("Blue")])
1065 if (i_page == 0) return;
1067 p_vbi = (vlc_object_t *) vlc_object_find_name(pl_Get(VLCIntf), "zvbi");
1069 var_SetInteger(p_vbi, "vbi-page", i_page);
1070 vlc_object_release(p_vbi);
1074 #pragma mark - Panels
1076 - (IBAction)intfOpenFile:(id)sender
1078 [[[VLCMain sharedInstance] open] openFile];
1081 - (IBAction)intfOpenFileGeneric:(id)sender
1083 [[[VLCMain sharedInstance] open] openFileGeneric];
1086 - (IBAction)intfOpenDisc:(id)sender
1088 [[[VLCMain sharedInstance] open] openDisc];
1091 - (IBAction)intfOpenNet:(id)sender
1093 [[[VLCMain sharedInstance] open] openNet];
1096 - (IBAction)intfOpenCapture:(id)sender
1098 [[[VLCMain sharedInstance] open] openCapture];
1101 - (IBAction)showWizard:(id)sender
1103 [[[VLCMain sharedInstance] wizard] resetWizard];
1104 [[[VLCMain sharedInstance] wizard] showWizard];
1107 - (IBAction)savePlaylist:(id)sender
1109 [[[VLCMain sharedInstance] playlist] savePlaylist:sender];
1112 - (IBAction)showConvertAndSave:(id)sender
1114 if (o_convertandsave == nil)
1115 o_convertandsave = [[VLCConvertAndSave alloc] init];
1117 if (!b_nib_convertandsave_loaded)
1118 b_nib_convertandsave_loaded = [NSBundle loadNibNamed:@"ConvertAndSave" owner: NSApp];
1120 [o_convertandsave toggleWindow];
1123 - (IBAction)showVideoEffects:(id)sender
1125 if (o_videoeffects == nil)
1126 o_videoeffects = [[VLCVideoEffects alloc] init];
1128 if (!b_nib_videoeffects_loaded)
1129 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
1131 [o_videoeffects toggleWindow:sender];
1134 - (IBAction)showTrackSynchronization:(id)sender
1136 if (!o_trackSynchronization)
1137 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
1139 if (!b_nib_tracksynchro_loaded)
1140 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
1142 [o_trackSynchronization toggleWindow:sender];
1145 - (IBAction)showAudioEffects:(id)sender
1147 if (!o_audioeffects)
1148 o_audioeffects = [[VLCAudioEffects alloc] init];
1150 if (!b_nib_audioeffects_loaded)
1151 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
1153 [o_audioeffects toggleWindow:sender];
1156 - (IBAction)showBookmarks:(id)sender
1158 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
1161 - (IBAction)viewPreferences:(id)sender
1163 NSInteger i_level = [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel];
1164 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefsWithLevel:i_level];
1167 - (IBAction)openAddonManager:(id)sender
1169 if (!o_addonManager)
1170 o_addonManager = [[VLCAddonManager alloc] init];
1172 if (!b_nib_addonmanager_loaded)
1173 b_nib_addonmanager_loaded = [NSBundle loadNibNamed:@"AddonManager" owner:NSApp];
1175 [o_addonManager showWindow];
1178 - (IBAction)showMessagesPanel:(id)showMessagesPanel
1180 [[VLCDebugMessageVisualizer sharedInstance] showPanel];
1183 - (IBAction)showMainWindow:(id)sender
1185 [[VLCMainWindow sharedInstance] makeKeyAndOrderFront:sender];
1188 - (IBAction)showPlaylist:(id)sender
1190 [[VLCMainWindow sharedInstance] changePlaylistState: psUserMenuEvent];
1193 #pragma mark - Help and Docs
1198 o_about = [[VLAboutBox alloc] init];
1200 if (!b_nib_about_loaded)
1201 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
1204 - (IBAction)viewAbout:(id)sender
1207 [o_about showAbout];
1210 - (IBAction)showLicense:(id)sender
1216 - (IBAction)viewHelp:(id)sender
1222 - (IBAction)openReadMe:(id)sender
1224 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
1226 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
1229 - (IBAction)openDocumentation:(id)sender
1231 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
1233 [[NSWorkspace sharedWorkspace] openURL: o_url];
1236 - (IBAction)openWebsite:(id)sender
1238 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
1240 [[NSWorkspace sharedWorkspace] openURL: o_url];
1243 - (IBAction)openForum:(id)sender
1245 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
1247 [[NSWorkspace sharedWorkspace] openURL: o_url];
1250 - (IBAction)openDonate:(id)sender
1252 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
1254 [[NSWorkspace sharedWorkspace] openURL: o_url];
1257 #pragma mark - Errors, warnings and messages
1259 - (IBAction)viewErrorsAndWarnings:(id)sender
1261 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
1264 - (IBAction)showInformationPanel:(id)sender
1266 [[[VLCMain sharedInstance] info] initPanel];
1269 #pragma mark - convinience stuff for other objects
1273 [o_mi_play setTitle: _NS("Play")];
1274 [o_dmi_play setTitle: _NS("Play")];
1275 [o_vmi_play setTitle: _NS("Play")];
1280 [o_mi_play setTitle: _NS("Pause")];
1281 [o_dmi_play setTitle: _NS("Pause")];
1282 [o_vmi_play setTitle: _NS("Pause")];
1285 - (void)setRepeatOne
1287 [o_mi_repeat setState: NSOnState];
1288 [o_mi_loop setState: NSOffState];
1291 - (void)setRepeatAll
1293 [o_mi_repeat setState: NSOffState];
1294 [o_mi_loop setState: NSOnState];
1297 - (void)setRepeatOff
1299 [o_mi_repeat setState: NSOffState];
1300 [o_mi_loop setState: NSOffState];
1306 playlist_t *p_playlist = pl_Get(VLCIntf);
1307 b_value = var_GetBool(p_playlist, "random");
1309 [o_mi_random setState: b_value];
1312 #pragma mark - Dynamic menu creation and validation
1314 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
1315 target:(vlc_object_t *)p_object
1316 var:(const char *)psz_variable
1317 selector:(SEL)pf_callback
1319 vlc_value_t val, text;
1320 int i_type = var_Type(p_object, psz_variable);
1322 switch(i_type & VLC_VAR_TYPE) {
1325 case VLC_VAR_VARIABLE:
1326 case VLC_VAR_STRING:
1327 case VLC_VAR_INTEGER:
1330 /* Variable doesn't exist or isn't handled */
1331 msg_Warn(p_object, "variable %s doesn't exist or isn't handled", psz_variable);
1335 /* Get the descriptive name of the variable */
1336 var_Change(p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL);
1337 [o_mi setTitle: _NS(text.psz_string ? text.psz_string : psz_variable)];
1339 if (i_type & VLC_VAR_HASCHOICE) {
1340 NSMenu *o_menu = [o_mi submenu];
1342 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
1343 var:psz_variable selector:pf_callback];
1345 free(text.psz_string);
1349 if (var_Get(p_object, psz_variable, &val) < 0)
1352 VLCAutoGeneratedMenuContent *o_data;
1353 switch(i_type & VLC_VAR_TYPE) {
1355 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1356 andValue: val ofType: i_type];
1357 [o_mi setRepresentedObject: [o_data autorelease]];
1361 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1362 andValue: val ofType: i_type];
1363 [o_mi setRepresentedObject: [o_data autorelease]];
1364 if (!(i_type & VLC_VAR_ISCOMMAND))
1365 [o_mi setState: val.b_bool ? TRUE : FALSE ];
1372 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1373 free(text.psz_string);
1377 - (void)setupVarMenu:(NSMenu *)o_menu
1378 forMenuItem: (NSMenuItem *)o_parent
1379 target:(vlc_object_t *)p_object
1380 var:(const char *)psz_variable
1381 selector:(SEL)pf_callback
1383 vlc_value_t val, val_list, text_list;
1386 /* remove previous items */
1387 [o_menu removeAllItems];
1389 /* we disable everything here, and enable it again when needed, below */
1390 [o_parent setEnabled:NO];
1393 if ([[o_parent title] isEqualToString: _NS("Aspect ratio")] == YES) {
1394 NSMenuItem *o_lmi_tmp2;
1395 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1396 [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1397 [o_lmi_tmp2 setEnabled: YES];
1398 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1399 [o_parent setEnabled: YES];
1400 [o_menu addItem: [NSMenuItem separatorItem]];
1403 /* Check the type of the object variable */
1404 i_type = var_Type(p_object, psz_variable);
1406 /* Make sure we want to display the variable */
1407 if (i_type & VLC_VAR_HASCHOICE) {
1408 var_Change(p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL);
1411 if ((i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1)
1417 switch(i_type & VLC_VAR_TYPE) {
1420 case VLC_VAR_VARIABLE:
1421 case VLC_VAR_STRING:
1422 case VLC_VAR_INTEGER:
1425 /* Variable doesn't exist or isn't handled */
1429 if (var_Get(p_object, psz_variable, &val) < 0) {
1433 if (var_Change(p_object, psz_variable, VLC_VAR_GETLIST,
1434 &val_list, &text_list) < 0) {
1435 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1439 /* make (un)sensitive */
1440 [o_parent setEnabled: (val_list.p_list->i_count > 1)];
1442 for (i = 0; i < val_list.p_list->i_count; i++) {
1444 NSString *o_title = @"";
1445 VLCAutoGeneratedMenuContent *o_data;
1447 switch(i_type & VLC_VAR_TYPE) {
1448 case VLC_VAR_STRING:
1450 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);
1452 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1453 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1454 andValue: val_list.p_list->p_values[i] ofType: i_type];
1455 [o_lmi setRepresentedObject: [o_data autorelease]];
1456 [o_lmi setTarget: self];
1458 if (!strcmp(val.psz_string, val_list.p_list->p_values[i].psz_string) && !(i_type & VLC_VAR_ISCOMMAND))
1459 [o_lmi setState: TRUE ];
1463 case VLC_VAR_INTEGER:
1465 o_title = text_list.p_list->p_values[i].psz_string ?
1466 _NS(text_list.p_list->p_values[i].psz_string) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1468 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1469 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1470 andValue: val_list.p_list->p_values[i] ofType: i_type];
1471 [o_lmi setRepresentedObject: [o_data autorelease]];
1472 [o_lmi setTarget: self];
1474 if (val_list.p_list->p_values[i].i_int == val.i_int && !(i_type & VLC_VAR_ISCOMMAND))
1475 [o_lmi setState: TRUE ];
1483 /* clean up everything */
1484 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING) free(val.psz_string);
1485 var_FreeList(&val_list, &text_list);
1488 - (IBAction)toggleVar:(id)sender
1490 NSMenuItem *o_mi = (NSMenuItem *)sender;
1491 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1492 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1493 toTarget: self withObject: o_data];
1498 - (int)toggleVarThread: (id)data
1500 vlc_object_t *p_object;
1501 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1503 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1504 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1506 p_object = [menuContent vlcObject];
1508 if (p_object != NULL) {
1509 var_Set(p_object, [menuContent name], [menuContent value]);
1510 vlc_object_release(p_object);
1515 return VLC_EGENERIC;
1520 @implementation VLCMainMenu (NSMenuValidation)
1522 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1524 NSString *o_title = [o_mi title];
1525 BOOL bEnabled = TRUE;
1527 playlist_t * p_playlist = pl_Get(p_intf);
1528 input_thread_t * p_input = playlist_CurrentInput(p_playlist);
1530 if ([o_title isEqualToString: _NS("Stop")]) {
1533 [self setupMenus]; /* Make sure input menu is up to date */
1534 } else if ([o_title isEqualToString: _NS("Previous")] ||
1535 [o_title isEqualToString: _NS("Next")]) {
1537 bEnabled = playlist_CurrentSize(p_playlist) > 1;
1539 } else if ([o_title isEqualToString: _NS("Random")]) {
1541 var_Get(p_playlist, "random", &val);
1542 i_state = val.b_bool ? NSOnState : NSOffState;
1543 [o_mi setState: i_state];
1544 } else if ([o_title isEqualToString: _NS("Repeat One")]) {
1546 var_Get(p_playlist, "repeat", &val);
1547 i_state = val.b_bool ? NSOnState : NSOffState;
1548 [o_mi setState: i_state];
1549 } else if ([o_title isEqualToString: _NS("Repeat All")]) {
1551 var_Get(p_playlist, "loop", &val);
1552 i_state = val.b_bool ? NSOnState : NSOffState;
1553 [o_mi setState: i_state];
1554 } else if ([o_title isEqualToString: _NS("Quit after Playback")]) {
1556 bool b_value = var_InheritBool(p_playlist, "play-and-exit");
1557 i_state = b_value ? NSOnState : NSOffState;
1558 [o_mi setState: i_state];
1559 } else if ([o_title isEqualToString: _NS("Step Forward")] ||
1560 [o_title isEqualToString: _NS("Step Backward")] ||
1561 [o_title isEqualToString: _NS("Jump to Time")]) {
1562 if (p_input != NULL) {
1563 var_Get(p_input, "can-seek", &val);
1564 bEnabled = val.b_bool;
1566 else bEnabled = FALSE;
1567 } else if ([o_title isEqualToString: _NS("Mute")]) {
1568 [o_mi setState: [[VLCCoreInteraction sharedInstance] mute] ? NSOnState : NSOffState];
1569 [self setupMenus]; /* Make sure audio menu is up to date */
1570 [self refreshAudioDeviceList];
1571 } else if ([o_title isEqualToString: _NS("Half Size")] ||
1572 [o_title isEqualToString: _NS("Normal Size")] ||
1573 [o_title isEqualToString: _NS("Double Size")] ||
1574 [o_title isEqualToString: _NS("Fit to Screen")] ||
1575 [o_title isEqualToString: _NS("Snapshot")] ||
1576 [o_title isEqualToString: _NS("Fullscreen")] ||
1577 [o_title isEqualToString: _NS("Float on Top")]) {
1580 if (p_input != NULL) {
1581 vout_thread_t *p_vout = getVoutForActiveWindow();
1582 if (p_vout != NULL) {
1583 if ([o_title isEqualToString: _NS("Float on Top")])
1584 [o_mi setState: var_GetBool(p_vout, "video-on-top")];
1586 if ([o_title isEqualToString: _NS("Fullscreen")])
1587 [o_mi setState: var_GetBool(p_vout, "fullscreen")];
1590 vlc_object_release(p_vout);
1594 [self setupMenus]; /* Make sure video menu is up to date */
1596 } else if ([o_title isEqualToString: _NS("Add Subtitle File...")]) {
1597 bEnabled = [o_mi isEnabled];
1598 [self setupMenus]; /* Make sure subtitles menu is up to date */
1600 NSMenuItem *o_mi_parent = [o_mi parentItem];
1601 if (o_mi_parent == o_mi_subtitle_size || o_mi == o_mi_subtitle_size ||
1602 o_mi_parent == o_mi_subtitle_textcolor || o_mi == o_mi_subtitle_textcolor ||
1603 o_mi_parent == o_mi_subtitle_bgcolor || o_mi == o_mi_subtitle_bgcolor ||
1604 o_mi_parent == o_mi_subtitle_bgopacity || o_mi == o_mi_subtitle_bgopacity ||
1605 o_mi_parent == o_mi_subtitle_outlinethickness || o_mi == o_mi_subtitle_outlinethickness ||
1606 o_mi_parent == o_mi_teletext || o_mi == o_mi_teletext)
1607 bEnabled = o_mi_openSubtitleFile.isEnabled;
1610 /* Special case for telx menu */
1611 if ([o_title isEqualToString: _NS("Normal Size")]) {
1612 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1613 bool b_telx = p_input && var_GetInteger(p_input, "teletext-es") >= 0;
1615 [[item submenu] setAutoenablesItems:NO];
1617 for (int k=0; k < [[item submenu] numberOfItems]; k++)
1618 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1622 vlc_object_release(p_input);
1630 /*****************************************************************************
1631 * VLCAutoGeneratedMenuContent implementation
1632 *****************************************************************************
1633 * Object connected to a playlistitem which remembers the data belonging to
1634 * the variable of the autogenerated menu
1635 *****************************************************************************/
1636 @implementation VLCAutoGeneratedMenuContent
1638 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1639 andValue:(vlc_value_t)val ofType:(int)type
1641 self = [super init];
1644 _vlc_object = vlc_object_hold(object);
1645 psz_name = strdup(name);
1648 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1649 value.psz_string = strdup(val.psz_string);
1658 vlc_object_release(_vlc_object);
1659 if ((i_type & VLC_VAR_TYPE) == VLC_VAR_STRING)
1660 free(value.psz_string);
1665 - (const char *)name
1670 - (vlc_value_t)value
1675 - (vlc_object_t *)vlcObject
1677 return vlc_object_hold(_vlc_object);