1 /*****************************************************************************
2 * MainMenu.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2011 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")];
285 [o_mi_program setTitle: _NS("Program")];
286 [o_mu_program setTitle: _NS("Program")];
287 [o_mi_title setTitle: _NS("Title")];
288 [o_mu_title setTitle: _NS("Title")];
289 [o_mi_chapter setTitle: _NS("Chapter")];
290 [o_mu_chapter setTitle: _NS("Chapter")];
292 [o_mu_audio setTitle: _NS("Audio")];
293 [o_mi_vol_up setTitle: _NS("Increase Volume")];
294 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
295 [o_mi_mute setTitle: _NS("Mute")];
296 [o_mi_audiotrack setTitle: _NS("Audio Track")];
297 [o_mu_audiotrack setTitle: _NS("Audio Track")];
298 [o_mi_channels setTitle: _NS("Audio Channels")];
299 [o_mu_channels setTitle: _NS("Audio Channels")];
300 [o_mi_device setTitle: _NS("Audio Device")];
301 [o_mu_device setTitle: _NS("Audio Device")];
302 [o_mi_visual setTitle: _NS("Visualizations")];
303 [o_mu_visual setTitle: _NS("Visualizations")];
305 [o_mu_video setTitle: _NS("Video")];
306 [o_mi_half_window setTitle: _NS("Half Size")];
307 [o_mi_normal_window setTitle: _NS("Normal Size")];
308 [o_mi_double_window setTitle: _NS("Double Size")];
309 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
310 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
311 [o_mi_floatontop setTitle: _NS("Float on Top")];
312 [o_mi_snapshot setTitle: _NS("Snapshot")];
313 [o_mi_videotrack setTitle: _NS("Video Track")];
314 [o_mu_videotrack setTitle: _NS("Video Track")];
315 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
316 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
317 [o_mi_crop setTitle: _NS("Crop")];
318 [o_mu_crop setTitle: _NS("Crop")];
319 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
320 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
321 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
322 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
323 [o_mi_addSub setTitle: _NS("Open File...")];
324 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
325 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
326 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
327 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
328 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
329 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
330 [o_mi_teletext setTitle: _NS("Teletext")];
331 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
332 [o_mi_teletext_index setTitle: _NS("Index")];
333 [o_mi_teletext_red setTitle: _NS("Red")];
334 [o_mi_teletext_green setTitle: _NS("Green")];
335 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
336 [o_mi_teletext_blue setTitle: _NS("Blue")];
338 [o_mu_window setTitle: _NS("Window")];
339 [o_mi_minimize setTitle: _NS("Minimize Window")];
340 [o_mi_close_window setTitle: _NS("Close Window")];
341 [o_mi_player setTitle: _NS("Player...")];
342 [o_mi_controller setTitle: _NS("Main Window...")];
343 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
344 [o_mi_videoeffects setTitle: _NS("Video Filters...")];
345 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
346 [o_mi_playlist setTitle: _NS("Playlist...")];
347 [o_mi_info setTitle: _NS("Media Information...")];
348 [o_mi_messages setTitle: _NS("Messages...")];
349 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
351 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
353 [o_mu_help setTitle: _NS("Help")];
354 [o_mi_help setTitle: _NS("VLC media player Help...")];
355 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
356 [o_mi_license setTitle: _NS("License")];
357 [o_mi_documentation setTitle: _NS("Online Documentation...")];
358 [o_mi_website setTitle: _NS("VideoLAN Website...")];
359 [o_mi_donation setTitle: _NS("Make a donation...")];
360 [o_mi_forum setTitle: _NS("Online Forum...")];
363 [o_dmi_play setTitle: _NS("Play")];
364 [o_dmi_stop setTitle: _NS("Stop")];
365 [o_dmi_next setTitle: _NS("Next")];
366 [o_dmi_previous setTitle: _NS("Previous")];
367 [o_dmi_mute setTitle: _NS("Mute")];
370 [o_vmi_play setTitle: _NS("Play")];
371 [o_vmi_stop setTitle: _NS("Stop")];
372 [o_vmi_prev setTitle: _NS("Previous")];
373 [o_vmi_next setTitle: _NS("Next")];
374 [o_vmi_volup setTitle: _NS("Volume Up")];
375 [o_vmi_voldown setTitle: _NS("Volume Down")];
376 [o_vmi_mute setTitle: _NS("Mute")];
377 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
378 [o_vmi_snapshot setTitle: _NS("Snapshot")];
382 #pragma mark Termination
384 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
386 if( !p_intf ) return;
388 NSArray *menuitems_array = [the_menu itemArray];
389 NSUInteger menuItemCount = [menuitems_array count];
390 for( NSUInteger i=0; i < menuItemCount; i++ )
392 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
393 if( [one_item hasSubmenu] )
394 [self releaseRepresentedObjects: [one_item submenu]];
396 [one_item setRepresentedObject:NULL];
401 #pragma mark Interface update
405 playlist_t * p_playlist = pl_Get( p_intf );
406 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
407 if( p_input != NULL )
409 [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
411 [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
412 var: "program" selector: @selector(toggleVar:)];
414 [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
415 var: "title" selector: @selector(toggleVar:)];
417 [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
418 var: "chapter" selector: @selector(toggleVar:)];
420 [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
421 var: "audio-es" selector: @selector(toggleVar:)];
423 [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
424 var: "video-es" selector: @selector(toggleVar:)];
426 [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
427 var: "spu-es" selector: @selector(toggleVar:)];
429 /* special case for "Open File" inside the subtitles menu item */
430 if( [o_mi_videotrack isEnabled] == YES )
431 [o_mi_subtitle setEnabled: YES];
433 audio_output_t * p_aout = input_GetAout( p_input );
436 [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
437 var: "audio-channels" selector: @selector(toggleVar:)];
439 [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
440 var: "audio-device" selector: @selector(toggleVar:)];
442 [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
443 var: "visual" selector: @selector(toggleVar:)];
444 vlc_object_release( (vlc_object_t *)p_aout );
447 vout_thread_t * p_vout = input_GetVout( p_input );
451 vlc_object_t * p_dec_obj;
453 [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
454 var: "aspect-ratio" selector: @selector(toggleVar:)];
456 [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
457 var: "crop" selector: @selector(toggleVar:)];
459 [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
460 var: "deinterlace" selector: @selector(toggleVar:)];
462 [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
463 var: "deinterlace-mode" selector: @selector(toggleVar:)];
466 [self setupVarMenuItem: o_mi_ffmpeg_pp target:
467 (vlc_object_t *)p_vout var:"postprocess" selector:
468 @selector(toggleVar:)];
470 vlc_object_release( (vlc_object_t *)p_vout );
472 [self refreshVoutDeviceMenu:nil];
473 [self setSubmenusEnabled: YES];
475 vlc_object_release( p_input );
479 [o_mi_record setEnabled: NO];
483 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
485 NSUInteger count = [o_mu_screen numberOfItems];
486 NSMenu * o_submenu = o_mu_screen;
491 NSUInteger count = [o_submenu numberOfItems];
492 for( NSUInteger i = 0; i < count; i++ )
493 [o_submenu removeItemAtIndex: 0];
496 [o_submenu removeAllItems];
499 NSArray * o_screens = [NSScreen screens];
500 NSMenuItem * o_mitem;
501 count = [o_screens count];
502 [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
503 o_mitem = [o_submenu itemAtIndex: 0];
505 [o_mitem setEnabled: YES];
506 [o_mitem setTarget: self];
508 for (NSUInteger i = 0; i < count; i++)
510 s_rect = [[o_screens objectAtIndex: i] frame];
511 [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
512 (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
513 o_mitem = [o_submenu itemAtIndex:i+1];
514 [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
515 [o_mitem setEnabled: YES];
516 [o_mitem setTarget: self];
518 [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
521 - (void)setSubmenusEnabled:(BOOL)b_enabled
523 [o_mi_program setEnabled: b_enabled];
524 [o_mi_title setEnabled: b_enabled];
525 [o_mi_chapter setEnabled: b_enabled];
526 [o_mi_audiotrack setEnabled: b_enabled];
527 [o_mi_visual setEnabled: b_enabled];
528 [o_mi_videotrack setEnabled: b_enabled];
529 [o_mi_subtitle setEnabled: b_enabled];
530 [o_mi_channels setEnabled: b_enabled];
531 [o_mi_deinterlace setEnabled: b_enabled];
532 [o_mi_deinterlace_mode setEnabled: b_enabled];
533 [o_mi_ffmpeg_pp setEnabled: b_enabled];
534 [o_mi_device setEnabled: b_enabled];
535 [o_mi_screen setEnabled: b_enabled];
536 [o_mi_aspect_ratio setEnabled: b_enabled];
537 [o_mi_crop setEnabled: b_enabled];
538 [o_mi_teletext setEnabled: b_enabled];
541 - (void)setRateControlsEnabled:(BOOL)b_enabled
543 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
544 [o_mi_rate_sld setEnabled: b_enabled];
545 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
546 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
547 double speed = pow( 2, (double)i / 17 );
548 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
550 [o_mi_rate_lbl setHidden: NO];
551 [o_mi_rate_lbl_gray setHidden: YES];
555 [o_mi_rate_lbl setHidden: YES];
556 [o_mi_rate_lbl_gray setHidden: NO];
562 #pragma mark Extensions
564 - (void)setupExtensionsMenu
566 /* Load extensions if needed */
567 // TODO: Implement preference for autoloading extensions on mac
569 // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
570 // && ![o_extMgr isLoaded] )
575 if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
577 [o_extMgr loadExtensions];
580 /* Let the ExtensionsManager itself build the menu */
581 [o_extMgr buildMenu:o_mu_extensions];
585 #pragma mark Playback
586 - (IBAction)toggleRecord:(id)sender
588 [[VLCCoreInteraction sharedInstance] toggleRecord];
591 - (void)updateRecordState:(BOOL)b_value
593 [o_mi_record setState:b_value];
596 - (IBAction)setPlaybackRate:(id)sender
598 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
599 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
600 double speed = pow( 2, (double)i / 17 );
601 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
604 - (void)updatePlaybackRate
606 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
607 double speed = pow( 2, (double)i / 17 );
608 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
609 [o_mi_rate_sld setIntValue: i];
614 - (IBAction)toggleFullscreen:(id)sender
616 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
619 - (IBAction)resizeVideoWindow:(id)sender
621 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
624 vout_thread_t *p_vout = getVout();
627 if (sender == o_mi_half_window)
628 var_SetFloat( p_vout, "zoom", 0.5 );
629 else if (sender == o_mi_normal_window)
630 var_SetFloat( p_vout, "zoom", 1.0 );
631 else if (sender == o_mi_double_window)
632 var_SetFloat( p_vout, "zoom", 2.0 );
635 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
637 vlc_object_release( p_vout );
639 vlc_object_release( p_input );
643 - (IBAction)floatOnTop:(id)sender
645 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
648 vout_thread_t *p_vout = getVout();
651 var_ToggleBool( p_vout, "video-on-top" );
652 vlc_object_release( p_vout );
654 vlc_object_release( p_input );
658 - (IBAction)createVideoSnapshot:(id)sender
660 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
663 vout_thread_t *p_vout = getVout();
666 var_TriggerCallback( p_vout, "video-snapshot" );
667 vlc_object_release( p_vout );
669 vlc_object_release( p_input );
673 - (IBAction)toggleFullscreenDevice:(id)sender
675 config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
676 [self refreshVoutDeviceMenu: nil];
687 - (IBAction)intfOpenFile:(id)sender
689 [[[VLCMain sharedInstance] open] openFile];
692 - (IBAction)intfOpenFileGeneric:(id)sender
694 [[[VLCMain sharedInstance] open] openFileGeneric];
697 - (IBAction)intfOpenDisc:(id)sender
699 [[[VLCMain sharedInstance] open] openDisc];
702 - (IBAction)intfOpenNet:(id)sender
704 [[[VLCMain sharedInstance] open] openNet];
707 - (IBAction)intfOpenCapture:(id)sender
709 [[[VLCMain sharedInstance] open] openCapture];
712 - (IBAction)showWizard:(id)sender
714 [[[VLCMain sharedInstance] wizard] resetWizard];
715 [[[VLCMain sharedInstance] wizard] showWizard];
718 - (IBAction)showVideoEffects:(id)sender
720 if( o_videoeffects == nil )
721 o_videoeffects = [[VLCVideoEffects alloc] init];
723 if( !b_nib_videoeffects_loaded )
724 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
726 [o_videoeffects toggleWindow:sender];
729 - (IBAction)showTrackSynchronization:(id)sender
731 if (!o_trackSynchronization)
732 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
734 if (!b_nib_tracksynchro_loaded)
735 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
737 [o_trackSynchronization toggleWindow:sender];
740 - (IBAction)showAudioEffects:(id)sender
743 o_audioeffects = [[VLCAudioEffects alloc] init];
745 if (!b_nib_audioeffects_loaded)
746 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
748 [o_audioeffects toggleWindow:sender];
751 - (IBAction)showBookmarks:(id)sender
753 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
756 - (IBAction)viewPreferences:(id)sender
758 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
762 #pragma mark Help and Docs
767 o_about = [[VLAboutBox alloc] init];
769 if( !b_nib_about_loaded )
770 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
773 - (IBAction)viewAbout:(id)sender
779 - (IBAction)showLicense:(id)sender
782 [o_about showGPL: sender];
785 - (IBAction)viewHelp:(id)sender
791 - (IBAction)openReadMe:(id)sender
793 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
795 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
798 - (IBAction)openDocumentation:(id)sender
800 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
802 [[NSWorkspace sharedWorkspace] openURL: o_url];
805 - (IBAction)openWebsite:(id)sender
807 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
809 [[NSWorkspace sharedWorkspace] openURL: o_url];
812 - (IBAction)openForum:(id)sender
814 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
816 [[NSWorkspace sharedWorkspace] openURL: o_url];
819 - (IBAction)openDonate:(id)sender
821 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
823 [[NSWorkspace sharedWorkspace] openURL: o_url];
827 #pragma mark Errors, warnings and messages
829 - (IBAction)viewErrorsAndWarnings:(id)sender
831 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
834 - (IBAction)showInformationPanel:(id)sender
836 [[[VLCMain sharedInstance] info] initPanel];
840 #pragma mark convinience stuff for other objects
843 [o_mi_play setTitle: _NS("Play")];
844 [o_dmi_play setTitle: _NS("Play")];
845 [o_vmi_play setTitle: _NS("Play")];
850 [o_mi_play setTitle: _NS("Pause")];
851 [o_dmi_play setTitle: _NS("Pause")];
852 [o_vmi_play setTitle: _NS("Pause")];
857 [o_mi_repeat setState: NSOnState];
858 [o_mi_loop setState: NSOffState];
863 [o_mi_repeat setState: NSOffState];
864 [o_mi_loop setState: NSOnState];
869 [o_mi_repeat setState: NSOffState];
870 [o_mi_loop setState: NSOffState];
876 playlist_t *p_playlist = pl_Get( VLCIntf );
877 b_value = var_GetBool( p_playlist, "random" );
879 [o_mi_random setState: b_value];
883 #pragma mark Dynamic menu creation and validation
885 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
886 target:(vlc_object_t *)p_object
887 var:(const char *)psz_variable
888 selector:(SEL)pf_callback
890 vlc_value_t val, text;
891 int i_type = var_Type( p_object, psz_variable );
893 switch( i_type & VLC_VAR_TYPE )
897 case VLC_VAR_VARIABLE:
899 case VLC_VAR_INTEGER:
902 /* Variable doesn't exist or isn't handled */
906 /* Make sure we want to display the variable
907 * special case for spu-es, which we want to display in any case */
908 if( i_type & VLC_VAR_HASCHOICE && strcmp( psz_variable, "spu-es" ) )
910 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
913 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
917 /* Get the descriptive name of the variable */
918 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
919 [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
921 if( i_type & VLC_VAR_HASCHOICE )
923 NSMenu *o_menu = [o_mi submenu];
925 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
926 var:psz_variable selector:pf_callback];
928 free( text.psz_string );
932 if( var_Get( p_object, psz_variable, &val ) < 0 )
937 VLCAutoGeneratedMenuContent *o_data;
938 switch( i_type & VLC_VAR_TYPE )
941 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
942 andValue: val ofType: i_type];
943 [o_mi setRepresentedObject: [o_data autorelease]];
947 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
948 andValue: val ofType: i_type];
949 [o_mi setRepresentedObject: [o_data autorelease]];
950 if( !( i_type & VLC_VAR_ISCOMMAND ) )
951 [o_mi setState: val.b_bool ? TRUE : FALSE ];
958 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
959 free( text.psz_string );
963 - (void)setupVarMenu:(NSMenu *)o_menu
964 forMenuItem: (NSMenuItem *)o_parent
965 target:(vlc_object_t *)p_object
966 var:(const char *)psz_variable
967 selector:(SEL)pf_callback
969 vlc_value_t val, val_list, text_list;
972 /* remove previous items */
976 i_nb_items = [o_menu numberOfItems];
977 for( i = 0; i < i_nb_items; i++ )
978 [o_menu removeItemAtIndex: 0];
982 /* this is more efficient then the legacy code, but 10.6+ only */
983 [o_menu removeAllItems];
987 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
989 NSMenuItem *o_lmi_tmp2;
990 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
991 [o_lmi_tmp2 setTarget: self];
992 [o_lmi_tmp2 setEnabled: YES];
993 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
994 [o_parent setEnabled: YES];
995 [o_menu addItem: [NSMenuItem separatorItem]];
998 /* special case for the subtitles item */
999 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1001 NSMenuItem * o_lmi_tmp;
1002 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1003 [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1004 [o_lmi_tmp setEnabled: YES];
1005 [o_parent setEnabled: YES];
1008 /* Check the type of the object variable */
1009 i_type = var_Type( p_object, psz_variable );
1011 /* Make sure we want to display the variable */
1012 if( i_type & VLC_VAR_HASCHOICE )
1014 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1015 if( val.i_int == 0 ) return;
1016 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1022 switch( i_type & VLC_VAR_TYPE )
1026 case VLC_VAR_VARIABLE:
1027 case VLC_VAR_STRING:
1028 case VLC_VAR_INTEGER:
1031 /* Variable doesn't exist or isn't handled */
1035 if( var_Get( p_object, psz_variable, &val ) < 0 )
1040 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1041 &val_list, &text_list ) < 0 )
1043 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1047 /* make (un)sensitive */
1048 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1050 /* another special case for the subtitles item */
1051 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1052 [o_menu addItem: [NSMenuItem separatorItem]];
1054 for( i = 0; i < val_list.p_list->i_count; i++ )
1057 NSString *o_title = @"";
1058 VLCAutoGeneratedMenuContent *o_data;
1060 switch( i_type & VLC_VAR_TYPE )
1062 case VLC_VAR_STRING:
1064 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 );
1066 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1067 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1068 andValue: val_list.p_list->p_values[i] ofType: i_type];
1069 [o_lmi setRepresentedObject: [o_data autorelease]];
1070 [o_lmi setTarget: self];
1072 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1073 [o_lmi setState: TRUE ];
1077 case VLC_VAR_INTEGER:
1079 o_title = text_list.p_list->p_values[i].psz_string ?
1080 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1082 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1083 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1084 andValue: val_list.p_list->p_values[i] ofType: i_type];
1085 [o_lmi setRepresentedObject: [o_data autorelease]];
1086 [o_lmi setTarget: self];
1088 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1089 [o_lmi setState: TRUE ];
1097 /* special case for the subtitles sub-menu
1098 * In case that we don't have any subs, we don't want a separator item at the end */
1099 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1101 if( [o_menu numberOfItems] == 2 )
1102 [o_menu removeItemAtIndex: 1];
1105 /* clean up everything */
1106 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1107 var_FreeList( &val_list, &text_list );
1110 - (IBAction)toggleVar:(id)sender
1112 NSMenuItem *o_mi = (NSMenuItem *)sender;
1113 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1114 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1115 toTarget: self withObject: o_data];
1120 - (int)toggleVarThread: (id)data
1122 vlc_object_t *p_object;
1123 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1125 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1126 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1128 /* Preserve settings across vouts via the playlist object: */
1129 if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1130 var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1132 /* save our audio device across multiple sessions */
1133 if( !strcmp( [menuContent name], "audio-device" ) )
1134 config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1136 p_object = [menuContent vlcObject];
1138 if( p_object != NULL )
1140 var_Set( p_object, [menuContent name], [menuContent value] );
1141 vlc_object_release( p_object );
1146 return VLC_EGENERIC;
1151 @implementation VLCMainMenu (NSMenuValidation)
1153 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1155 NSString *o_title = [o_mi title];
1156 BOOL bEnabled = TRUE;
1158 playlist_t * p_playlist = pl_Get( p_intf );
1159 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1161 if( [o_title isEqualToString: _NS("Stop")] )
1163 if( p_input == NULL )
1167 [self setupMenus]; /* Make sure input menu is up to date */
1169 else if( [o_title isEqualToString: _NS("Previous")] ||
1170 [o_title isEqualToString: _NS("Next")] )
1173 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1176 else if( [o_title isEqualToString: _NS("Random")] )
1179 var_Get( p_playlist, "random", &val );
1180 i_state = val.b_bool ? NSOnState : NSOffState;
1181 [o_mi setState: i_state];
1183 else if( [o_title isEqualToString: _NS("Repeat One")] )
1186 var_Get( p_playlist, "repeat", &val );
1187 i_state = val.b_bool ? NSOnState : NSOffState;
1188 [o_mi setState: i_state];
1190 else if( [o_title isEqualToString: _NS("Repeat All")] )
1193 var_Get( p_playlist, "loop", &val );
1194 i_state = val.b_bool ? NSOnState : NSOffState;
1195 [o_mi setState: i_state];
1197 else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1200 var_Get( p_playlist, "play-and-exit", &val );
1201 i_state = val.b_bool ? NSOnState : NSOffState;
1202 [o_mi setState: i_state];
1204 else if( [o_title isEqualToString: _NS("Step Forward")] ||
1205 [o_title isEqualToString: _NS("Step Backward")] ||
1206 [o_title isEqualToString: _NS("Jump To Time")])
1208 if( p_input != NULL )
1210 var_Get( p_input, "can-seek", &val);
1211 bEnabled = val.b_bool;
1213 else bEnabled = FALSE;
1215 else if( [o_title isEqualToString: _NS("Mute")] )
1217 [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1218 [self setupMenus]; /* Make sure audio menu is up to date */
1220 else if( [o_title isEqualToString: _NS("Half Size")] ||
1221 [o_title isEqualToString: _NS("Normal Size")] ||
1222 [o_title isEqualToString: _NS("Double Size")] ||
1223 [o_title isEqualToString: _NS("Fit to Screen")] ||
1224 [o_title isEqualToString: _NS("Snapshot")] ||
1225 [o_title isEqualToString: _NS("Fullscreen")] ||
1226 [o_title isEqualToString: _NS("Float on Top")] )
1230 if( p_input != NULL )
1232 vout_thread_t *p_vout = input_GetVout( p_input );
1233 if( p_vout != NULL )
1235 if( [o_title isEqualToString: _NS("Float on Top")] )
1237 [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1242 vlc_object_release( (vlc_object_t *)p_vout );
1245 if( [o_title isEqualToString: _NS("Fullscreen")] )
1247 [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1250 [self setupMenus]; /* Make sure video menu is up to date */
1253 /* Special case for telx menu */
1254 if( [o_title isEqualToString: _NS("Normal Size")] )
1256 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1259 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1261 [[item submenu] setAutoenablesItems:NO];
1262 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1264 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1268 if( p_input ) vlc_object_release( p_input );
1276 /*****************************************************************************
1277 * VLCAutoGeneratedMenuContent implementation
1278 *****************************************************************************
1279 * Object connected to a playlistitem which remembers the data belonging to
1280 * the variable of the autogenerated menu
1281 *****************************************************************************/
1282 @implementation VLCAutoGeneratedMenuContent
1284 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1285 andValue:(vlc_value_t)val ofType:(int)type
1287 self = [super init];
1291 _vlc_object = vlc_object_hold( object );
1292 psz_name = strdup( name );
1295 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1296 value.psz_string = strdup( val.psz_string );
1304 vlc_object_release( _vlc_object );
1305 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1306 free( value.psz_string );
1311 - (const char *)name
1316 - (vlc_value_t)value
1321 - (vlc_object_t *)vlcObject
1323 return vlc_object_hold( _vlc_object );