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_add_intf setTitle: _NS("Add Interface")];
240 [o_mu_add_intf setTitle: _NS("Add Interface")];
241 [o_mi_services setTitle: _NS("Services")];
242 [o_mi_hide setTitle: _NS("Hide VLC")];
243 [o_mi_hide_others setTitle: _NS("Hide Others")];
244 [o_mi_show_all setTitle: _NS("Show All")];
245 [o_mi_quit setTitle: _NS("Quit VLC")];
247 [o_mu_file setTitle: _ANS("1:File")];
248 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
249 [o_mi_open_file setTitle: _NS("Open File...")];
250 [o_mi_open_disc setTitle: _NS("Open Disc...")];
251 [o_mi_open_net setTitle: _NS("Open Network...")];
252 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
253 [o_mi_open_recent setTitle: _NS("Open Recent")];
254 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
256 [o_mu_edit setTitle: _NS("Edit")];
257 [o_mi_cut setTitle: _NS("Cut")];
258 [o_mi_copy setTitle: _NS("Copy")];
259 [o_mi_paste setTitle: _NS("Paste")];
260 [o_mi_clear setTitle: _NS("Clear")];
261 [o_mi_select_all setTitle: _NS("Select All")];
263 [o_mu_extensions setTitle: _NS("Extensions")];
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];
549 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
551 [o_mi_rate_lbl setHidden: NO];
552 [o_mi_rate_lbl_gray setHidden: YES];
556 [o_mi_rate_lbl setHidden: YES];
557 [o_mi_rate_lbl_gray setHidden: NO];
563 #pragma mark Extensions
565 - (void)setupExtensionsMenu
567 /* Load extensions if needed */
568 // TODO: Implement preference for autoloading extensions on mac
570 // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
571 // && ![o_extMgr isLoaded] )
576 if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
578 [o_extMgr loadExtensions];
581 /* Let the ExtensionsManager itself build the menu */
582 [o_extMgr buildMenu:o_mu_extensions];
586 #pragma mark Playback
587 - (IBAction)toggleRecord:(id)sender
589 [[VLCCoreInteraction sharedInstance] toggleRecord];
592 - (void)updateRecordState:(BOOL)b_value
594 [o_mi_record setState:b_value];
597 - (IBAction)setPlaybackRate:(id)sender
599 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
600 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
603 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
606 - (void)updatePlaybackRate
608 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
611 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
612 [o_mi_rate_sld setIntValue: i];
617 - (IBAction)toggleFullscreen:(id)sender
619 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
622 - (IBAction)resizeVideoWindow:(id)sender
624 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
627 vout_thread_t *p_vout = getVout();
630 if (sender == o_mi_half_window)
631 var_SetFloat( p_vout, "zoom", 0.5 );
632 else if (sender == o_mi_normal_window)
633 var_SetFloat( p_vout, "zoom", 1.0 );
634 else if (sender == o_mi_double_window)
635 var_SetFloat( p_vout, "zoom", 2.0 );
638 var_ToggleBool( p_vout, "autoscale" );
640 vlc_object_release( p_vout );
642 vlc_object_release( p_input );
646 - (IBAction)floatOnTop:(id)sender
648 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
651 vout_thread_t *p_vout = getVout();
654 var_ToggleBool( p_vout, "video-on-top" );
655 vlc_object_release( p_vout );
657 vlc_object_release( p_input );
661 - (IBAction)createVideoSnapshot:(id)sender
663 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
666 vout_thread_t *p_vout = getVout();
669 var_TriggerCallback( p_vout, "video-snapshot" );
670 vlc_object_release( p_vout );
672 vlc_object_release( p_input );
676 - (IBAction)toggleFullscreenDevice:(id)sender
678 config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
679 [self refreshVoutDeviceMenu: nil];
690 - (IBAction)intfOpenFile:(id)sender
692 [[[VLCMain sharedInstance] open] openFile];
695 - (IBAction)intfOpenFileGeneric:(id)sender
697 [[[VLCMain sharedInstance] open] openFileGeneric];
700 - (IBAction)intfOpenDisc:(id)sender
702 [[[VLCMain sharedInstance] open] openDisc];
705 - (IBAction)intfOpenNet:(id)sender
707 [[[VLCMain sharedInstance] open] openNet];
710 - (IBAction)intfOpenCapture:(id)sender
712 [[[VLCMain sharedInstance] open] openCapture];
715 - (IBAction)showWizard:(id)sender
717 [[[VLCMain sharedInstance] wizard] resetWizard];
718 [[[VLCMain sharedInstance] wizard] showWizard];
721 - (IBAction)showVideoEffects:(id)sender
723 if( o_videoeffects == nil )
724 o_videoeffects = [[VLCVideoEffects alloc] init];
726 if( !b_nib_videoeffects_loaded )
727 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
729 [o_videoeffects toggleWindow:sender];
732 - (IBAction)showTrackSynchronization:(id)sender
734 if (!o_trackSynchronization)
735 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
737 if (!b_nib_tracksynchro_loaded)
738 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
740 [o_trackSynchronization toggleWindow:sender];
743 - (IBAction)showAudioEffects:(id)sender
746 o_audioeffects = [[VLCAudioEffects alloc] init];
748 if (!b_nib_audioeffects_loaded)
749 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
751 [o_audioeffects toggleWindow:sender];
754 - (IBAction)showBookmarks:(id)sender
756 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
759 - (IBAction)viewPreferences:(id)sender
761 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
765 #pragma mark Help and Docs
770 o_about = [[VLAboutBox alloc] init];
772 if( !b_nib_about_loaded )
773 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
776 - (IBAction)viewAbout:(id)sender
782 - (IBAction)showLicense:(id)sender
785 [o_about showGPL: sender];
788 - (IBAction)viewHelp:(id)sender
794 - (IBAction)openReadMe:(id)sender
796 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
798 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
801 - (IBAction)openDocumentation:(id)sender
803 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
805 [[NSWorkspace sharedWorkspace] openURL: o_url];
808 - (IBAction)openWebsite:(id)sender
810 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
812 [[NSWorkspace sharedWorkspace] openURL: o_url];
815 - (IBAction)openForum:(id)sender
817 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
819 [[NSWorkspace sharedWorkspace] openURL: o_url];
822 - (IBAction)openDonate:(id)sender
824 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
826 [[NSWorkspace sharedWorkspace] openURL: o_url];
830 #pragma mark Errors, warnings and messages
832 - (IBAction)viewErrorsAndWarnings:(id)sender
834 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
837 - (IBAction)showInformationPanel:(id)sender
839 [[[VLCMain sharedInstance] info] initPanel];
843 #pragma mark convinience stuff for other objects
846 [o_mi_play setTitle: _NS("Play")];
847 [o_dmi_play setTitle: _NS("Play")];
848 [o_vmi_play setTitle: _NS("Play")];
853 [o_mi_play setTitle: _NS("Pause")];
854 [o_dmi_play setTitle: _NS("Pause")];
855 [o_vmi_play setTitle: _NS("Pause")];
860 [o_mi_repeat setState: NSOnState];
861 [o_mi_loop setState: NSOffState];
866 [o_mi_repeat setState: NSOffState];
867 [o_mi_loop setState: NSOnState];
872 [o_mi_repeat setState: NSOffState];
873 [o_mi_loop setState: NSOffState];
879 playlist_t *p_playlist = pl_Get( VLCIntf );
880 b_value = var_GetBool( p_playlist, "random" );
881 [o_mi_random setState: b_value];
885 #pragma mark Dynamic menu creation and validation
887 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
888 target:(vlc_object_t *)p_object
889 var:(const char *)psz_variable
890 selector:(SEL)pf_callback
892 vlc_value_t val, text;
893 int i_type = var_Type( p_object, psz_variable );
895 switch( i_type & VLC_VAR_TYPE )
899 case VLC_VAR_VARIABLE:
901 case VLC_VAR_INTEGER:
904 /* Variable doesn't exist or isn't handled */
908 /* Make sure we want to display the variable */
909 if( i_type & VLC_VAR_HASCHOICE )
911 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
912 if( val.i_int == 0 ) return;
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: [[VLCMain sharedInstance] localizedString: text.psz_string ?
920 text.psz_string : psz_variable ]];
922 if( i_type & VLC_VAR_HASCHOICE )
924 NSMenu *o_menu = [o_mi submenu];
926 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
927 var:psz_variable selector:pf_callback];
929 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];
986 /* Check the type of the object variable */
987 i_type = var_Type( p_object, psz_variable );
989 /* Make sure we want to display the variable */
990 if( i_type & VLC_VAR_HASCHOICE )
992 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
993 if( val.i_int == 0 ) return;
994 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1000 switch( i_type & VLC_VAR_TYPE )
1004 case VLC_VAR_VARIABLE:
1005 case VLC_VAR_STRING:
1006 case VLC_VAR_INTEGER:
1009 /* Variable doesn't exist or isn't handled */
1013 if( var_Get( p_object, psz_variable, &val ) < 0 )
1018 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1019 &val_list, &text_list ) < 0 )
1021 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1025 /* make (un)sensitive */
1026 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1029 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1031 NSMenuItem *o_lmi_tmp2;
1032 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1033 [o_lmi_tmp2 setTarget: self];
1034 [o_lmi_tmp2 setEnabled: YES];
1035 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1036 [o_parent setEnabled: YES];
1037 [o_menu addItem: [NSMenuItem separatorItem]];
1040 /* special case for the subtitles items */
1041 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1043 NSMenuItem * o_lmi_tmp;
1044 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1045 [o_lmi_tmp setTarget: self];
1046 [o_lmi_tmp setEnabled: YES];
1047 [o_parent setEnabled: YES];
1048 [o_menu addItem: [NSMenuItem separatorItem]];
1051 for( i = 0; i < val_list.p_list->i_count; i++ )
1054 NSString *o_title = @"";
1055 VLCAutoGeneratedMenuContent *o_data;
1057 switch( i_type & VLC_VAR_TYPE )
1059 case VLC_VAR_STRING:
1061 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
1062 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
1064 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1065 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1066 andValue: val_list.p_list->p_values[i] ofType: i_type];
1067 [o_lmi setRepresentedObject: [o_data autorelease]];
1068 [o_lmi setTarget: self];
1070 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1071 [o_lmi setState: TRUE ];
1075 case VLC_VAR_INTEGER:
1077 o_title = text_list.p_list->p_values[i].psz_string ?
1078 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
1079 [NSString stringWithFormat: @"%"PRId64,
1080 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 p_object = [menuContent vlcObject];
1130 if( p_object != NULL )
1132 var_Set( p_object, [menuContent name], [menuContent value] );
1133 vlc_object_release( p_object );
1138 return VLC_EGENERIC;
1143 @implementation VLCMainMenu (NSMenuValidation)
1145 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1147 NSString *o_title = [o_mi title];
1148 BOOL bEnabled = TRUE;
1150 playlist_t * p_playlist = pl_Get( p_intf );
1151 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1153 if( [o_title isEqualToString: _NS("Stop")] )
1155 if( p_input == NULL )
1159 [self setupMenus]; /* Make sure input menu is up to date */
1161 else if( [o_title isEqualToString: _NS("Previous")] ||
1162 [o_title isEqualToString: _NS("Next")] )
1165 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1168 else if( [o_title isEqualToString: _NS("Random")] )
1171 var_Get( p_playlist, "random", &val );
1172 i_state = val.b_bool ? NSOnState : NSOffState;
1173 [o_mi setState: i_state];
1175 else if( [o_title isEqualToString: _NS("Repeat One")] )
1178 var_Get( p_playlist, "repeat", &val );
1179 i_state = val.b_bool ? NSOnState : NSOffState;
1180 [o_mi setState: i_state];
1182 else if( [o_title isEqualToString: _NS("Repeat All")] )
1185 var_Get( p_playlist, "loop", &val );
1186 i_state = val.b_bool ? NSOnState : NSOffState;
1187 [o_mi setState: i_state];
1189 else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1192 var_Get( p_playlist, "play-and-exit", &val );
1193 i_state = val.b_bool ? NSOnState : NSOffState;
1194 [o_mi setState: i_state];
1196 else if( [o_title isEqualToString: _NS("Step Forward")] ||
1197 [o_title isEqualToString: _NS("Step Backward")] ||
1198 [o_title isEqualToString: _NS("Jump To Time")])
1200 if( p_input != NULL )
1202 var_Get( p_input, "can-seek", &val);
1203 bEnabled = val.b_bool;
1205 else bEnabled = FALSE;
1207 else if( [o_title isEqualToString: _NS("Mute")] )
1209 [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1210 [self setupMenus]; /* Make sure audio menu is up to date */
1212 else if( [o_title isEqualToString: _NS("Half Size")] ||
1213 [o_title isEqualToString: _NS("Normal Size")] ||
1214 [o_title isEqualToString: _NS("Double Size")] ||
1215 [o_title isEqualToString: _NS("Fit to Screen")] ||
1216 [o_title isEqualToString: _NS("Snapshot")] ||
1217 [o_title isEqualToString: _NS("Fullscreen")] ||
1218 [o_title isEqualToString: _NS("Float on Top")] )
1222 if( p_input != NULL )
1224 vout_thread_t *p_vout = input_GetVout( p_input );
1225 if( p_vout != NULL )
1227 if( [o_title isEqualToString: _NS("Float on Top")] )
1229 [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1234 vlc_object_release( (vlc_object_t *)p_vout );
1237 if( [o_title isEqualToString: _NS("Fullscreen")] )
1239 [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1242 [self setupMenus]; /* Make sure video menu is up to date */
1245 /* Special case for telx menu */
1246 if( [o_title isEqualToString: _NS("Normal Size")] )
1248 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1249 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1251 [[item submenu] setAutoenablesItems:NO];
1252 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1254 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1258 if( p_input ) vlc_object_release( p_input );
1266 /*****************************************************************************
1267 * VLCAutoGeneratedMenuContent implementation
1268 *****************************************************************************
1269 * Object connected to a playlistitem which remembers the data belonging to
1270 * the variable of the autogenerated menu
1271 *****************************************************************************/
1272 @implementation VLCAutoGeneratedMenuContent
1274 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1275 andValue:(vlc_value_t)val ofType:(int)type
1277 self = [super init];
1281 _vlc_object = vlc_object_hold( object );
1282 psz_name = strdup( name );
1285 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1286 value.psz_string = strdup( val.psz_string );
1294 vlc_object_release( _vlc_object );
1295 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1296 free( value.psz_string );
1301 - (const char *)name
1306 - (vlc_value_t)value
1311 - (vlc_object_t *)vlcObject
1313 return vlc_object_hold( _vlc_object );