macosx: re-implement 'keep aspect ratio' (close #6430)
[vlc.git] / modules / gui / macosx / MainMenu.m
1 /*****************************************************************************
2  * MainMenu.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #import "MainMenu.h"
25 #import <vlc_common.h>
26 #import <vlc_playlist.h>
27
28 #import "intf.h"
29 #import "open.h"
30 #import "wizard.h"
31 #import "about.h"
32 #import "AudioEffects.h"
33 #import "TrackSynchronization.h"
34 #import "VideoEffects.h"
35 #import "bookmarks.h"
36 #import "simple_prefs.h"
37 #import "coredialogs.h"
38 #import "controls.h"
39 #import "playlistinfo.h"
40 #import "VideoView.h"
41 #import "CoreInteraction.h"
42 #import "MainWindow.h"
43 #import "ExtensionsManager.h"
44
45 @implementation VLCMainMenu
46 static VLCMainMenu *_o_sharedInstance = nil;
47
48 + (VLCMainMenu *)sharedInstance
49 {
50     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
51 }
52
53 #pragma mark -
54 #pragma mark Initialization
55
56 - (id)init
57 {
58     if( _o_sharedInstance)
59     {
60         [self dealloc];
61         return _o_sharedInstance;
62     }
63     else
64     {
65         _o_sharedInstance = [super init];
66     }
67
68     return _o_sharedInstance;
69 }
70
71 - (void)dealloc
72 {
73     [[NSNotificationCenter defaultCenter] removeObserver: self];
74
75     if (b_nib_about_loaded)
76         [o_about release];
77
78     if (b_nib_videoeffects_loaded)
79         [o_videoeffects release];
80
81     if (b_nib_audioeffects_loaded)
82         [o_audioeffects release];
83
84     if (b_nib_tracksynchro_loaded)
85         [o_trackSynchronization release];
86
87     [o_extMgr release];
88
89     [super dealloc];
90 }
91
92 - (void)awakeFromNib
93 {
94     [[NSNotificationCenter defaultCenter] addObserver: self 
95                                              selector: @selector(applicationWillFinishLaunching:)
96                                                  name: NSApplicationWillFinishLaunchingNotification
97                                                object: nil];
98 }
99
100 - (void)applicationWillFinishLaunching:(NSNotification *)o_notification
101 {
102     p_intf = VLCIntf;
103
104     NSString* o_key;
105     playlist_t *p_playlist;
106     vlc_value_t val;
107     id o_vlcmain = [VLCMain sharedInstance];
108     char * key;
109
110     /* Check if we already did this once. Opening the other nibs calls it too,
111      because VLCMain is the owner */
112     if( b_mainMenu_setup ) return;
113
114     /* Get ExtensionsManager */
115     o_extMgr = [ExtensionsManager getInstance:p_intf];
116     [o_extMgr retain];
117
118     [self initStrings];
119
120     key = config_GetPsz( p_intf, "key-quit" );
121     o_key = [NSString stringWithFormat:@"%s", key];
122     [o_mi_quit setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
123     [o_mi_quit setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
124     FREENULL( key );
125
126     key = config_GetPsz( p_intf, "key-play-pause" );
127     o_key = [NSString stringWithFormat:@"%s", key];
128     [o_mi_play setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
129     [o_mi_play setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
130     FREENULL( key );
131
132     key = config_GetPsz( p_intf, "key-stop" );
133     o_key = [NSString stringWithFormat:@"%s", key];
134     [o_mi_stop setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
135     [o_mi_stop setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
136     FREENULL( key );
137
138     key = config_GetPsz( p_intf, "key-prev" );
139     o_key = [NSString stringWithFormat:@"%s", key];
140     [o_mi_previous setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
141     [o_mi_previous setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
142     FREENULL( key );
143
144     key = config_GetPsz( p_intf, "key-next" );
145     o_key = [NSString stringWithFormat:@"%s", key];
146     [o_mi_next setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
147     [o_mi_next setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
148     FREENULL( key );
149
150     key = config_GetPsz( p_intf, "key-jump+short" );
151     o_key = [NSString stringWithFormat:@"%s", key];
152     [o_mi_fwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
153     [o_mi_fwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
154     FREENULL( key );
155
156     key = config_GetPsz( p_intf, "key-jump-short" );
157     o_key = [NSString stringWithFormat:@"%s", key];
158     [o_mi_bwd setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
159     [o_mi_bwd setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
160     FREENULL( key );
161
162     key = config_GetPsz( p_intf, "key-vol-up" );
163     o_key = [NSString stringWithFormat:@"%s", key];
164     [o_mi_vol_up setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
165     [o_mi_vol_up setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
166     FREENULL( key );
167
168     key = config_GetPsz( p_intf, "key-vol-down" );
169     o_key = [NSString stringWithFormat:@"%s", key];
170     [o_mi_vol_down setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
171     [o_mi_vol_down setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
172     FREENULL( key );
173
174     key = config_GetPsz( p_intf, "key-vol-mute" );
175     o_key = [NSString stringWithFormat:@"%s", key];
176     [o_mi_mute setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
177     [o_mi_mute setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
178     FREENULL( key );
179
180     key = config_GetPsz( p_intf, "key-toggle-fullscreen" );
181     o_key = [NSString stringWithFormat:@"%s", key];
182     [o_mi_fullscreen setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
183     [o_mi_fullscreen setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
184     FREENULL( key );
185
186     key = config_GetPsz( p_intf, "key-snapshot" );
187     o_key = [NSString stringWithFormat:@"%s", key];
188     [o_mi_snapshot setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
189     [o_mi_snapshot setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
190     FREENULL( key );
191
192     key = config_GetPsz( p_intf, "key-random" );
193     o_key = [NSString stringWithFormat:@"%s", key];
194     [o_mi_random setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
195     [o_mi_random setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
196     FREENULL( key );
197
198     key = config_GetPsz( p_intf, "key-zoom-half" );
199     o_key = [NSString stringWithFormat:@"%s", key];
200     [o_mi_half_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
201     [o_mi_half_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
202     FREENULL( key );
203
204     key = config_GetPsz( p_intf, "key-zoom-original" );
205     o_key = [NSString stringWithFormat:@"%s", key];
206     [o_mi_normal_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
207     [o_mi_normal_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
208     FREENULL( key );
209
210     key = config_GetPsz( p_intf, "key-zoom-double" );
211     o_key = [NSString stringWithFormat:@"%s", key];
212     [o_mi_double_window setKeyEquivalent: [o_vlcmain VLCKeyToString: o_key]];
213     [o_mi_double_window setKeyEquivalentModifierMask: [o_vlcmain VLCModifiersToCocoa:o_key]];
214     FREENULL( key );
215
216     [self setSubmenusEnabled: FALSE];
217
218     [[NSNotificationCenter defaultCenter] addObserver: self
219                                              selector: @selector(refreshVoutDeviceMenu:)
220                                                  name: NSApplicationDidChangeScreenParametersNotification
221                                                object: nil];
222
223     /* we're done */
224     b_mainMenu_setup = YES;
225
226     [self setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
227                              var: "intf-add" selector: @selector(toggleVar:)];
228
229     [self setupExtensionsMenu];
230 }
231
232 - (void)initStrings
233 {
234     /* main menu */
235     [o_mi_about setTitle: [_NS("About VLC media player") \
236                            stringByAppendingString: @"..."]];
237     [o_mi_checkForUpdate setTitle: _NS("Check for Update...")];
238     [o_mi_prefs setTitle: _NS("Preferences...")];
239     [o_mi_extensions setTitle: _NS("Extensions")];
240     [o_mu_extensions setTitle: _NS("Extensions")];
241     [o_mi_add_intf setTitle: _NS("Add Interface")];
242     [o_mu_add_intf setTitle: _NS("Add Interface")];
243     [o_mi_services setTitle: _NS("Services")];
244     [o_mi_hide setTitle: _NS("Hide VLC")];
245     [o_mi_hide_others setTitle: _NS("Hide Others")];
246     [o_mi_show_all setTitle: _NS("Show All")];
247     [o_mi_quit setTitle: _NS("Quit VLC")];
248
249     [o_mu_file setTitle: _ANS("1:File")];
250     [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
251     [o_mi_open_file setTitle: _NS("Open File...")];
252     [o_mi_open_disc setTitle: _NS("Open Disc...")];
253     [o_mi_open_net setTitle: _NS("Open Network...")];
254     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
255     [o_mi_open_recent setTitle: _NS("Open Recent")];
256     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
257
258     [o_mu_edit setTitle: _NS("Edit")];
259     [o_mi_cut setTitle: _NS("Cut")];
260     [o_mi_copy setTitle: _NS("Copy")];
261     [o_mi_paste setTitle: _NS("Paste")];
262     [o_mi_clear setTitle: _NS("Clear")];
263     [o_mi_select_all setTitle: _NS("Select All")];
264
265     [o_mu_controls setTitle: _NS("Playback")];
266     [o_mi_play setTitle: _NS("Play")];
267     [o_mi_stop setTitle: _NS("Stop")];
268     [o_mi_record setTitle: _NS("Record")];
269     [o_mi_rate setView: o_mi_rate_view];
270     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
271     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
272     [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
273     [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
274     [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
275     [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
276     [o_mi_previous setTitle: _NS("Previous")];
277     [o_mi_next setTitle: _NS("Next")];
278     [o_mi_random setTitle: _NS("Random")];
279     [o_mi_repeat setTitle: _NS("Repeat One")];
280     [o_mi_loop setTitle: _NS("Repeat All")];
281     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
282     [o_mi_fwd setTitle: _NS("Step Forward")];
283     [o_mi_bwd setTitle: _NS("Step Backward")];
284
285     [o_mi_program setTitle: _NS("Program")];
286     [o_mu_program setTitle: _NS("Program")];
287     [o_mi_title setTitle: _NS("Title")];
288     [o_mu_title setTitle: _NS("Title")];
289     [o_mi_chapter setTitle: _NS("Chapter")];
290     [o_mu_chapter setTitle: _NS("Chapter")];
291
292     [o_mu_audio setTitle: _NS("Audio")];
293     [o_mi_vol_up setTitle: _NS("Increase Volume")];
294     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
295     [o_mi_mute setTitle: _NS("Mute")];
296     [o_mi_audiotrack setTitle: _NS("Audio Track")];
297     [o_mu_audiotrack setTitle: _NS("Audio Track")];
298     [o_mi_channels setTitle: _NS("Audio Channels")];
299     [o_mu_channels setTitle: _NS("Audio Channels")];
300     [o_mi_device setTitle: _NS("Audio Device")];
301     [o_mu_device setTitle: _NS("Audio Device")];
302     [o_mi_visual setTitle: _NS("Visualizations")];
303     [o_mu_visual setTitle: _NS("Visualizations")];
304
305     [o_mu_video setTitle: _NS("Video")];
306     [o_mi_half_window setTitle: _NS("Half Size")];
307     [o_mi_normal_window setTitle: _NS("Normal Size")];
308     [o_mi_double_window setTitle: _NS("Double Size")];
309     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
310     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
311     [o_mi_floatontop setTitle: _NS("Float on Top")];
312     [o_mi_snapshot setTitle: _NS("Snapshot")];
313     [o_mi_videotrack setTitle: _NS("Video Track")];
314     [o_mu_videotrack setTitle: _NS("Video Track")];
315     [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
316     [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
317     [o_mi_crop setTitle: _NS("Crop")];
318     [o_mu_crop setTitle: _NS("Crop")];
319     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
320     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
321     [o_mi_subtitle setTitle: _NS("Subtitles Track")];
322     [o_mu_subtitle setTitle: _NS("Subtitles Track")];
323     [o_mi_addSub setTitle: _NS("Open File...")];
324     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
325     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
326     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
327     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
328     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
329     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
330     [o_mi_teletext setTitle: _NS("Teletext")];
331     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
332     [o_mi_teletext_index setTitle: _NS("Index")];
333     [o_mi_teletext_red setTitle: _NS("Red")];
334     [o_mi_teletext_green setTitle: _NS("Green")];
335     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
336     [o_mi_teletext_blue setTitle: _NS("Blue")];
337
338     [o_mu_window setTitle: _NS("Window")];
339     [o_mi_minimize setTitle: _NS("Minimize Window")];
340     [o_mi_close_window setTitle: _NS("Close Window")];
341     [o_mi_player setTitle: _NS("Player...")];
342     [o_mi_controller setTitle: _NS("Main Window...")];
343     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
344     [o_mi_videoeffects setTitle: _NS("Video Filters...")];
345     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
346     [o_mi_playlist setTitle: _NS("Playlist...")];
347     [o_mi_info setTitle: _NS("Media Information...")];
348     [o_mi_messages setTitle: _NS("Messages...")];
349     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
350
351     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
352
353     [o_mu_help setTitle: _NS("Help")];
354     [o_mi_help setTitle: _NS("VLC media player Help...")];
355     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
356     [o_mi_license setTitle: _NS("License")];
357     [o_mi_documentation setTitle: _NS("Online Documentation...")];
358     [o_mi_website setTitle: _NS("VideoLAN Website...")];
359     [o_mi_donation setTitle: _NS("Make a donation...")];
360     [o_mi_forum setTitle: _NS("Online Forum...")];
361
362     /* dock menu */
363     [o_dmi_play setTitle: _NS("Play")];
364     [o_dmi_stop setTitle: _NS("Stop")];
365     [o_dmi_next setTitle: _NS("Next")];
366     [o_dmi_previous setTitle: _NS("Previous")];
367     [o_dmi_mute setTitle: _NS("Mute")];
368
369     /* vout menu */
370     [o_vmi_play setTitle: _NS("Play")];
371     [o_vmi_stop setTitle: _NS("Stop")];
372     [o_vmi_prev setTitle: _NS("Previous")];
373     [o_vmi_next setTitle: _NS("Next")];
374     [o_vmi_volup setTitle: _NS("Volume Up")];
375     [o_vmi_voldown setTitle: _NS("Volume Down")];
376     [o_vmi_mute setTitle: _NS("Mute")];
377     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
378     [o_vmi_snapshot setTitle: _NS("Snapshot")];
379 }
380
381 #pragma mark -
382 #pragma mark Termination
383
384 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
385 {
386     if( !p_intf ) return;
387
388     NSArray *menuitems_array = [the_menu itemArray];
389     NSUInteger menuItemCount = [menuitems_array count];
390     for( NSUInteger i=0; i < menuItemCount; i++ )
391     {
392         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
393         if( [one_item hasSubmenu] )
394             [self releaseRepresentedObjects: [one_item submenu]];
395
396         [one_item setRepresentedObject:NULL];
397     }
398 }
399
400 #pragma mark -
401 #pragma mark Interface update
402
403 - (void)setupMenus
404 {
405     playlist_t * p_playlist = pl_Get( p_intf );
406     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
407     if( p_input != NULL )
408     {
409         [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
410
411         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
412                                  var: "program" selector: @selector(toggleVar:)];
413
414         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
415                                  var: "title" selector: @selector(toggleVar:)];
416
417         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
418                                  var: "chapter" selector: @selector(toggleVar:)];
419
420         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
421                                  var: "audio-es" selector: @selector(toggleVar:)];
422
423         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
424                                  var: "video-es" selector: @selector(toggleVar:)];
425
426         [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
427                                  var: "spu-es" selector: @selector(toggleVar:)];
428
429         /* special case for "Open File" inside the subtitles menu item */
430         if( [o_mi_videotrack isEnabled] == YES )
431             [o_mi_subtitle setEnabled: YES];
432
433         audio_output_t * p_aout = input_GetAout( p_input );
434         if( p_aout != NULL )
435         {
436             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
437                                      var: "audio-channels" selector: @selector(toggleVar:)];
438
439             [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
440                                      var: "audio-device" selector: @selector(toggleVar:)];
441
442             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
443                                      var: "visual" selector: @selector(toggleVar:)];
444             vlc_object_release( (vlc_object_t *)p_aout );
445         }
446
447         vout_thread_t * p_vout = input_GetVout( p_input );
448
449         if( p_vout != NULL )
450         {
451             vlc_object_t * p_dec_obj;
452
453             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
454                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
455
456             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
457                                      var: "crop" selector: @selector(toggleVar:)];
458
459             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
460                                      var: "deinterlace" selector: @selector(toggleVar:)];
461
462             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
463                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
464
465 #if 1
466             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
467              (vlc_object_t *)p_vout var:"postprocess" selector:
468              @selector(toggleVar:)];
469 #endif
470             vlc_object_release( (vlc_object_t *)p_vout );
471
472             [self refreshVoutDeviceMenu:nil];
473             [self setSubmenusEnabled: YES];
474         }
475         vlc_object_release( p_input );
476     }
477     else
478     {
479         [o_mi_record setEnabled: NO];
480     }
481 }
482
483 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
484 {
485     NSUInteger count = [o_mu_screen numberOfItems];
486     NSMenu * o_submenu = o_mu_screen;
487     if (count > 0)
488     {
489         if (OSX_LEOPARD)
490         {
491             NSUInteger count = [o_submenu numberOfItems];
492             for( NSUInteger i = 0; i < count; i++ )
493                 [o_submenu removeItemAtIndex: 0];
494         }
495         else
496             [o_submenu removeAllItems];
497     }
498
499     NSArray * o_screens = [NSScreen screens];
500     NSMenuItem * o_mitem;
501     count = [o_screens count];
502     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
503     o_mitem = [o_submenu itemAtIndex: 0];
504     [o_mitem setTag: 0];
505     [o_mitem setEnabled: YES];
506     [o_mitem setTarget: self];
507     NSRect s_rect;
508     for (NSUInteger i = 0; i < count; i++)
509     {
510         s_rect = [[o_screens objectAtIndex: i] frame];
511         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %i (%ix%i)", _NS("Screen"), i+1,
512                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
513         o_mitem = [o_submenu itemAtIndex:i+1];
514         [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
515         [o_mitem setEnabled: YES];
516         [o_mitem setTarget: self];
517     }
518     [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
519 }
520
521 - (void)setSubmenusEnabled:(BOOL)b_enabled
522 {
523     [o_mi_program setEnabled: b_enabled];
524     [o_mi_title setEnabled: b_enabled];
525     [o_mi_chapter setEnabled: b_enabled];
526     [o_mi_audiotrack setEnabled: b_enabled];
527     [o_mi_visual setEnabled: b_enabled];
528     [o_mi_videotrack setEnabled: b_enabled];
529     [o_mi_subtitle setEnabled: b_enabled];
530     [o_mi_channels setEnabled: b_enabled];
531     [o_mi_deinterlace setEnabled: b_enabled];
532     [o_mi_deinterlace_mode setEnabled: b_enabled];
533     [o_mi_ffmpeg_pp setEnabled: b_enabled];
534     [o_mi_device setEnabled: b_enabled];
535     [o_mi_screen setEnabled: b_enabled];
536     [o_mi_aspect_ratio setEnabled: b_enabled];
537     [o_mi_crop setEnabled: b_enabled];
538     [o_mi_teletext setEnabled: b_enabled];
539 }
540
541 - (void)setRateControlsEnabled:(BOOL)b_enabled
542 {
543     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
544     [o_mi_rate_sld setEnabled: b_enabled];
545     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
546     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
547     double speed =  pow( 2, (double)i / 17 );
548     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
549     if (b_enabled) {
550         [o_mi_rate_lbl setHidden: NO];
551         [o_mi_rate_lbl_gray setHidden: YES];
552     }
553     else
554     {
555         [o_mi_rate_lbl setHidden: YES];
556         [o_mi_rate_lbl_gray setHidden: NO];
557     }
558     [o_pool release];
559 }
560
561 #pragma mark -
562 #pragma mark Extensions
563
564 - (void)setupExtensionsMenu
565 {
566     /* Load extensions if needed */
567     // TODO: Implement preference for autoloading extensions on mac
568
569     // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
570     //     && ![o_extMgr isLoaded] )
571     // {
572     //     return;
573     // }
574
575     if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
576     {
577         [o_extMgr loadExtensions];
578     }
579
580     /* Let the ExtensionsManager itself build the menu */
581     [o_extMgr buildMenu:o_mu_extensions];
582 }
583
584 #pragma mark -
585 #pragma mark Playback
586 - (IBAction)toggleRecord:(id)sender
587 {
588     [[VLCCoreInteraction sharedInstance] toggleRecord];
589 }
590
591 - (void)updateRecordState:(BOOL)b_value
592 {
593     [o_mi_record setState:b_value];
594 }
595
596 - (IBAction)setPlaybackRate:(id)sender
597 {
598     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
599     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
600     double speed =  pow( 2, (double)i / 17 );
601     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
602 }
603
604 - (void)updatePlaybackRate
605 {
606     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
607     double speed =  pow( 2, (double)i / 17 );
608     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
609     [o_mi_rate_sld setIntValue: i];
610 }
611
612 #pragma mark -
613 #pragma video menu
614 - (IBAction)toggleFullscreen:(id)sender
615 {
616     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
617 }
618
619 - (IBAction)resizeVideoWindow:(id)sender
620 {
621     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
622     if (p_input)
623     {
624         vout_thread_t *p_vout = getVout();
625         if (p_vout)
626         {
627             if (sender == o_mi_half_window)
628                 var_SetFloat( p_vout, "zoom", 0.5 );
629             else if (sender == o_mi_normal_window)
630                 var_SetFloat( p_vout, "zoom", 1.0 );
631             else if (sender == o_mi_double_window)
632                 var_SetFloat( p_vout, "zoom", 2.0 );
633             else
634             {
635                 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
636             }
637             vlc_object_release( p_vout );
638         }
639         vlc_object_release( p_input );
640     }
641 }
642
643 - (IBAction)floatOnTop:(id)sender
644 {
645     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
646     if (p_input)
647     {
648         vout_thread_t *p_vout = getVout();
649         if (p_vout)
650         {
651             var_ToggleBool( p_vout, "video-on-top" );
652             vlc_object_release( p_vout );
653         }
654         vlc_object_release( p_input );
655     }
656 }
657
658 - (IBAction)createVideoSnapshot:(id)sender
659 {
660     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
661     if (p_input)
662     {
663         vout_thread_t *p_vout = getVout();
664         if (p_vout)
665         {
666             var_TriggerCallback( p_vout, "video-snapshot" );
667             vlc_object_release( p_vout );
668         }
669         vlc_object_release( p_input );
670     }
671 }
672
673 - (IBAction)toggleFullscreenDevice:(id)sender
674 {
675     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
676     [self refreshVoutDeviceMenu: nil];
677 }
678
679 - (id)voutMenu
680 {
681     return o_vout_menu;
682 }
683
684 #pragma mark -
685 #pragma mark Panels
686
687 - (IBAction)intfOpenFile:(id)sender
688 {
689     [[[VLCMain sharedInstance] open] openFile];
690 }
691
692 - (IBAction)intfOpenFileGeneric:(id)sender
693 {
694     [[[VLCMain sharedInstance] open] openFileGeneric];
695 }
696
697 - (IBAction)intfOpenDisc:(id)sender
698 {
699     [[[VLCMain sharedInstance] open] openDisc];
700 }
701
702 - (IBAction)intfOpenNet:(id)sender
703 {
704     [[[VLCMain sharedInstance] open] openNet];
705 }
706
707 - (IBAction)intfOpenCapture:(id)sender
708 {
709     [[[VLCMain sharedInstance] open] openCapture];
710 }
711
712 - (IBAction)showWizard:(id)sender
713 {
714     [[[VLCMain sharedInstance] wizard] resetWizard];
715     [[[VLCMain sharedInstance] wizard] showWizard];
716 }
717
718 - (IBAction)showVideoEffects:(id)sender
719 {
720     if( o_videoeffects == nil )
721         o_videoeffects = [[VLCVideoEffects alloc] init];
722
723     if( !b_nib_videoeffects_loaded )
724         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
725
726     [o_videoeffects toggleWindow:sender];
727 }
728
729 - (IBAction)showTrackSynchronization:(id)sender
730 {
731     if (!o_trackSynchronization)
732         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
733
734     if (!b_nib_tracksynchro_loaded)
735         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
736
737     [o_trackSynchronization toggleWindow:sender];
738 }
739
740 - (IBAction)showAudioEffects:(id)sender
741 {
742     if (!o_audioeffects)
743         o_audioeffects = [[VLCAudioEffects alloc] init];
744
745     if (!b_nib_audioeffects_loaded)
746         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
747
748     [o_audioeffects toggleWindow:sender];
749 }
750
751 - (IBAction)showBookmarks:(id)sender
752 {
753     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
754 }
755
756 - (IBAction)viewPreferences:(id)sender
757 {
758     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
759 }
760
761 #pragma mark -
762 #pragma mark Help and Docs
763
764 - (void)initAbout
765 {
766     if(! o_about )
767         o_about = [[VLAboutBox alloc] init];
768
769     if( !b_nib_about_loaded )
770         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
771 }
772
773 - (IBAction)viewAbout:(id)sender
774 {
775     [self initAbout];
776     [o_about showAbout];
777 }
778
779 - (IBAction)showLicense:(id)sender
780 {
781     [self initAbout];
782     [o_about showGPL: sender];
783 }
784
785 - (IBAction)viewHelp:(id)sender
786 {
787     [self initAbout];
788     [o_about showHelp];
789 }
790
791 - (IBAction)openReadMe:(id)sender
792 {
793     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
794
795     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
796 }
797
798 - (IBAction)openDocumentation:(id)sender
799 {
800     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
801
802     [[NSWorkspace sharedWorkspace] openURL: o_url];
803 }
804
805 - (IBAction)openWebsite:(id)sender
806 {
807     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
808
809     [[NSWorkspace sharedWorkspace] openURL: o_url];
810 }
811
812 - (IBAction)openForum:(id)sender
813 {
814     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
815
816     [[NSWorkspace sharedWorkspace] openURL: o_url];
817 }
818
819 - (IBAction)openDonate:(id)sender
820 {
821     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
822
823     [[NSWorkspace sharedWorkspace] openURL: o_url];
824 }
825
826 #pragma mark -
827 #pragma mark Errors, warnings and messages
828
829 - (IBAction)viewErrorsAndWarnings:(id)sender
830 {
831     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
832 }
833
834 - (IBAction)showInformationPanel:(id)sender
835 {
836     [[[VLCMain sharedInstance] info] initPanel];
837 }
838
839 #pragma mark -
840 #pragma mark convinience stuff for other objects
841 - (void)setPlay
842 {
843     [o_mi_play setTitle: _NS("Play")];
844     [o_dmi_play setTitle: _NS("Play")];
845     [o_vmi_play setTitle: _NS("Play")];
846 }
847
848 - (void)setPause
849 {
850     [o_mi_play setTitle: _NS("Pause")];
851     [o_dmi_play setTitle: _NS("Pause")];
852     [o_vmi_play setTitle: _NS("Pause")];
853 }
854
855 - (void)setRepeatOne
856 {
857     [o_mi_repeat setState: NSOnState];
858     [o_mi_loop setState: NSOffState];
859 }
860
861 - (void)setRepeatAll
862 {
863     [o_mi_repeat setState: NSOffState];
864     [o_mi_loop setState: NSOnState];
865 }
866
867 - (void)setRepeatOff
868 {
869     [o_mi_repeat setState: NSOffState];
870     [o_mi_loop setState: NSOffState];
871 }
872
873 - (void)setShuffle
874 {
875     bool b_value;
876     playlist_t *p_playlist = pl_Get( VLCIntf );
877     b_value = var_GetBool( p_playlist, "random" );
878
879     [o_mi_random setState: b_value];
880 }
881
882 #pragma mark -
883 #pragma mark Dynamic menu creation and validation
884
885 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
886                   target:(vlc_object_t *)p_object
887                      var:(const char *)psz_variable
888                 selector:(SEL)pf_callback
889 {
890     vlc_value_t val, text;
891     int i_type = var_Type( p_object, psz_variable );
892
893     switch( i_type & VLC_VAR_TYPE )
894     {
895         case VLC_VAR_VOID:
896         case VLC_VAR_BOOL:
897         case VLC_VAR_VARIABLE:
898         case VLC_VAR_STRING:
899         case VLC_VAR_INTEGER:
900             break;
901         default:
902             /* Variable doesn't exist or isn't handled */
903             return;
904     }
905
906     /* Make sure we want to display the variable
907      * special case for spu-es, which we want to display in any case */
908     if( i_type & VLC_VAR_HASCHOICE && strcmp( psz_variable, "spu-es" ) )
909     {
910         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
911         if( val.i_int == 0 )
912             return;
913         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
914             return;
915     }
916
917     /* Get the descriptive name of the variable */
918     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
919     [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
920
921     if( i_type & VLC_VAR_HASCHOICE )
922     {
923         NSMenu *o_menu = [o_mi submenu];
924
925         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
926                        var:psz_variable selector:pf_callback];
927
928         free( text.psz_string );
929         return;
930     }
931
932     if( var_Get( p_object, psz_variable, &val ) < 0 )
933     {
934         return;
935     }
936
937     VLCAutoGeneratedMenuContent *o_data;
938     switch( i_type & VLC_VAR_TYPE )
939     {
940         case VLC_VAR_VOID:
941             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
942                                                                       andValue: val ofType: i_type];
943             [o_mi setRepresentedObject: [o_data autorelease]];
944             break;
945
946         case VLC_VAR_BOOL:
947             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
948                                                                       andValue: val ofType: i_type];
949             [o_mi setRepresentedObject: [o_data autorelease]];
950             if( !( i_type & VLC_VAR_ISCOMMAND ) )
951                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
952             break;
953
954         default:
955             break;
956     }
957
958     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
959     free( text.psz_string );
960 }
961
962
963 - (void)setupVarMenu:(NSMenu *)o_menu
964          forMenuItem: (NSMenuItem *)o_parent
965               target:(vlc_object_t *)p_object
966                  var:(const char *)psz_variable
967             selector:(SEL)pf_callback
968 {
969     vlc_value_t val, val_list, text_list;
970     int i_type, i;
971
972     /* remove previous items */
973     if (OSX_LEOPARD)
974     {
975         int i_nb_items;
976         i_nb_items = [o_menu numberOfItems];
977         for( i = 0; i < i_nb_items; i++ )
978             [o_menu removeItemAtIndex: 0];
979     }
980     else
981     {
982         /* this is more efficient then the legacy code, but 10.6+ only */
983         [o_menu removeAllItems];
984     }
985
986     /* Aspect Ratio */
987     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
988     {
989         NSMenuItem *o_lmi_tmp2;
990         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
991         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
992         [o_lmi_tmp2 setEnabled: YES];
993         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
994         [o_parent setEnabled: YES];
995         [o_menu addItem: [NSMenuItem separatorItem]];
996     }
997
998     /* special case for the subtitles item */
999     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1000     {
1001         NSMenuItem * o_lmi_tmp;
1002         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1003         [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1004         [o_lmi_tmp setEnabled: YES];
1005         [o_parent setEnabled: YES];
1006     }
1007
1008     /* Check the type of the object variable */
1009     i_type = var_Type( p_object, psz_variable );
1010
1011     /* Make sure we want to display the variable */
1012     if( i_type & VLC_VAR_HASCHOICE )
1013     {
1014         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1015         if( val.i_int == 0 ) return;
1016         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1017             return;
1018     }
1019     else
1020         return;
1021
1022     switch( i_type & VLC_VAR_TYPE )
1023     {
1024         case VLC_VAR_VOID:
1025         case VLC_VAR_BOOL:
1026         case VLC_VAR_VARIABLE:
1027         case VLC_VAR_STRING:
1028         case VLC_VAR_INTEGER:
1029             break;
1030         default:
1031             /* Variable doesn't exist or isn't handled */
1032             return;
1033     }
1034
1035     if( var_Get( p_object, psz_variable, &val ) < 0 )
1036     {
1037         return;
1038     }
1039
1040     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1041                    &val_list, &text_list ) < 0 )
1042     {
1043         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1044         return;
1045     }
1046
1047     /* make (un)sensitive */
1048     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1049
1050     /* another special case for the subtitles item */
1051     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1052         [o_menu addItem: [NSMenuItem separatorItem]];
1053
1054     for( i = 0; i < val_list.p_list->i_count; i++ )
1055     {
1056         NSMenuItem * o_lmi;
1057         NSString *o_title = @"";
1058         VLCAutoGeneratedMenuContent *o_data;
1059
1060         switch( i_type & VLC_VAR_TYPE )
1061         {
1062             case VLC_VAR_STRING:
1063
1064                 o_title = _NS( text_list.p_list->p_values[i].psz_string ? text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string );
1065
1066                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1067                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1068                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1069                 [o_lmi setRepresentedObject: [o_data autorelease]];
1070                 [o_lmi setTarget: self];
1071
1072                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1073                     [o_lmi setState: TRUE ];
1074
1075                 break;
1076
1077             case VLC_VAR_INTEGER:
1078
1079                 o_title = text_list.p_list->p_values[i].psz_string ?
1080                 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1081
1082                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1083                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1084                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1085                 [o_lmi setRepresentedObject: [o_data autorelease]];
1086                 [o_lmi setTarget: self];
1087
1088                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1089                     [o_lmi setState: TRUE ];
1090                 break;
1091
1092             default:
1093                 break;
1094         }
1095     }
1096
1097     /* special case for the subtitles sub-menu
1098      * In case that we don't have any subs, we don't want a separator item at the end */
1099     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1100     {
1101         if( [o_menu numberOfItems] == 2 )
1102             [o_menu removeItemAtIndex: 1];
1103     }
1104
1105     /* clean up everything */
1106     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1107     var_FreeList( &val_list, &text_list );
1108 }
1109
1110 - (IBAction)toggleVar:(id)sender
1111 {
1112     NSMenuItem *o_mi = (NSMenuItem *)sender;
1113     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1114     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1115                              toTarget: self withObject: o_data];
1116
1117     return;
1118 }
1119
1120 - (int)toggleVarThread: (id)data
1121 {
1122     vlc_object_t *p_object;
1123     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1124
1125     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1126     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1127
1128     /* Preserve settings across vouts via the playlist object: */
1129     if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1130         var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1131
1132     /* save our audio device across multiple sessions */
1133     if( !strcmp( [menuContent name], "audio-device" ) )
1134         config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1135
1136     p_object = [menuContent vlcObject];
1137
1138     if( p_object != NULL )
1139     {
1140         var_Set( p_object, [menuContent name], [menuContent value] );
1141         vlc_object_release( p_object );
1142         [o_pool release];
1143         return true;
1144     }
1145     [o_pool release];
1146     return VLC_EGENERIC;
1147 }
1148
1149 @end
1150
1151 @implementation VLCMainMenu (NSMenuValidation)
1152
1153 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1154 {
1155     NSString *o_title = [o_mi title];
1156     BOOL bEnabled = TRUE;
1157     vlc_value_t val;
1158     playlist_t * p_playlist = pl_Get( p_intf );
1159     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1160
1161     if( [o_title isEqualToString: _NS("Stop")] )
1162     {
1163         if( p_input == NULL )
1164         {
1165             bEnabled = FALSE;
1166         }
1167         [self setupMenus]; /* Make sure input menu is up to date */
1168     }
1169     else if( [o_title isEqualToString: _NS("Previous")] ||
1170             [o_title isEqualToString: _NS("Next")] )
1171     {
1172         PL_LOCK;
1173         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1174         PL_UNLOCK;
1175     }
1176     else if( [o_title isEqualToString: _NS("Random")] )
1177     {
1178         int i_state;
1179         var_Get( p_playlist, "random", &val );
1180         i_state = val.b_bool ? NSOnState : NSOffState;
1181         [o_mi setState: i_state];
1182     }
1183     else if( [o_title isEqualToString: _NS("Repeat One")] )
1184     {
1185         int i_state;
1186         var_Get( p_playlist, "repeat", &val );
1187         i_state = val.b_bool ? NSOnState : NSOffState;
1188         [o_mi setState: i_state];
1189     }
1190     else if( [o_title isEqualToString: _NS("Repeat All")] )
1191     {
1192         int i_state;
1193         var_Get( p_playlist, "loop", &val );
1194         i_state = val.b_bool ? NSOnState : NSOffState;
1195         [o_mi setState: i_state];
1196     }
1197     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1198     {
1199         int i_state;
1200         var_Get( p_playlist, "play-and-exit", &val );
1201         i_state = val.b_bool ? NSOnState : NSOffState;
1202         [o_mi setState: i_state];
1203     }
1204     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1205             [o_title isEqualToString: _NS("Step Backward")] ||
1206             [o_title isEqualToString: _NS("Jump To Time")])
1207     {
1208         if( p_input != NULL )
1209         {
1210             var_Get( p_input, "can-seek", &val);
1211             bEnabled = val.b_bool;
1212         }
1213         else bEnabled = FALSE;
1214     }
1215     else if( [o_title isEqualToString: _NS("Mute")] )
1216     {
1217         [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1218         [self setupMenus]; /* Make sure audio menu is up to date */
1219     }
1220     else if( [o_title isEqualToString: _NS("Half Size")] ||
1221             [o_title isEqualToString: _NS("Normal Size")] ||
1222             [o_title isEqualToString: _NS("Double Size")] ||
1223             [o_title isEqualToString: _NS("Fit to Screen")] ||
1224             [o_title isEqualToString: _NS("Snapshot")] ||
1225             [o_title isEqualToString: _NS("Fullscreen")] ||
1226             [o_title isEqualToString: _NS("Float on Top")] )
1227     {
1228         bEnabled = FALSE;
1229
1230         if( p_input != NULL )
1231         {
1232             vout_thread_t *p_vout = input_GetVout( p_input );
1233             if( p_vout != NULL )
1234             {
1235                 if( [o_title isEqualToString: _NS("Float on Top")] )
1236                 {
1237                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1238                 }
1239
1240                 bEnabled = TRUE;
1241
1242                 vlc_object_release( (vlc_object_t *)p_vout );
1243             }
1244         }
1245         if( [o_title isEqualToString: _NS("Fullscreen")] )
1246         {
1247         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1248             bEnabled = TRUE;
1249         }
1250         [self setupMenus]; /* Make sure video menu is up to date */
1251     }
1252
1253     /* Special case for telx menu */
1254     if( [o_title isEqualToString: _NS("Normal Size")] )
1255     {
1256         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1257
1258
1259 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1260
1261         [[item submenu] setAutoenablesItems:NO];
1262         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1263         {
1264             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1265         }
1266     }
1267
1268     if( p_input ) vlc_object_release( p_input );
1269
1270     return( bEnabled );
1271 }
1272
1273 @end
1274
1275
1276 /*****************************************************************************
1277  * VLCAutoGeneratedMenuContent implementation
1278  *****************************************************************************
1279  * Object connected to a playlistitem which remembers the data belonging to
1280  * the variable of the autogenerated menu
1281  *****************************************************************************/
1282 @implementation VLCAutoGeneratedMenuContent
1283
1284 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1285                   andValue:(vlc_value_t)val ofType:(int)type
1286 {
1287     self = [super init];
1288
1289     if( self != nil )
1290     {
1291         _vlc_object = vlc_object_hold( object );
1292         psz_name = strdup( name );
1293         i_type = type;
1294         value = val;
1295         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1296             value.psz_string = strdup( val.psz_string );
1297     }
1298
1299     return( self );
1300 }
1301
1302 - (void)dealloc
1303 {
1304     vlc_object_release( _vlc_object );
1305     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1306         free( value.psz_string );
1307     free( psz_name );
1308     [super dealloc];
1309 }
1310
1311 - (const char *)name
1312 {
1313     return psz_name;
1314 }
1315
1316 - (vlc_value_t)value
1317 {
1318     return value;
1319 }
1320
1321 - (vlc_object_t *)vlcObject
1322 {
1323     return vlc_object_hold( _vlc_object );
1324 }
1325
1326
1327 - (int)type
1328 {
1329     return i_type;
1330 }
1331
1332 @end