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"
44 @implementation VLCMainMenu
45 static VLCMainMenu *_o_sharedInstance = nil;
47 + (VLCMainMenu *)sharedInstance
49 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
53 #pragma mark Initialization
57 if( _o_sharedInstance)
60 return _o_sharedInstance;
64 _o_sharedInstance = [super init];
67 return _o_sharedInstance;
72 [[NSNotificationCenter defaultCenter] removeObserver: self];
74 if (b_nib_about_loaded)
77 if (b_nib_videoeffects_loaded)
78 [o_videoeffects release];
80 if (b_nib_audioeffects_loaded)
81 [o_audioeffects release];
83 if (b_nib_tracksynchro_loaded)
84 [o_trackSynchronization release];
91 [[NSNotificationCenter defaultCenter] addObserver: self
92 selector: @selector(applicationWillFinishLaunching:)
93 name: NSApplicationWillFinishLaunchingNotification
97 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
102 playlist_t *p_playlist;
104 id o_vlcmain = [VLCMain sharedInstance];
107 /* Check if we already did this once. Opening the other nibs calls it too,
108 because VLCMain is the owner */
109 if( b_mainMenu_setup ) return;
113 key = config_GetPsz( p_intf, "key-quit" );
114 o_key = [NSString stringWithFormat:@"%s", key];
115 [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
116 [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
119 key = config_GetPsz( p_intf, "key-play-pause" );
120 o_key = [NSString stringWithFormat:@"%s", key];
121 [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
122 [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
125 key = config_GetPsz( p_intf, "key-stop" );
126 o_key = [NSString stringWithFormat:@"%s", key];
127 [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
128 [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
131 key = config_GetPsz( p_intf, "key-prev" );
132 o_key = [NSString stringWithFormat:@"%s", key];
133 [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
134 [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
137 key = config_GetPsz( p_intf, "key-next" );
138 o_key = [NSString stringWithFormat:@"%s", key];
139 [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
140 [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
143 key = config_GetPsz( p_intf, "key-jump+short" );
144 o_key = [NSString stringWithFormat:@"%s", key];
145 [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
146 [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
149 key = config_GetPsz( p_intf, "key-jump-short" );
150 o_key = [NSString stringWithFormat:@"%s", key];
151 [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
152 [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
155 key = config_GetPsz( p_intf, "key-vol-up" );
156 o_key = [NSString stringWithFormat:@"%s", key];
157 [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
158 [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
161 key = config_GetPsz( p_intf, "key-vol-down" );
162 o_key = [NSString stringWithFormat:@"%s", key];
163 [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
164 [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
167 key = config_GetPsz( p_intf, "key-vol-mute" );
168 o_key = [NSString stringWithFormat:@"%s", key];
169 [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
170 [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
173 key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
174 o_key = [NSString stringWithFormat:@"%s", key];
175 [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
176 [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
179 key = config_GetPsz( p_intf, "key-snapshot" );
180 o_key = [NSString stringWithFormat:@"%s", key];
181 [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
182 [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
185 key = config_GetPsz( p_intf, "key-random" );
186 o_key = [NSString stringWithFormat:@"%s", key];
187 [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
188 [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
191 key = config_GetPsz( p_intf, "key-zoom-half" );
192 o_key = [NSString stringWithFormat:@"%s", key];
193 [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
194 [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
197 key = config_GetPsz( p_intf, "key-zoom-original" );
198 o_key = [NSString stringWithFormat:@"%s", key];
199 [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
200 [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
203 key = config_GetPsz( p_intf, "key-zoom-double" );
204 o_key = [NSString stringWithFormat:@"%s", key];
205 [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
206 [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
209 [self setSubmenusEnabled: FALSE];
211 [[NSNotificationCenter defaultCenter] addObserver: self
212 selector: @selector(refreshVoutDeviceMenu:)
213 name: NSApplicationDidChangeScreenParametersNotification
217 b_mainMenu_setup = YES;
219 [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
220 var: "intf-add" selector: @selector(toggleVar:)];
226 [o_mi_about setTitle: [_NS("About VLC media player") \
227 stringByAppendingString: @"..."]];
228 [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
229 [o_mi_prefs setTitle: _NS("Preferences...")];
230 [o_mi_add_intf setTitle: _NS("Add Interface")];
231 [o_mu_add_intf setTitle: _NS("Add Interface")];
232 [o_mi_services setTitle: _NS("Services")];
233 [o_mi_hide setTitle: _NS("Hide VLC")];
234 [o_mi_hide_others setTitle: _NS("Hide Others")];
235 [o_mi_show_all setTitle: _NS("Show All")];
236 [o_mi_quit setTitle: _NS("Quit VLC")];
238 [o_mu_file setTitle: _ANS("1:File")];
239 [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
240 [o_mi_open_file setTitle: _NS("Open File...")];
241 [o_mi_open_disc setTitle: _NS("Open Disc...")];
242 [o_mi_open_net setTitle: _NS("Open Network...")];
243 [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
244 [o_mi_open_recent setTitle: _NS("Open Recent")];
245 [o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
246 [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
248 [o_mu_edit setTitle: _NS("Edit")];
249 [o_mi_cut setTitle: _NS("Cut")];
250 [o_mi_copy setTitle: _NS("Copy")];
251 [o_mi_paste setTitle: _NS("Paste")];
252 [o_mi_clear setTitle: _NS("Clear")];
253 [o_mi_select_all setTitle: _NS("Select All")];
255 [o_mu_controls setTitle: _NS("Playback")];
256 [o_mi_play setTitle: _NS("Play")];
257 [o_mi_stop setTitle: _NS("Stop")];
258 [o_mi_record setTitle: _NS("Record")];
259 [o_mi_rate setView: o_mi_rate_view];
260 [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
261 [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
262 [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
263 [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
264 [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
265 [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
266 [o_mi_previous setTitle: _NS("Previous")];
267 [o_mi_next setTitle: _NS("Next")];
268 [o_mi_random setTitle: _NS("Random")];
269 [o_mi_repeat setTitle: _NS("Repeat One")];
270 [o_mi_loop setTitle: _NS("Repeat All")];
271 [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
272 [o_mi_fwd setTitle: _NS("Step Forward")];
273 [o_mi_bwd setTitle: _NS("Step Backward")];
275 [o_mi_program setTitle: _NS("Program")];
276 [o_mu_program setTitle: _NS("Program")];
277 [o_mi_title setTitle: _NS("Title")];
278 [o_mu_title setTitle: _NS("Title")];
279 [o_mi_chapter setTitle: _NS("Chapter")];
280 [o_mu_chapter setTitle: _NS("Chapter")];
282 [o_mu_audio setTitle: _NS("Audio")];
283 [o_mi_vol_up setTitle: _NS("Increase Volume")];
284 [o_mi_vol_down setTitle: _NS("Decrease Volume")];
285 [o_mi_mute setTitle: _NS("Mute")];
286 [o_mi_audiotrack setTitle: _NS("Audio Track")];
287 [o_mu_audiotrack setTitle: _NS("Audio Track")];
288 [o_mi_channels setTitle: _NS("Audio Channels")];
289 [o_mu_channels setTitle: _NS("Audio Channels")];
290 [o_mi_device setTitle: _NS("Audio Device")];
291 [o_mu_device setTitle: _NS("Audio Device")];
292 [o_mi_visual setTitle: _NS("Visualizations")];
293 [o_mu_visual setTitle: _NS("Visualizations")];
295 [o_mu_video setTitle: _NS("Video")];
296 [o_mi_half_window setTitle: _NS("Half Size")];
297 [o_mi_normal_window setTitle: _NS("Normal Size")];
298 [o_mi_double_window setTitle: _NS("Double Size")];
299 [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
300 [o_mi_fullscreen setTitle: _NS("Fullscreen")];
301 [o_mi_floatontop setTitle: _NS("Float on Top")];
302 [o_mi_snapshot setTitle: _NS("Snapshot")];
303 [o_mi_videotrack setTitle: _NS("Video Track")];
304 [o_mu_videotrack setTitle: _NS("Video Track")];
305 [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
306 [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
307 [o_mi_crop setTitle: _NS("Crop")];
308 [o_mu_crop setTitle: _NS("Crop")];
309 [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
310 [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
311 [o_mi_subtitle setTitle: _NS("Subtitles Track")];
312 [o_mu_subtitle setTitle: _NS("Subtitles Track")];
313 [o_mi_addSub setTitle: _NS("Open File...")];
314 [o_mi_deinterlace setTitle: _NS("Deinterlace")];
315 [o_mu_deinterlace setTitle: _NS("Deinterlace")];
316 [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
317 [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
318 [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
319 [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
320 [o_mi_teletext setTitle: _NS("Teletext")];
321 [o_mi_teletext_transparent setTitle: _NS("Transparent")];
322 [o_mi_teletext_index setTitle: _NS("Index")];
323 [o_mi_teletext_red setTitle: _NS("Red")];
324 [o_mi_teletext_green setTitle: _NS("Green")];
325 [o_mi_teletext_yellow setTitle: _NS("Yellow")];
326 [o_mi_teletext_blue setTitle: _NS("Blue")];
328 [o_mu_window setTitle: _NS("Window")];
329 [o_mi_minimize setTitle: _NS("Minimize Window")];
330 [o_mi_close_window setTitle: _NS("Close Window")];
331 [o_mi_player setTitle: _NS("Player...")];
332 [o_mi_controller setTitle: _NS("Main Window...")];
333 [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
334 [o_mi_videoeffects setTitle: _NS("Video Filters...")];
335 [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
336 [o_mi_playlist setTitle: _NS("Playlist...")];
337 [o_mi_info setTitle: _NS("Media Information...")];
338 [o_mi_messages setTitle: _NS("Messages...")];
339 [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
341 [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
343 [o_mu_help setTitle: _NS("Help")];
344 [o_mi_help setTitle: _NS("VLC media player Help...")];
345 [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
346 [o_mi_license setTitle: _NS("License")];
347 [o_mi_documentation setTitle: _NS("Online Documentation...")];
348 [o_mi_website setTitle: _NS("VideoLAN Website...")];
349 [o_mi_donation setTitle: _NS("Make a donation...")];
350 [o_mi_forum setTitle: _NS("Online Forum...")];
353 [o_dmi_play setTitle: _NS("Play")];
354 [o_dmi_stop setTitle: _NS("Stop")];
355 [o_dmi_next setTitle: _NS("Next")];
356 [o_dmi_previous setTitle: _NS("Previous")];
357 [o_dmi_mute setTitle: _NS("Mute")];
360 [o_vmi_play setTitle: _NS("Play")];
361 [o_vmi_stop setTitle: _NS("Stop")];
362 [o_vmi_prev setTitle: _NS("Previous")];
363 [o_vmi_next setTitle: _NS("Next")];
364 [o_vmi_volup setTitle: _NS("Volume Up")];
365 [o_vmi_voldown setTitle: _NS("Volume Down")];
366 [o_vmi_mute setTitle: _NS("Mute")];
367 [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
368 [o_vmi_snapshot setTitle: _NS("Snapshot")];
372 #pragma mark Termination
374 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
376 if( !p_intf ) return;
378 NSArray *menuitems_array = [the_menu itemArray];
379 NSUInteger menuItemCount = [menuitems_array count];
380 for( NSUInteger i=0; i < menuItemCount; i++ )
382 NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
383 if( [one_item hasSubmenu] )
384 [self releaseRepresentedObjects: [one_item submenu]];
386 [one_item setRepresentedObject:NULL];
391 #pragma mark Interface update
395 playlist_t * p_playlist = pl_Get( p_intf );
396 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
397 if( p_input != NULL )
399 [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
401 [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
402 var: "program" selector: @selector(toggleVar:)];
404 [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
405 var: "title" selector: @selector(toggleVar:)];
407 [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
408 var: "chapter" selector: @selector(toggleVar:)];
410 [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
411 var: "audio-es" selector: @selector(toggleVar:)];
413 [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
414 var: "video-es" selector: @selector(toggleVar:)];
416 [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
417 var: "spu-es" selector: @selector(toggleVar:)];
419 /* special case for "Open File" inside the subtitles menu item */
420 if( [o_mi_videotrack isEnabled] == YES )
421 [o_mi_subtitle setEnabled: YES];
423 audio_output_t * p_aout = input_GetAout( p_input );
426 [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
427 var: "audio-channels" selector: @selector(toggleVar:)];
429 [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
430 var: "audio-device" selector: @selector(toggleVar:)];
432 [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
433 var: "visual" selector: @selector(toggleVar:)];
434 vlc_object_release( (vlc_object_t *)p_aout );
437 vout_thread_t * p_vout = input_GetVout( p_input );
441 vlc_object_t * p_dec_obj;
443 [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
444 var: "aspect-ratio" selector: @selector(toggleVar:)];
446 [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
447 var: "crop" selector: @selector(toggleVar:)];
449 [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
450 var: "video-device" selector: @selector(toggleVar:)];
452 [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
453 var: "deinterlace" selector: @selector(toggleVar:)];
455 [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
456 var: "deinterlace-mode" selector: @selector(toggleVar:)];
459 [self setupVarMenuItem: o_mi_ffmpeg_pp target:
460 (vlc_object_t *)p_vout var:"postprocess" selector:
461 @selector(toggleVar:)];
463 vlc_object_release( (vlc_object_t *)p_vout );
465 vlc_object_release( p_input );
469 [o_mi_record setEnabled: NO];
473 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
476 vout_thread_t * p_vout = getVout();
480 /* clean the menu before adding new entries */
481 if( [o_mi_screen hasSubmenu] )
483 y = [[o_mi_screen submenu] numberOfItems] - 1;
484 msg_Dbg( VLCIntf, "%i items in submenu", y );
487 msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
488 [[o_mi_screen submenu] removeItemAtIndex: x];
493 [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
494 var: "video-device" selector: @selector(toggleVar:)];
495 vlc_object_release( (vlc_object_t *)p_vout );
498 - (void)setSubmenusEnabled:(BOOL)b_enabled
500 [o_mi_program setEnabled: b_enabled];
501 [o_mi_title setEnabled: b_enabled];
502 [o_mi_chapter setEnabled: b_enabled];
503 [o_mi_audiotrack setEnabled: b_enabled];
504 [o_mi_visual setEnabled: b_enabled];
505 [o_mi_videotrack setEnabled: b_enabled];
506 [o_mi_subtitle setEnabled: b_enabled];
507 [o_mi_channels setEnabled: b_enabled];
508 [o_mi_deinterlace setEnabled: b_enabled];
509 [o_mi_deinterlace_mode setEnabled: b_enabled];
510 [o_mi_ffmpeg_pp setEnabled: b_enabled];
511 [o_mi_device setEnabled: b_enabled];
512 [o_mi_screen setEnabled: b_enabled];
513 [o_mi_aspect_ratio setEnabled: b_enabled];
514 [o_mi_crop setEnabled: b_enabled];
515 [o_mi_teletext setEnabled: b_enabled];
518 - (void)setRateControlsEnabled:(BOOL)b_enabled
520 NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
521 [o_mi_rate_sld setEnabled: b_enabled];
522 [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
523 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
526 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
528 [o_mi_rate_lbl setHidden: NO];
529 [o_mi_rate_lbl_gray setHidden: YES];
533 [o_mi_rate_lbl setHidden: YES];
534 [o_mi_rate_lbl_gray setHidden: NO];
540 #pragma mark Recent Items
541 - (void)openRecentItem:(id)item
543 [[VLCMain sharedInstance] application: nil openFile: [item title]];
546 - (IBAction)clearRecentItems:(id)sender
548 [[NSDocumentController sharedDocumentController]
549 clearRecentDocuments: nil];
553 #pragma mark Playback
554 - (IBAction)toggleRecord:(id)sender
556 [[VLCCoreInteraction sharedInstance] toggleRecord];
559 - (void)updateRecordState:(BOOL)b_value
561 [o_mi_record setState:b_value];
564 - (IBAction)setPlaybackRate:(id)sender
566 [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
567 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
570 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
573 - (void)updatePlaybackRate
575 int i = [[VLCCoreInteraction sharedInstance] playbackRate];
578 [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
579 [o_mi_rate_sld setIntValue: i];
584 - (IBAction)toggleFullscreen:(id)sender
586 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
589 - (IBAction)resizeVideoWindow:(id)sender
591 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
594 vout_thread_t *p_vout = getVout();
597 if (sender == o_mi_half_window)
598 var_SetFloat( p_vout, "zoom", 0.5 );
599 else if (sender == o_mi_normal_window)
600 var_SetFloat( p_vout, "zoom", 1.0 );
601 else if (sender == o_mi_double_window)
602 var_SetFloat( p_vout, "zoom", 2.0 );
605 var_ToggleBool( p_vout, "autoscale" );
607 vlc_object_release( p_vout );
609 vlc_object_release( p_input );
613 - (IBAction)floatOnTop:(id)sender
615 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
618 vout_thread_t *p_vout = getVout();
621 var_ToggleBool( p_vout, "video-on-top" );
622 vlc_object_release( p_vout );
624 vlc_object_release( p_input );
628 - (IBAction)createVideoSnapshot:(id)sender
630 input_thread_t *p_input = pl_CurrentInput( VLCIntf );
633 vout_thread_t *p_vout = getVout();
636 var_TriggerCallback( p_vout, "video-snapshot" );
637 vlc_object_release( p_vout );
639 vlc_object_release( p_input );
651 - (IBAction)intfOpenFile:(id)sender
653 [[[VLCMain sharedInstance] open] openFile];
656 - (IBAction)intfOpenFileGeneric:(id)sender
658 [[[VLCMain sharedInstance] open] openFileGeneric];
661 - (IBAction)intfOpenDisc:(id)sender
663 [[[VLCMain sharedInstance] open] openDisc];
666 - (IBAction)intfOpenNet:(id)sender
668 [[[VLCMain sharedInstance] open] openNet];
671 - (IBAction)intfOpenCapture:(id)sender
673 [[[VLCMain sharedInstance] open] openCapture];
676 - (IBAction)showWizard:(id)sender
678 [[[VLCMain sharedInstance] wizard] resetWizard];
679 [[[VLCMain sharedInstance] wizard] showWizard];
682 - (IBAction)showVideoEffects:(id)sender
684 if( o_videoeffects == nil )
685 o_videoeffects = [[VLCVideoEffects alloc] init];
687 if( !b_nib_videoeffects_loaded )
688 b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
690 [o_videoeffects toggleWindow:sender];
693 - (IBAction)showTrackSynchronization:(id)sender
695 if (!o_trackSynchronization)
696 o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
698 if (!b_nib_tracksynchro_loaded)
699 b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
701 [o_trackSynchronization toggleWindow:sender];
704 - (IBAction)showAudioEffects:(id)sender
707 o_audioeffects = [[VLCAudioEffects alloc] init];
709 if (!b_nib_audioeffects_loaded)
710 b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
712 [o_audioeffects toggleWindow:sender];
715 - (IBAction)showBookmarks:(id)sender
717 [[[VLCMain sharedInstance] bookmarks] showBookmarks];
720 - (IBAction)viewPreferences:(id)sender
722 [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
726 #pragma mark Help and Docs
731 o_about = [[VLAboutBox alloc] init];
733 if( !b_nib_about_loaded )
734 b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
737 - (IBAction)viewAbout:(id)sender
743 - (IBAction)showLicense:(id)sender
746 [o_about showGPL: sender];
749 - (IBAction)viewHelp:(id)sender
755 - (IBAction)openReadMe:(id)sender
757 NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
759 [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
762 - (IBAction)openDocumentation:(id)sender
764 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
766 [[NSWorkspace sharedWorkspace] openURL: o_url];
769 - (IBAction)openWebsite:(id)sender
771 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
773 [[NSWorkspace sharedWorkspace] openURL: o_url];
776 - (IBAction)openForum:(id)sender
778 NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
780 [[NSWorkspace sharedWorkspace] openURL: o_url];
783 - (IBAction)openDonate:(id)sender
785 NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
787 [[NSWorkspace sharedWorkspace] openURL: o_url];
791 #pragma mark Errors, warnings and messages
793 - (IBAction)viewErrorsAndWarnings:(id)sender
795 [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
798 - (IBAction)showInformationPanel:(id)sender
800 [[[VLCMain sharedInstance] info] initPanel];
804 #pragma mark convinience stuff for other objects
807 [o_mi_play setTitle: _NS("Play")];
808 [o_dmi_play setTitle: _NS("Play")];
809 [o_vmi_play setTitle: _NS("Play")];
814 [o_mi_play setTitle: _NS("Pause")];
815 [o_dmi_play setTitle: _NS("Pause")];
816 [o_vmi_play setTitle: _NS("Pause")];
821 [o_mi_repeat setState: NSOnState];
822 [o_mi_loop setState: NSOffState];
827 [o_mi_repeat setState: NSOffState];
828 [o_mi_loop setState: NSOnState];
833 [o_mi_repeat setState: NSOffState];
834 [o_mi_loop setState: NSOffState];
840 playlist_t *p_playlist = pl_Get( VLCIntf );
841 b_value = var_GetBool( p_playlist, "random" );
842 [o_mi_random setState: b_value];
846 #pragma mark Dynamic menu creation and validation
848 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
849 target:(vlc_object_t *)p_object
850 var:(const char *)psz_variable
851 selector:(SEL)pf_callback
853 vlc_value_t val, text;
854 int i_type = var_Type( p_object, psz_variable );
856 switch( i_type & VLC_VAR_TYPE )
860 case VLC_VAR_VARIABLE:
862 case VLC_VAR_INTEGER:
865 /* Variable doesn't exist or isn't handled */
869 /* Make sure we want to display the variable */
870 if( i_type & VLC_VAR_HASCHOICE )
872 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
873 if( val.i_int == 0 ) return;
874 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
878 /* Get the descriptive name of the variable */
879 var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
880 [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
881 text.psz_string : psz_variable ]];
883 if( i_type & VLC_VAR_HASCHOICE )
885 NSMenu *o_menu = [o_mi submenu];
887 [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
888 var:psz_variable selector:pf_callback];
890 free( text.psz_string );
893 if( var_Get( p_object, psz_variable, &val ) < 0 )
898 VLCAutoGeneratedMenuContent *o_data;
899 switch( i_type & VLC_VAR_TYPE )
902 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
903 andValue: val ofType: i_type];
904 [o_mi setRepresentedObject: [o_data autorelease]];
908 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
909 andValue: val ofType: i_type];
910 [o_mi setRepresentedObject: [o_data autorelease]];
911 if( !( i_type & VLC_VAR_ISCOMMAND ) )
912 [o_mi setState: val.b_bool ? TRUE : FALSE ];
919 if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
920 free( text.psz_string );
924 - (void)setupVarMenu:(NSMenu *)o_menu
925 forMenuItem: (NSMenuItem *)o_parent
926 target:(vlc_object_t *)p_object
927 var:(const char *)psz_variable
928 selector:(SEL)pf_callback
930 vlc_value_t val, val_list, text_list;
931 int i_type, i, i_nb_items;
933 /* remove previous items */
934 i_nb_items = [o_menu numberOfItems];
935 for( i = 0; i < i_nb_items; i++ )
936 [o_menu removeItemAtIndex: 0];
938 /* Check the type of the object variable */
939 i_type = var_Type( p_object, psz_variable );
941 /* Make sure we want to display the variable */
942 if( i_type & VLC_VAR_HASCHOICE )
944 var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
945 if( val.i_int == 0 ) return;
946 if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
952 switch( i_type & VLC_VAR_TYPE )
956 case VLC_VAR_VARIABLE:
958 case VLC_VAR_INTEGER:
961 /* Variable doesn't exist or isn't handled */
965 if( var_Get( p_object, psz_variable, &val ) < 0 )
970 if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
971 &val_list, &text_list ) < 0 )
973 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
977 /* make (un)sensitive */
978 [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
981 if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
983 NSMenuItem *o_lmi_tmp2;
984 o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
985 [o_lmi_tmp2 setTarget: self];
986 [o_lmi_tmp2 setEnabled: YES];
987 [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
988 [o_parent setEnabled: YES];
989 [o_menu addItem: [NSMenuItem separatorItem]];
992 /* special case for the subtitles items */
993 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
995 NSMenuItem * o_lmi_tmp;
996 o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
997 [o_lmi_tmp setTarget: self];
998 [o_lmi_tmp setEnabled: YES];
999 [o_parent setEnabled: YES];
1000 [o_menu addItem: [NSMenuItem separatorItem]];
1003 for( i = 0; i < val_list.p_list->i_count; i++ )
1006 NSString *o_title = @"";
1007 VLCAutoGeneratedMenuContent *o_data;
1009 switch( i_type & VLC_VAR_TYPE )
1011 case VLC_VAR_STRING:
1013 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
1014 text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
1016 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1017 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1018 andValue: val_list.p_list->p_values[i] ofType: i_type];
1019 [o_lmi setRepresentedObject: [o_data autorelease]];
1020 [o_lmi setTarget: self];
1022 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1023 [o_lmi setState: TRUE ];
1027 case VLC_VAR_INTEGER:
1029 o_title = text_list.p_list->p_values[i].psz_string ?
1030 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
1031 [NSString stringWithFormat: @"%"PRId64,
1032 val_list.p_list->p_values[i].i_int];
1034 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1035 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1036 andValue: val_list.p_list->p_values[i] ofType: i_type];
1037 [o_lmi setRepresentedObject: [o_data autorelease]];
1038 [o_lmi setTarget: self];
1040 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1041 [o_lmi setState: TRUE ];
1049 /* special case for the subtitles sub-menu
1050 * In case that we don't have any subs, we don't want a separator item at the end */
1051 if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1053 if( [o_menu numberOfItems] == 2 )
1054 [o_menu removeItemAtIndex: 1];
1057 /* clean up everything */
1058 if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1059 var_FreeList( &val_list, &text_list );
1062 - (IBAction)toggleVar:(id)sender
1064 NSMenuItem *o_mi = (NSMenuItem *)sender;
1065 VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1066 [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1067 toTarget: self withObject: o_data];
1072 - (int)toggleVarThread: (id)data
1074 vlc_object_t *p_object;
1075 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1077 assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1078 VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1080 p_object = [menuContent vlcObject];
1082 if( p_object != NULL )
1084 var_Set( p_object, [menuContent name], [menuContent value] );
1085 vlc_object_release( p_object );
1090 return VLC_EGENERIC;
1095 @implementation VLCMainMenu (NSMenuValidation)
1097 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1099 NSString *o_title = [o_mi title];
1100 BOOL bEnabled = TRUE;
1102 playlist_t * p_playlist = pl_Get( p_intf );
1103 input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1105 /* Recent Items Menu */
1106 if( [o_title isEqualToString: _NS("Clear Menu")] )
1108 NSMenu * o_menu = [o_mi_open_recent submenu];
1109 int i_nb_items = [o_menu numberOfItems];
1110 NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1111 recentDocumentURLs];
1112 UInt32 i_nb_docs = [o_docs count];
1114 if( i_nb_items > 1 )
1116 while( --i_nb_items )
1118 [o_menu removeItemAtIndex: 0];
1127 [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1133 o_url = [o_docs objectAtIndex: i_nb_docs];
1135 if( [o_url isFileURL] )
1136 o_doc = [o_url path];
1138 o_doc = [o_url absoluteString];
1140 [o_menu insertItemWithTitle: o_doc
1141 action: @selector(openRecentItem:)
1142 keyEquivalent: @"" atIndex: 0];
1144 if( i_nb_docs == 0 )
1153 else 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 //FIXME [o_mi setState: p_intf->p_sys->b_mute ? 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 );