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