1 /*****************************************************************************
2 * MainMenu.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2011-2012 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 *****************************************************************************/
25 #import <vlc_common.h>
26 #import <vlc_playlist.h>
32 #import "AudioEffects.h"
33 #import "TrackSynchronization.h"
34 #import "VideoEffects.h"
36 #import "simple_prefs.h"
37 #import "coredialogs.h"
39 #import "playlistinfo.h"
41 #import "CoreInteraction.h"
42 #import "MainWindow.h"
43 #import "ExtensionsManager.h"
45 @implementation VLCMainMenu
46 static VLCMainMenu *_o_sharedInstance = nil;
48 + (VLCMainMenu *)sharedInstance
50 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
54 #pragma mark Initialization
58 if( _o_sharedInstance)
61 return _o_sharedInstance;
65 _o_sharedInstance = [super init];
68 return _o_sharedInstance;
73 [[NSNotificationCenter defaultCenter] removeObserver: self];
75 if (b_nib_about_loaded)
78 if (b_nib_videoeffects_loaded)
79 [o_videoeffects release];
81 if (b_nib_audioeffects_loaded)
82 [o_audioeffects release];
84 if (b_nib_tracksynchro_loaded)
85 [o_trackSynchronization release];
94 [[NSNotificationCenter defaultCenter] addObserver: self
95 selector: @selector(applicationWillFinishLaunching:)
96 name: NSApplicationWillFinishLaunchingNotification
100 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
105 playlist_t *p_playlist;
107 id o_vlcmain = [VLCMain sharedInstance];
110 /* Check if we already did this once. Opening the other nibs calls it too,
111 because VLCMain is the owner */
112 if( b_mainMenu_setup ) return;
114 /* Get ExtensionsManager */
115 o_extMgr = [ExtensionsManager getInstance:p_intf];
120 key = config_GetPsz( p_intf, "key-quit" );
121 o_key = [NSString stringWithFormat:@"%s", key];
122 [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
123 [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
126 key = config_GetPsz( p_intf, "key-play-pause" );
127 o_key = [NSString stringWithFormat:@"%s", key];
128 [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
129 [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
132 key = config_GetPsz( p_intf, "key-stop" );
133 o_key = [NSString stringWithFormat:@"%s", key];
134 [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
135 [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
138 key = config_GetPsz( p_intf, "key-prev" );
139 o_key = [NSString stringWithFormat:@"%s", key];
140 [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
141 [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
144 key = config_GetPsz( p_intf, "key-next" );
145 o_key = [NSString stringWithFormat:@"%s", key];
146 [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
147 [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
150 key = config_GetPsz( p_intf, "key-jump+short" );
151 o_key = [NSString stringWithFormat:@"%s", key];
152 [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
153 [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
156 key = config_GetPsz( p_intf, "key-jump-short" );
157 o_key = [NSString stringWithFormat:@"%s", key];
158 [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
159 [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
162 key = config_GetPsz( p_intf, "key-vol-up" );
163 o_key = [NSString stringWithFormat:@"%s", key];
164 [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
165 [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
168 key = config_GetPsz( p_intf, "key-vol-down" );
169 o_key = [NSString stringWithFormat:@"%s", key];
170 [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
171 [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
174 key = config_GetPsz( p_intf, "key-vol-mute" );
175 o_key = [NSString stringWithFormat:@"%s", key];
176 [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
177 [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
180 key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
181 o_key = [NSString stringWithFormat:@"%s", key];
182 [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
183 [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
186 key = config_GetPsz( p_intf, "key-snapshot" );
187 o_key = [NSString stringWithFormat:@"%s", key];
188 [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
189 [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
192 key = config_GetPsz( p_intf, "key-random" );
193 o_key = [NSString stringWithFormat:@"%s", key];
194 [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
195 [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
198 key = config_GetPsz( p_intf, "key-zoom-half" );
199 o_key = [NSString stringWithFormat:@"%s", key];
200 [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
201 [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
204 key = config_GetPsz( p_intf, "key-zoom-original" );
205 o_key = [NSString stringWithFormat:@"%s", key];
206 [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
207 [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
210 key = config_GetPsz( p_intf, "key-zoom-double" );
211 o_key = [NSString stringWithFormat:@"%s", key];
212 [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
213 [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
216 [self setSubmenusEnabled: FALSE];
218 [[NSNotificationCenter defaultCenter] addObserver: self
219 selector: @selector(refreshVoutDeviceMenu:)
220 name: NSApplicationDidChangeScreenParametersNotification
224 b_mainMenu_setup = YES;
226 [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
227 var: "intf-add" selector: @selector(toggleVar:)];
229 [self setupExtensionsMenu];
235 [o_mi_about setTitle: [_NS("About VLC media player") \
236 stringByAppendingString: @"..."]];
237 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
238 [o_mi_prefs setTitle: _NS("Preferences...")];
239 [o_mi_extensions setTitle: _NS("Extensions")];
240 [o_mu_extensions setTitle: _NS("Extensions")];
241 [o_mi_add_intf setTitle: _NS("Add Interface")];
242 [o_mu_add_intf setTitle: _NS("Add Interface")];
243 [o_mi_services setTitle: _NS("Services")];
244 [o_mi_hide setTitle: _NS("Hide VLC")];
245 [o_mi_hide_others setTitle: _NS("Hide Others")];
246 [o_mi_show_all setTitle: _NS("Show All")];
247 [o_mi_quit setTitle: _NS("Quit VLC")];
249 [o_mu_file setTitle: _ANS("1:File")];
250 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
251 [o_mi_open_file setTitle: _NS("Open File...")];
252 [o_mi_open_disc setTitle: _NS("Open Disc...")];
253 [o_mi_open_net setTitle: _NS("Open Network...")];
254 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
255 [o_mi_open_recent setTitle: _NS("Open Recent")];
256 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
258 [o_mu_edit setTitle: _NS("Edit")];
259 [o_mi_cut setTitle: _NS("Cut")];
260 [o_mi_copy setTitle: _NS("Copy")];
261 [o_mi_paste setTitle: _NS("Paste")];
262 [o_mi_clear setTitle: _NS("Clear")];
263 [o_mi_select_all setTitle: _NS("Select All")];
265 [o_mu_controls setTitle: _NS("Playback")];
266 [o_mi_play setTitle: _NS("Play")];
267 [o_mi_stop setTitle: _NS("Stop")];
268 [o_mi_record setTitle: _NS("Record")];
269 [o_mi_rate setView: o_mi_rate_view];
270 [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
271 [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
272 [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
273 [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
274 [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
275 [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
276 [o_mi_previous setTitle: _NS("Previous")];
277 [o_mi_next setTitle: _NS("Next")];
278 [o_mi_random setTitle: _NS("Random")];
279 [o_mi_repeat setTitle: _NS("Repeat One")];
280 [o_mi_loop setTitle: _NS("Repeat All")];
281 [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
282 [o_mi_fwd setTitle: _NS("Step Forward")];
283 [o_mi_bwd setTitle: _NS("Step Backward")];
284 [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
285 [o_mi_toggleJumpButtons setState: config_GetInt( VLCIntf, "macosx-show-playback-buttons")];
286 [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
287 [o_mi_togglePlaymodeButtons setState: config_GetInt( VLCIntf, "macosx-show-playmode-buttons")];
289 [o_mi_program setTitle: _NS("Program")];
290 [o_mu_program setTitle: _NS("Program")];
291 [o_mi_title setTitle: _NS("Title")];
292 [o_mu_title setTitle: _NS("Title")];
293 [o_mi_chapter setTitle: _NS("Chapter")];
294 [o_mu_chapter setTitle: _NS("Chapter")];
296 [o_mu_audio setTitle: _NS("Audio")];
297 [o_mi_vol_up setTitle: _NS("Increase Volume")];
298 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
299 [o_mi_mute setTitle: _NS("Mute")];
300 [o_mi_audiotrack setTitle: _NS("Audio Track")];
301 [o_mu_audiotrack setTitle: _NS("Audio Track")];
302 [o_mi_channels setTitle: _NS("Audio Channels")];
303 [o_mu_channels setTitle: _NS("Audio Channels")];
304 [o_mi_device setTitle: _NS("Audio Device")];
305 [o_mu_device setTitle: _NS("Audio Device")];
306 [o_mi_visual setTitle: _NS("Visualizations")];
307 [o_mu_visual setTitle: _NS("Visualizations")];
309 [o_mu_video setTitle: _NS("Video")];
310 [o_mi_half_window setTitle: _NS("Half Size")];
311 [o_mi_normal_window setTitle: _NS("Normal Size")];
312 [o_mi_double_window setTitle: _NS("Double Size")];
313 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
314 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
315 [o_mi_floatontop setTitle: _NS("Float on Top")];
316 [o_mi_snapshot setTitle: _NS("Snapshot")];
317 [o_mi_videotrack setTitle: _NS("Video Track")];
318 [o_mu_videotrack setTitle: _NS("Video Track")];
319 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
320 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
321 [o_mi_crop setTitle: _NS("Crop")];
322 [o_mu_crop setTitle: _NS("Crop")];
323 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
324 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
325 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
326 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
327 [o_mi_addSub setTitle: _NS("Open File...")];
328 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
329 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
330 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
331 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
332 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
333 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
334 [o_mi_teletext setTitle: _NS("Teletext")];
335 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
336 [o_mi_teletext_index setTitle: _NS("Index")];
337 [o_mi_teletext_red setTitle: _NS("Red")];
338 [o_mi_teletext_green setTitle: _NS("Green")];
339 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
340 [o_mi_teletext_blue setTitle: _NS("Blue")];
342 [o_mu_window setTitle: _NS("Window")];
343 [o_mi_minimize setTitle: _NS("Minimize Window")];
344 [o_mi_close_window setTitle: _NS("Close Window")];
345 [o_mi_player setTitle: _NS("Player...")];
346 [o_mi_controller setTitle: _NS("Main Window...")];
347 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
348 [o_mi_videoeffects setTitle: _NS("Video Filters...")];
349 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
350 [o_mi_playlist setTitle: _NS("Playlist...")];
351 [o_mi_info setTitle: _NS("Media Information...")];
352 [o_mi_messages setTitle: _NS("Messages...")];
353 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
355 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
357 [o_mu_help setTitle: _NS("Help")];
358 [o_mi_help setTitle: _NS("VLC media player Help...")];
359 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
360 [o_mi_license setTitle: _NS("License")];
361 [o_mi_documentation setTitle: _NS("Online Documentation...")];
362 [o_mi_website setTitle: _NS("VideoLAN Website...")];
363 [o_mi_donation setTitle: _NS("Make a donation...")];
364 [o_mi_forum setTitle: _NS("Online Forum...")];
367 [o_dmi_play setTitle: _NS("Play")];
368 [o_dmi_stop setTitle: _NS("Stop")];
369 [o_dmi_next setTitle: _NS("Next")];
370 [o_dmi_previous setTitle: _NS("Previous")];
371 [o_dmi_mute setTitle: _NS("Mute")];
374 [o_vmi_play setTitle: _NS("Play")];
375 [o_vmi_stop setTitle: _NS("Stop")];
376 [o_vmi_prev setTitle: _NS("Previous")];
377 [o_vmi_next setTitle: _NS("Next")];
378 [o_vmi_volup setTitle: _NS("Volume Up")];
379 [o_vmi_voldown setTitle: _NS("Volume Down")];
380 [o_vmi_mute setTitle: _NS("Mute")];
381 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
382 [o_vmi_snapshot setTitle: _NS("Snapshot")];
386 #pragma mark Termination
388 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
390 if( !p_intf ) return;
392 NSArray *menuitems_array = [the_menu itemArray];
393 NSUInteger menuItemCount = [menuitems_array count];
394 for( NSUInteger i=0; i < menuItemCount; i++ )
396 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
397 if( [one_item hasSubmenu] )
398 [self releaseRepresentedObjects: [one_item submenu]];
400 [one_item setRepresentedObject:NULL];
405 #pragma mark Interface update
409 playlist_t * p_playlist = pl_Get( p_intf );
410 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
411 if( p_input != NULL )
413 [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
415 [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
416 var: "program" selector: @selector(toggleVar:)];
418 [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
419 var: "title" selector: @selector(toggleVar:)];
421 [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
422 var: "chapter" selector: @selector(toggleVar:)];
424 [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
425 var: "audio-es" selector: @selector(toggleVar:)];
427 [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
428 var: "video-es" selector: @selector(toggleVar:)];
430 [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
431 var: "spu-es" selector: @selector(toggleVar:)];
433 /* special case for "Open File" inside the subtitles menu item */
434 if( [o_mi_videotrack isEnabled] == YES )
435 [o_mi_subtitle setEnabled: YES];
437 audio_output_t * p_aout = input_GetAout( p_input );
440 [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
441 var: "audio-channels" selector: @selector(toggleVar:)];
443 [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
444 var: "audio-device" selector: @selector(toggleVar:)];
446 [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
447 var: "visual" selector: @selector(toggleVar:)];
448 vlc_object_release( (vlc_object_t *)p_aout );
451 vout_thread_t * p_vout = input_GetVout( p_input );
455 vlc_object_t * p_dec_obj;
457 [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
458 var: "aspect-ratio" selector: @selector(toggleVar:)];
460 [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
461 var: "crop" selector: @selector(toggleVar:)];
463 [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
464 var: "deinterlace" selector: @selector(toggleVar:)];
466 [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
467 var: "deinterlace-mode" selector: @selector(toggleVar:)];
470 [self setupVarMenuItem: o_mi_ffmpeg_pp target:
471 (vlc_object_t *)p_vout var:"postprocess" selector:
472 @selector(toggleVar:)];
474 vlc_object_release( (vlc_object_t *)p_vout );
476 [self refreshVoutDeviceMenu:nil];
477 [self setSubmenusEnabled: YES];
479 vlc_object_release( p_input );
483 [o_mi_record setEnabled: NO];
487 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
489 NSUInteger count = [o_mu_screen numberOfItems];
490 NSMenu * o_submenu = o_mu_screen;
495 NSUInteger count = [o_submenu numberOfItems];
496 for( NSUInteger i = 0; i < count; i++ )
497 [o_submenu removeItemAtIndex: 0];
500 [o_submenu removeAllItems];
503 NSArray * o_screens = [NSScreen screens];
504 NSMenuItem * o_mitem;
505 count = [o_screens count];
506 [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
507 o_mitem = [o_submenu itemAtIndex: 0];
509 [o_mitem setEnabled: YES];
510 [o_mitem setTarget: self];
512 for (NSUInteger i = 0; i < count; i++)
514 s_rect = [[o_screens objectAtIndex: i] frame];
515 [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
516 (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
517 o_mitem = [o_submenu itemAtIndex:i+1];
518 [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
519 [o_mitem setEnabled: YES];
520 [o_mitem setTarget: self];
522 [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
525 - (void)setSubmenusEnabled:(BOOL)b_enabled
527 [o_mi_program setEnabled: b_enabled];
528 [o_mi_title setEnabled: b_enabled];
529 [o_mi_chapter setEnabled: b_enabled];
530 [o_mi_audiotrack setEnabled: b_enabled];
531 [o_mi_visual setEnabled: b_enabled];
532 [o_mi_videotrack setEnabled: b_enabled];
533 [o_mi_subtitle setEnabled: b_enabled];
534 [o_mi_channels setEnabled: b_enabled];
535 [o_mi_deinterlace setEnabled: b_enabled];
536 [o_mi_deinterlace_mode setEnabled: b_enabled];
537 [o_mi_ffmpeg_pp setEnabled: b_enabled];
538 [o_mi_device setEnabled: b_enabled];
539 [o_mi_screen setEnabled: b_enabled];
540 [o_mi_aspect_ratio setEnabled: b_enabled];
541 [o_mi_crop setEnabled: b_enabled];
542 [o_mi_teletext setEnabled: b_enabled];
545 - (void)setRateControlsEnabled:(BOOL)b_enabled
547 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
548 [o_mi_rate_sld setEnabled: b_enabled];
549 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
550 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
551 double speed = pow( 2, (double)i / 17 );
552 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
554 [o_mi_rate_lbl setHidden: NO];
555 [o_mi_rate_lbl_gray setHidden: YES];
559 [o_mi_rate_lbl setHidden: YES];
560 [o_mi_rate_lbl_gray setHidden: NO];
566 #pragma mark Extensions
568 - (void)setupExtensionsMenu
570 /* Load extensions if needed */
571 // TODO: Implement preference for autoloading extensions on mac
573 // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
574 // && ![o_extMgr isLoaded] )
579 if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
581 [o_extMgr loadExtensions];
584 /* Let the ExtensionsManager itself build the menu */
585 [o_extMgr buildMenu:o_mu_extensions];
589 #pragma mark Playback
590 - (IBAction)toggleRecord:(id)sender
592 [[VLCCoreInteraction sharedInstance] toggleRecord];
595 - (void)updateRecordState:(BOOL)b_value
597 [o_mi_record setState:b_value];
600 - (IBAction)setPlaybackRate:(id)sender
602 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
603 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
604 double speed = pow( 2, (double)i / 17 );
605 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
608 - (void)updatePlaybackRate
610 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
611 double speed = pow( 2, (double)i / 17 );
612 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
613 [o_mi_rate_sld setIntValue: i];
616 - (IBAction)toggleJumpButtons:(id)sender
618 BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playback-buttons" );
619 config_PutInt( VLCIntf, "macosx-show-playback-buttons", b_value );
620 [[[VLCMain sharedInstance] mainWindow] toggleJumpButtons];
621 [o_mi_toggleJumpButtons setState: b_value];
624 - (IBAction)togglePlaymodeButtons:(id)sender
626 BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playmode-buttons" );
627 config_PutInt( VLCIntf, "macosx-show-playmode-buttons", b_value );
628 [[[VLCMain sharedInstance] mainWindow] togglePlaymodeButtons];
629 [o_mi_togglePlaymodeButtons setState: b_value];
633 #pragma mark video menu
634 - (IBAction)toggleFullscreen:(id)sender
636 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
639 - (IBAction)resizeVideoWindow:(id)sender
641 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
644 vout_thread_t *p_vout = getVout();
647 if (sender == o_mi_half_window)
648 var_SetFloat( p_vout, "zoom", 0.5 );
649 else if (sender == o_mi_normal_window)
650 var_SetFloat( p_vout, "zoom", 1.0 );
651 else if (sender == o_mi_double_window)
652 var_SetFloat( p_vout, "zoom", 2.0 );
655 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
657 vlc_object_release( p_vout );
659 vlc_object_release( p_input );
663 - (IBAction)floatOnTop:(id)sender
665 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
668 vout_thread_t *p_vout = getVout();
671 var_ToggleBool( p_vout, "video-on-top" );
672 vlc_object_release( p_vout );
674 vlc_object_release( p_input );
678 - (IBAction)createVideoSnapshot:(id)sender
680 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
683 vout_thread_t *p_vout = getVout();
686 var_TriggerCallback( p_vout, "video-snapshot" );
687 vlc_object_release( p_vout );
689 vlc_object_release( p_input );
693 - (IBAction)toggleFullscreenDevice:(id)sender
695 config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
696 [self refreshVoutDeviceMenu: nil];
707 - (IBAction)intfOpenFile:(id)sender
709 [[[VLCMain sharedInstance] open] openFile];
712 - (IBAction)intfOpenFileGeneric:(id)sender
714 [[[VLCMain sharedInstance] open] openFileGeneric];
717 - (IBAction)intfOpenDisc:(id)sender
719 [[[VLCMain sharedInstance] open] openDisc];
722 - (IBAction)intfOpenNet:(id)sender
724 [[[VLCMain sharedInstance] open] openNet];
727 - (IBAction)intfOpenCapture:(id)sender
729 [[[VLCMain sharedInstance] open] openCapture];
732 - (IBAction)showWizard:(id)sender
734 [[[VLCMain sharedInstance] wizard] resetWizard];
735 [[[VLCMain sharedInstance] wizard] showWizard];
738 - (IBAction)showVideoEffects:(id)sender
740 if( o_videoeffects == nil )
741 o_videoeffects = [[VLCVideoEffects alloc] init];
743 if( !b_nib_videoeffects_loaded )
744 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
746 [o_videoeffects toggleWindow:sender];
749 - (IBAction)showTrackSynchronization:(id)sender
751 if (!o_trackSynchronization)
752 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
754 if (!b_nib_tracksynchro_loaded)
755 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
757 [o_trackSynchronization toggleWindow:sender];
760 - (IBAction)showAudioEffects:(id)sender
763 o_audioeffects = [[VLCAudioEffects alloc] init];
765 if (!b_nib_audioeffects_loaded)
766 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
768 [o_audioeffects toggleWindow:sender];
771 - (IBAction)showBookmarks:(id)sender
773 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
776 - (IBAction)viewPreferences:(id)sender
778 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
782 #pragma mark Help and Docs
787 o_about = [[VLAboutBox alloc] init];
789 if( !b_nib_about_loaded )
790 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
793 - (IBAction)viewAbout:(id)sender
799 - (IBAction)showLicense:(id)sender
802 [o_about showGPL: sender];
805 - (IBAction)viewHelp:(id)sender
811 - (IBAction)openReadMe:(id)sender
813 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
815 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
818 - (IBAction)openDocumentation:(id)sender
820 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
822 [[NSWorkspace sharedWorkspace] openURL: o_url];
825 - (IBAction)openWebsite:(id)sender
827 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
829 [[NSWorkspace sharedWorkspace] openURL: o_url];
832 - (IBAction)openForum:(id)sender
834 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
836 [[NSWorkspace sharedWorkspace] openURL: o_url];
839 - (IBAction)openDonate:(id)sender
841 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
843 [[NSWorkspace sharedWorkspace] openURL: o_url];
847 #pragma mark Errors, warnings and messages
849 - (IBAction)viewErrorsAndWarnings:(id)sender
851 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
854 - (IBAction)showInformationPanel:(id)sender
856 [[[VLCMain sharedInstance] info] initPanel];
860 #pragma mark convinience stuff for other objects
863 [o_mi_play setTitle: _NS("Play")];
864 [o_dmi_play setTitle: _NS("Play")];
865 [o_vmi_play setTitle: _NS("Play")];
870 [o_mi_play setTitle: _NS("Pause")];
871 [o_dmi_play setTitle: _NS("Pause")];
872 [o_vmi_play setTitle: _NS("Pause")];
877 [o_mi_repeat setState: NSOnState];
878 [o_mi_loop setState: NSOffState];
883 [o_mi_repeat setState: NSOffState];
884 [o_mi_loop setState: NSOnState];
889 [o_mi_repeat setState: NSOffState];
890 [o_mi_loop setState: NSOffState];
896 playlist_t *p_playlist = pl_Get( VLCIntf );
897 b_value = var_GetBool( p_playlist, "random" );
899 [o_mi_random setState: b_value];
903 #pragma mark Dynamic menu creation and validation
905 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
906 target:(vlc_object_t *)p_object
907 var:(const char *)psz_variable
908 selector:(SEL)pf_callback
910 vlc_value_t val, text;
911 int i_type = var_Type( p_object, psz_variable );
913 switch( i_type & VLC_VAR_TYPE )
917 case VLC_VAR_VARIABLE:
919 case VLC_VAR_INTEGER:
922 /* Variable doesn't exist or isn't handled */
926 /* Make sure we want to display the variable
927 * special case for spu-es, which we want to display in any case */
928 if( i_type & VLC_VAR_HASCHOICE && strcmp( psz_variable, "spu-es" ) )
930 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
933 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
937 /* Get the descriptive name of the variable */
938 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
939 [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
941 if( i_type & VLC_VAR_HASCHOICE )
943 NSMenu *o_menu = [o_mi submenu];
945 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
946 var:psz_variable selector:pf_callback];
948 free( text.psz_string );
952 if( var_Get( p_object, psz_variable, &val ) < 0 )
957 VLCAutoGeneratedMenuContent *o_data;
958 switch( i_type & VLC_VAR_TYPE )
961 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
962 andValue: val ofType: i_type];
963 [o_mi setRepresentedObject: [o_data autorelease]];
967 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
968 andValue: val ofType: i_type];
969 [o_mi setRepresentedObject: [o_data autorelease]];
970 if( !( i_type & VLC_VAR_ISCOMMAND ) )
971 [o_mi setState: val.b_bool ? TRUE : FALSE ];
978 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
979 free( text.psz_string );
983 - (void)setupVarMenu:(NSMenu *)o_menu
984 forMenuItem: (NSMenuItem *)o_parent
985 target:(vlc_object_t *)p_object
986 var:(const char *)psz_variable
987 selector:(SEL)pf_callback
989 vlc_value_t val, val_list, text_list;
992 /* remove previous items */
996 i_nb_items = [o_menu numberOfItems];
997 for( i = 0; i < i_nb_items; i++ )
998 [o_menu removeItemAtIndex: 0];
1002 /* this is more efficient then the legacy code, but 10.6+ only */
1003 [o_menu removeAllItems];
1007 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1009 NSMenuItem *o_lmi_tmp2;
1010 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1011 [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1012 [o_lmi_tmp2 setEnabled: YES];
1013 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1014 [o_parent setEnabled: YES];
1015 [o_menu addItem: [NSMenuItem separatorItem]];
1018 /* special case for the subtitles item */
1019 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1021 NSMenuItem * o_lmi_tmp;
1022 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1023 [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1024 [o_lmi_tmp setEnabled: YES];
1025 [o_parent setEnabled: YES];
1028 /* Check the type of the object variable */
1029 i_type = var_Type( p_object, psz_variable );
1031 /* Make sure we want to display the variable */
1032 if( i_type & VLC_VAR_HASCHOICE )
1034 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1035 if( val.i_int == 0 ) return;
1036 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1042 switch( i_type & VLC_VAR_TYPE )
1046 case VLC_VAR_VARIABLE:
1047 case VLC_VAR_STRING:
1048 case VLC_VAR_INTEGER:
1051 /* Variable doesn't exist or isn't handled */
1055 if( var_Get( p_object, psz_variable, &val ) < 0 )
1060 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1061 &val_list, &text_list ) < 0 )
1063 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1067 /* make (un)sensitive */
1068 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1070 /* another special case for the subtitles item */
1071 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1072 [o_menu addItem: [NSMenuItem separatorItem]];
1074 for( i = 0; i < val_list.p_list->i_count; i++ )
1077 NSString *o_title = @"";
1078 VLCAutoGeneratedMenuContent *o_data;
1080 switch( i_type & VLC_VAR_TYPE )
1082 case VLC_VAR_STRING:
1084 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 );
1086 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1087 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1088 andValue: val_list.p_list->p_values[i] ofType: i_type];
1089 [o_lmi setRepresentedObject: [o_data autorelease]];
1090 [o_lmi setTarget: self];
1092 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1093 [o_lmi setState: TRUE ];
1097 case VLC_VAR_INTEGER:
1099 o_title = text_list.p_list->p_values[i].psz_string ?
1100 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1102 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1103 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1104 andValue: val_list.p_list->p_values[i] ofType: i_type];
1105 [o_lmi setRepresentedObject: [o_data autorelease]];
1106 [o_lmi setTarget: self];
1108 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1109 [o_lmi setState: TRUE ];
1117 /* special case for the subtitles sub-menu
1118 * In case that we don't have any subs, we don't want a separator item at the end */
1119 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1121 if( [o_menu numberOfItems] == 2 )
1122 [o_menu removeItemAtIndex: 1];
1125 /* clean up everything */
1126 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1127 var_FreeList( &val_list, &text_list );
1130 - (IBAction)toggleVar:(id)sender
1132 NSMenuItem *o_mi = (NSMenuItem *)sender;
1133 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1134 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1135 toTarget: self withObject: o_data];
1140 - (int)toggleVarThread: (id)data
1142 vlc_object_t *p_object;
1143 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1145 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1146 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1148 /* Preserve settings across vouts via the playlist object: */
1149 if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1150 var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1152 /* save our audio device across multiple sessions */
1153 if( !strcmp( [menuContent name], "audio-device" ) )
1154 config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1156 p_object = [menuContent vlcObject];
1158 if( p_object != NULL )
1160 var_Set( p_object, [menuContent name], [menuContent value] );
1161 vlc_object_release( p_object );
1166 return VLC_EGENERIC;
1171 @implementation VLCMainMenu (NSMenuValidation)
1173 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1175 NSString *o_title = [o_mi title];
1176 BOOL bEnabled = TRUE;
1178 playlist_t * p_playlist = pl_Get( p_intf );
1179 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1181 if( [o_title isEqualToString: _NS("Stop")] )
1183 if( p_input == NULL )
1187 [self setupMenus]; /* Make sure input menu is up to date */
1189 else if( [o_title isEqualToString: _NS("Previous")] ||
1190 [o_title isEqualToString: _NS("Next")] )
1193 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1196 else if( [o_title isEqualToString: _NS("Random")] )
1199 var_Get( p_playlist, "random", &val );
1200 i_state = val.b_bool ? NSOnState : NSOffState;
1201 [o_mi setState: i_state];
1203 else if( [o_title isEqualToString: _NS("Repeat One")] )
1206 var_Get( p_playlist, "repeat", &val );
1207 i_state = val.b_bool ? NSOnState : NSOffState;
1208 [o_mi setState: i_state];
1210 else if( [o_title isEqualToString: _NS("Repeat All")] )
1213 var_Get( p_playlist, "loop", &val );
1214 i_state = val.b_bool ? NSOnState : NSOffState;
1215 [o_mi setState: i_state];
1217 else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1220 var_Get( p_playlist, "play-and-exit", &val );
1221 i_state = val.b_bool ? NSOnState : NSOffState;
1222 [o_mi setState: i_state];
1224 else if( [o_title isEqualToString: _NS("Step Forward")] ||
1225 [o_title isEqualToString: _NS("Step Backward")] ||
1226 [o_title isEqualToString: _NS("Jump To Time")])
1228 if( p_input != NULL )
1230 var_Get( p_input, "can-seek", &val);
1231 bEnabled = val.b_bool;
1233 else bEnabled = FALSE;
1235 else if( [o_title isEqualToString: _NS("Mute")] )
1237 [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1238 [self setupMenus]; /* Make sure audio menu is up to date */
1240 else if( [o_title isEqualToString: _NS("Half Size")] ||
1241 [o_title isEqualToString: _NS("Normal Size")] ||
1242 [o_title isEqualToString: _NS("Double Size")] ||
1243 [o_title isEqualToString: _NS("Fit to Screen")] ||
1244 [o_title isEqualToString: _NS("Snapshot")] ||
1245 [o_title isEqualToString: _NS("Fullscreen")] ||
1246 [o_title isEqualToString: _NS("Float on Top")] )
1250 if( p_input != NULL )
1252 vout_thread_t *p_vout = input_GetVout( p_input );
1253 if( p_vout != NULL )
1255 if( [o_title isEqualToString: _NS("Float on Top")] )
1257 [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1262 vlc_object_release( (vlc_object_t *)p_vout );
1265 if( [o_title isEqualToString: _NS("Fullscreen")] )
1267 [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1270 [self setupMenus]; /* Make sure video menu is up to date */
1273 /* Special case for telx menu */
1274 if( [o_title isEqualToString: _NS("Normal Size")] )
1276 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1279 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1281 [[item submenu] setAutoenablesItems:NO];
1282 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1284 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1288 if( p_input ) vlc_object_release( p_input );
1296 /*****************************************************************************
1297 * VLCAutoGeneratedMenuContent implementation
1298 *****************************************************************************
1299 * Object connected to a playlistitem which remembers the data belonging to
1300 * the variable of the autogenerated menu
1301 *****************************************************************************/
1302 @implementation VLCAutoGeneratedMenuContent
1304 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1305 andValue:(vlc_value_t)val ofType:(int)type
1307 self = [super init];
1311 _vlc_object = vlc_object_hold( object );
1312 psz_name = strdup( name );
1315 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1316 value.psz_string = strdup( val.psz_string );
1324 vlc_object_release( _vlc_object );
1325 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1326 free( value.psz_string );
1331 - (const char *)name
1336 - (vlc_value_t)value
1341 - (vlc_object_t *)vlcObject
1343 return vlc_object_hold( _vlc_object );