]> git.sesse.net Git - vlc/blob - modules/gui/macosx/MainMenu.m
macosx: added an option to hide the playmode buttons (displayed by default)
[vlc] / modules / gui / macosx / MainMenu.m
1 /*****************************************************************************
2  * MainMenu.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2012 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     [o_mi_toggleJumpButtons setTitle: _NS("Show Previous & Next Buttons")];
285     [o_mi_toggleJumpButtons setState: config_GetInt( VLCIntf, "macosx-show-playback-buttons")];
286     [o_mi_togglePlaymodeButtons setTitle: _NS("Show Shuffle & Repeat Buttons")];
287     [o_mi_togglePlaymodeButtons setState: config_GetInt( VLCIntf, "macosx-show-playmode-buttons")];
288
289     [o_mi_program setTitle: _NS("Program")];
290     [o_mu_program setTitle: _NS("Program")];
291     [o_mi_title setTitle: _NS("Title")];
292     [o_mu_title setTitle: _NS("Title")];
293     [o_mi_chapter setTitle: _NS("Chapter")];
294     [o_mu_chapter setTitle: _NS("Chapter")];
295
296     [o_mu_audio setTitle: _NS("Audio")];
297     [o_mi_vol_up setTitle: _NS("Increase Volume")];
298     [o_mi_vol_down setTitle: _NS("Decrease Volume")];
299     [o_mi_mute setTitle: _NS("Mute")];
300     [o_mi_audiotrack setTitle: _NS("Audio Track")];
301     [o_mu_audiotrack setTitle: _NS("Audio Track")];
302     [o_mi_channels setTitle: _NS("Audio Channels")];
303     [o_mu_channels setTitle: _NS("Audio Channels")];
304     [o_mi_device setTitle: _NS("Audio Device")];
305     [o_mu_device setTitle: _NS("Audio Device")];
306     [o_mi_visual setTitle: _NS("Visualizations")];
307     [o_mu_visual setTitle: _NS("Visualizations")];
308
309     [o_mu_video setTitle: _NS("Video")];
310     [o_mi_half_window setTitle: _NS("Half Size")];
311     [o_mi_normal_window setTitle: _NS("Normal Size")];
312     [o_mi_double_window setTitle: _NS("Double Size")];
313     [o_mi_fittoscreen setTitle: _NS("Fit to Screen")];
314     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
315     [o_mi_floatontop setTitle: _NS("Float on Top")];
316     [o_mi_snapshot setTitle: _NS("Snapshot")];
317     [o_mi_videotrack setTitle: _NS("Video Track")];
318     [o_mu_videotrack setTitle: _NS("Video Track")];
319     [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
320     [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
321     [o_mi_crop setTitle: _NS("Crop")];
322     [o_mu_crop setTitle: _NS("Crop")];
323     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
324     [o_mu_screen setTitle: _NS("Fullscreen Video Device")];
325     [o_mi_subtitle setTitle: _NS("Subtitles Track")];
326     [o_mu_subtitle setTitle: _NS("Subtitles Track")];
327     [o_mi_addSub setTitle: _NS("Open File...")];
328     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
329     [o_mu_deinterlace setTitle: _NS("Deinterlace")];
330     [o_mi_deinterlace_mode setTitle: _NS("Deinterlace mode")];
331     [o_mu_deinterlace_mode setTitle: _NS("Deinterlace mode")];
332     [o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
333     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
334     [o_mi_teletext setTitle: _NS("Teletext")];
335     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
336     [o_mi_teletext_index setTitle: _NS("Index")];
337     [o_mi_teletext_red setTitle: _NS("Red")];
338     [o_mi_teletext_green setTitle: _NS("Green")];
339     [o_mi_teletext_yellow setTitle: _NS("Yellow")];
340     [o_mi_teletext_blue setTitle: _NS("Blue")];
341
342     [o_mu_window setTitle: _NS("Window")];
343     [o_mi_minimize setTitle: _NS("Minimize Window")];
344     [o_mi_close_window setTitle: _NS("Close Window")];
345     [o_mi_player setTitle: _NS("Player...")];
346     [o_mi_controller setTitle: _NS("Main Window...")];
347     [o_mi_audioeffects setTitle: _NS("Audio Effects...")];
348     [o_mi_videoeffects setTitle: _NS("Video Filters...")];
349     [o_mi_bookmarks setTitle: _NS("Bookmarks...")];
350     [o_mi_playlist setTitle: _NS("Playlist...")];
351     [o_mi_info setTitle: _NS("Media Information...")];
352     [o_mi_messages setTitle: _NS("Messages...")];
353     [o_mi_errorsAndWarnings setTitle: _NS("Errors and Warnings...")];
354
355     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
356
357     [o_mu_help setTitle: _NS("Help")];
358     [o_mi_help setTitle: _NS("VLC media player Help...")];
359     [o_mi_readme setTitle: _NS("ReadMe / FAQ...")];
360     [o_mi_license setTitle: _NS("License")];
361     [o_mi_documentation setTitle: _NS("Online Documentation...")];
362     [o_mi_website setTitle: _NS("VideoLAN Website...")];
363     [o_mi_donation setTitle: _NS("Make a donation...")];
364     [o_mi_forum setTitle: _NS("Online Forum...")];
365
366     /* dock menu */
367     [o_dmi_play setTitle: _NS("Play")];
368     [o_dmi_stop setTitle: _NS("Stop")];
369     [o_dmi_next setTitle: _NS("Next")];
370     [o_dmi_previous setTitle: _NS("Previous")];
371     [o_dmi_mute setTitle: _NS("Mute")];
372
373     /* vout menu */
374     [o_vmi_play setTitle: _NS("Play")];
375     [o_vmi_stop setTitle: _NS("Stop")];
376     [o_vmi_prev setTitle: _NS("Previous")];
377     [o_vmi_next setTitle: _NS("Next")];
378     [o_vmi_volup setTitle: _NS("Volume Up")];
379     [o_vmi_voldown setTitle: _NS("Volume Down")];
380     [o_vmi_mute setTitle: _NS("Mute")];
381     [o_vmi_fullscreen setTitle: _NS("Fullscreen")];
382     [o_vmi_snapshot setTitle: _NS("Snapshot")];
383 }
384
385 #pragma mark -
386 #pragma mark Termination
387
388 - (void)releaseRepresentedObjects:(NSMenu *)the_menu
389 {
390     if( !p_intf ) return;
391
392     NSArray *menuitems_array = [the_menu itemArray];
393     NSUInteger menuItemCount = [menuitems_array count];
394     for( NSUInteger i=0; i < menuItemCount; i++ )
395     {
396         NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
397         if( [one_item hasSubmenu] )
398             [self releaseRepresentedObjects: [one_item submenu]];
399
400         [one_item setRepresentedObject:NULL];
401     }
402 }
403
404 #pragma mark -
405 #pragma mark Interface update
406
407 - (void)setupMenus
408 {
409     playlist_t * p_playlist = pl_Get( p_intf );
410     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
411     if( p_input != NULL )
412     {
413         [o_mi_record setEnabled: var_GetBool( p_input, "can-record" )];
414
415         [self setupVarMenuItem: o_mi_program target: (vlc_object_t *)p_input
416                                  var: "program" selector: @selector(toggleVar:)];
417
418         [self setupVarMenuItem: o_mi_title target: (vlc_object_t *)p_input
419                                  var: "title" selector: @selector(toggleVar:)];
420
421         [self setupVarMenuItem: o_mi_chapter target: (vlc_object_t *)p_input
422                                  var: "chapter" selector: @selector(toggleVar:)];
423
424         [self setupVarMenuItem: o_mi_audiotrack target: (vlc_object_t *)p_input
425                                  var: "audio-es" selector: @selector(toggleVar:)];
426
427         [self setupVarMenuItem: o_mi_videotrack target: (vlc_object_t *)p_input
428                                  var: "video-es" selector: @selector(toggleVar:)];
429
430         [self setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
431                                  var: "spu-es" selector: @selector(toggleVar:)];
432
433         /* special case for "Open File" inside the subtitles menu item */
434         if( [o_mi_videotrack isEnabled] == YES )
435             [o_mi_subtitle setEnabled: YES];
436
437         audio_output_t * p_aout = input_GetAout( p_input );
438         if( p_aout != NULL )
439         {
440             [self setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
441                                      var: "audio-channels" selector: @selector(toggleVar:)];
442
443             [self setupVarMenuItem: o_mi_device target: (vlc_object_t *)p_aout
444                                      var: "audio-device" selector: @selector(toggleVar:)];
445
446             [self setupVarMenuItem: o_mi_visual target: (vlc_object_t *)p_aout
447                                      var: "visual" selector: @selector(toggleVar:)];
448             vlc_object_release( (vlc_object_t *)p_aout );
449         }
450
451         vout_thread_t * p_vout = input_GetVout( p_input );
452
453         if( p_vout != NULL )
454         {
455             vlc_object_t * p_dec_obj;
456
457             [self setupVarMenuItem: o_mi_aspect_ratio target: (vlc_object_t *)p_vout
458                                      var: "aspect-ratio" selector: @selector(toggleVar:)];
459
460             [self setupVarMenuItem: o_mi_crop target: (vlc_object_t *) p_vout
461                                      var: "crop" selector: @selector(toggleVar:)];
462
463             [self setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
464                                      var: "deinterlace" selector: @selector(toggleVar:)];
465
466             [self setupVarMenuItem: o_mi_deinterlace_mode target: (vlc_object_t *)p_vout
467                                      var: "deinterlace-mode" selector: @selector(toggleVar:)];
468
469 #if 1
470             [self setupVarMenuItem: o_mi_ffmpeg_pp target:
471              (vlc_object_t *)p_vout var:"postprocess" selector:
472              @selector(toggleVar:)];
473 #endif
474             vlc_object_release( (vlc_object_t *)p_vout );
475
476             [self refreshVoutDeviceMenu:nil];
477             [self setSubmenusEnabled: YES];
478         }
479         vlc_object_release( p_input );
480     }
481     else
482     {
483         [o_mi_record setEnabled: NO];
484     }
485 }
486
487 - (void)refreshVoutDeviceMenu:(NSNotification *)o_notification
488 {
489     NSUInteger count = [o_mu_screen numberOfItems];
490     NSMenu * o_submenu = o_mu_screen;
491     if (count > 0)
492     {
493         if (OSX_LEOPARD)
494         {
495             NSUInteger count = [o_submenu numberOfItems];
496             for( NSUInteger i = 0; i < count; i++ )
497                 [o_submenu removeItemAtIndex: 0];
498         }
499         else
500             [o_submenu removeAllItems];
501     }
502
503     NSArray * o_screens = [NSScreen screens];
504     NSMenuItem * o_mitem;
505     count = [o_screens count];
506     [o_submenu addItemWithTitle: _NS("Default") action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
507     o_mitem = [o_submenu itemAtIndex: 0];
508     [o_mitem setTag: 0];
509     [o_mitem setEnabled: YES];
510     [o_mitem setTarget: self];
511     NSRect s_rect;
512     for (NSUInteger i = 0; i < count; i++)
513     {
514         s_rect = [[o_screens objectAtIndex: i] frame];
515         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
516                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
517         o_mitem = [o_submenu itemAtIndex:i+1];
518         [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
519         [o_mitem setEnabled: YES];
520         [o_mitem setTarget: self];
521     }
522     [[o_submenu itemWithTag: config_GetInt( VLCIntf, "macosx-vdev" )] setState: NSOnState];
523 }
524
525 - (void)setSubmenusEnabled:(BOOL)b_enabled
526 {
527     [o_mi_program setEnabled: b_enabled];
528     [o_mi_title setEnabled: b_enabled];
529     [o_mi_chapter setEnabled: b_enabled];
530     [o_mi_audiotrack setEnabled: b_enabled];
531     [o_mi_visual setEnabled: b_enabled];
532     [o_mi_videotrack setEnabled: b_enabled];
533     [o_mi_subtitle setEnabled: b_enabled];
534     [o_mi_channels setEnabled: b_enabled];
535     [o_mi_deinterlace setEnabled: b_enabled];
536     [o_mi_deinterlace_mode setEnabled: b_enabled];
537     [o_mi_ffmpeg_pp setEnabled: b_enabled];
538     [o_mi_device setEnabled: b_enabled];
539     [o_mi_screen setEnabled: b_enabled];
540     [o_mi_aspect_ratio setEnabled: b_enabled];
541     [o_mi_crop setEnabled: b_enabled];
542     [o_mi_teletext setEnabled: b_enabled];
543 }
544
545 - (void)setRateControlsEnabled:(BOOL)b_enabled
546 {
547     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
548     [o_mi_rate_sld setEnabled: b_enabled];
549     [o_mi_rate_sld setIntValue: [[VLCCoreInteraction sharedInstance] playbackRate]];
550     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
551     double speed =  pow( 2, (double)i / 17 );
552     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
553     if (b_enabled) {
554         [o_mi_rate_lbl setHidden: NO];
555         [o_mi_rate_lbl_gray setHidden: YES];
556     }
557     else
558     {
559         [o_mi_rate_lbl setHidden: YES];
560         [o_mi_rate_lbl_gray setHidden: NO];
561     }
562     [o_pool release];
563 }
564
565 #pragma mark -
566 #pragma mark Extensions
567
568 - (void)setupExtensionsMenu
569 {
570     /* Load extensions if needed */
571     // TODO: Implement preference for autoloading extensions on mac
572
573     // if( !var_InheritBool( p_intf, "qt-autoload-extensions")
574     //     && ![o_extMgr isLoaded] )
575     // {
576     //     return;
577     // }
578
579     if( ![o_extMgr isLoaded] && ![o_extMgr cannotLoad] )
580     {
581         [o_extMgr loadExtensions];
582     }
583
584     /* Let the ExtensionsManager itself build the menu */
585     [o_extMgr buildMenu:o_mu_extensions];
586 }
587
588 #pragma mark -
589 #pragma mark Playback
590 - (IBAction)toggleRecord:(id)sender
591 {
592     [[VLCCoreInteraction sharedInstance] toggleRecord];
593 }
594
595 - (void)updateRecordState:(BOOL)b_value
596 {
597     [o_mi_record setState:b_value];
598 }
599
600 - (IBAction)setPlaybackRate:(id)sender
601 {
602     [[VLCCoreInteraction sharedInstance] setPlaybackRate: [o_mi_rate_sld intValue]];
603     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
604     double speed =  pow( 2, (double)i / 17 );
605     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
606 }
607
608 - (void)updatePlaybackRate
609 {
610     int i = [[VLCCoreInteraction sharedInstance] playbackRate];
611     double speed =  pow( 2, (double)i / 17 );
612     [o_mi_rate_fld setStringValue: [NSString stringWithFormat:@"%.2fx", speed]];
613     [o_mi_rate_sld setIntValue: i];
614 }
615
616 - (IBAction)toggleJumpButtons:(id)sender
617 {
618     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playback-buttons" );
619     config_PutInt( VLCIntf, "macosx-show-playback-buttons", b_value );
620     [[[VLCMain sharedInstance] mainWindow] toggleJumpButtons];
621     [o_mi_toggleJumpButtons setState: b_value];
622 }
623
624 - (IBAction)togglePlaymodeButtons:(id)sender
625 {
626     BOOL b_value = !config_GetInt( VLCIntf, "macosx-show-playmode-buttons" );
627     config_PutInt( VLCIntf, "macosx-show-playmode-buttons", b_value );
628     [[[VLCMain sharedInstance] mainWindow] togglePlaymodeButtons];
629     [o_mi_togglePlaymodeButtons setState: b_value];
630 }
631
632 #pragma mark -
633 #pragma mark video menu
634 - (IBAction)toggleFullscreen:(id)sender
635 {
636     [[VLCCoreInteraction sharedInstance] toggleFullscreen];
637 }
638
639 - (IBAction)resizeVideoWindow:(id)sender
640 {
641     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
642     if (p_input)
643     {
644         vout_thread_t *p_vout = getVout();
645         if (p_vout)
646         {
647             if (sender == o_mi_half_window)
648                 var_SetFloat( p_vout, "zoom", 0.5 );
649             else if (sender == o_mi_normal_window)
650                 var_SetFloat( p_vout, "zoom", 1.0 );
651             else if (sender == o_mi_double_window)
652                 var_SetFloat( p_vout, "zoom", 2.0 );
653             else
654             {
655                 [[[[[VLCMain sharedInstance] mainWindow] videoView] window] performZoom:sender];
656             }
657             vlc_object_release( p_vout );
658         }
659         vlc_object_release( p_input );
660     }
661 }
662
663 - (IBAction)floatOnTop:(id)sender
664 {
665     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
666     if (p_input)
667     {
668         vout_thread_t *p_vout = getVout();
669         if (p_vout)
670         {
671             var_ToggleBool( p_vout, "video-on-top" );
672             vlc_object_release( p_vout );
673         }
674         vlc_object_release( p_input );
675     }
676 }
677
678 - (IBAction)createVideoSnapshot:(id)sender
679 {
680     input_thread_t *p_input = pl_CurrentInput( VLCIntf );
681     if (p_input)
682     {
683         vout_thread_t *p_vout = getVout();
684         if (p_vout)
685         {
686             var_TriggerCallback( p_vout, "video-snapshot" );
687             vlc_object_release( p_vout );
688         }
689         vlc_object_release( p_input );
690     }
691 }
692
693 - (IBAction)toggleFullscreenDevice:(id)sender
694 {
695     config_PutInt( VLCIntf, "macosx-vdev", [sender tag] );
696     [self refreshVoutDeviceMenu: nil];
697 }
698
699 - (id)voutMenu
700 {
701     return o_vout_menu;
702 }
703
704 #pragma mark -
705 #pragma mark Panels
706
707 - (IBAction)intfOpenFile:(id)sender
708 {
709     [[[VLCMain sharedInstance] open] openFile];
710 }
711
712 - (IBAction)intfOpenFileGeneric:(id)sender
713 {
714     [[[VLCMain sharedInstance] open] openFileGeneric];
715 }
716
717 - (IBAction)intfOpenDisc:(id)sender
718 {
719     [[[VLCMain sharedInstance] open] openDisc];
720 }
721
722 - (IBAction)intfOpenNet:(id)sender
723 {
724     [[[VLCMain sharedInstance] open] openNet];
725 }
726
727 - (IBAction)intfOpenCapture:(id)sender
728 {
729     [[[VLCMain sharedInstance] open] openCapture];
730 }
731
732 - (IBAction)showWizard:(id)sender
733 {
734     [[[VLCMain sharedInstance] wizard] resetWizard];
735     [[[VLCMain sharedInstance] wizard] showWizard];
736 }
737
738 - (IBAction)showVideoEffects:(id)sender
739 {
740     if( o_videoeffects == nil )
741         o_videoeffects = [[VLCVideoEffects alloc] init];
742
743     if( !b_nib_videoeffects_loaded )
744         b_nib_videoeffects_loaded = [NSBundle loadNibNamed:@"VideoEffects" owner: NSApp];
745
746     [o_videoeffects toggleWindow:sender];
747 }
748
749 - (IBAction)showTrackSynchronization:(id)sender
750 {
751     if (!o_trackSynchronization)
752         o_trackSynchronization = [[VLCTrackSynchronization alloc] init];
753
754     if (!b_nib_tracksynchro_loaded)
755         b_nib_tracksynchro_loaded = [NSBundle loadNibNamed:@"SyncTracks" owner:NSApp];
756
757     [o_trackSynchronization toggleWindow:sender];
758 }
759
760 - (IBAction)showAudioEffects:(id)sender
761 {
762     if (!o_audioeffects)
763         o_audioeffects = [[VLCAudioEffects alloc] init];
764
765     if (!b_nib_audioeffects_loaded)
766         b_nib_audioeffects_loaded = [NSBundle loadNibNamed:@"AudioEffects" owner:NSApp];
767
768     [o_audioeffects toggleWindow:sender];
769 }
770
771 - (IBAction)showBookmarks:(id)sender
772 {
773     [[[VLCMain sharedInstance] bookmarks] showBookmarks];
774 }
775
776 - (IBAction)viewPreferences:(id)sender
777 {
778     [[[VLCMain sharedInstance] simplePreferences] showSimplePrefs];
779 }
780
781 #pragma mark -
782 #pragma mark Help and Docs
783
784 - (void)initAbout
785 {
786     if(! o_about )
787         o_about = [[VLAboutBox alloc] init];
788
789     if( !b_nib_about_loaded )
790         b_nib_about_loaded = [NSBundle loadNibNamed:@"About" owner: NSApp];
791 }
792
793 - (IBAction)viewAbout:(id)sender
794 {
795     [self initAbout];
796     [o_about showAbout];
797 }
798
799 - (IBAction)showLicense:(id)sender
800 {
801     [self initAbout];
802     [o_about showGPL: sender];
803 }
804
805 - (IBAction)viewHelp:(id)sender
806 {
807     [self initAbout];
808     [o_about showHelp];
809 }
810
811 - (IBAction)openReadMe:(id)sender
812 {
813     NSString * o_path = [[NSBundle mainBundle] pathForResource: @"README.MacOSX" ofType: @"rtf"];
814
815     [[NSWorkspace sharedWorkspace] openFile: o_path withApplication: @"TextEdit"];
816 }
817
818 - (IBAction)openDocumentation:(id)sender
819 {
820     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/doc/"];
821
822     [[NSWorkspace sharedWorkspace] openURL: o_url];
823 }
824
825 - (IBAction)openWebsite:(id)sender
826 {
827     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/"];
828
829     [[NSWorkspace sharedWorkspace] openURL: o_url];
830 }
831
832 - (IBAction)openForum:(id)sender
833 {
834     NSURL * o_url = [NSURL URLWithString: @"http://forum.videolan.org/"];
835
836     [[NSWorkspace sharedWorkspace] openURL: o_url];
837 }
838
839 - (IBAction)openDonate:(id)sender
840 {
841     NSURL * o_url = [NSURL URLWithString: @"http://www.videolan.org/contribute.html#paypal"];
842
843     [[NSWorkspace sharedWorkspace] openURL: o_url];
844 }
845
846 #pragma mark -
847 #pragma mark Errors, warnings and messages
848
849 - (IBAction)viewErrorsAndWarnings:(id)sender
850 {
851     [[[[VLCMain sharedInstance] coreDialogProvider] errorPanel] showPanel];
852 }
853
854 - (IBAction)showInformationPanel:(id)sender
855 {
856     [[[VLCMain sharedInstance] info] initPanel];
857 }
858
859 #pragma mark -
860 #pragma mark convinience stuff for other objects
861 - (void)setPlay
862 {
863     [o_mi_play setTitle: _NS("Play")];
864     [o_dmi_play setTitle: _NS("Play")];
865     [o_vmi_play setTitle: _NS("Play")];
866 }
867
868 - (void)setPause
869 {
870     [o_mi_play setTitle: _NS("Pause")];
871     [o_dmi_play setTitle: _NS("Pause")];
872     [o_vmi_play setTitle: _NS("Pause")];
873 }
874
875 - (void)setRepeatOne
876 {
877     [o_mi_repeat setState: NSOnState];
878     [o_mi_loop setState: NSOffState];
879 }
880
881 - (void)setRepeatAll
882 {
883     [o_mi_repeat setState: NSOffState];
884     [o_mi_loop setState: NSOnState];
885 }
886
887 - (void)setRepeatOff
888 {
889     [o_mi_repeat setState: NSOffState];
890     [o_mi_loop setState: NSOffState];
891 }
892
893 - (void)setShuffle
894 {
895     bool b_value;
896     playlist_t *p_playlist = pl_Get( VLCIntf );
897     b_value = var_GetBool( p_playlist, "random" );
898
899     [o_mi_random setState: b_value];
900 }
901
902 #pragma mark -
903 #pragma mark Dynamic menu creation and validation
904
905 - (void)setupVarMenuItem:(NSMenuItem *)o_mi
906                   target:(vlc_object_t *)p_object
907                      var:(const char *)psz_variable
908                 selector:(SEL)pf_callback
909 {
910     vlc_value_t val, text;
911     int i_type = var_Type( p_object, psz_variable );
912
913     switch( i_type & VLC_VAR_TYPE )
914     {
915         case VLC_VAR_VOID:
916         case VLC_VAR_BOOL:
917         case VLC_VAR_VARIABLE:
918         case VLC_VAR_STRING:
919         case VLC_VAR_INTEGER:
920             break;
921         default:
922             /* Variable doesn't exist or isn't handled */
923             return;
924     }
925
926     /* Make sure we want to display the variable
927      * special case for spu-es, which we want to display in any case */
928     if( i_type & VLC_VAR_HASCHOICE && strcmp( psz_variable, "spu-es" ) )
929     {
930         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
931         if( val.i_int == 0 )
932             return;
933         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
934             return;
935     }
936
937     /* Get the descriptive name of the variable */
938     var_Change( p_object, psz_variable, VLC_VAR_GETTEXT, &text, NULL );
939     [o_mi setTitle: _NS( text.psz_string ? text.psz_string : psz_variable )];
940
941     if( i_type & VLC_VAR_HASCHOICE )
942     {
943         NSMenu *o_menu = [o_mi submenu];
944
945         [self setupVarMenu: o_menu forMenuItem: o_mi target:p_object
946                        var:psz_variable selector:pf_callback];
947
948         free( text.psz_string );
949         return;
950     }
951
952     if( var_Get( p_object, psz_variable, &val ) < 0 )
953     {
954         return;
955     }
956
957     VLCAutoGeneratedMenuContent *o_data;
958     switch( i_type & VLC_VAR_TYPE )
959     {
960         case VLC_VAR_VOID:
961             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
962                                                                       andValue: val ofType: i_type];
963             [o_mi setRepresentedObject: [o_data autorelease]];
964             break;
965
966         case VLC_VAR_BOOL:
967             o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
968                                                                       andValue: val ofType: i_type];
969             [o_mi setRepresentedObject: [o_data autorelease]];
970             if( !( i_type & VLC_VAR_ISCOMMAND ) )
971                 [o_mi setState: val.b_bool ? TRUE : FALSE ];
972             break;
973
974         default:
975             break;
976     }
977
978     if( ( i_type & VLC_VAR_TYPE ) == VLC_VAR_STRING ) free( val.psz_string );
979     free( text.psz_string );
980 }
981
982
983 - (void)setupVarMenu:(NSMenu *)o_menu
984          forMenuItem: (NSMenuItem *)o_parent
985               target:(vlc_object_t *)p_object
986                  var:(const char *)psz_variable
987             selector:(SEL)pf_callback
988 {
989     vlc_value_t val, val_list, text_list;
990     int i_type, i;
991
992     /* remove previous items */
993     if (OSX_LEOPARD)
994     {
995         int i_nb_items;
996         i_nb_items = [o_menu numberOfItems];
997         for( i = 0; i < i_nb_items; i++ )
998             [o_menu removeItemAtIndex: 0];
999     }
1000     else
1001     {
1002         /* this is more efficient then the legacy code, but 10.6+ only */
1003         [o_menu removeAllItems];
1004     }
1005
1006     /* Aspect Ratio */
1007     if( [[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES )
1008     {
1009         NSMenuItem *o_lmi_tmp2;
1010         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
1011         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
1012         [o_lmi_tmp2 setEnabled: YES];
1013         [o_lmi_tmp2 setState: [[VLCCoreInteraction sharedInstance] aspectRatioIsLocked]];
1014         [o_parent setEnabled: YES];
1015         [o_menu addItem: [NSMenuItem separatorItem]];
1016     }
1017
1018     /* special case for the subtitles item */
1019     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1020     {
1021         NSMenuItem * o_lmi_tmp;
1022         o_lmi_tmp = [o_menu addItemWithTitle: _NS("Open File...") action: @selector(addSubtitleFile:) keyEquivalent: @""];
1023         [o_lmi_tmp setTarget: [[VLCMain sharedInstance] controls]];
1024         [o_lmi_tmp setEnabled: YES];
1025         [o_parent setEnabled: YES];
1026     }
1027
1028     /* Check the type of the object variable */
1029     i_type = var_Type( p_object, psz_variable );
1030
1031     /* Make sure we want to display the variable */
1032     if( i_type & VLC_VAR_HASCHOICE )
1033     {
1034         var_Change( p_object, psz_variable, VLC_VAR_CHOICESCOUNT, &val, NULL );
1035         if( val.i_int == 0 ) return;
1036         if( (i_type & VLC_VAR_TYPE) != VLC_VAR_VARIABLE && val.i_int == 1 )
1037             return;
1038     }
1039     else
1040         return;
1041
1042     switch( i_type & VLC_VAR_TYPE )
1043     {
1044         case VLC_VAR_VOID:
1045         case VLC_VAR_BOOL:
1046         case VLC_VAR_VARIABLE:
1047         case VLC_VAR_STRING:
1048         case VLC_VAR_INTEGER:
1049             break;
1050         default:
1051             /* Variable doesn't exist or isn't handled */
1052             return;
1053     }
1054
1055     if( var_Get( p_object, psz_variable, &val ) < 0 )
1056     {
1057         return;
1058     }
1059
1060     if( var_Change( p_object, psz_variable, VLC_VAR_GETLIST,
1061                    &val_list, &text_list ) < 0 )
1062     {
1063         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1064         return;
1065     }
1066
1067     /* make (un)sensitive */
1068     [o_parent setEnabled: ( val_list.p_list->i_count > 1 )];
1069
1070     /* another special case for the subtitles item */
1071     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1072         [o_menu addItem: [NSMenuItem separatorItem]];
1073
1074     for( i = 0; i < val_list.p_list->i_count; i++ )
1075     {
1076         NSMenuItem * o_lmi;
1077         NSString *o_title = @"";
1078         VLCAutoGeneratedMenuContent *o_data;
1079
1080         switch( i_type & VLC_VAR_TYPE )
1081         {
1082             case VLC_VAR_STRING:
1083
1084                 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 );
1085
1086                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1087                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1088                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1089                 [o_lmi setRepresentedObject: [o_data autorelease]];
1090                 [o_lmi setTarget: self];
1091
1092                 if( !strcmp( val.psz_string, val_list.p_list->p_values[i].psz_string ) && !( i_type & VLC_VAR_ISCOMMAND ) )
1093                     [o_lmi setState: TRUE ];
1094
1095                 break;
1096
1097             case VLC_VAR_INTEGER:
1098
1099                 o_title = text_list.p_list->p_values[i].psz_string ?
1100                 _NS( text_list.p_list->p_values[i].psz_string ) : [NSString stringWithFormat: @"%"PRId64, val_list.p_list->p_values[i].i_int];
1101
1102                 o_lmi = [o_menu addItemWithTitle: o_title action: pf_callback keyEquivalent: @""];
1103                 o_data = [[VLCAutoGeneratedMenuContent alloc] initWithVariableName: psz_variable ofObject: p_object
1104                                                                           andValue: val_list.p_list->p_values[i] ofType: i_type];
1105                 [o_lmi setRepresentedObject: [o_data autorelease]];
1106                 [o_lmi setTarget: self];
1107
1108                 if( val_list.p_list->p_values[i].i_int == val.i_int && !( i_type & VLC_VAR_ISCOMMAND ) )
1109                     [o_lmi setState: TRUE ];
1110                 break;
1111
1112             default:
1113                 break;
1114         }
1115     }
1116
1117     /* special case for the subtitles sub-menu
1118      * In case that we don't have any subs, we don't want a separator item at the end */
1119     if( [[o_parent title] isEqualToString: _NS("Subtitles Track")] == YES )
1120     {
1121         if( [o_menu numberOfItems] == 2 )
1122             [o_menu removeItemAtIndex: 1];
1123     }
1124
1125     /* clean up everything */
1126     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
1127     var_FreeList( &val_list, &text_list );
1128 }
1129
1130 - (IBAction)toggleVar:(id)sender
1131 {
1132     NSMenuItem *o_mi = (NSMenuItem *)sender;
1133     VLCAutoGeneratedMenuContent *o_data = [o_mi representedObject];
1134     [NSThread detachNewThreadSelector: @selector(toggleVarThread:)
1135                              toTarget: self withObject: o_data];
1136
1137     return;
1138 }
1139
1140 - (int)toggleVarThread: (id)data
1141 {
1142     vlc_object_t *p_object;
1143     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
1144
1145     assert([data isKindOfClass:[VLCAutoGeneratedMenuContent class]]);
1146     VLCAutoGeneratedMenuContent *menuContent = (VLCAutoGeneratedMenuContent *)data;
1147
1148     /* Preserve settings across vouts via the playlist object: */
1149     if( !strcmp( [menuContent name], "fullscreen" ) || !strcmp( [menuContent name], "video-on-top" ) )
1150         var_Set( pl_Get( VLCIntf ), [menuContent name] , [menuContent value] );
1151
1152     /* save our audio device across multiple sessions */
1153     if( !strcmp( [menuContent name], "audio-device" ) )
1154         config_PutInt( VLCIntf, "macosx-audio-device", [menuContent value].i_int );
1155
1156     p_object = [menuContent vlcObject];
1157
1158     if( p_object != NULL )
1159     {
1160         var_Set( p_object, [menuContent name], [menuContent value] );
1161         vlc_object_release( p_object );
1162         [o_pool release];
1163         return true;
1164     }
1165     [o_pool release];
1166     return VLC_EGENERIC;
1167 }
1168
1169 @end
1170
1171 @implementation VLCMainMenu (NSMenuValidation)
1172
1173 - (BOOL)validateMenuItem:(NSMenuItem *)o_mi
1174 {
1175     NSString *o_title = [o_mi title];
1176     BOOL bEnabled = TRUE;
1177     vlc_value_t val;
1178     playlist_t * p_playlist = pl_Get( p_intf );
1179     input_thread_t * p_input = playlist_CurrentInput( p_playlist );
1180
1181     if( [o_title isEqualToString: _NS("Stop")] )
1182     {
1183         if( p_input == NULL )
1184         {
1185             bEnabled = FALSE;
1186         }
1187         [self setupMenus]; /* Make sure input menu is up to date */
1188     }
1189     else if( [o_title isEqualToString: _NS("Previous")] ||
1190             [o_title isEqualToString: _NS("Next")] )
1191     {
1192         PL_LOCK;
1193         bEnabled = playlist_CurrentSize( p_playlist ) > 1;
1194         PL_UNLOCK;
1195     }
1196     else if( [o_title isEqualToString: _NS("Random")] )
1197     {
1198         int i_state;
1199         var_Get( p_playlist, "random", &val );
1200         i_state = val.b_bool ? NSOnState : NSOffState;
1201         [o_mi setState: i_state];
1202     }
1203     else if( [o_title isEqualToString: _NS("Repeat One")] )
1204     {
1205         int i_state;
1206         var_Get( p_playlist, "repeat", &val );
1207         i_state = val.b_bool ? NSOnState : NSOffState;
1208         [o_mi setState: i_state];
1209     }
1210     else if( [o_title isEqualToString: _NS("Repeat All")] )
1211     {
1212         int i_state;
1213         var_Get( p_playlist, "loop", &val );
1214         i_state = val.b_bool ? NSOnState : NSOffState;
1215         [o_mi setState: i_state];
1216     }
1217     else if( [o_title isEqualToString: _NS("Quit after Playback")] )
1218     {
1219         int i_state;
1220         var_Get( p_playlist, "play-and-exit", &val );
1221         i_state = val.b_bool ? NSOnState : NSOffState;
1222         [o_mi setState: i_state];
1223     }
1224     else if( [o_title isEqualToString: _NS("Step Forward")] ||
1225             [o_title isEqualToString: _NS("Step Backward")] ||
1226             [o_title isEqualToString: _NS("Jump To Time")])
1227     {
1228         if( p_input != NULL )
1229         {
1230             var_Get( p_input, "can-seek", &val);
1231             bEnabled = val.b_bool;
1232         }
1233         else bEnabled = FALSE;
1234     }
1235     else if( [o_title isEqualToString: _NS("Mute")] )
1236     {
1237         [o_mi setState: [[VLCCoreInteraction sharedInstance] isMuted] ? NSOnState : NSOffState];
1238         [self setupMenus]; /* Make sure audio menu is up to date */
1239     }
1240     else if( [o_title isEqualToString: _NS("Half Size")] ||
1241             [o_title isEqualToString: _NS("Normal Size")] ||
1242             [o_title isEqualToString: _NS("Double Size")] ||
1243             [o_title isEqualToString: _NS("Fit to Screen")] ||
1244             [o_title isEqualToString: _NS("Snapshot")] ||
1245             [o_title isEqualToString: _NS("Fullscreen")] ||
1246             [o_title isEqualToString: _NS("Float on Top")] )
1247     {
1248         bEnabled = FALSE;
1249
1250         if( p_input != NULL )
1251         {
1252             vout_thread_t *p_vout = input_GetVout( p_input );
1253             if( p_vout != NULL )
1254             {
1255                 if( [o_title isEqualToString: _NS("Float on Top")] )
1256                 {
1257                     [o_mi setState: var_GetBool( p_vout, "video-on-top" )];
1258                 }
1259
1260                 bEnabled = TRUE;
1261
1262                 vlc_object_release( (vlc_object_t *)p_vout );
1263             }
1264         }
1265         if( [o_title isEqualToString: _NS("Fullscreen")] )
1266         {
1267         [o_mi setState: var_GetBool( p_playlist, "fullscreen" )];
1268             bEnabled = TRUE;
1269         }
1270         [self setupMenus]; /* Make sure video menu is up to date */
1271     }
1272
1273     /* Special case for telx menu */
1274     if( [o_title isEqualToString: _NS("Normal Size")] )
1275     {
1276         NSMenuItem *item = [[o_mi menu] itemWithTitle:_NS("Teletext")];
1277
1278
1279 bool b_telx = p_input && var_GetInteger( p_input, "teletext-es" ) >= 0;
1280
1281         [[item submenu] setAutoenablesItems:NO];
1282         for( int k=0; k < [[item submenu] numberOfItems]; k++ )
1283         {
1284             [[[item submenu] itemAtIndex:k] setEnabled: b_telx];
1285         }
1286     }
1287
1288     if( p_input ) vlc_object_release( p_input );
1289
1290     return( bEnabled );
1291 }
1292
1293 @end
1294
1295
1296 /*****************************************************************************
1297  * VLCAutoGeneratedMenuContent implementation
1298  *****************************************************************************
1299  * Object connected to a playlistitem which remembers the data belonging to
1300  * the variable of the autogenerated menu
1301  *****************************************************************************/
1302 @implementation VLCAutoGeneratedMenuContent
1303
1304 -(id) initWithVariableName:(const char *)name ofObject:(vlc_object_t *)object
1305                   andValue:(vlc_value_t)val ofType:(int)type
1306 {
1307     self = [super init];
1308
1309     if( self != nil )
1310     {
1311         _vlc_object = vlc_object_hold( object );
1312         psz_name = strdup( name );
1313         i_type = type;
1314         value = val;
1315         if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1316             value.psz_string = strdup( val.psz_string );
1317     }
1318
1319     return( self );
1320 }
1321
1322 - (void)dealloc
1323 {
1324     vlc_object_release( _vlc_object );
1325     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING )
1326         free( value.psz_string );
1327     free( psz_name );
1328     [super dealloc];
1329 }
1330
1331 - (const char *)name
1332 {
1333     return psz_name;
1334 }
1335
1336 - (vlc_value_t)value
1337 {
1338     return value;
1339 }
1340
1341 - (vlc_object_t *)vlcObject
1342 {
1343     return vlc_object_hold( _vlc_object );
1344 }
1345
1346
1347 - (int)type
1348 {
1349     return i_type;
1350 }
1351
1352 @end