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