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