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("Main Window...")];
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 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
512 [o_mi_rate_sld setEnabled: b_enabled];
513 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
514 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
517 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
519 [o_mi_rate_lbl setHidden: NO];
520 [o_mi_rate_lbl_gray setHidden: YES];
524 [o_mi_rate_lbl setHidden: YES];
525 [o_mi_rate_lbl_gray setHidden: NO];
531 #pragma mark Recent Items
532 - (void)openRecentItem:(id)item
534 [[VLCMain sharedInstance] application: nil openFile: [item title]];
537 - (IBAction)clearRecentItems:(id)sender
539 [[NSDocumentController sharedDocumentController]
540 clearRecentDocuments: nil];
544 #pragma mark Playback
545 - (IBAction)setPlaybackRate:(id)sender
547 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
548 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
551 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
554 - (void)updatePlaybackRate
556 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
559 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
560 [o_mi_rate_sld setIntValue: i];
566 - (IBAction)intfOpenFile:(id)sender
568 [[[VLCMain sharedInstance] open] openFile];
571 - (IBAction)intfOpenFileGeneric:(id)sender
573 [[[VLCMain sharedInstance] open] openFileGeneric];
576 - (IBAction)intfOpenDisc:(id)sender
578 [[[VLCMain sharedInstance] open] openDisc];
581 - (IBAction)intfOpenNet:(id)sender
583 [[[VLCMain sharedInstance] open] openNet];
586 - (IBAction)intfOpenCapture:(id)sender
588 [[[VLCMain sharedInstance] open] openCapture];
591 - (IBAction)showWizard:(id)sender
593 [[[VLCMain sharedInstance] wizard] resetWizard];
594 [[[VLCMain sharedInstance] wizard] showWizard];
597 - (IBAction)showVideoEffects:(id)sender
599 if( o_videoeffects == nil )
600 o_videoeffects = [[VLCVideoEffects alloc] init];
602 if( !b_nib_videoeffects_loaded )
603 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
605 [o_videoeffects toggleWindow:sender];
608 - (IBAction)showTrackSynchronization:(id)sender
610 if (!o_trackSynchronization)
611 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
613 if (!b_nib_tracksynchro_loaded)
614 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
616 [o_trackSynchronization toggleWindow:sender];
619 - (IBAction)showAudioEffects:(id)sender
622 o_audioeffects = [[VLCAudioEffects alloc] init];
624 if (!b_nib_audioeffects_loaded)
625 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
627 [o_audioeffects toggleWindow:sender];
630 - (IBAction)showBookmarks:(id)sender
632 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
635 - (IBAction)viewPreferences:(id)sender
637 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
641 #pragma mark Help and Docs
646 o_about = [[VLAboutBox alloc] init];
648 if( !b_nib_about_loaded )
649 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
652 - (IBAction)viewAbout:(id)sender
658 - (IBAction)showLicense:(id)sender
661 [o_about showGPL: sender];
664 - (IBAction)viewHelp:(id)sender
670 - (IBAction)openReadMe:(id)sender
672 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
674 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
677 - (IBAction)openDocumentation:(id)sender
679 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
681 [[NSWorkspace sharedWorkspace] openURL: o_url];
684 - (IBAction)openWebsite:(id)sender
686 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
688 [[NSWorkspace sharedWorkspace] openURL: o_url];
691 - (IBAction)openForum:(id)sender
693 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
695 [[NSWorkspace sharedWorkspace] openURL: o_url];
698 - (IBAction)openDonate:(id)sender
700 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
702 [[NSWorkspace sharedWorkspace] openURL: o_url];
706 #pragma mark Errors, warnings and messages
708 - (IBAction)viewErrorsAndWarnings:(id)sender
710 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
713 - (IBAction)showInformationPanel:(id)sender
715 [[[VLCMain sharedInstance] info] initPanel];
719 #pragma mark convinience stuff for other objects
722 [o_mi_play setTitle: _NS("Play")];
723 [o_dmi_play setTitle: _NS("Play")];
724 [o_vmi_play setTitle: _NS("Play")];
729 [o_mi_play setTitle: _NS("Pause")];
730 [o_dmi_play setTitle: _NS("Pause")];
731 [o_vmi_play setTitle: _NS("Pause")];
736 [o_mi_repeat setState: NSOnState];
737 [o_mi_loop setState: NSOffState];
742 [o_mi_repeat setState: NSOffState];
743 [o_mi_loop setState: NSOnState];
748 [o_mi_repeat setState: NSOffState];
749 [o_mi_loop setState: NSOffState];
755 playlist_t *p_playlist = pl_Get( VLCIntf );
756 b_value = var_GetBool( p_playlist, "random" );
757 [o_mi_random setState: b_value];
761 #pragma mark Dynamic menu creation and validation
763 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
764 target:(vlc_object_t *)p_object
765 var:(const char *)psz_variable
766 selector:(SEL)pf_callback
768 vlc_value_t val, text;
769 int i_type = var_Type( p_object, psz_variable );
771 switch( i_type & VLC_VAR_TYPE )
775 case VLC_VAR_VARIABLE:
777 case VLC_VAR_INTEGER:
780 /* Variable doesn't exist or isn't handled */
784 /* Make sure we want to display the variable */
785 if( i_type & VLC_VAR_HASCHOICE )
787 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
788 if( val.i_int == 0 ) return;
789 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
793 /* Get the descriptive name of the variable */
794 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
795 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
796 text.psz_string : psz_variable ]];
798 if( i_type & VLC_VAR_HASCHOICE )
800 NSMenu *o_menu = [o_mi submenu];
802 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
803 var:psz_variable selector:pf_callback];
805 free( text.psz_string );
808 if( var_Get( p_object, psz_variable, &val ) < 0 )
813 VLCAutoGeneratedMenuContent *o_data;
814 switch( i_type & VLC_VAR_TYPE )
817 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
818 andValue: val ofType: i_type];
819 [o_mi setRepresentedObject: [o_data autorelease]];
823 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
824 andValue: val ofType: i_type];
825 [o_mi setRepresentedObject: [o_data autorelease]];
826 if( !( i_type & VLC_VAR_ISCOMMAND ) )
827 [o_mi setState: val.b_bool ? TRUE : FALSE ];
834 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
835 free( text.psz_string );
839 - (void)setupVarMenu:(NSMenu *)o_menu
840 forMenuItem: (NSMenuItem *)o_parent
841 target:(vlc_object_t *)p_object
842 var:(const char *)psz_variable
843 selector:(SEL)pf_callback
845 vlc_value_t val, val_list, text_list;
846 int i_type, i, i_nb_items;
848 /* remove previous items */
849 i_nb_items = [o_menu numberOfItems];
850 for( i = 0; i < i_nb_items; i++ )
851 [o_menu removeItemAtIndex: 0];
853 /* Check the type of the object variable */
854 i_type = var_Type( p_object, psz_variable );
856 /* Make sure we want to display the variable */
857 if( i_type & VLC_VAR_HASCHOICE )
859 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
860 if( val.i_int == 0 ) return;
861 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
867 switch( i_type & VLC_VAR_TYPE )
871 case VLC_VAR_VARIABLE:
873 case VLC_VAR_INTEGER:
876 /* Variable doesn't exist or isn't handled */
880 if( var_Get( p_object, psz_variable, &val ) < 0 )
885 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
886 &val_list, &text_list ) < 0 )
888 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
892 /* make (un)sensitive */
893 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
896 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
898 NSMenuItem *o_lmi_tmp2;
899 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
900 [o_lmi_tmp2 setTarget: self];
901 [o_lmi_tmp2 setEnabled: YES];
902 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
903 [o_parent setEnabled: YES];
904 [o_menu addItem: [NSMenuItem separatorItem]];
907 /* special case for the subtitles items */
908 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
910 NSMenuItem * o_lmi_tmp;
911 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
912 [o_lmi_tmp setTarget: self];
913 [o_lmi_tmp setEnabled: YES];
914 [o_parent setEnabled: YES];
915 [o_menu addItem: [NSMenuItem separatorItem]];
918 for( i = 0; i < val_list.p_list->i_count; i++ )
921 NSString *o_title = @"";
922 VLCAutoGeneratedMenuContent *o_data;
924 switch( i_type & VLC_VAR_TYPE )
928 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
929 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
931 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
932 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
933 andValue: val_list.p_list->p_values[i] ofType: i_type];
934 [o_lmi setRepresentedObject: [o_data autorelease]];
935 [o_lmi setTarget: self];
937 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
938 [o_lmi setState: TRUE ];
942 case VLC_VAR_INTEGER:
944 o_title = text_list.p_list->p_values[i].psz_string ?
945 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
946 [NSString stringWithFormat: @"%"PRId64,
947 val_list.p_list->p_values[i].i_int];
949 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
950 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
951 andValue: val_list.p_list->p_values[i] ofType: i_type];
952 [o_lmi setRepresentedObject: [o_data autorelease]];
953 [o_lmi setTarget: self];
955 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
956 [o_lmi setState: TRUE ];
964 /* special case for the subtitles sub-menu
965 * In case that we don't have any subs, we don't want a separator item at the end */
966 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
968 if( [o_menu numberOfItems] == 2 )
969 [o_menu removeItemAtIndex: 1];
972 /* clean up everything */
973 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
974 var_FreeList( &val_list, &text_list );
977 - (IBAction)toggleVar:(id)sender
979 NSMenuItem *o_mi = (NSMenuItem *)sender;
980 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
981 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
982 toTarget: self withObject: o_data];
987 - (int)toggleVarThread: (id)data
989 vlc_object_t *p_object;
990 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
992 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
993 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
995 p_object = [menuContent vlcObject];
997 if( p_object != NULL )
999 var_Set( p_object, [menuContent name], [menuContent value] );
1000 vlc_object_release( p_object );
1005 return VLC_EGENERIC;
1010 @implementation VLCMainMenu (NSMenuValidation)
1012 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1014 NSString *o_title = [o_mi title];
1015 BOOL bEnabled = TRUE;
1017 playlist_t * p_playlist = pl_Get( p_intf );
1018 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1020 /* Recent Items Menu */
1021 if( [o_title isEqualToString: _NS("Clear Menu")] )
1023 NSMenu * o_menu = [o_mi_open_recent submenu];
1024 int i_nb_items = [o_menu numberOfItems];
1025 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1026 recentDocumentURLs];
1027 UInt32 i_nb_docs = [o_docs count];
1029 if( i_nb_items > 1 )
1031 while( --i_nb_items )
1033 [o_menu removeItemAtIndex: 0];
1042 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1048 o_url = [o_docs objectAtIndex: i_nb_docs];
1050 if( [o_url isFileURL] )
1051 o_doc = [o_url path];
1053 o_doc = [o_url absoluteString];
1055 [o_menu insertItemWithTitle: o_doc
1056 action: @selector(openRecentItem:)
1057 keyEquivalent: @"" atIndex: 0];
1059 if( i_nb_docs == 0 )
1068 else if( [o_title isEqualToString: _NS("Stop")] )
1070 if( p_input == NULL )
1074 [self setupMenus]; /* Make sure input menu is up to date */
1076 else if( [o_title isEqualToString: _NS("Previous")] ||
1077 [o_title isEqualToString: _NS("Next")] )
1080 bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1083 else if( [o_title isEqualToString: _NS("Random")] )
1086 var_Get( p_playlist, "random", &val );
1087 i_state = val.b_bool ? NSOnState : NSOffState;
1088 [o_mi setState: i_state];
1090 else if( [o_title isEqualToString: _NS("Repeat One")] )
1093 var_Get( p_playlist, "repeat", &val );
1094 i_state = val.b_bool ? NSOnState : NSOffState;
1095 [o_mi setState: i_state];
1097 else if( [o_title isEqualToString: _NS("Repeat All")] )
1100 var_Get( p_playlist, "loop", &val );
1101 i_state = val.b_bool ? NSOnState : NSOffState;
1102 [o_mi setState: i_state];
1104 else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1107 var_Get( p_playlist, "play-and-exit", &val );
1108 i_state = val.b_bool ? NSOnState : NSOffState;
1109 [o_mi setState: i_state];
1111 else if( [o_title isEqualToString: _NS("Step Forward")] ||
1112 [o_title isEqualToString: _NS("Step Backward")] ||
1113 [o_title isEqualToString: _NS("Jump To Time")])
1115 if( p_input != NULL )
1117 var_Get( p_input, "can-seek", &val);
1118 bEnabled = val.b_bool;
1120 else bEnabled = FALSE;
1122 else if( [o_title isEqualToString: _NS("Mute")] )
1124 //FIXME [o_mi setState: p_intf->p_sys->b_mute ? NSOnState : NSOffState];
1125 [self setupMenus]; /* Make sure audio menu is up to date */
1127 else if( [o_title isEqualToString: _NS("Half Size")] ||
1128 [o_title isEqualToString: _NS("Normal Size")] ||
1129 [o_title isEqualToString: _NS("Double Size")] ||
1130 [o_title isEqualToString: _NS("Fit to Screen")] ||
1131 [o_title isEqualToString: _NS("Snapshot")] ||
1132 [o_title isEqualToString: _NS("Fullscreen")] ||
1133 [o_title isEqualToString: _NS("Float on Top")] )
1136 NSArray *o_windows = [NSApp orderedWindows];
1137 NSEnumerator *o_enumerator = [o_windows objectEnumerator];
1140 if( p_input != NULL )
1142 vout_thread_t *p_vout = input_GetVout( p_input );
1143 if( p_vout != NULL )
1145 if( [o_title isEqualToString: _NS("Float on Top")] )
1147 var_Get( p_vout, "video-on-top", &val );
1148 [o_mi setState: val.b_bool ? NSOnState : NSOffState];
1151 while( (o_window = [o_enumerator nextObject]))
1153 if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ||
1154 [[[VLCMain sharedInstance] embeddedList]
1155 windowContainsEmbedded: o_window])
1162 vlc_object_release( (vlc_object_t *)p_vout );
1165 if( [o_title isEqualToString: _NS("Fullscreen")] )
1167 var_Get( p_playlist, "fullscreen", &val );
1168 [o_mi setState: val.b_bool];
1171 [self setupMenus]; /* Make sure video menu is up to date */
1174 /* Special case for telx menu */
1175 if( [o_title isEqualToString: _NS("Normal Size")] )
1177 NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1178 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1180 [[item submenu] setAutoenablesItems:NO];
1181 for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1183 [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1187 if( p_input ) vlc_object_release( p_input );
1195 /*****************************************************************************
1196 * VLCAutoGeneratedMenuContent implementation
1197 *****************************************************************************
1198 * Object connected to a playlistitem which remembers the data belonging to
1199 * the variable of the autogenerated menu
1200 *****************************************************************************/
1201 @implementation VLCAutoGeneratedMenuContent
1203 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1204 andValue:(vlc_value_t)val ofType:(int)type
1206 self = [super init];
1210 _vlc_object = vlc_object_hold( object );
1211 psz_name = strdup( name );
1214 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1215 value.psz_string = strdup( val.psz_string );
1223 vlc_object_release( _vlc_object );
1224 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1225 free( value.psz_string );
1230 - (const char *)name
1235 - (vlc_value_t)value
1240 - (vlc_object_t *)vlcObject
1242 return vlc_object_hold( _vlc_object );