macosx: Add extensions menu entry
[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_add_intf setTitle: _NS("Add Interface")];
240     [o_mu_add_intf setTitle: _NS("Add Interface")];
241     [o_mi_services setTitle: _NS("Services")];
242     [o_mi_hide setTitle: _NS("Hide VLC")];
243     [o_mi_hide_others setTitle: _NS("Hide Others")];
244     [o_mi_show_all setTitle: _NS("Show All")];
245     [o_mi_quit setTitle: _NS("Quit VLC")];
246
247     [o_mu_file setTitle: _ANS("1:File")];
248     [o_mi_open_generic setTitle: _NS("Advanced Open File...")];
249     [o_mi_open_file setTitle: _NS("Open File...")];
250     [o_mi_open_disc setTitle: _NS("Open Disc...")];
251     [o_mi_open_net setTitle: _NS("Open Network...")];
252     [o_mi_open_capture setTitle: _NS("Open Capture Device...")];
253     [o_mi_open_recent setTitle: _NS("Open Recent")];
254     [o_mi_open_wizard setTitle: _NS("Streaming/Exporting Wizard...")];
255
256     [o_mu_edit setTitle: _NS("Edit")];
257     [o_mi_cut setTitle: _NS("Cut")];
258     [o_mi_copy setTitle: _NS("Copy")];
259     [o_mi_paste setTitle: _NS("Paste")];
260     [o_mi_clear setTitle: _NS("Clear")];
261     [o_mi_select_all setTitle: _NS("Select All")];
262
263     [o_mu_extensions setTitle: _NS("Extensions")];
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     if (i == 0)
548         i = 1;
549     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
550     if (b_enabled) {
551         [o_mi_rate_lbl setHidden: NO];
552         [o_mi_rate_lbl_gray setHidden: YES];
553     }
554     else
555     {
556         [o_mi_rate_lbl setHidden: YES];
557         [o_mi_rate_lbl_gray setHidden: NO];
558     }
559     [o_pool release];
560 }
561
562 #pragma mark -
563 #pragma mark Extensions
564
565 - (void)setupExtensionsMenu
566 {
567     /* Load extensions if needed */
568     // TODO: Implement preference for autoloading extensions on mac
569
570     // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
571     //     && ![o_extMgr isLoaded] )
572     // {
573     //     return;
574     // }
575
576     if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
577     {
578         [o_extMgr loadExtensions];
579     }
580
581     /* Let the ExtensionsManager itself build the menu */
582     [o_extMgr buildMenu:o_mu_extensions];
583 }
584
585 #pragma mark -
586 #pragma mark Playback
587 - (IBAction)toggleRecord:(id)sender
588 {
589     [[VLCCoreInteraction sharedInstance] toggleRecord];
590 }
591
592 - (void)updateRecordState:(BOOL)b_value
593 {
594     [o_mi_record setState:b_value];
595 }
596
597 - (IBAction)setPlaybackRate:(id)sender
598 {
599     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
600     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
601     if (i == 0)
602         i = 1;
603     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
604 }
605
606 - (void)updatePlaybackRate
607 {
608     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
609     if (i == 0)
610         i = 1;
611     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
612     [o_mi_rate_sld setIntValue: i];
613 }
614
615 #pragma mark -
616 #pragma video menu
617 - (IBAction)toggleFullscreen:(id)sender
618 {
619     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
620 }
621
622 - (IBAction)resizeVideoWindow:(id)sender
623 {
624     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
625     if (p_input)
626     {
627         vout_thread_t *p_vout = getVout();
628         if (p_vout)
629         {
630             if (sender == o_mi_half_window)
631                 var_SetFloat( p_vout, "zoom", 0.5 );
632             else if (sender == o_mi_normal_window)
633                 var_SetFloat( p_vout, "zoom", 1.0 );
634             else if (sender == o_mi_double_window)
635                 var_SetFloat( p_vout, "zoom", 2.0 );
636             else
637             {
638                 var_ToggleBool( p_vout, "autoscale" );
639             }
640             vlc_object_release( p_vout );
641         }
642         vlc_object_release( p_input );
643     }
644 }
645
646 - (IBAction)floatOnTop:(id)sender
647 {
648     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
649     if (p_input)
650     {
651         vout_thread_t *p_vout = getVout();
652         if (p_vout)
653         {
654             var_ToggleBool( p_vout, "video-on-top" );
655             vlc_object_release( p_vout );
656         }
657         vlc_object_release( p_input );
658     }
659 }
660
661 - (IBAction)createVideoSnapshot:(id)sender
662 {
663     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
664     if (p_input)
665     {
666         vout_thread_t *p_vout = getVout();
667         if (p_vout)
668         {
669             var_TriggerCallback( p_vout, "video-snapshot" );
670             vlc_object_release( p_vout );
671         }
672         vlc_object_release( p_input );
673     }
674 }
675
676 - (IBAction)toggleFullscreenDevice:(id)sender
677 {
678     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
679     [self refreshVoutDeviceMenu: nil];
680 }
681
682 - (id)voutMenu
683 {
684     return o_vout_menu;
685 }
686
687 #pragma mark -
688 #pragma mark Panels
689
690 - (IBAction)intfOpenFile:(id)sender
691 {
692     [[[VLCMain sharedInstance] open] openFile];
693 }
694
695 - (IBAction)intfOpenFileGeneric:(id)sender
696 {
697     [[[VLCMain sharedInstance] open] openFileGeneric];
698 }
699
700 - (IBAction)intfOpenDisc:(id)sender
701 {
702     [[[VLCMain sharedInstance] open] openDisc];
703 }
704
705 - (IBAction)intfOpenNet:(id)sender
706 {
707     [[[VLCMain sharedInstance] open] openNet];
708 }
709
710 - (IBAction)intfOpenCapture:(id)sender
711 {
712     [[[VLCMain sharedInstance] open] openCapture];
713 }
714
715 - (IBAction)showWizard:(id)sender
716 {
717     [[[VLCMain sharedInstance] wizard] resetWizard];
718     [[[VLCMain sharedInstance] wizard] showWizard];
719 }
720
721 - (IBAction)showVideoEffects:(id)sender
722 {
723     if( o_videoeffects == nil )
724         o_videoeffects = [[VLCVideoEffects alloc] init];
725
726     if( !b_nib_videoeffects_loaded )
727         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
728
729     [o_videoeffects toggleWindow:sender];
730 }
731
732 - (IBAction)showTrackSynchronization:(id)sender
733 {
734     if (!o_trackSynchronization)
735         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
736
737     if (!b_nib_tracksynchro_loaded)
738         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
739
740     [o_trackSynchronization toggleWindow:sender];
741 }
742
743 - (IBAction)showAudioEffects:(id)sender
744 {
745     if (!o_audioeffects)
746         o_audioeffects = [[VLCAudioEffects alloc] init];
747
748     if (!b_nib_audioeffects_loaded)
749         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
750
751     [o_audioeffects toggleWindow:sender];
752 }
753
754 - (IBAction)showBookmarks:(id)sender
755 {
756     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
757 }
758
759 - (IBAction)viewPreferences:(id)sender
760 {
761     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
762 }
763
764 #pragma mark -
765 #pragma mark Help and Docs
766
767 - (void)initAbout
768 {
769     if(! o_about )
770         o_about = [[VLAboutBox alloc] init];
771
772     if( !b_nib_about_loaded )
773         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
774 }
775
776 - (IBAction)viewAbout:(id)sender
777 {
778     [self initAbout];
779     [o_about showAbout];
780 }
781
782 - (IBAction)showLicense:(id)sender
783 {
784     [self initAbout];
785     [o_about showGPL: sender];
786 }
787
788 - (IBAction)viewHelp:(id)sender
789 {
790     [self initAbout];
791     [o_about showHelp];
792 }
793
794 - (IBAction)openReadMe:(id)sender
795 {
796     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
797
798     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
799 }
800
801 - (IBAction)openDocumentation:(id)sender
802 {
803     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
804
805     [[NSWorkspace sharedWorkspace] openURL: o_url];
806 }
807
808 - (IBAction)openWebsite:(id)sender
809 {
810     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
811
812     [[NSWorkspace sharedWorkspace] openURL: o_url];
813 }
814
815 - (IBAction)openForum:(id)sender
816 {
817     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
818
819     [[NSWorkspace sharedWorkspace] openURL: o_url];
820 }
821
822 - (IBAction)openDonate:(id)sender
823 {
824     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
825
826     [[NSWorkspace sharedWorkspace] openURL: o_url];
827 }
828
829 #pragma mark -
830 #pragma mark Errors, warnings and messages
831
832 - (IBAction)viewErrorsAndWarnings:(id)sender
833 {
834     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
835 }
836
837 - (IBAction)showInformationPanel:(id)sender
838 {
839     [[[VLCMain sharedInstance] info] initPanel];
840 }
841
842 #pragma mark -
843 #pragma mark convinience stuff for other objects
844 - (void)setPlay
845 {
846     [o_mi_play setTitle: _NS("Play")];
847     [o_dmi_play setTitle: _NS("Play")];
848     [o_vmi_play setTitle: _NS("Play")];
849 }
850
851 - (void)setPause
852 {
853     [o_mi_play setTitle: _NS("Pause")];
854     [o_dmi_play setTitle: _NS("Pause")];
855     [o_vmi_play setTitle: _NS("Pause")];
856 }
857
858 - (void)setRepeatOne
859 {
860     [o_mi_repeat setState: NSOnState];
861     [o_mi_loop setState: NSOffState];
862 }
863
864 - (void)setRepeatAll
865 {
866     [o_mi_repeat setState: NSOffState];
867     [o_mi_loop setState: NSOnState];
868 }
869
870 - (void)setRepeatOff
871 {
872     [o_mi_repeat setState: NSOffState];
873     [o_mi_loop setState: NSOffState];
874 }
875
876 - (void)setShuffle
877 {
878     bool b_value;
879     playlist_t *p_playlist = pl_Get( VLCIntf );
880     b_value = var_GetBool( p_playlist, "random" );
881         [o_mi_random setState: b_value];
882 }
883
884 #pragma mark -
885 #pragma mark Dynamic menu creation and validation
886
887 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
888                   target:(vlc_object_t *)p_object
889                      var:(const char *)psz_variable
890                 selector:(SEL)pf_callback
891 {
892     vlc_value_t val, text;
893     int i_type = var_Type( p_object, psz_variable );
894
895     switch( i_type & VLC_VAR_TYPE )
896     {
897         case VLC_VAR_VOID:
898         case VLC_VAR_BOOL:
899         case VLC_VAR_VARIABLE:
900         case VLC_VAR_STRING:
901         case VLC_VAR_INTEGER:
902             break;
903         default:
904             /* Variable doesn't exist or isn't handled */
905             return;
906     }
907
908     /* Make sure we want to display the variable */
909     if( i_type & VLC_VAR_HASCHOICE )
910     {
911         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
912         if( val.i_int == 0 ) return;
913         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
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: [[VLCMain sharedInstance] localizedString: text.psz_string ?
920                      text.psz_string : psz_variable ]];
921
922     if( i_type & VLC_VAR_HASCHOICE )
923     {
924         NSMenu *o_menu = [o_mi submenu];
925         
926         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
927                        var:psz_variable selector:pf_callback];
928         
929         free( text.psz_string );
930         return;
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     /* Check the type of the object variable */
987     i_type = var_Type( p_object, psz_variable );
988
989     /* Make sure we want to display the variable */
990     if( i_type & VLC_VAR_HASCHOICE )
991     {
992         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
993         if( val.i_int == 0 ) return;
994         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
995             return;
996     }
997     else
998         return;
999
1000     switch( i_type & VLC_VAR_TYPE )
1001     {
1002         case VLC_VAR_VOID:
1003         case VLC_VAR_BOOL:
1004         case VLC_VAR_VARIABLE:
1005         case VLC_VAR_STRING:
1006         case VLC_VAR_INTEGER:
1007             break;
1008         default:
1009             /* Variable doesn't exist or isn't handled */
1010             return;
1011     }
1012
1013     if( var_Get( p_object, psz_variable, &val ) < 0 )
1014     {
1015         return;
1016     }
1017
1018     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1019                    &val_list, &text_list ) < 0 )
1020     {
1021         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1022         return;
1023     }
1024
1025     /* make (un)sensitive */
1026     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1027
1028     /* Aspect Ratio */
1029     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1030     {
1031         NSMenuItem *o_lmi_tmp2;
1032         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1033         [o_lmi_tmp2 setTarget: self];
1034         [o_lmi_tmp2 setEnabled: YES];
1035         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1036         [o_parent setEnabled: YES];
1037         [o_menu addItem: [NSMenuItem separatorItem]];
1038     }
1039
1040     /* special case for the subtitles items */
1041     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1042     {
1043         NSMenuItem * o_lmi_tmp;
1044         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1045         [o_lmi_tmp setTarget: self];
1046         [o_lmi_tmp setEnabled: YES];
1047         [o_parent setEnabled: YES];
1048         [o_menu addItem: [NSMenuItem separatorItem]];
1049     }
1050
1051     for( i = 0; i < val_list.p_list->i_count; i++ )
1052     {
1053         NSMenuItem * o_lmi;
1054         NSString *o_title = @"";
1055         VLCAutoGeneratedMenuContent *o_data;
1056
1057         switch( i_type & VLC_VAR_TYPE )
1058         {
1059             case VLC_VAR_STRING:
1060
1061                 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
1062                            text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
1063
1064                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1065                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1066                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1067                 [o_lmi setRepresentedObject: [o_data autorelease]];
1068                 [o_lmi setTarget: self];
1069
1070                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1071                     [o_lmi setState: TRUE ];
1072
1073                 break;
1074
1075             case VLC_VAR_INTEGER:
1076
1077                 o_title = text_list.p_list->p_values[i].psz_string ?
1078                 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
1079                 [NSString stringWithFormat: @"%"PRId64,
1080                  val_list.p_list->p_values[i].i_int];
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     p_object = [menuContent vlcObject];
1129
1130     if( p_object != NULL )
1131     {
1132         var_Set( p_object, [menuContent name], [menuContent value] );
1133         vlc_object_release( p_object );
1134         [o_pool release];
1135         return true;
1136     }
1137     [o_pool release];
1138     return VLC_EGENERIC;
1139 }
1140
1141 @end
1142
1143 @implementation VLCMainMenu (NSMenuValidation)
1144
1145 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1146 {
1147     NSString *o_title = [o_mi title];
1148     BOOL bEnabled = TRUE;
1149     vlc_value_t val;
1150     playlist_t * p_playlist = pl_Get( p_intf );
1151     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1152
1153     if( [o_title isEqualToString: _NS("Stop")] )
1154     {
1155         if( p_input == NULL )
1156         {
1157             bEnabled = FALSE;
1158         }
1159         [self setupMenus]; /* Make sure input menu is up to date */
1160     }
1161     else if( [o_title isEqualToString: _NS("Previous")] ||
1162             [o_title isEqualToString: _NS("Next")] )
1163     {
1164         PL_LOCK;
1165         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1166         PL_UNLOCK;
1167     }
1168     else if( [o_title isEqualToString: _NS("Random")] )
1169     {
1170         int i_state;
1171         var_Get( p_playlist, "random", &val );
1172         i_state = val.b_bool ? NSOnState : NSOffState;
1173         [o_mi setState: i_state];
1174     }
1175     else if( [o_title isEqualToString: _NS("Repeat One")] )
1176     {
1177         int i_state;
1178         var_Get( p_playlist, "repeat", &val );
1179         i_state = val.b_bool ? NSOnState : NSOffState;
1180         [o_mi setState: i_state];
1181     }
1182     else if( [o_title isEqualToString: _NS("Repeat All")] )
1183     {
1184         int i_state;
1185         var_Get( p_playlist, "loop", &val );
1186         i_state = val.b_bool ? NSOnState : NSOffState;
1187         [o_mi setState: i_state];
1188     }
1189     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1190     {
1191         int i_state;
1192         var_Get( p_playlist, "play-and-exit", &val );
1193         i_state = val.b_bool ? NSOnState : NSOffState;
1194         [o_mi setState: i_state];
1195     }
1196     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1197             [o_title isEqualToString: _NS("Step Backward")] ||
1198             [o_title isEqualToString: _NS("Jump To Time")])
1199     {
1200         if( p_input != NULL )
1201         {
1202             var_Get( p_input, "can-seek", &val);
1203             bEnabled = val.b_bool;
1204         }
1205         else bEnabled = FALSE;
1206     }
1207     else if( [o_title isEqualToString: _NS("Mute")] )
1208     {
1209         [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1210         [self setupMenus]; /* Make sure audio menu is up to date */
1211     }
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")] )
1219     {
1220         bEnabled = FALSE;
1221
1222         if( p_input != NULL )
1223         {
1224             vout_thread_t *p_vout = input_GetVout( p_input );
1225             if( p_vout != NULL )
1226             {
1227                 if( [o_title isEqualToString: _NS("Float on Top")] )
1228                 {
1229                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1230                 }
1231
1232                 bEnabled = TRUE;
1233
1234                 vlc_object_release( (vlc_object_t *)p_vout );
1235             }
1236         }
1237         if( [o_title isEqualToString: _NS("Fullscreen")] )
1238         {
1239         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1240             bEnabled = TRUE;
1241         }
1242         [self setupMenus]; /* Make sure video menu is up to date */
1243     }
1244
1245     /* Special case for telx menu */
1246     if( [o_title isEqualToString: _NS("Normal Size")] )
1247     {
1248         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1249                 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1250
1251         [[item submenu] setAutoenablesItems:NO];
1252         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1253         {
1254             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1255         }
1256     }
1257
1258     if( p_input ) vlc_object_release( p_input );
1259
1260     return( bEnabled );
1261 }
1262
1263 @end
1264
1265
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
1273
1274 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1275                   andValue:(vlc_value_t)val ofType:(int)type
1276 {
1277     self = [super init];
1278
1279     if( self != nil )
1280     {
1281         _vlc_object = vlc_object_hold( object );
1282         psz_name = strdup( name );
1283         i_type = type;
1284         value = val;
1285         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1286             value.psz_string = strdup( val.psz_string );
1287     }
1288
1289     return( self );
1290 }
1291
1292 - (void)dealloc
1293 {
1294     vlc_object_release( _vlc_object );
1295     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1296         free( value.psz_string );
1297     free( psz_name );
1298     [super dealloc];
1299 }
1300
1301 - (const char *)name
1302 {
1303     return psz_name;
1304 }
1305
1306 - (vlc_value_t)value
1307 {
1308     return value;
1309 }
1310
1311 - (vlc_object_t *)vlcObject
1312 {
1313     return vlc_object_hold( _vlc_object );
1314 }
1315
1316
1317 - (int)type
1318 {
1319     return i_type;
1320 }
1321
1322 @end