]> git.sesse.net Git - vlc/blob - modules/gui/macosx/MainMenu.m
macosx: implement a 'Record' menu item
[vlc] / 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_record setTitle: _NS("Record")];
259     [o_mi_rate setView: o_mi_rate_view];
260     [o_mi_rate_lbl setStringValue: _NS("Playback Speed")];
261     [o_mi_rate_lbl_gray setStringValue: _NS("Playback Speed")];
262     [o_mi_rate_slower_lbl setStringValue: _NS("Slower")];
263     [o_mi_rate_normal_lbl setStringValue: _NS("Normal")];
264     [o_mi_rate_faster_lbl setStringValue: _NS("Faster")];
265     [o_mi_trackSynchronization setTitle: _NS("Track Synchronization")];
266     [o_mi_previous setTitle: _NS("Previous")];
267     [o_mi_next setTitle: _NS("Next")];
268     [o_mi_random setTitle: _NS("Random")];
269     [o_mi_repeat setTitle: _NS("Repeat One")];
270     [o_mi_loop setTitle: _NS("Repeat All")];
271     [o_mi_quitAfterPB setTitle: _NS("Quit after Playback")];
272     [o_mi_fwd setTitle: _NS("Step Forward")];
273     [o_mi_bwd setTitle: _NS("Step Backward")];
274
275     [o_mi_program setTitle: _NS("Program")];
276     [o_mu_program setTitle: _NS("Program")];
277     [o_mi_title setTitle: _NS("Title")];
278     [o_mu_title setTitle: _NS("Title")];
279     [o_mi_chapter setTitle: _NS("Chapter")];
280     [o_mu_chapter setTitle: _NS("Chapter")];
281
282     [o_mu_audio setTitle: _NS("Audio")];
283     [o_mi_vol_up setTitle: _NS("Increase Volume")];
284     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
285     [o_mi_mute setTitle: _NS("Mute")];
286     [o_mi_audiotrack setTitle: _NS("Audio Track")];
287     [o_mu_audiotrack setTitle: _NS("Audio Track")];
288     [o_mi_channels setTitle: _NS("Audio Channels")];
289     [o_mu_channels setTitle: _NS("Audio Channels")];
290     [o_mi_device setTitle: _NS("Audio Device")];
291     [o_mu_device setTitle: _NS("Audio Device")];
292     [o_mi_visual setTitle: _NS("Visualizations")];
293     [o_mu_visual setTitle: _NS("Visualizations")];
294
295     [o_mu_video setTitle: _NS("Video")];
296     [o_mi_half_window setTitle: _NS("Half Size")];
297     [o_mi_normal_window setTitle: _NS("Normal Size")];
298     [o_mi_double_window setTitle: _NS("Double Size")];
299     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
300     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
301     [o_mi_floatontop setTitle: _NS("Float on Top")];
302     [o_mi_snapshot setTitle: _NS("Snapshot")];
303     [o_mi_videotrack setTitle: _NS("Video Track")];
304     [o_mu_videotrack setTitle: _NS("Video Track")];
305     [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
306     [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
307     [o_mi_crop setTitle: _NS("Crop")];
308     [o_mu_crop setTitle: _NS("Crop")];
309     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
310     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
311     [o_mi_subtitle setTitle: _NS("Subtitles Track")];
312     [o_mu_subtitle setTitle: _NS("Subtitles Track")];
313     [o_mi_addSub setTitle: _NS("Open File...")];
314     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
315     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
316     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
317     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
318     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
319     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
320     [o_mi_teletext setTitle: _NS("Teletext")];
321     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
322     [o_mi_teletext_index setTitle: _NS("Index")];
323     [o_mi_teletext_red setTitle: _NS("Red")];
324     [o_mi_teletext_green setTitle: _NS("Green")];
325     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
326     [o_mi_teletext_blue setTitle: _NS("Blue")];
327
328     [o_mu_window setTitle: _NS("Window")];
329     [o_mi_minimize setTitle: _NS("Minimize Window")];
330     [o_mi_close_window setTitle: _NS("Close Window")];
331     [o_mi_player setTitle: _NS("Player...")];
332     [o_mi_controller setTitle: _NS("Main Window...")];
333     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
334     [o_mi_videoeffects setTitle: _NS("Video Filters...")];
335     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
336     [o_mi_playlist setTitle: _NS("Playlist...")];
337     [o_mi_info setTitle: _NS("Media Information...")];
338     [o_mi_messages setTitle: _NS("Messages...")];
339     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
340
341     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
342
343     [o_mu_help setTitle: _NS("Help")];
344     [o_mi_help setTitle: _NS("VLC media player Help...")];
345     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
346     [o_mi_license setTitle: _NS("License")];
347     [o_mi_documentation setTitle: _NS("Online Documentation...")];
348     [o_mi_website setTitle: _NS("VideoLAN Website...")];
349     [o_mi_donation setTitle: _NS("Make a donation...")];
350     [o_mi_forum setTitle: _NS("Online Forum...")];
351
352     /* dock menu */
353     [o_dmi_play setTitle: _NS("Play")];
354     [o_dmi_stop setTitle: _NS("Stop")];
355     [o_dmi_next setTitle: _NS("Next")];
356     [o_dmi_previous setTitle: _NS("Previous")];
357     [o_dmi_mute setTitle: _NS("Mute")];
358
359     /* vout menu */
360     [o_vmi_play setTitle: _NS("Play")];
361     [o_vmi_stop setTitle: _NS("Stop")];
362     [o_vmi_prev setTitle: _NS("Previous")];
363     [o_vmi_next setTitle: _NS("Next")];
364     [o_vmi_volup setTitle: _NS("Volume Up")];
365     [o_vmi_voldown setTitle: _NS("Volume Down")];
366     [o_vmi_mute setTitle: _NS("Mute")];
367     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
368     [o_vmi_snapshot setTitle: _NS("Snapshot")];
369 }
370
371 #pragma mark -
372 #pragma mark Termination
373
374 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
375 {
376     if( !p_intf ) return;
377     
378     NSArray *menuitems_array = [the_menu itemArray];
379     NSUInteger menuItemCount = [menuitems_array count];
380     for( NSUInteger i=0; i < menuItemCount; i++ )
381     {
382         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
383         if( [one_item hasSubmenu] )
384             [self releaseRepresentedObjects: [one_item submenu]];
385
386         [one_item setRepresentedObject:NULL];
387     }
388 }
389
390 #pragma mark -
391 #pragma mark Interface update
392
393 - (void)setupMenus
394 {
395     playlist_t * p_playlist = pl_Get( p_intf );
396     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
397     if( p_input != NULL )
398     {
399         [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
400
401         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
402                                  var: "program" selector: @selector(toggleVar:)];
403
404         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
405                                  var: "title" selector: @selector(toggleVar:)];
406
407         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
408                                  var: "chapter" selector: @selector(toggleVar:)];
409
410         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
411                                  var: "audio-es" selector: @selector(toggleVar:)];
412
413         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
414                                  var: "video-es" selector: @selector(toggleVar:)];
415
416         [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
417                                  var: "spu-es" selector: @selector(toggleVar:)];
418
419         /* special case for "Open File" inside the subtitles menu item */
420         if( [o_mi_videotrack isEnabled] == YES )
421             [o_mi_subtitle setEnabled: YES];
422
423         audio_output_t * p_aout = input_GetAout( p_input );
424         if( p_aout != NULL )
425         {
426             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
427                                      var: "audio-channels" selector: @selector(toggleVar:)];
428
429             [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
430                                      var: "audio-device" selector: @selector(toggleVar:)];
431
432             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
433                                      var: "visual" selector: @selector(toggleVar:)];
434             vlc_object_release( (vlc_object_t *)p_aout );
435         }
436
437         vout_thread_t * p_vout = input_GetVout( p_input );
438
439         if( p_vout != NULL )
440         {
441             vlc_object_t * p_dec_obj;
442
443             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
444                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
445
446             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
447                                      var: "crop" selector: @selector(toggleVar:)];
448
449             [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
450                                      var: "video-device" selector: @selector(toggleVar:)];
451
452             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
453                                      var: "deinterlace" selector: @selector(toggleVar:)];
454
455             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
456                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
457
458 #if 1
459             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
460              (vlc_object_t *)p_vout var:"postprocess" selector:
461              @selector(toggleVar:)];
462 #endif
463             vlc_object_release( (vlc_object_t *)p_vout );
464         }
465         vlc_object_release( p_input );
466     }
467     else
468     {
469         [o_mi_record setEnabled: NO];
470     }
471 }
472
473 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
474 {
475     int x, y = 0;
476     vout_thread_t * p_vout = getVout();
477     if( !p_vout )
478         return;
479
480     /* clean the menu before adding new entries */
481     if( [o_mi_screen hasSubmenu] )
482     {
483         y = [[o_mi_screen submenu] numberOfItems] - 1;
484         msg_Dbg( VLCIntf, "%i items in submenu", y );
485         while( x != y )
486         {
487             msg_Dbg( VLCIntf, "removing item %i of %i", x, y );
488             [[o_mi_screen submenu] removeItemAtIndex: x];
489             x++;
490         }
491     }
492
493     [self setupVarMenuItem: o_mi_screen target: (vlc_object_t *)p_vout
494                              var: "video-device" selector: @selector(toggleVar:)];
495     vlc_object_release( (vlc_object_t *)p_vout );
496 }
497
498 - (void)setSubmenusEnabled:(BOOL)b_enabled
499 {
500     [o_mi_program setEnabled: b_enabled];
501     [o_mi_title setEnabled: b_enabled];
502     [o_mi_chapter setEnabled: b_enabled];
503     [o_mi_audiotrack setEnabled: b_enabled];
504     [o_mi_visual setEnabled: b_enabled];
505     [o_mi_videotrack setEnabled: b_enabled];
506     [o_mi_subtitle setEnabled: b_enabled];
507     [o_mi_channels setEnabled: b_enabled];
508     [o_mi_deinterlace setEnabled: b_enabled];
509     [o_mi_deinterlace_mode setEnabled: b_enabled];
510     [o_mi_ffmpeg_pp setEnabled: b_enabled];
511     [o_mi_device setEnabled: b_enabled];
512     [o_mi_screen setEnabled: b_enabled];
513     [o_mi_aspect_ratio setEnabled: b_enabled];
514     [o_mi_crop setEnabled: b_enabled];
515     [o_mi_teletext setEnabled: b_enabled];
516 }
517
518 - (void)setRateControlsEnabled:(BOOL)b_enabled
519 {
520     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
521     [o_mi_rate_sld setEnabled: b_enabled];
522     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
523     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
524     if (i == 0)
525         i = 1;
526     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
527     if (b_enabled) {
528         [o_mi_rate_lbl setHidden: NO];
529         [o_mi_rate_lbl_gray setHidden: YES];
530     }
531     else
532     {
533         [o_mi_rate_lbl setHidden: YES];
534         [o_mi_rate_lbl_gray setHidden: NO];
535     }
536     [o_pool release];
537 }
538
539 #pragma mark -
540 #pragma mark Recent Items
541 - (void)openRecentItem:(id)item
542 {
543     [[VLCMain sharedInstance] application: nil openFile: [item title]];
544 }
545
546 - (IBAction)clearRecentItems:(id)sender
547 {
548     [[NSDocumentController sharedDocumentController]
549      clearRecentDocuments: nil];
550 }
551
552 #pragma mark -
553 #pragma mark Playback
554 - (IBAction)toggleRecord:(id)sender
555 {
556     [[VLCCoreInteraction sharedInstance] toggleRecord];
557 }
558
559 - (void)updateRecordState:(BOOL)b_value
560 {
561     [o_mi_record setState:b_value];
562 }
563
564 - (IBAction)setPlaybackRate:(id)sender
565 {
566     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
567     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
568     if (i == 0)
569         i = 1;
570     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
571 }
572
573 - (void)updatePlaybackRate
574 {
575     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
576     if (i == 0)
577         i = 1;
578     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%ix", i]];
579     [o_mi_rate_sld setIntValue: i];
580 }
581
582 #pragma mark -
583 #pragma video menu
584 - (IBAction)toggleFullscreen:(id)sender
585 {
586     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
587 }
588
589 - (IBAction)resizeVideoWindow:(id)sender
590 {
591     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
592     if (p_input)
593     {
594         vout_thread_t *p_vout = getVout();
595         if (p_vout)
596         {
597             if (sender == o_mi_half_window)
598                 var_SetFloat( p_vout, "zoom", 0.5 );
599             else if (sender == o_mi_normal_window)
600                 var_SetFloat( p_vout, "zoom", 1.0 );
601             else if (sender == o_mi_double_window)
602                 var_SetFloat( p_vout, "zoom", 2.0 );
603             else
604             {
605                 var_ToggleBool( p_vout, "autoscale" );
606             }
607             vlc_object_release( p_vout );
608         }
609         vlc_object_release( p_input );
610     }
611 }
612
613 - (IBAction)floatOnTop:(id)sender
614 {
615     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
616     if (p_input)
617     {
618         vout_thread_t *p_vout = getVout();
619         if (p_vout)
620         {
621             var_ToggleBool( p_vout, "video-on-top" );
622             vlc_object_release( p_vout );
623         }
624         vlc_object_release( p_input );
625     }
626 }
627
628 - (IBAction)createVideoSnapshot:(id)sender
629 {
630     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
631     if (p_input)
632     {
633         vout_thread_t *p_vout = getVout();
634         if (p_vout)
635         {
636             var_TriggerCallback( p_vout, "video-snapshot" );
637             vlc_object_release( p_vout );
638         }
639         vlc_object_release( p_input );
640     }
641 }
642
643 - (id)voutMenu
644 {
645     return o_vout_menu;
646 }
647
648 #pragma mark -
649 #pragma mark Panels
650
651 - (IBAction)intfOpenFile:(id)sender
652 {
653     [[[VLCMain sharedInstance] open] openFile];
654 }
655
656 - (IBAction)intfOpenFileGeneric:(id)sender
657 {
658     [[[VLCMain sharedInstance] open] openFileGeneric];
659 }
660
661 - (IBAction)intfOpenDisc:(id)sender
662 {
663     [[[VLCMain sharedInstance] open] openDisc];
664 }
665
666 - (IBAction)intfOpenNet:(id)sender
667 {
668     [[[VLCMain sharedInstance] open] openNet];
669 }
670
671 - (IBAction)intfOpenCapture:(id)sender
672 {
673     [[[VLCMain sharedInstance] open] openCapture];
674 }
675
676 - (IBAction)showWizard:(id)sender
677 {
678     [[[VLCMain sharedInstance] wizard] resetWizard];
679     [[[VLCMain sharedInstance] wizard] showWizard];
680 }
681
682 - (IBAction)showVideoEffects:(id)sender
683 {
684     if( o_videoeffects == nil )
685         o_videoeffects = [[VLCVideoEffects alloc] init];
686
687     if( !b_nib_videoeffects_loaded )
688         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
689
690     [o_videoeffects toggleWindow:sender];
691 }
692
693 - (IBAction)showTrackSynchronization:(id)sender
694 {
695     if (!o_trackSynchronization)
696         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
697
698     if (!b_nib_tracksynchro_loaded)
699         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
700
701     [o_trackSynchronization toggleWindow:sender];
702 }
703
704 - (IBAction)showAudioEffects:(id)sender
705 {
706     if (!o_audioeffects)
707         o_audioeffects = [[VLCAudioEffects alloc] init];
708
709     if (!b_nib_audioeffects_loaded)
710         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
711
712     [o_audioeffects toggleWindow:sender];
713 }
714
715 - (IBAction)showBookmarks:(id)sender
716 {
717     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
718 }
719
720 - (IBAction)viewPreferences:(id)sender
721 {
722     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
723 }
724
725 #pragma mark -
726 #pragma mark Help and Docs
727
728 - (void)initAbout
729 {
730     if(! o_about )
731         o_about = [[VLAboutBox alloc] init];
732
733     if( !b_nib_about_loaded )
734         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
735 }
736
737 - (IBAction)viewAbout:(id)sender
738 {
739     [self initAbout];
740     [o_about showAbout];
741 }
742
743 - (IBAction)showLicense:(id)sender
744 {
745     [self initAbout];
746     [o_about showGPL: sender];
747 }
748
749 - (IBAction)viewHelp:(id)sender
750 {
751     [self initAbout];
752     [o_about showHelp];
753 }
754
755 - (IBAction)openReadMe:(id)sender
756 {
757     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
758
759     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
760 }
761
762 - (IBAction)openDocumentation:(id)sender
763 {
764     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
765
766     [[NSWorkspace sharedWorkspace] openURL: o_url];
767 }
768
769 - (IBAction)openWebsite:(id)sender
770 {
771     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
772
773     [[NSWorkspace sharedWorkspace] openURL: o_url];
774 }
775
776 - (IBAction)openForum:(id)sender
777 {
778     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
779
780     [[NSWorkspace sharedWorkspace] openURL: o_url];
781 }
782
783 - (IBAction)openDonate:(id)sender
784 {
785     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
786
787     [[NSWorkspace sharedWorkspace] openURL: o_url];
788 }
789
790 #pragma mark -
791 #pragma mark Errors, warnings and messages
792
793 - (IBAction)viewErrorsAndWarnings:(id)sender
794 {
795     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
796 }
797
798 - (IBAction)showInformationPanel:(id)sender
799 {
800     [[[VLCMain sharedInstance] info] initPanel];
801 }
802
803 #pragma mark -
804 #pragma mark convinience stuff for other objects
805 - (void)setPlay
806 {
807     [o_mi_play setTitle: _NS("Play")];
808     [o_dmi_play setTitle: _NS("Play")];
809     [o_vmi_play setTitle: _NS("Play")];
810 }
811
812 - (void)setPause
813 {
814     [o_mi_play setTitle: _NS("Pause")];
815     [o_dmi_play setTitle: _NS("Pause")];
816     [o_vmi_play setTitle: _NS("Pause")];
817 }
818
819 - (void)setRepeatOne
820 {
821     [o_mi_repeat setState: NSOnState];
822     [o_mi_loop setState: NSOffState];
823 }
824
825 - (void)setRepeatAll
826 {
827     [o_mi_repeat setState: NSOffState];
828     [o_mi_loop setState: NSOnState];
829 }
830
831 - (void)setRepeatOff
832 {
833     [o_mi_repeat setState: NSOffState];
834     [o_mi_loop setState: NSOffState];
835 }
836
837 - (void)setShuffle
838 {
839     bool b_value;
840     playlist_t *p_playlist = pl_Get( VLCIntf );
841     b_value = var_GetBool( p_playlist, "random" );
842         [o_mi_random setState: b_value];
843 }
844
845 #pragma mark -
846 #pragma mark Dynamic menu creation and validation
847
848 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
849                   target:(vlc_object_t *)p_object
850                      var:(const char *)psz_variable
851                 selector:(SEL)pf_callback
852 {
853     vlc_value_t val, text;
854     int i_type = var_Type( p_object, psz_variable );
855
856     switch( i_type & VLC_VAR_TYPE )
857     {
858         case VLC_VAR_VOID:
859         case VLC_VAR_BOOL:
860         case VLC_VAR_VARIABLE:
861         case VLC_VAR_STRING:
862         case VLC_VAR_INTEGER:
863             break;
864         default:
865             /* Variable doesn't exist or isn't handled */
866             return;
867     }
868
869     /* Make sure we want to display the variable */
870     if( i_type & VLC_VAR_HASCHOICE )
871     {
872         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
873         if( val.i_int == 0 ) return;
874         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
875             return;
876     }
877
878     /* Get the descriptive name of the variable */
879     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
880     [o_mi setTitle: [[VLCMain sharedInstance] localizedString: text.psz_string ?
881                      text.psz_string : psz_variable ]];
882
883     if( i_type & VLC_VAR_HASCHOICE )
884     {
885         NSMenu *o_menu = [o_mi submenu];
886         
887         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
888                        var:psz_variable selector:pf_callback];
889         
890         free( text.psz_string );
891         return;
892     }
893     if( var_Get( p_object, psz_variable, &val ) < 0 )
894     {
895         return;
896     }
897
898     VLCAutoGeneratedMenuContent *o_data;
899     switch( i_type & VLC_VAR_TYPE )
900     {
901         case VLC_VAR_VOID:
902             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
903                                                                       andValue: val ofType: i_type];
904             [o_mi setRepresentedObject: [o_data autorelease]];
905             break;
906
907         case VLC_VAR_BOOL:
908             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
909                                                                       andValue: val ofType: i_type];
910             [o_mi setRepresentedObject: [o_data autorelease]];
911             if( !( i_type & VLC_VAR_ISCOMMAND ) )
912                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
913             break;
914
915         default:
916             break;
917     }
918
919     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
920     free( text.psz_string );
921 }
922
923
924 - (void)setupVarMenu:(NSMenu *)o_menu
925          forMenuItem: (NSMenuItem *)o_parent
926               target:(vlc_object_t *)p_object
927                  var:(const char *)psz_variable
928             selector:(SEL)pf_callback
929 {
930     vlc_value_t val, val_list, text_list;
931     int i_type, i, i_nb_items;
932
933     /* remove previous items */
934     i_nb_items = [o_menu numberOfItems];
935     for( i = 0; i < i_nb_items; i++ )
936         [o_menu removeItemAtIndex: 0];
937
938     /* Check the type of the object variable */
939     i_type = var_Type( p_object, psz_variable );
940
941     /* Make sure we want to display the variable */
942     if( i_type & VLC_VAR_HASCHOICE )
943     {
944         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
945         if( val.i_int == 0 ) return;
946         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
947             return;
948     }
949     else
950         return;
951
952     switch( i_type & VLC_VAR_TYPE )
953     {
954         case VLC_VAR_VOID:
955         case VLC_VAR_BOOL:
956         case VLC_VAR_VARIABLE:
957         case VLC_VAR_STRING:
958         case VLC_VAR_INTEGER:
959             break;
960         default:
961             /* Variable doesn't exist or isn't handled */
962             return;
963     }
964
965     if( var_Get( p_object, psz_variable, &val ) < 0 )
966     {
967         return;
968     }
969
970     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
971                    &val_list, &text_list ) < 0 )
972     {
973         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
974         return;
975     }
976
977     /* make (un)sensitive */
978     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
979
980     /* Aspect Ratio */
981     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
982     {
983         NSMenuItem *o_lmi_tmp2;
984         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
985         [o_lmi_tmp2 setTarget: self];
986         [o_lmi_tmp2 setEnabled: YES];
987         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
988         [o_parent setEnabled: YES];
989         [o_menu addItem: [NSMenuItem separatorItem]];
990     }
991
992     /* special case for the subtitles items */
993     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
994     {
995         NSMenuItem * o_lmi_tmp;
996         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
997         [o_lmi_tmp setTarget: self];
998         [o_lmi_tmp setEnabled: YES];
999         [o_parent setEnabled: YES];
1000         [o_menu addItem: [NSMenuItem separatorItem]];
1001     }
1002
1003     for( i = 0; i < val_list.p_list->i_count; i++ )
1004     {
1005         NSMenuItem * o_lmi;
1006         NSString *o_title = @"";
1007         VLCAutoGeneratedMenuContent *o_data;
1008
1009         switch( i_type & VLC_VAR_TYPE )
1010         {
1011             case VLC_VAR_STRING:
1012
1013                 o_title = [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string ?
1014                            text_list.p_list->p_values[i].psz_string : val_list.p_list->p_values[i].psz_string ];
1015
1016                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1017                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1018                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1019                 [o_lmi setRepresentedObject: [o_data autorelease]];
1020                 [o_lmi setTarget: self];
1021
1022                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1023                     [o_lmi setState: TRUE ];
1024
1025                 break;
1026
1027             case VLC_VAR_INTEGER:
1028
1029                 o_title = text_list.p_list->p_values[i].psz_string ?
1030                 [[VLCMain sharedInstance] localizedString: text_list.p_list->p_values[i].psz_string] :
1031                 [NSString stringWithFormat: @"%"PRId64,
1032                  val_list.p_list->p_values[i].i_int];
1033
1034                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1035                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1036                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1037                 [o_lmi setRepresentedObject: [o_data autorelease]];
1038                 [o_lmi setTarget: self];
1039
1040                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1041                     [o_lmi setState: TRUE ];
1042                 break;
1043
1044             default:
1045                 break;
1046         }
1047     }
1048
1049     /* special case for the subtitles sub-menu
1050      * In case that we don't have any subs, we don't want a separator item at the end */
1051     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1052     {
1053         if( [o_menu numberOfItems] == 2 )
1054             [o_menu removeItemAtIndex: 1];
1055     }
1056
1057     /* clean up everything */
1058     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1059     var_FreeList( &val_list, &text_list );
1060 }
1061
1062 - (IBAction)toggleVar:(id)sender
1063 {
1064     NSMenuItem *o_mi = (NSMenuItem *)sender;
1065     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1066     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1067                              toTarget: self withObject: o_data];
1068
1069     return;
1070 }
1071
1072 - (int)toggleVarThread: (id)data
1073 {
1074     vlc_object_t *p_object;
1075     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1076
1077     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1078     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1079
1080     p_object = [menuContent vlcObject];
1081
1082     if( p_object != NULL )
1083     {
1084         var_Set( p_object, [menuContent name], [menuContent value] );
1085         vlc_object_release( p_object );
1086         [o_pool release];
1087         return true;
1088     }
1089     [o_pool release];
1090     return VLC_EGENERIC;
1091 }
1092
1093 @end
1094
1095 @implementation VLCMainMenu (NSMenuValidation)
1096
1097 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1098 {
1099     NSString *o_title = [o_mi title];
1100     BOOL bEnabled = TRUE;
1101     vlc_value_t val;
1102     playlist_t * p_playlist = pl_Get( p_intf );
1103     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1104
1105     /* Recent Items Menu */
1106     if( [o_title isEqualToString: _NS("Clear Menu")] )
1107     {
1108         NSMenu * o_menu = [o_mi_open_recent submenu];
1109         int i_nb_items = [o_menu numberOfItems];
1110         NSArray * o_docs = [[NSDocumentController sharedDocumentController]
1111                             recentDocumentURLs];
1112         UInt32 i_nb_docs = [o_docs count];
1113
1114         if( i_nb_items > 1 )
1115         {
1116             while( --i_nb_items )
1117             {
1118                 [o_menu removeItemAtIndex: 0];
1119             }
1120         }
1121
1122         if( i_nb_docs > 0 )
1123         {
1124             NSURL * o_url;
1125             NSString * o_doc;
1126
1127             [o_menu insertItem: [NSMenuItem separatorItem] atIndex: 0];
1128
1129             while( TRUE )
1130             {
1131                 i_nb_docs--;
1132
1133                 o_url = [o_docs objectAtIndex: i_nb_docs];
1134
1135                 if( [o_url isFileURL] )
1136                     o_doc = [o_url path];
1137                 else
1138                     o_doc = [o_url absoluteString];
1139
1140                 [o_menu insertItemWithTitle: o_doc
1141                                      action: @selector(openRecentItem:)
1142                               keyEquivalent: @"" atIndex: 0];
1143
1144                 if( i_nb_docs == 0 )
1145                     break;
1146             }
1147         }
1148         else
1149         {
1150             bEnabled = FALSE;
1151         }
1152     }
1153     else 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         //FIXME [o_mi setState: p_intf->p_sys->b_mute ? 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