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"
43 @implementation VLCMainMenu
44 static VLCMainMenu *_o_sharedInstance = nil;
46 + (VLCMainMenu *)sharedInstance
48 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
52 #pragma mark Initialization
56 if( _o_sharedInstance)
59 return _o_sharedInstance;
63 _o_sharedInstance = [super init];
66 return _o_sharedInstance;
71 [[NSNotificationCenter defaultCenter] removeObserver: self];
73 if (b_nib_about_loaded)
76 if (b_nib_videoeffects_loaded)
77 [o_videoeffects release];
79 if (b_nib_audioeffects_loaded)
80 [o_audioeffects release];
82 if (b_nib_tracksynchro_loaded)
83 [o_trackSynchronization release];
90 [[NSNotificationCenter defaultCenter] addObserver: self
91 selector: @selector(applicationWillFinishLaunching:)
92 name: NSApplicationWillFinishLaunchingNotification
96 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
101 playlist_t *p_playlist;
103 id o_vlcmain = [VLCMain sharedInstance];
106 /* Check if we already did this once. Opening the other nibs calls it too,
107 because VLCMain is the owner */
108 if( b_mainMenu_setup ) return;
112 key = config_GetPsz( p_intf, "key-quit" );
113 o_key = [NSString stringWithFormat:@"%s", key];
114 [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
115 [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
118 key = config_GetPsz( p_intf, "key-play-pause" );
119 o_key = [NSString stringWithFormat:@"%s", key];
120 [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
121 [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
124 key = config_GetPsz( p_intf, "key-stop" );
125 o_key = [NSString stringWithFormat:@"%s", key];
126 [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
127 [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
130 key = config_GetPsz( p_intf, "key-prev" );
131 o_key = [NSString stringWithFormat:@"%s", key];
132 [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
133 [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
136 key = config_GetPsz( p_intf, "key-next" );
137 o_key = [NSString stringWithFormat:@"%s", key];
138 [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
139 [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
142 key = config_GetPsz( p_intf, "key-jump+short" );
143 o_key = [NSString stringWithFormat:@"%s", key];
144 [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
145 [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
148 key = config_GetPsz( p_intf, "key-jump-short" );
149 o_key = [NSString stringWithFormat:@"%s", key];
150 [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
151 [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
154 key = config_GetPsz( p_intf, "key-vol-up" );
155 o_key = [NSString stringWithFormat:@"%s", key];
156 [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
157 [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
160 key = config_GetPsz( p_intf, "key-vol-down" );
161 o_key = [NSString stringWithFormat:@"%s", key];
162 [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
163 [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
166 key = config_GetPsz( p_intf, "key-vol-mute" );
167 o_key = [NSString stringWithFormat:@"%s", key];
168 [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
169 [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
172 key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
173 o_key = [NSString stringWithFormat:@"%s", key];
174 [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
175 [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
178 key = config_GetPsz( p_intf, "key-snapshot" );
179 o_key = [NSString stringWithFormat:@"%s", key];
180 [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
181 [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
184 key = config_GetPsz( p_intf, "key-random" );
185 o_key = [NSString stringWithFormat:@"%s", key];
186 [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
187 [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
190 key = config_GetPsz( p_intf, "key-zoom-half" );
191 o_key = [NSString stringWithFormat:@"%s", key];
192 [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
193 [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
196 key = config_GetPsz( p_intf, "key-zoom-original" );
197 o_key = [NSString stringWithFormat:@"%s", key];
198 [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
199 [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
202 key = config_GetPsz( p_intf, "key-zoom-double" );
203 o_key = [NSString stringWithFormat:@"%s", key];
204 [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
205 [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
208 [self setSubmenusEnabled: FALSE];
210 [[NSNotificationCenter defaultCenter] addObserver: self
211 selector: @selector(refreshVoutDeviceMenu:)
212 name: NSApplicationDidChangeScreenParametersNotification
216 b_mainMenu_setup = YES;
218 [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
219 var: "intf-add" selector: @selector(toggleVar:)];
225 [o_mi_about setTitle: [_NS("About VLC media player") \
226 stringByAppendingString: @"..."]];
227 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
228 [o_mi_prefs setTitle: _NS("Preferences...")];
229 [o_mi_add_intf setTitle: _NS("Add Interface")];
230 [o_mu_add_intf setTitle: _NS("Add Interface")];
231 [o_mi_services setTitle: _NS("Services")];
232 [o_mi_hide setTitle: _NS("Hide VLC")];
233 [o_mi_hide_others setTitle: _NS("Hide Others")];
234 [o_mi_show_all setTitle: _NS("Show All")];
235 [o_mi_quit setTitle: _NS("Quit VLC")];
237 [o_mu_file setTitle: _ANS("1:File")];
238 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
239 [o_mi_open_file setTitle: _NS("Open File...")];
240 [o_mi_open_disc setTitle: _NS("Open Disc...")];
241 [o_mi_open_net setTitle: _NS("Open Network...")];
242 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
243 [o_mi_open_recent setTitle: _NS("Open Recent")];
244 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
245 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
247 [o_mu_edit setTitle: _NS("Edit")];
248 [o_mi_cut setTitle: _NS("Cut")];
249 [o_mi_copy setTitle: _NS("Copy")];
250 [o_mi_paste setTitle: _NS("Paste")];
251 [o_mi_clear setTitle: _NS("Clear")];
252 [o_mi_select_all setTitle: _NS("Select All")];
254 [o_mu_controls setTitle: _NS("Playback")];
255 [o_mi_play setTitle: _NS("Play")];
256 [o_mi_stop setTitle: _NS("Stop")];
257 [o_mi_rate setView: o_mi_rate_view];
258 [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
259 [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
260 [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
261 [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
262 [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
263 [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
264 [o_mi_previous setTitle: _NS("Previous")];
265 [o_mi_next setTitle: _NS("Next")];
266 [o_mi_random setTitle: _NS("Random")];
267 [o_mi_repeat setTitle: _NS("Repeat One")];
268 [o_mi_loop setTitle: _NS("Repeat All")];
269 [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
270 [o_mi_fwd setTitle: _NS("Step Forward")];
271 [o_mi_bwd setTitle: _NS("Step Backward")];
273 [o_mi_program setTitle: _NS("Program")];
274 [o_mu_program setTitle: _NS("Program")];
275 [o_mi_title setTitle: _NS("Title")];
276 [o_mu_title setTitle: _NS("Title")];
277 [o_mi_chapter setTitle: _NS("Chapter")];
278 [o_mu_chapter setTitle: _NS("Chapter")];
280 [o_mu_audio setTitle: _NS("Audio")];
281 [o_mi_vol_up setTitle: _NS("Increase Volume")];
282 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
283 [o_mi_mute setTitle: _NS("Mute")];
284 [o_mi_audiotrack setTitle: _NS("Audio Track")];
285 [o_mu_audiotrack setTitle: _NS("Audio Track")];
286 [o_mi_channels setTitle: _NS("Audio Channels")];
287 [o_mu_channels setTitle: _NS("Audio Channels")];
288 [o_mi_device setTitle: _NS("Audio Device")];
289 [o_mu_device setTitle: _NS("Audio Device")];
290 [o_mi_visual setTitle: _NS("Visualizations")];
291 [o_mu_visual setTitle: _NS("Visualizations")];
293 [o_mu_video setTitle: _NS("Video")];
294 [o_mi_half_window setTitle: _NS("Half Size")];
295 [o_mi_normal_window setTitle: _NS("Normal Size")];
296 [o_mi_double_window setTitle: _NS("Double Size")];
297 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
298 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
299 [o_mi_floatontop setTitle: _NS("Float on Top")];
300 [o_mi_snapshot setTitle: _NS("Snapshot")];
301 [o_mi_videotrack setTitle: _NS("Video Track")];
302 [o_mu_videotrack setTitle: _NS("Video Track")];
303 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
304 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
305 [o_mi_crop setTitle: _NS("Crop")];
306 [o_mu_crop setTitle: _NS("Crop")];
307 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
308 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
309 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
310 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
311 [o_mi_addSub setTitle: _NS("Open File...")];
312 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
313 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
314 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
315 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
316 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
317 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
318 [o_mi_teletext setTitle: _NS("Teletext")];
319 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
320 [o_mi_teletext_index setTitle: _NS("Index")];
321 [o_mi_teletext_red setTitle: _NS("Red")];
322 [o_mi_teletext_green setTitle: _NS("Green")];
323 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
324 [o_mi_teletext_blue setTitle: _NS("Blue")];
326 [o_mu_window setTitle: _NS("Window")];
327 [o_mi_minimize setTitle: _NS("Minimize Window")];
328 [o_mi_close_window setTitle: _NS("Close Window")];
329 [o_mi_player setTitle: _NS("Player...")];
330 [o_mi_controller setTitle: _NS("Controller...")];
331 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
332 [o_mi_videoeffects setTitle: _NS("Video Filters...")];
333 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
334 [o_mi_playlist setTitle: _NS("Playlist...")];
335 [o_mi_info setTitle: _NS("Media Information...")];
336 [o_mi_messages setTitle: _NS("Messages...")];
337 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
339 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
341 [o_mu_help setTitle: _NS("Help")];
342 [o_mi_help setTitle: _NS("VLC media player Help...")];
343 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
344 [o_mi_license setTitle: _NS("License")];
345 [o_mi_documentation setTitle: _NS("Online Documentation...")];
346 [o_mi_website setTitle: _NS("VideoLAN Website...")];
347 [o_mi_donation setTitle: _NS("Make a donation...")];
348 [o_mi_forum setTitle: _NS("Online Forum...")];
351 [o_dmi_play setTitle: _NS("Play")];
352 [o_dmi_stop setTitle: _NS("Stop")];
353 [o_dmi_next setTitle: _NS("Next")];
354 [o_dmi_previous setTitle: _NS("Previous")];
355 [o_dmi_mute setTitle: _NS("Mute")];
358 [o_vmi_play setTitle: _NS("Play")];
359 [o_vmi_stop setTitle: _NS("Stop")];
360 [o_vmi_prev setTitle: _NS("Previous")];
361 [o_vmi_next setTitle: _NS("Next")];
362 [o_vmi_volup setTitle: _NS("Volume Up")];
363 [o_vmi_voldown setTitle: _NS("Volume Down")];
364 [o_vmi_mute setTitle: _NS("Mute")];
365 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
366 [o_vmi_snapshot setTitle: _NS("Snapshot")];
370 #pragma mark Termination
372 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
374 if( !p_intf ) return;
376 NSArray *menuitems_array = [the_menu itemArray];
377 for( int i=0; i<[menuitems_array count]; i++ )
379 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
380 if( [one_item hasSubmenu] )
381 [self releaseRepresentedObjects: [one_item submenu]];
383 [one_item setRepresentedObject:NULL];
388 #pragma mark Interface update
392 playlist_t * p_playlist = pl_Get( p_intf );
393 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
394 if( p_input != NULL )
396 [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
397 var: "program" selector: @selector(toggleVar:)];
399 [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
400 var: "title" selector: @selector(toggleVar:)];
402 [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
403 var: "chapter" selector: @selector(toggleVar:)];
405 [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
406 var: "audio-es" selector: @selector(toggleVar:)];
408 [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
409 var: "video-es" selector: @selector(toggleVar:)];
411 [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
412 var: "spu-es" selector: @selector(toggleVar:)];
414 /* special case for "Open File" inside the subtitles menu item */
415 if( [o_mi_videotrack isEnabled] == YES )
416 [o_mi_subtitle setEnabled: YES];
418 audio_output_t * p_aout = input_GetAout( p_input );
421 [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
422 var: "audio-channels" selector: @selector(toggleVar:)];
424 [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
425 var: "audio-device" selector: @selector(toggleVar:)];
427 [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
428 var: "visual" selector: @selector(toggleVar:)];
429 vlc_object_release( (vlc_object_t *)p_aout );
432 vout_thread_t * p_vout = input_GetVout( p_input );
436 vlc_object_t * p_dec_obj;
438 [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
439 var: "aspect-ratio" selector: @selector(toggleVar:)];
441 [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
442 var: "crop" selector: @selector(toggleVar:)];
444 [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
445 var: "video-device" selector: @selector(toggleVar:)];
447 [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
448 var: "deinterlace" selector: @selector(toggleVar:)];
450 [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
451 var: "deinterlace-mode" selector: @selector(toggleVar:)];
454 [self setupVarMenuItem: o_mi_ffmpeg_pp target:
455 (vlc_object_t *)p_vout var:"postprocess" selector:
456 @selector(toggleVar:)];
458 vlc_object_release( (vlc_object_t *)p_vout );
460 vlc_object_release( p_input );
464 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
467 vout_thread_t * p_vout = getVout();
471 /* clean the menu before adding new entries */
472 if( [o_mi_screen hasSubmenu] )
474 y = [[o_mi_screen submenu] numberOfItems] - 1;
475 msg_Dbg( VLCIntf, "%i items in submenu", y );
478 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
479 [[o_mi_screen submenu] removeItemAtIndex: x];
484 [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
485 var: "video-device" selector: @selector(toggleVar:)];
486 vlc_object_release( (vlc_object_t *)p_vout );
489 - (void)setSubmenusEnabled:(BOOL)b_enabled
491 [o_mi_program setEnabled: b_enabled];
492 [o_mi_title setEnabled: b_enabled];
493 [o_mi_chapter setEnabled: b_enabled];
494 [o_mi_audiotrack setEnabled: b_enabled];
495 [o_mi_visual setEnabled: b_enabled];
496 [o_mi_videotrack setEnabled: b_enabled];
497 [o_mi_subtitle setEnabled: b_enabled];
498 [o_mi_channels setEnabled: b_enabled];
499 [o_mi_deinterlace setEnabled: b_enabled];
500 [o_mi_deinterlace_mode setEnabled: b_enabled];
501 [o_mi_ffmpeg_pp setEnabled: b_enabled];
502 [o_mi_device setEnabled: b_enabled];
503 [o_mi_screen setEnabled: b_enabled];
504 [o_mi_aspect_ratio setEnabled: b_enabled];
505 [o_mi_crop setEnabled: b_enabled];
506 [o_mi_teletext setEnabled: b_enabled];
509 - (void)setRateControlsEnabled:(BOOL)b_enabled
511 [o_mi_rate_sld setEnabled: b_enabled];
512 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
513 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
516 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
518 [o_mi_rate_lbl setHidden: NO];
519 [o_mi_rate_lbl_gray setHidden: YES];
523 [o_mi_rate_lbl setHidden: YES];
524 [o_mi_rate_lbl_gray setHidden: NO];
529 #pragma mark Recent Items
530 - (void)openRecentItem:(id)item
532 [[VLCMain sharedInstance] application: nil openFile: [item title]];
535 - (IBAction)clearRecentItems:(id)sender
537 [[NSDocumentController sharedDocumentController]
538 clearRecentDocuments: nil];
542 #pragma mark Playback
543 - (IBAction)setPlaybackRate:(id)sender
545 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
546 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
549 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
552 - (void)updatePlaybackRate
554 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
557 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
558 [o_mi_rate_sld setIntValue: i];
564 - (IBAction)intfOpenFile:(id)sender
566 [[[VLCMain sharedInstance] open] openFile];
569 - (IBAction)intfOpenFileGeneric:(id)sender
571 [[[VLCMain sharedInstance] open] openFileGeneric];
574 - (IBAction)intfOpenDisc:(id)sender
576 [[[VLCMain sharedInstance] open] openDisc];
579 - (IBAction)intfOpenNet:(id)sender
581 [[[VLCMain sharedInstance] open] openNet];
584 - (IBAction)intfOpenCapture:(id)sender
586 [[[VLCMain sharedInstance] open] openCapture];
589 - (IBAction)showWizard:(id)sender
591 [[[VLCMain sharedInstance] wizard] resetWizard];
592 [[[VLCMain sharedInstance] wizard] showWizard];
595 - (IBAction)showVideoEffects:(id)sender
597 if( o_videoeffects == nil )
598 o_videoeffects = [[VLCVideoEffects alloc] init];
600 if( !b_nib_videoeffects_loaded )
601 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
603 [o_videoeffects toggleWindow:sender];
606 - (IBAction)showTrackSynchronization:(id)sender
608 if (!o_trackSynchronization)
609 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
611 if (!b_nib_tracksynchro_loaded)
612 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
614 [o_trackSynchronization toggleWindow:sender];
617 - (IBAction)showAudioEffects:(id)sender
620 o_audioeffects = [[VLCAudioEffects alloc] init];
622 if (!b_nib_audioeffects_loaded)
623 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
625 [o_audioeffects toggleWindow:sender];
628 - (IBAction)showBookmarks:(id)sender
630 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
633 - (IBAction)viewPreferences:(id)sender
635 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
639 #pragma mark Help and Docs
644 o_about = [[VLAboutBox alloc] init];
646 if( !b_nib_about_loaded )
647 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
650 - (IBAction)viewAbout:(id)sender
656 - (IBAction)showLicense:(id)sender
659 [o_about showGPL: sender];
662 - (IBAction)viewHelp:(id)sender
668 - (IBAction)openReadMe:(id)sender
670 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
672 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
675 - (IBAction)openDocumentation:(id)sender
677 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
679 [[NSWorkspace sharedWorkspace] openURL: o_url];
682 - (IBAction)openWebsite:(id)sender
684 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
686 [[NSWorkspace sharedWorkspace] openURL: o_url];
689 - (IBAction)openForum:(id)sender
691 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
693 [[NSWorkspace sharedWorkspace] openURL: o_url];
696 - (IBAction)openDonate:(id)sender
698 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
700 [[NSWorkspace sharedWorkspace] openURL: o_url];
704 #pragma mark Errors, warnings and messages
706 - (IBAction)viewErrorsAndWarnings:(id)sender
708 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
711 - (IBAction)showInformationPanel:(id)sender
713 [[[VLCMain sharedInstance] info] initPanel];
717 #pragma mark convinience stuff for other objects
720 [o_mi_play setTitle: _NS("Play")];
721 [o_dmi_play setTitle: _NS("Play")];
722 [o_vmi_play setTitle: _NS("Play")];
727 [o_mi_play setTitle: _NS("Pause")];
728 [o_dmi_play setTitle: _NS("Pause")];
729 [o_vmi_play setTitle: _NS("Pause")];
734 [o_mi_repeat setState: NSOnState];
735 [o_mi_loop setState: NSOffState];
740 [o_mi_repeat setState: NSOffState];
741 [o_mi_loop setState: NSOnState];
746 [o_mi_repeat setState: NSOffState];
747 [o_mi_loop setState: NSOffState];
753 playlist_t *p_playlist = pl_Get( VLCIntf );
754 b_value = var_GetBool( p_playlist, "random" );
755 [o_mi_random setState: b_value];
759 #pragma mark Dynamic menu creation and validation
761 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
762 target:(vlc_object_t *)p_object
763 var:(const char *)psz_variable
764 selector:(SEL)pf_callback
766 vlc_value_t val, text;
767 int i_type = var_Type( p_object, psz_variable );
769 switch( i_type & VLC_VAR_TYPE )
773 case VLC_VAR_VARIABLE:
775 case VLC_VAR_INTEGER:
778 /* Variable doesn't exist or isn't handled */
782 /* Make sure we want to display the variable */
783 if( i_type & VLC_VAR_HASCHOICE )
785 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
786 if( val.i_int == 0 ) return;
787 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
791 /* Get the descriptive name of the variable */
792 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
793 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
794 text.psz_string : psz_variable ]];
796 if( i_type & VLC_VAR_HASCHOICE )
798 NSMenu *o_menu = [o_mi submenu];
800 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
801 var:psz_variable selector:pf_callback];
803 free( text.psz_string );
806 if( var_Get( p_object, psz_variable, &val ) < 0 )
811 VLCAutoGeneratedMenuContent *o_data;
812 switch( i_type & VLC_VAR_TYPE )
815 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
816 andValue: val ofType: i_type];
817 [o_mi setRepresentedObject: [o_data autorelease]];
821 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
822 andValue: val ofType: i_type];
823 [o_mi setRepresentedObject: [o_data autorelease]];
824 if( !( i_type & VLC_VAR_ISCOMMAND ) )
825 [o_mi setState: val.b_bool ? TRUE : FALSE ];
832 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
833 free( text.psz_string );
837 - (void)setupVarMenu:(NSMenu *)o_menu
838 forMenuItem: (NSMenuItem *)o_parent
839 target:(vlc_object_t *)p_object
840 var:(const char *)psz_variable
841 selector:(SEL)pf_callback
843 vlc_value_t val, val_list, text_list;
844 int i_type, i, i_nb_items;
846 /* remove previous items */
847 i_nb_items = [o_menu numberOfItems];
848 for( i = 0; i < i_nb_items; i++ )
849 [o_menu removeItemAtIndex: 0];
851 /* Check the type of the object variable */
852 i_type = var_Type( p_object, psz_variable );
854 /* Make sure we want to display the variable */
855 if( i_type & VLC_VAR_HASCHOICE )
857 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
858 if( val.i_int == 0 ) return;
859 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
865 switch( i_type & VLC_VAR_TYPE )
869 case VLC_VAR_VARIABLE:
871 case VLC_VAR_INTEGER:
874 /* Variable doesn't exist or isn't handled */
878 if( var_Get( p_object, psz_variable, &val ) < 0 )
883 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
884 &val_list, &text_list ) < 0 )
886 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
890 /* make (un)sensitive */
891 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
894 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
896 NSMenuItem *o_lmi_tmp2;
897 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
898 [o_lmi_tmp2 setTarget: self];
899 [o_lmi_tmp2 setEnabled: YES];
900 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
901 [o_parent setEnabled: YES];
902 [o_menu addItem: [NSMenuItem separatorItem]];
905 /* special case for the subtitles items */
906 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
908 NSMenuItem * o_lmi_tmp;
909 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
910 [o_lmi_tmp setTarget: self];
911 [o_lmi_tmp setEnabled: YES];
912 [o_parent setEnabled: YES];
913 [o_menu addItem: [NSMenuItem separatorItem]];
916 for( i = 0; i < val_list.p_list->i_count; i++ )
919 NSString *o_title = @"";
920 VLCAutoGeneratedMenuContent *o_data;
922 switch( i_type & VLC_VAR_TYPE )
926 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
927 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
929 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
930 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
931 andValue: val_list.p_list->p_values[i] ofType: i_type];
932 [o_lmi setRepresentedObject: [o_data autorelease]];
933 [o_lmi setTarget: self];
935 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
936 [o_lmi setState: TRUE ];
940 case VLC_VAR_INTEGER:
942 o_title = text_list.p_list->p_values[i].psz_string ?
943 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
944 [NSString stringWithFormat: @"%"PRId64,
945 val_list.p_list->p_values[i].i_int];
947 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
948 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
949 andValue: val_list.p_list->p_values[i] ofType: i_type];
950 [o_lmi setRepresentedObject: [o_data autorelease]];
951 [o_lmi setTarget: self];
953 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
954 [o_lmi setState: TRUE ];
962 /* special case for the subtitles sub-menu
963 * In case that we don't have any subs, we don't want a separator item at the end */
964 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
966 if( [o_menu numberOfItems] == 2 )
967 [o_menu removeItemAtIndex: 1];
970 /* clean up everything */
971 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
972 var_FreeList( &val_list, &text_list );
975 - (IBAction)toggleVar:(id)sender
977 NSMenuItem *o_mi = (NSMenuItem *)sender;
978 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
979 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
980 toTarget: self withObject: o_data];
985 - (int)toggleVarThread: (id)data
987 vlc_object_t *p_object;
988 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
990 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
991 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
993 p_object = [menuContent vlcObject];
995 if( p_object != NULL )
997 var_Set( p_object, [menuContent name], [menuContent value] );
998 vlc_object_release( p_object );
1003 return VLC_EGENERIC;
1008 @implementation VLCMainMenu (NSMenuValidation)
1010 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1012 NSString *o_title = [o_mi title];
1013 BOOL bEnabled = TRUE;
1015 playlist_t * p_playlist = pl_Get( p_intf );
1016 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1018 /* Recent Items Menu */
1019 if( [o_title isEqualToString: _NS("Clear Menu")] )
1021 NSMenu * o_menu = [o_mi_open_recent submenu];
1022 int i_nb_items = [o_menu numberOfItems];
1023 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1024 recentDocumentURLs];
1025 UInt32 i_nb_docs = [o_docs count];
1027 if( i_nb_items > 1 )
1029 while( --i_nb_items )
1031 [o_menu removeItemAtIndex: 0];
1040 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1046 o_url = [o_docs objectAtIndex: i_nb_docs];
1048 if( [o_url isFileURL] )
1049 o_doc = [o_url path];
1051 o_doc = [o_url absoluteString];
1053 [o_menu insertItemWithTitle: o_doc
1054 action: @selector(openRecentItem:)
1055 keyEquivalent: @"" atIndex: 0];
1057 if( i_nb_docs == 0 )
1066 else if( [o_title isEqualToString: _NS("Stop")] )
1068 if( p_input == NULL )
1072 [self setupMenus]; /* Make sure input menu is up to date */
1074 else if( [o_title isEqualToString: _NS("Previous")] ||
1075 [o_title isEqualToString: _NS("Next")] )
1078 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1081 else if( [o_title isEqualToString: _NS("Random")] )
1084 var_Get( p_playlist, "random", &val );
1085 i_state = val.b_bool ? NSOnState : NSOffState;
1086 [o_mi setState: i_state];
1088 else if( [o_title isEqualToString: _NS("Repeat One")] )
1091 var_Get( p_playlist, "repeat", &val );
1092 i_state = val.b_bool ? NSOnState : NSOffState;
1093 [o_mi setState: i_state];
1095 else if( [o_title isEqualToString: _NS("Repeat All")] )
1098 var_Get( p_playlist, "loop", &val );
1099 i_state = val.b_bool ? NSOnState : NSOffState;
1100 [o_mi setState: i_state];
1102 else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1105 var_Get( p_playlist, "play-and-exit", &val );
1106 i_state = val.b_bool ? NSOnState : NSOffState;
1107 [o_mi setState: i_state];
1109 else if( [o_title isEqualToString: _NS("Step Forward")] ||
1110 [o_title isEqualToString: _NS("Step Backward")] ||
1111 [o_title isEqualToString: _NS("Jump To Time")])
1113 if( p_input != NULL )
1115 var_Get( p_input, "can-seek", &val);
1116 bEnabled = val.b_bool;
1118 else bEnabled = FALSE;
1120 else if( [o_title isEqualToString: _NS("Mute")] )
1122 //FIXME [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1123 [self setupMenus]; /* Make sure audio menu is up to date */
1125 else if( [o_title isEqualToString: _NS("Half Size")] ||
1126 [o_title isEqualToString: _NS("Normal Size")] ||
1127 [o_title isEqualToString: _NS("Double Size")] ||
1128 [o_title isEqualToString: _NS("Fit to Screen")] ||
1129 [o_title isEqualToString: _NS("Snapshot")] ||
1130 [o_title isEqualToString: _NS("Fullscreen")] ||
1131 [o_title isEqualToString: _NS("Float on Top")] )
1134 NSArray *o_windows = [NSApp orderedWindows];
1135 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1138 if( p_input != NULL )
1140 vout_thread_t *p_vout = input_GetVout( p_input );
1141 if( p_vout != NULL )
1143 if( [o_title isEqualToString: _NS("Float on Top")] )
1145 var_Get( p_vout, "video-on-top", &val );
1146 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1149 while( (o_window = [o_enumerator nextObject]))
1151 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1152 [[[VLCMain sharedInstance] embeddedList]
1153 windowContainsEmbedded: o_window])
1160 vlc_object_release( (vlc_object_t *)p_vout );
1163 if( [o_title isEqualToString: _NS("Fullscreen")] )
1165 var_Get( p_playlist, "fullscreen", &val );
1166 [o_mi setState: val.b_bool];
1169 [self setupMenus]; /* Make sure video menu is up to date */
1172 /* Special case for telx menu */
1173 if( [o_title isEqualToString: _NS("Normal Size")] )
1175 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1176 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1178 [[item submenu] setAutoenablesItems:NO];
1179 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1181 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1185 if( p_input ) vlc_object_release( p_input );
1193 /*****************************************************************************
1194 * VLCAutoGeneratedMenuContent implementation
1195 *****************************************************************************
1196 * Object connected to a playlistitem which remembers the data belonging to
1197 * the variable of the autogenerated menu
1198 *****************************************************************************/
1199 @implementation VLCAutoGeneratedMenuContent
1201 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1202 andValue:(vlc_value_t)val ofType:(int)type
1204 self = [super init];
1208 _vlc_object = vlc_object_hold( object );
1209 psz_name = strdup( name );
1212 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1213 value.psz_string = strdup( val.psz_string );
1221 vlc_object_release( _vlc_object );
1222 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1223 free( value.psz_string );
1228 - (const char *)name
1233 - (vlc_value_t)value
1238 - (vlc_object_t *)vlcObject
1240 return vlc_object_hold( _vlc_object );