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