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